mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 20:41:17 +00:00
feat: add possibility to fetch video notifications
This commit is contained in:
@@ -130,7 +130,7 @@ async function commentVideo(session, video_id, text) {
|
||||
createCommentParams: Utils.encodeId(video_id)
|
||||
};
|
||||
|
||||
const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/comment/create_comment?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, video_id, data })).catch((error) => error);
|
||||
const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/comment/create_comment?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, id: video_id, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -145,4 +145,27 @@ async function commentVideo(session, video_id, text) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { subscribe, unsubscribe, likeVideo, dislikeVideo, removeLike, commentVideo };
|
||||
async function getNotifications(session) {
|
||||
if (!session.logged_in) throw new Error('You must be logged in to fetch notifications');
|
||||
let data = {
|
||||
context: session.context,
|
||||
notificationsMenuRequestType: 'NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX'
|
||||
};
|
||||
|
||||
const response = await axios.post(Constants.urls.YT_BASE_URL + '/youtubei/v1/notification/get_notification_menu?key=' + session.key, JSON.stringify(data), Constants.innertube_request_opts({ session, data })).catch((error) => error);
|
||||
if (response instanceof Error) {
|
||||
return {
|
||||
success: false,
|
||||
status_code: response.response.status,
|
||||
message: response.message
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
status_code: response.status,
|
||||
data: response.data
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { subscribe, unsubscribe, likeVideo, dislikeVideo, removeLike, commentVideo, getNotifications };
|
||||
@@ -103,7 +103,26 @@ class Innertube {
|
||||
|
||||
return video_data;
|
||||
}
|
||||
|
||||
|
||||
async getNotifications() {
|
||||
const response = await Actions.getNotifications(this);
|
||||
const contents = response.data.actions[0].openPopupAction.popup.multiPageMenuRenderer.sections[0].multiPageMenuNotificationSectionRenderer.items;
|
||||
return contents.map((notification) => {
|
||||
if (!notification.notificationRenderer) return;
|
||||
notification = notification.notificationRenderer;
|
||||
return {
|
||||
title: notification.shortMessage.simpleText,
|
||||
sent_time: notification.sentTimeText.simpleText,
|
||||
channel_name: notification.contextualMenu.menuRenderer.items[1].menuServiceItemRenderer.text.runs[1].text,
|
||||
channel_thumbnail: notification.thumbnail.thumbnails[0],
|
||||
video_thumbnail: notification.videoThumbnail.thumbnails[0],
|
||||
video_url: 'https://youtu.be/' + notification.navigationEndpoint.watchEndpoint.videoId,
|
||||
read: notification.read,
|
||||
notification_id: notification.notificationId,
|
||||
};
|
||||
}).filter((notification_block) => notification_block);
|
||||
}
|
||||
|
||||
async requestVideoInfo(id, desktop) {
|
||||
let response;
|
||||
if (!desktop) {
|
||||
@@ -114,7 +133,7 @@ class Innertube {
|
||||
if (response instanceof Error) throw new Error('Could not retrieve watch page info: ' + response.message);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
|
||||
download(id, options = {}) {
|
||||
options.quality = options.quality || '360p';
|
||||
options.type = options.type || 'both';
|
||||
|
||||
Reference in New Issue
Block a user