feat: test for youtube recommendation change after click on video

This commit is contained in:
Alex 2022-03-29 20:02:52 +13:00
parent c540930135
commit fba7caef4c
5 changed files with 28 additions and 11 deletions

View File

@ -160,6 +160,7 @@ export default {
},
},
mounted() {
this.$youtube.saveApiStats("detailpage", this.$route.query.v, "streamingstats")
this.getVideo();
},
methods: {

View File

@ -6,6 +6,7 @@ const url = {
YT_MUSIC_URL: "https://music.youtube.com",
YT_BASE_API: "https://www.youtube.com/youtubei/v1",
YT_SUGGESTIONS: "https://suggestqueries.google.com/complete",
YT_API_STATS: "https://www.youtube.com/api/stats/atr",
VT_GITHUB: "https://api.github.com/repos/Frontesque/VueTube",
};

View File

@ -152,6 +152,23 @@ class Innertube {
};
}
// WARNING: This is tracking the user's activity, but is required for recommendations to properly work
async apiStats(currentPageType, id, event) {
const params = {
key: this.key,
el: currentPageType,
ns: "yt",
docid: id,
event: event,
feature: "g-high-rec",
c: this.context.client.clientName,
volume: 100,
cver: this.context.client.clientVersion,
hl: this.context.client.hl,
};
await Http.post({ url: constants.URLS.YT_API_STATS, params: params });
}
// Static methods
static getThumbnail(id, resolution) {

View File

@ -4,6 +4,7 @@ import Innertube from "./innertube";
import constants from "./constants";
import rendererUtils from "./renderers";
import { Buffer } from "buffer";
import iconv from "iconv-lite";
//--- Logger Function ---//
function logger(func, data, isError = false) {
@ -19,15 +20,7 @@ function getEncoding(contentType) {
const re = /charset=([^()<>@,;:\"/[\]?.=\s]*)/i;
const content = re.exec(contentType);
console.log(content);
if (!content || content[1].toLowerCase() == "utf-8") {
return "utf8";
}
if (content[1].toLowerCase() == "iso-8859-1") {
return "latin1";
}
if (content[1].toLowerCase() == "utf16le") {
return "utf16le";
}
return content[1].toLowerCase();
}
const searchModule = {
@ -45,7 +38,7 @@ const searchModule = {
// make a new buffer object from res.data
const buffer = Buffer.from(res.data, "base64");
// convert res.data from iso-8859-1 to utf-8
const data = buffer.toString(getEncoding(contentType));
const data = iconv.decode(buffer, getEncoding(contentType));
logger(constants.LOGGER_NAMES.autoComplete, data);
callback(data);
})
@ -137,6 +130,10 @@ const innertubeModule = {
logger(constants.LOGGER_NAMES.search, err, true);
}
},
async saveApiStats(currentPageType, id, event) {
await InnertubeAPI.apiStats(currentPageType, id, event);
},
};
//--- Start ---//

View File

@ -10,6 +10,7 @@
"@capacitor/share": "^1.1.2",
"@capacitor/splash-screen": "^1.2.2",
"@capacitor/status-bar": "^1.0.8",
"@hugotomazi/capacitor-navigation-bar": "^1.1.1"
"@hugotomazi/capacitor-navigation-bar": "^1.1.1",
"iconv-lite": "^0.6.3"
}
}