diff --git a/src/core/mixins/MediaInfo.ts b/src/core/mixins/MediaInfo.ts index d18411c2a..7441d6066 100644 --- a/src/core/mixins/MediaInfo.ts +++ b/src/core/mixins/MediaInfo.ts @@ -224,6 +224,29 @@ export default class MediaInfo { }, url_params); } + /** + * Adds video to the watch history. + */ + async updateWatchHistoryTime(playedSeconds: number, client_name: string = Constants.CLIENTS.WEB.NAME, client_version: string = Constants.CLIENTS.WEB.VERSION, replacement = 'https://www.'): Promise { + if (!this.#playback_tracking) + throw new InnertubeError('Playback tracking not available'); + + const url_params = { + cpn: this.#cpn, + st: playedSeconds.toFixed(3), + et: playedSeconds.toFixed(3), + cmt: playedSeconds.toFixed(3), + final: '1' + }; + + const url = this.#playback_tracking.videostats_watchtime_url.replace('https://s.', replacement); + + return await this.#actions.stats(url, { + client_name, + client_version + }, url_params); + } + get actions(): Actions { return this.#actions; } diff --git a/src/parser/youtube/VideoInfo.ts b/src/parser/youtube/VideoInfo.ts index 21efafe45..4f8eb48fa 100644 --- a/src/parser/youtube/VideoInfo.ts +++ b/src/parser/youtube/VideoInfo.ts @@ -175,6 +175,13 @@ export default class VideoInfo extends MediaInfo { return super.addToWatchHistory(); } + /** + * Updates video in the watch history with specific point (after being added to watch history). + */ + async updateWatchTime(playedSeconds: number): Promise { + return super.updateWatchHistoryTime(playedSeconds); + } + /** * Retrieves watch next feed continuation. */ diff --git a/src/parser/ytmusic/TrackInfo.ts b/src/parser/ytmusic/TrackInfo.ts index b7a22de0b..46ec400c1 100644 --- a/src/parser/ytmusic/TrackInfo.ts +++ b/src/parser/ytmusic/TrackInfo.ts @@ -145,6 +145,13 @@ class TrackInfo extends MediaInfo { return super.addToWatchHistory(Constants.CLIENTS.YTMUSIC.NAME, Constants.CLIENTS.YTMUSIC.VERSION, 'https://music.'); } + /** + * Updates video in the watch history with specific point (after being added to watch history). + */ + async updateWatchTime(playedSeconds: number): Promise { + return super.updateWatchHistoryTime(playedSeconds, Constants.CLIENTS.YTMUSIC.NAME, Constants.CLIENTS.YTMUSIC.VERSION, 'https://music.'); + } + get available_tabs(): string[] { return this.tabs ? this.tabs.map((tab) => tab.title) : []; }