yt error handling
This commit is contained in:
parent
13b3430f51
commit
51fcac95cd
3 changed files with 26 additions and 18 deletions
20
app/cyp.js
20
app/cyp.js
|
@ -1455,15 +1455,19 @@ class YT extends Component {
|
||||||
|
|
||||||
let url = `/youtube?q=${encodeURIComponent(query)}&limit=${encodeURIComponent(ytLimit)}`;
|
let url = `/youtube?q=${encodeURIComponent(query)}&limit=${encodeURIComponent(ytLimit)}`;
|
||||||
let response = await fetch(url);
|
let response = await fetch(url);
|
||||||
let results = await response.json();
|
if (response.status == 200) {
|
||||||
|
let results = await response.json();
|
||||||
|
results.forEach(result => {
|
||||||
|
let node = new YtResult(result.title);
|
||||||
|
this.appendChild(node);
|
||||||
|
node.addButton("download", () => this._download(result.id));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let text = await response.text();
|
||||||
|
alert(text);
|
||||||
|
}
|
||||||
|
|
||||||
this._search.pending(false);
|
this._search.pending(false);
|
||||||
|
|
||||||
results.forEach(result => {
|
|
||||||
let node = new YtResult(result.title);
|
|
||||||
this.appendChild(node);
|
|
||||||
node.addButton("download", () => this._download(result.id));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1497,7 +1501,7 @@ class YT extends Component {
|
||||||
const wasHidden = this.hidden;
|
const wasHidden = this.hidden;
|
||||||
this.hidden = !isThis;
|
this.hidden = !isThis;
|
||||||
|
|
||||||
if (!wasHidden && isThis) { this._showRoot(); }
|
if (!wasHidden && isThis) { this._clear(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,15 +41,19 @@ class YT extends Component {
|
||||||
|
|
||||||
let url = `/youtube?q=${encodeURIComponent(query)}&limit=${encodeURIComponent(conf.ytLimit)}`;
|
let url = `/youtube?q=${encodeURIComponent(query)}&limit=${encodeURIComponent(conf.ytLimit)}`;
|
||||||
let response = await fetch(url);
|
let response = await fetch(url);
|
||||||
let results = await response.json();
|
if (response.status == 200) {
|
||||||
|
let results = await response.json();
|
||||||
|
results.forEach(result => {
|
||||||
|
let node = new Result(result.title);
|
||||||
|
this.appendChild(node);
|
||||||
|
node.addButton("download", () => this._download(result.id));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let text = await response.text();
|
||||||
|
alert(text);
|
||||||
|
}
|
||||||
|
|
||||||
this._search.pending(false);
|
this._search.pending(false);
|
||||||
|
|
||||||
results.forEach(result => {
|
|
||||||
let node = new Result(result.title);
|
|
||||||
this.appendChild(node);
|
|
||||||
node.addButton("download", () => this._download(result.id));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +87,7 @@ class YT extends Component {
|
||||||
const wasHidden = this.hidden;
|
const wasHidden = this.hidden;
|
||||||
this.hidden = !isThis;
|
this.hidden = !isThis;
|
||||||
|
|
||||||
if (!wasHidden && isThis) { this._showRoot(); }
|
if (!wasHidden && isThis) { this._clear(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
index.js
4
index.js
|
@ -15,9 +15,9 @@ function searchYoutube(q, limit, response) {
|
||||||
|
|
||||||
console.log("YouTube searching", q, limit);
|
console.log("YouTube searching", q, limit);
|
||||||
q = escape(`ytsearch${limit}:${q}`);
|
q = escape(`ytsearch${limit}:${q}`);
|
||||||
const command = `${cmd} -j ${q} | jq "{id,title}" | jq -s .`;
|
const command = `set -o pipefail; ${cmd} -j ${q} | jq "{id,title}" | jq -s .`;
|
||||||
|
|
||||||
require("child_process").exec(command, {}, (error, stdout, stderr) => {
|
require("child_process").exec(command, {shell:"/bin/bash"}, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("error", error);
|
console.log("error", error);
|
||||||
response.writeHead(500);
|
response.writeHead(500);
|
||||||
|
|
Loading…
Reference in a new issue