refactor: centralized logger names

This commit is contained in:
Alex 2022-03-19 18:35:28 +13:00
parent 1b6a9f4a48
commit eb1aca2627
4 changed files with 42 additions and 32 deletions

View File

@ -31,32 +31,30 @@
export default {
data() {
return {
recommends: null
recommends: []
}
},
// The following code is only a demo for debugging purposes, note that each "shelfRenderer" has a "title" value that seems to align to the categories at the top of the vanilla yt app
mounted() {
const vm = this;
this.$youtube.recommend().then(
result => {
const videoList = []
console.log(result)
const recommendContent = result.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents // I feel like I've committed programming sin
recommendContent.forEach(function (contents, index) {
contents.shelfRenderer.content.horizontalListRenderer.items.forEach(function (item, index) {
const video = item.gridVideoRenderer
console.log(video)
console.log(video.onTap)
videoList.push(video)
})
})
vm.recommends = videoList;
}
).catch ((error) => {
try {
this.$youtube.recommend().then(
result => {
console.log(result)
const recommendContent = result.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents // I feel like I've committed programming sin
recommendContent.forEach(function (contents, index) {
contents.shelfRenderer.content.horizontalListRenderer.items.forEach(function (item, index) {
const video = item.gridVideoRenderer
console.log(video)
console.log(video.onTap)
this.recommends.push(video)
})
})}
)
} catch (error) {
this.$logger("Home Page", error, true)
})
}
},
methods: {

View File

@ -111,7 +111,7 @@ class Innertube {
async getRecommendationsAsync() {
const rec = await this.browseAsync("recommendations");
console.log(rec.data)
return rec.data;
return rec;
}

View File

@ -29,17 +29,17 @@ function youtubeParse(html, callback) {
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);
logger(constants.LOGGER_NAMES.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);
logger(constants.LOGGER_NAMES.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);
logger(constants.LOGGER_NAMES.search, results);
callback(results);
} catch (e) {}
}
@ -66,7 +66,7 @@ function youtubeSearch(text, callback) {
})
.catch((err) => {
logger("search", err, true);
logger(constants.LOGGER_NAMES.search, err, true);
callback(err);
});
}
@ -82,11 +82,11 @@ const searchModule = {
params: { client: 'youtube', q: text }
})
.then((res) => {
logger("autoComplete", res);
logger(constants.LOGGER_NAMES.autoComplete, res);
callback(res.data);
})
.catch((err) => {
logger("autoComplete", err, true);
logger(constants.LOGGER_NAMES.autoComplete, err, true);
callback(err);
});
},
@ -110,7 +110,7 @@ const searchModule = {
})
} else {
//--- If Entry Is Not A Video ---//
//logger("search", { type: "Error Caught Successfully", error: video }, true);
//logger(constants.LOGGER_NAMES.search, { type: "Error Caught Successfully", error: video }, true);
}
@ -130,13 +130,13 @@ const searchModule = {
let InnertubeAPI;
// Lazy loads Innertube object. This will be the object used in all future Innertube API calls. Code provided by Lightfire228 (https://github.com/Lightfire228)
// Loads Innertube object. This will be the object used in all future Innertube API calls. Code provided by Lightfire228 (https://github.com/Lightfire228)
// These are just a way for the backend Javascript to communicate with the front end Vue scripts. Essentially a wrapper inside a wrapper
const recommendationModule = {
async getAPI() {
if (!InnertubeAPI) {
InnertubeAPI = await Innertube.createAsync((message, isError) => { logger("Innertube", message, isError); })
InnertubeAPI = await Innertube.createAsync((message, isError) => { logger(constants.LOGGER_NAMES.innertube, message, isError); })
}
return InnertubeAPI;
},
@ -146,7 +146,12 @@ const recommendationModule = {
},
async recommend() {
return InnertubeAPI.getRecommendationsAsync();
const response = InnertubeAPI.getRecommendationsAsync();
if (!response.success) {
logger(constants.LOGGER_NAMES.recommendations, "An error occurred and innertube failed to respond", true)
return
}
return
},
getThumbnail: (id, resolution) => Innertube.getThumbnail(id, resolution)
@ -157,4 +162,4 @@ export default ({ app }, inject) => {
inject('youtube', {...searchModule, ...recommendationModule, })
inject("logger", logger)
}
logger("Initialize", "Program Started");
logger(constants.LOGGER_NAMES.init, "Program Started");

View File

@ -17,6 +17,14 @@ module.exports = {
URLS: url,
YT_API_VALUES: ytApiVal,
LOGGER_NAMES: {
search: "Search",
autoComplete: "AutoComplete",
recommendations: "Recommendations",
init: "Initialize",
innertube: "Innertube"
},
INNERTUBE_HEADER: (info) => {
let headers = {
'accept': '*/*',
@ -46,7 +54,6 @@ module.exports = {
"configInfo": info.configInfo,
"remoteHost": info.remoteHost,
"visitorData": info.visitorData,
// This is, by all accounts, a horrible implementation, but this is currently the only solution besides
};
return client
}