Fix search tool & Update build scripts

This commit is contained in:
Front 2022-03-03 18:07:33 -05:00
parent 4961838f50
commit 3b91ee4155
5 changed files with 33 additions and 19 deletions

View File

@ -28,8 +28,8 @@
<v-card-title>Debug</v-card-title>
<section>
<div style="color: #999;">This is just a temporary section for messing with the tool while it's still being worked on :)</div>
<v-btn to="/watch">Open Watch Page</v-btn>
<v-btn to="/search">Open Search Page</v-btn>
<v-btn to="/watch">Watch Page</v-btn>
<v-btn to="/search">Search Page</v-btn>
</section>
</v-card>

View File

@ -29,6 +29,7 @@ const module = {
},
search(text, callback) {
Http.request({
method: 'GET',
url: 'https://youtube.com/results',
@ -38,17 +39,38 @@ const module = {
//--- 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);
html = html.split("var ytInitialData = '")[1].split("';</script>")[0];
//--- 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 ---//
logger("search", results);
callback(results);
//--- Parse JSON ---//
html = JSON.parse(html);
//--- Get Results ---// ( Thanks To appit-online On Github ) -> https://github.com/appit-online/youtube-search/blob/master/src/lib/search.ts
let results;
if (html && html.contents && html.contents.sectionListRenderer && html.contents.sectionListRenderer.contents
&& html.contents.sectionListRenderer.contents.length > 0
&& html.contents.sectionListRenderer.contents[0].itemSectionRenderer
&& html.contents.sectionListRenderer.contents[0].itemSectionRenderer.contents.length > 0) {
results = html.contents.sectionListRenderer.contents[0].itemSectionRenderer.contents;
logger("search", results);
callback(results);
} else {
try {
results = JSON.parse(html.split('{"itemSectionRenderer":{"contents":')[html.split('{"itemSectionRenderer":{"contents":').length - 1].split(',"continuations":[{')[0]);
logger("search", results);
callback(results);
} catch (e) {}
try {
results = JSON.parse(html.split('{"itemSectionRenderer":')[html.split('{"itemSectionRenderer":').length - 1].split('},{"continuationItemRenderer":{')[0]).contents;
logger("search", results);
callback(results);
} catch(e) {}
}
})
.catch((err) => {
logger("search", err);

View File

@ -1,5 +0,0 @@
cd ../NUXT
npm run generate
cd ..
npx cap sync
npx cap open android

1
scripts/build.ps1 Normal file
View File

@ -0,0 +1 @@
cd .\NUXT\; npm run generate; cd ..; npx cap sync

View File

@ -1,5 +1 @@
cd ../NUXT
npm run generate
cd ..
npx cap sync
npx cap open android
cd NUXT/; npm run generate; cd ..; npx cap sync