mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-26 08:08:54 +00:00
chore: add notification/record_interactions endpoint
This commit is contained in:
@@ -303,8 +303,10 @@ class Actions {
|
||||
data.notificationsMenuRequestType = 'NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX';
|
||||
args.ctoken && (data.ctoken = args.ctoken);
|
||||
break;
|
||||
case 'record_interactions':
|
||||
data.serializedRecordNotificationInteractionsRequest = args.params;
|
||||
break;
|
||||
case 'get_unseen_count':
|
||||
// doesn't require any parameter
|
||||
break;
|
||||
default:
|
||||
throw new Utils.InnertubeError('Action not implemented', action);
|
||||
|
||||
@@ -8,15 +8,16 @@ class NotificationItem {
|
||||
static parseItem(item) {
|
||||
if (item.notificationRenderer) {
|
||||
const notification = item.notificationRenderer;
|
||||
|
||||
return {
|
||||
title: notification?.shortMessage?.simpleText,
|
||||
sent_time: notification?.sentTimeText?.simpleText,
|
||||
timestamp: notification.notificationId,
|
||||
channel_name: notification?.contextualMenu?.menuRenderer?.items[1]?.menuServiceItemRenderer?.text?.runs[1]?.text || 'N/A',
|
||||
channel_thumbnail: notification?.thumbnail?.thumbnails[0],
|
||||
video_thumbnail: notification?.videoThumbnail?.thumbnails[0],
|
||||
video_url: notification.navigationEndpoint.watchEndpoint && `https://youtu.be/${notification.navigationEndpoint.watchEndpoint.videoId}` || 'N/A',
|
||||
read: notification.read,
|
||||
notification_id: notification.notificationId,
|
||||
read: notification.read
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class Proto {
|
||||
*
|
||||
* @param {string} id
|
||||
* @param {number} timestamp
|
||||
*
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
static encodeVisitorData(id, timestamp) {
|
||||
@@ -129,7 +129,7 @@ class Proto {
|
||||
* @returns {string}
|
||||
*/
|
||||
static encodeCommentsSectionParams(video_id, options = {}) {
|
||||
const sort_menu = { TOP_COMMENTS: 0, NEWEST_FIRST: 1 };
|
||||
const sort_options = { TOP_COMMENTS: 0, NEWEST_FIRST: 1 };
|
||||
|
||||
const buf = messages.GetCommentsSectionParams.encode({
|
||||
ctx: { video_id },
|
||||
@@ -137,7 +137,7 @@ class Proto {
|
||||
params: {
|
||||
opts: {
|
||||
video_id,
|
||||
sort_by: sort_menu[options.sort_by || 'TOP_COMMENTS'],
|
||||
sort_by: sort_options[options.sort_by || 'TOP_COMMENTS'],
|
||||
type: options.type || 2
|
||||
},
|
||||
target: 'comments-section'
|
||||
|
||||
@@ -38,6 +38,13 @@ var SoundInfoParams = exports.SoundInfoParams = {
|
||||
decode: null
|
||||
}
|
||||
|
||||
var NotificationInteraction = exports.NotificationInteraction = {
|
||||
buffer: true,
|
||||
encodingLength: null,
|
||||
encode: null,
|
||||
decode: null
|
||||
}
|
||||
|
||||
var NotificationPreferences = exports.NotificationPreferences = {
|
||||
buffer: true,
|
||||
encodingLength: null,
|
||||
@@ -91,6 +98,7 @@ defineVisitorData()
|
||||
defineChannelAnalytics()
|
||||
defineInnertubePayload()
|
||||
defineSoundInfoParams()
|
||||
defineNotificationInteraction()
|
||||
defineNotificationPreferences()
|
||||
defineLiveMessageParams()
|
||||
defineGetCommentsSectionParams()
|
||||
@@ -302,15 +310,7 @@ function defineInnertubePayload () {
|
||||
decode: null
|
||||
}
|
||||
|
||||
var SoundSearchParams = InnertubePayload.SoundSearchParams = {
|
||||
buffer: true,
|
||||
encodingLength: null,
|
||||
encode: null,
|
||||
decode: null
|
||||
}
|
||||
|
||||
defineContext()
|
||||
defineSoundSearchParams()
|
||||
|
||||
function defineContext () {
|
||||
var Client = Context.Client = {
|
||||
@@ -467,75 +467,6 @@ function defineInnertubePayload () {
|
||||
}
|
||||
}
|
||||
|
||||
function defineSoundSearchParams () {
|
||||
SoundSearchParams.encodingLength = encodingLength
|
||||
SoundSearchParams.encode = encode
|
||||
SoundSearchParams.decode = decode
|
||||
|
||||
function encodingLength (obj) {
|
||||
var length = 0
|
||||
if (defined(obj.target_id)) {
|
||||
var len = encodings.string.encodingLength(obj.target_id)
|
||||
length += 1 + len
|
||||
}
|
||||
if (defined(obj.query)) {
|
||||
var len = encodings.string.encodingLength(obj.query)
|
||||
length += 1 + len
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
function encode (obj, buf, offset) {
|
||||
if (!offset) offset = 0
|
||||
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
|
||||
var oldOffset = offset
|
||||
if (defined(obj.target_id)) {
|
||||
buf[offset++] = 18
|
||||
encodings.string.encode(obj.target_id, buf, offset)
|
||||
offset += encodings.string.encode.bytes
|
||||
}
|
||||
if (defined(obj.query)) {
|
||||
buf[offset++] = 26
|
||||
encodings.string.encode(obj.query, buf, offset)
|
||||
offset += encodings.string.encode.bytes
|
||||
}
|
||||
encode.bytes = offset - oldOffset
|
||||
return buf
|
||||
}
|
||||
|
||||
function decode (buf, offset, end) {
|
||||
if (!offset) offset = 0
|
||||
if (!end) end = buf.length
|
||||
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
|
||||
var oldOffset = offset
|
||||
var obj = {
|
||||
target_id: "",
|
||||
query: ""
|
||||
}
|
||||
while (true) {
|
||||
if (end <= offset) {
|
||||
decode.bytes = offset - oldOffset
|
||||
return obj
|
||||
}
|
||||
var prefix = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
var tag = prefix >> 3
|
||||
switch (tag) {
|
||||
case 2:
|
||||
obj.target_id = encodings.string.decode(buf, offset)
|
||||
offset += encodings.string.decode.bytes
|
||||
break
|
||||
case 3:
|
||||
obj.query = encodings.string.decode(buf, offset)
|
||||
offset += encodings.string.decode.bytes
|
||||
break
|
||||
default:
|
||||
offset = skip(prefix & 7, buf, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InnertubePayload.encodingLength = encodingLength
|
||||
InnertubePayload.encode = encode
|
||||
InnertubePayload.decode = decode
|
||||
@@ -551,11 +482,6 @@ function defineInnertubePayload () {
|
||||
var len = encodings.string.encodingLength(obj.target)
|
||||
length += 1 + len
|
||||
}
|
||||
if (defined(obj.sound_search_params)) {
|
||||
var len = SoundSearchParams.encodingLength(obj.sound_search_params)
|
||||
length += varint.encodingLength(len)
|
||||
length += 2 + len
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
@@ -575,14 +501,6 @@ function defineInnertubePayload () {
|
||||
encodings.string.encode(obj.target, buf, offset)
|
||||
offset += encodings.string.encode.bytes
|
||||
}
|
||||
if (defined(obj.sound_search_params)) {
|
||||
buf[offset++] = 130
|
||||
buf[offset++] = 1
|
||||
varint.encode(SoundSearchParams.encodingLength(obj.sound_search_params), buf, offset)
|
||||
offset += varint.encode.bytes
|
||||
SoundSearchParams.encode(obj.sound_search_params, buf, offset)
|
||||
offset += SoundSearchParams.encode.bytes
|
||||
}
|
||||
encode.bytes = offset - oldOffset
|
||||
return buf
|
||||
}
|
||||
@@ -594,8 +512,7 @@ function defineInnertubePayload () {
|
||||
var oldOffset = offset
|
||||
var obj = {
|
||||
context: null,
|
||||
target: "",
|
||||
sound_search_params: null
|
||||
target: ""
|
||||
}
|
||||
while (true) {
|
||||
if (end <= offset) {
|
||||
@@ -616,12 +533,6 @@ function defineInnertubePayload () {
|
||||
obj.target = encodings.string.decode(buf, offset)
|
||||
offset += encodings.string.decode.bytes
|
||||
break
|
||||
case 16:
|
||||
var len = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
obj.sound_search_params = SoundSearchParams.decode(buf, offset, offset + len)
|
||||
offset += SoundSearchParams.decode.bytes
|
||||
break
|
||||
default:
|
||||
offset = skip(prefix & 7, buf, offset)
|
||||
}
|
||||
@@ -920,6 +831,324 @@ function defineSoundInfoParams () {
|
||||
}
|
||||
}
|
||||
|
||||
function defineNotificationInteraction () {
|
||||
var Body = NotificationInteraction.Body = {
|
||||
buffer: true,
|
||||
encodingLength: null,
|
||||
encode: null,
|
||||
decode: null
|
||||
}
|
||||
|
||||
defineBody()
|
||||
|
||||
function defineBody () {
|
||||
var Params = Body.Params = {
|
||||
buffer: true,
|
||||
encodingLength: null,
|
||||
encode: null,
|
||||
decode: null
|
||||
}
|
||||
|
||||
defineParams()
|
||||
|
||||
function defineParams () {
|
||||
var Notification = Params.Notification = {
|
||||
buffer: true,
|
||||
encodingLength: null,
|
||||
encode: null,
|
||||
decode: null
|
||||
}
|
||||
|
||||
defineNotification()
|
||||
|
||||
function defineNotification () {
|
||||
Notification.encodingLength = encodingLength
|
||||
Notification.encode = encode
|
||||
Notification.decode = decode
|
||||
|
||||
function encodingLength (obj) {
|
||||
var length = 0
|
||||
if (defined(obj.id)) {
|
||||
var len = encodings.int32.encodingLength(obj.id)
|
||||
length += 1 + len
|
||||
}
|
||||
if (defined(obj.type)) {
|
||||
var len = encodings.int32.encodingLength(obj.type)
|
||||
length += 1 + len
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
function encode (obj, buf, offset) {
|
||||
if (!offset) offset = 0
|
||||
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
|
||||
var oldOffset = offset
|
||||
if (defined(obj.id)) {
|
||||
buf[offset++] = 8
|
||||
encodings.int32.encode(obj.id, buf, offset)
|
||||
offset += encodings.int32.encode.bytes
|
||||
}
|
||||
if (defined(obj.type)) {
|
||||
buf[offset++] = 16
|
||||
encodings.int32.encode(obj.type, buf, offset)
|
||||
offset += encodings.int32.encode.bytes
|
||||
}
|
||||
encode.bytes = offset - oldOffset
|
||||
return buf
|
||||
}
|
||||
|
||||
function decode (buf, offset, end) {
|
||||
if (!offset) offset = 0
|
||||
if (!end) end = buf.length
|
||||
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
|
||||
var oldOffset = offset
|
||||
var obj = {
|
||||
id: 0,
|
||||
type: 0
|
||||
}
|
||||
while (true) {
|
||||
if (end <= offset) {
|
||||
decode.bytes = offset - oldOffset
|
||||
return obj
|
||||
}
|
||||
var prefix = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
var tag = prefix >> 3
|
||||
switch (tag) {
|
||||
case 1:
|
||||
obj.id = encodings.int32.decode(buf, offset)
|
||||
offset += encodings.int32.decode.bytes
|
||||
break
|
||||
case 2:
|
||||
obj.type = encodings.int32.decode(buf, offset)
|
||||
offset += encodings.int32.decode.bytes
|
||||
break
|
||||
default:
|
||||
offset = skip(prefix & 7, buf, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Params.encodingLength = encodingLength
|
||||
Params.encode = encode
|
||||
Params.decode = decode
|
||||
|
||||
function encodingLength (obj) {
|
||||
var length = 0
|
||||
if (defined(obj.notification)) {
|
||||
var len = Notification.encodingLength(obj.notification)
|
||||
length += varint.encodingLength(len)
|
||||
length += 1 + len
|
||||
}
|
||||
if (defined(obj.cpn)) {
|
||||
var len = encodings.string.encodingLength(obj.cpn)
|
||||
length += 1 + len
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
function encode (obj, buf, offset) {
|
||||
if (!offset) offset = 0
|
||||
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
|
||||
var oldOffset = offset
|
||||
if (defined(obj.notification)) {
|
||||
buf[offset++] = 10
|
||||
varint.encode(Notification.encodingLength(obj.notification), buf, offset)
|
||||
offset += varint.encode.bytes
|
||||
Notification.encode(obj.notification, buf, offset)
|
||||
offset += Notification.encode.bytes
|
||||
}
|
||||
if (defined(obj.cpn)) {
|
||||
buf[offset++] = 18
|
||||
encodings.string.encode(obj.cpn, buf, offset)
|
||||
offset += encodings.string.encode.bytes
|
||||
}
|
||||
encode.bytes = offset - oldOffset
|
||||
return buf
|
||||
}
|
||||
|
||||
function decode (buf, offset, end) {
|
||||
if (!offset) offset = 0
|
||||
if (!end) end = buf.length
|
||||
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
|
||||
var oldOffset = offset
|
||||
var obj = {
|
||||
notification: null,
|
||||
cpn: ""
|
||||
}
|
||||
while (true) {
|
||||
if (end <= offset) {
|
||||
decode.bytes = offset - oldOffset
|
||||
return obj
|
||||
}
|
||||
var prefix = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
var tag = prefix >> 3
|
||||
switch (tag) {
|
||||
case 1:
|
||||
var len = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
obj.notification = Notification.decode(buf, offset, offset + len)
|
||||
offset += Notification.decode.bytes
|
||||
break
|
||||
case 2:
|
||||
obj.cpn = encodings.string.decode(buf, offset)
|
||||
offset += encodings.string.decode.bytes
|
||||
break
|
||||
default:
|
||||
offset = skip(prefix & 7, buf, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Body.encodingLength = encodingLength
|
||||
Body.encode = encode
|
||||
Body.decode = decode
|
||||
|
||||
function encodingLength (obj) {
|
||||
var length = 0
|
||||
if (defined(obj.unkparam)) {
|
||||
var len = encodings.int32.encodingLength(obj.unkparam)
|
||||
length += 1 + len
|
||||
}
|
||||
if (defined(obj.params)) {
|
||||
var len = Params.encodingLength(obj.params)
|
||||
length += varint.encodingLength(len)
|
||||
length += 1 + len
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
function encode (obj, buf, offset) {
|
||||
if (!offset) offset = 0
|
||||
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
|
||||
var oldOffset = offset
|
||||
if (defined(obj.unkparam)) {
|
||||
buf[offset++] = 8
|
||||
encodings.int32.encode(obj.unkparam, buf, offset)
|
||||
offset += encodings.int32.encode.bytes
|
||||
}
|
||||
if (defined(obj.params)) {
|
||||
buf[offset++] = 114
|
||||
varint.encode(Params.encodingLength(obj.params), buf, offset)
|
||||
offset += varint.encode.bytes
|
||||
Params.encode(obj.params, buf, offset)
|
||||
offset += Params.encode.bytes
|
||||
}
|
||||
encode.bytes = offset - oldOffset
|
||||
return buf
|
||||
}
|
||||
|
||||
function decode (buf, offset, end) {
|
||||
if (!offset) offset = 0
|
||||
if (!end) end = buf.length
|
||||
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
|
||||
var oldOffset = offset
|
||||
var obj = {
|
||||
unkparam: 0,
|
||||
params: null
|
||||
}
|
||||
while (true) {
|
||||
if (end <= offset) {
|
||||
decode.bytes = offset - oldOffset
|
||||
return obj
|
||||
}
|
||||
var prefix = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
var tag = prefix >> 3
|
||||
switch (tag) {
|
||||
case 1:
|
||||
obj.unkparam = encodings.int32.decode(buf, offset)
|
||||
offset += encodings.int32.decode.bytes
|
||||
break
|
||||
case 14:
|
||||
var len = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
obj.params = Params.decode(buf, offset, offset + len)
|
||||
offset += Params.decode.bytes
|
||||
break
|
||||
default:
|
||||
offset = skip(prefix & 7, buf, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationInteraction.encodingLength = encodingLength
|
||||
NotificationInteraction.encode = encode
|
||||
NotificationInteraction.decode = decode
|
||||
|
||||
function encodingLength (obj) {
|
||||
var length = 0
|
||||
if (defined(obj.body)) {
|
||||
var len = Body.encodingLength(obj.body)
|
||||
length += varint.encodingLength(len)
|
||||
length += 1 + len
|
||||
}
|
||||
if (defined(obj.unkparam)) {
|
||||
var len = encodings.int32.encodingLength(obj.unkparam)
|
||||
length += 1 + len
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
function encode (obj, buf, offset) {
|
||||
if (!offset) offset = 0
|
||||
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
|
||||
var oldOffset = offset
|
||||
if (defined(obj.body)) {
|
||||
buf[offset++] = 18
|
||||
varint.encode(Body.encodingLength(obj.body), buf, offset)
|
||||
offset += varint.encode.bytes
|
||||
Body.encode(obj.body, buf, offset)
|
||||
offset += Body.encode.bytes
|
||||
}
|
||||
if (defined(obj.unkparam)) {
|
||||
buf[offset++] = 40
|
||||
encodings.int32.encode(obj.unkparam, buf, offset)
|
||||
offset += encodings.int32.encode.bytes
|
||||
}
|
||||
encode.bytes = offset - oldOffset
|
||||
return buf
|
||||
}
|
||||
|
||||
function decode (buf, offset, end) {
|
||||
if (!offset) offset = 0
|
||||
if (!end) end = buf.length
|
||||
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
|
||||
var oldOffset = offset
|
||||
var obj = {
|
||||
body: null,
|
||||
unkparam: 0
|
||||
}
|
||||
while (true) {
|
||||
if (end <= offset) {
|
||||
decode.bytes = offset - oldOffset
|
||||
return obj
|
||||
}
|
||||
var prefix = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
var tag = prefix >> 3
|
||||
switch (tag) {
|
||||
case 2:
|
||||
var len = varint.decode(buf, offset)
|
||||
offset += varint.decode.bytes
|
||||
obj.body = Body.decode(buf, offset, offset + len)
|
||||
offset += Body.decode.bytes
|
||||
break
|
||||
case 5:
|
||||
obj.unkparam = encodings.int32.decode(buf, offset)
|
||||
offset += encodings.int32.decode.bytes
|
||||
break
|
||||
default:
|
||||
offset = skip(prefix & 7, buf, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function defineNotificationPreferences () {
|
||||
var Preference = NotificationPreferences.Preference = {
|
||||
buffer: true,
|
||||
|
||||
@@ -7,11 +7,11 @@ message VisitorData {
|
||||
}
|
||||
|
||||
message ChannelAnalytics {
|
||||
message Params {
|
||||
string channel_id = 1001;
|
||||
}
|
||||
message Params {
|
||||
string channel_id = 1001;
|
||||
}
|
||||
|
||||
Params params = 32;
|
||||
Params params = 32;
|
||||
}
|
||||
|
||||
message InnertubePayload {
|
||||
@@ -27,13 +27,6 @@ message InnertubePayload {
|
||||
Context context = 1;
|
||||
|
||||
optional string target = 2;
|
||||
|
||||
message SoundSearchParams {
|
||||
string target_id = 2;
|
||||
string query = 3;
|
||||
}
|
||||
|
||||
optional SoundSearchParams sound_search_params = 16;
|
||||
}
|
||||
|
||||
message SoundInfoParams {
|
||||
@@ -58,6 +51,7 @@ message NotificationPreferences {
|
||||
message Preference {
|
||||
int32 index = 1;
|
||||
}
|
||||
|
||||
Preference pref_id = 2;
|
||||
|
||||
optional int32 number_0 = 3;
|
||||
@@ -72,6 +66,7 @@ message LiveMessageParams {
|
||||
}
|
||||
Ids ids = 5;
|
||||
}
|
||||
|
||||
Params params = 1;
|
||||
|
||||
optional int32 number_0 = 2;
|
||||
|
||||
Reference in New Issue
Block a user