Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/core/mixins/MediaInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ export default class MediaInfo {
}, url_params);
}

/**
* Adds video to the watch history.
*/
async updateWatchHistoryTime(playedSeconds: number, client_name = Constants.CLIENTS.WEB.NAME, client_version = Constants.CLIENTS.WEB.VERSION, replacement = 'https://www.'): Promise<Response> {
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;
}
Expand Down
7 changes: 7 additions & 0 deletions src/parser/youtube/VideoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> {
return super.updateWatchHistoryTime(playedSeconds);
}

/**
* Retrieves watch next feed continuation.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/parser/ytmusic/TrackInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> {
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) : [];
}
Expand Down