mirror of
https://github.com/VueTubeApp/VueTube
synced 2024-11-22 19:25:16 +00:00
add this.$youtube.search()
THIS FEATURE IS INCOMPLETE!
This commit is contained in:
parent
63df4fb355
commit
8bcad94184
2 changed files with 30 additions and 2 deletions
|
@ -41,7 +41,7 @@ export default {
|
|||
methods: {
|
||||
textChanged() {
|
||||
this.$youtube.autoComplete(this.text, (res) => {
|
||||
const data = res.data.replace(/^.*?\(/,'').replace(/\)$/,''); //Format Response
|
||||
const data = res.replace(/^.*?\(/,'').replace(/\)$/,''); //Format Response
|
||||
this.response = JSON.parse(data)[1]
|
||||
});
|
||||
},
|
||||
|
|
|
@ -25,8 +25,36 @@ const module = {
|
|||
callback(err);
|
||||
});
|
||||
logger("autoComplete", res);
|
||||
callback(res);
|
||||
callback(res.data);
|
||||
},
|
||||
|
||||
search(text, callback) {
|
||||
Http.request({
|
||||
method: 'GET',
|
||||
url: 'https://youtube.com/results',
|
||||
params: { q: text, hl: "en" }
|
||||
})
|
||||
.then((res) => {
|
||||
//--- Get HTML Only ---//
|
||||
let html = res.data;
|
||||
//--- Isolate The Script Containing Video Information ---//
|
||||
html = html.split("var ytInitialData =")[1].split("</script>")[0].slice(0, -1);
|
||||
//--- Replace Encoded Characters ---///
|
||||
html = html.replace(/\\x([0-9A-F]{2})/ig, (...items) => { return String.fromCharCode(parseInt(items[1], 16)); });
|
||||
//--- Properly Format JSON ---//
|
||||
html = html.replaceAll("\\\\\"", "");
|
||||
//--- Parse JSON & Get Results ---//
|
||||
let results = JSON.parse(html);
|
||||
results = results.contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents[0].itemSectionRenderer.contents;
|
||||
//--- Output ---//
|
||||
callback(results);
|
||||
})
|
||||
.catch((err) => {
|
||||
logger("autoComplete", err);
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--- Start ---//
|
||||
|
|
Loading…
Reference in a new issue