diff --git a/lib/Actions.js b/lib/Actions.js index cd3db44f..26c80018 100644 --- a/lib/Actions.js +++ b/lib/Actions.js @@ -146,6 +146,7 @@ async function search(session, client, args = {}) { const response = await Axios.post(`${client === 'YOUTUBE' && Constants.URLS.YT_BASE_URL || Constants.URLS.YT_MUSIC_URL}/youtubei/v1/search${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.INNERTUBE_REQOPTS({ session, ytmusic: client === 'YTMUSIC' })).catch((error) => error); + if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message }; return { @@ -155,7 +156,6 @@ async function search(session, client, args = {}) { }; } - /** * Interacts with YouTube's notification system. * @@ -193,6 +193,7 @@ async function notifications(session, action_type, args = {}) { const response = await Axios.post(`${Constants.URLS.YT_BASE_URL}/youtubei/v1/notification/${action_type}${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.INNERTUBE_REQOPTS({ session })).catch((error) => error); + if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message }; if (action_type === 'modify_channel_preference') return { success: true, status_code: response.status }; @@ -203,7 +204,6 @@ async function notifications(session, action_type, args = {}) { }; } - /** * Interacts with YouTube's livechat system. * @@ -254,12 +254,12 @@ async function livechat(session, action_type, args = {}) { const response = await Axios.post(`${Constants.URLS.YT_BASE_URL}/youtubei/v1/${action_type}${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.INNERTUBE_REQOPTS({ session, params: args.params })).catch((error) => error); + if (response instanceof Error) return { success: false, message: response.message }; return { success: true, data: response.data }; } - /** * Gets detailed data for a video. * @@ -270,9 +270,11 @@ async function livechat(session, action_type, args = {}) { async function getVideoInfo(session, args = {}) { let response; - !args.is_desktop && (response = await Axios.get(`${Constants.URLS.YT_WATCH_PAGE}?v=${args.id}&t=8s&pbj=1`, Constants.INNERTUBE_REQOPTS({ session, id: args.id, desktop: false })).catch((error) => error)) || + !args.desktop && + (response = await Axios.get(`${Constants.URLS.YT_WATCH_PAGE}?v=${args.id}&t=8s&pbj=1`, Constants.INNERTUBE_REQOPTS({ session, id: args.id, desktop: false })).catch((error) => error)) || (response = await Axios.post(`${Constants.URLS.YT_BASE_URL}/youtubei/v1/player${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(Constants.VIDEO_INFO_REQBODY(args.id, session.sts, session.context)), Constants.INNERTUBE_REQOPTS({ session, id: args.id, desktop: true })).catch((error) => error)); + if (response instanceof Error) throw new Error(`Could not get video info: ${response.message}`); return response.data; @@ -316,6 +318,7 @@ async function getContinuation(session, args = {}) { const client_domain = args.ytmusic && Constants.URLS.YT_MUSIC_URL || Constants.URLS.YT_BASE_URL; const response = await Axios.post(`${client_domain}/youtubei/v1/next${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.INNERTUBE_REQOPTS({ session, ytmusic: args.ytmusic })).catch((error) => error); + if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message }; return { diff --git a/lib/Parser.js b/lib/Parser.js index 76908d83..d7efc31f 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -32,9 +32,10 @@ class Parser { .primaryContents.sectionListRenderer.contents[0].itemSectionRenderer .contents; - const continuation_token = this.data.contents.twoColumnSearchResultsRenderer - .primaryContents.sectionListRenderer.contents[1].continuationItemRenderer - .continuationEndpoint.continuationCommand.token; + // TODO: Implement search continuation + // const continuation_token = this.data.contents.twoColumnSearchResultsRenderer + // .primaryContents.sectionListRenderer.contents[1].continuationItemRenderer + // .continuationEndpoint.continuationCommand.token; response.search_metadata = {}; response.search_metadata.query = contents[0].showingResultsForRenderer && contents[0].showingResultsForRenderer.originalQuery.simpleText || this.args.query; diff --git a/lib/Utils.js b/lib/Utils.js index fa2360d1..9a3447d8 100644 --- a/lib/Utils.js +++ b/lib/Utils.js @@ -37,7 +37,6 @@ function generateSidAuth(sid) { return ['SAPISIDHASH', [timestamp, gen_hash].join('_')].join(' '); } - /** * Gets a string between two delimiters. * @@ -100,7 +99,6 @@ function encodeNotificationPref(channel_id, index) { return encodeURIComponent(Buffer.from(buf).toString('base64')); } - /** * Encodes livestream message protobuf. * @@ -124,7 +122,6 @@ function encodeMessageParams(channel_id, video_id) { return Buffer.from(encodeURIComponent(Buffer.from(buf).toString('base64'))).toString('base64'); } - /** * Encodes comment params protobuf. * @@ -144,7 +141,6 @@ function encodeCommentParams(video_id) { return encodeURIComponent(Buffer.from(buf).toString('base64')); } - /** * Encodes search filter protobuf *