Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 23 additions & 6 deletions src/core/mixins/MediaInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default class MediaInfo {
manifest_options
);
}

/**
* Get a cleaned up representation of the adaptive_formats
*/
Expand Down Expand Up @@ -207,10 +207,7 @@ export default class MediaInfo {
return new TranscriptInfo(this.actions, response);
}

/**
* Adds video to the watch history.
*/
async addToWatchHistory(client_name: string = Constants.CLIENTS.WEB.NAME, client_version: string = Constants.CLIENTS.WEB.VERSION, replacement = 'https://www.'): Promise<Response> {
async addToWatchHistory(client_name?: string, client_version?: string, replacement = 'https://www.'): Promise<Response> {
if (!this.#playback_tracking)
throw new InnertubeError('Playback tracking not available');

Expand All @@ -223,6 +220,26 @@ export default class MediaInfo {

const url = this.#playback_tracking.videostats_playback_url.replace('https://s.', replacement);

return await this.#actions.stats(url, {
client_name: client_name || Constants.CLIENTS.WEB.NAME,
client_version: client_version || Constants.CLIENTS.WEB.VERSION
}, url_params);
}

async updateWatchTime(startTime: number, client_name: string = Constants.CLIENTS.WEB.NAME, client_version: string = 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: startTime.toFixed(3),
et: startTime.toFixed(3),
cmt: startTime.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
Expand All @@ -243,7 +260,7 @@ export default class MediaInfo {
/**
* Parsed InnerTube response.
*/
get page(): [ IPlayerResponse, INextResponse? ] {
get page(): [IPlayerResponse, INextResponse?] {
return this.#page;
}
}
7 changes: 7 additions & 0 deletions src/parser/youtube/VideoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ export default class VideoInfo extends MediaInfo {
return super.addToWatchHistory();
}

/**
* Updates watch time for the video.
*/
async updateWatchTime(startTime: number): Promise<Response> {
return super.updateWatchTime(startTime);
}

/**
* 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 @@ -144,6 +144,13 @@ class TrackInfo extends MediaInfo {
async addToWatchHistory(): Promise<Response> {
return super.addToWatchHistory(Constants.CLIENTS.YTMUSIC.NAME, Constants.CLIENTS.YTMUSIC.VERSION, 'https://music.');
}

/**
* Updates the watch time of the song.
*/
async updateWatchTime(startTime: number): Promise<Response> {
return super.updateWatchTime(startTime, 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