Skip to content

Commit

Permalink
Add ability to remove videos from watch history
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolson committed Jul 27, 2024
1 parent 7fe1017 commit dfbd0a0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/parser/youtube/History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BrowseFeedActions from '../classes/BrowseFeedActions.js';

import type { Actions, ApiResponse } from '../../core/index.js';
import type { IBrowseResponse } from '../types/index.js';
import type Video from '../classes/Video.js';

// TODO: make feed actions usable
class History extends Feed<IBrowseResponse> {
Expand All @@ -25,6 +26,38 @@ class History extends Feed<IBrowseResponse> {
throw new Error('No continuation data found');
return new History(this.actions, response, true);
}

/**
* Removes a video from watch history.
*/
async removeVideo(video_id: string): Promise<Boolean> {
let feedbackToken;

for (const section of this.sections) {
for (const content of section.contents) {
const video = content as Video;
if (video.id === video_id) {
if (video.menu) {
feedbackToken = video.menu.top_level_buttons[0].endpoint.payload.feedbackToken;
}
}
}
}

if (!feedbackToken) {
throw new Error('Failed to get feedback token');
}

const body = { feedbackTokens: [ feedbackToken ] };
const response = await this.actions.execute('/feedback', body);
const data = response.data;

if (!data.feedbackResponses[0].isProcessed) {
throw new Error('Failed to remove video from watch history');
}

return true;
}
}

export default History;

0 comments on commit dfbd0a0

Please sign in to comment.