Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Created February 9, 2024 14:16
Show Gist options
  • Select an option

  • Save rochacbruno/dbedf63aa4d4d2909323facd9a0dc334 to your computer and use it in GitHub Desktop.

Select an option

Save rochacbruno/dbedf63aa4d4d2909323facd9a0dc334 to your computer and use it in GitHub Desktop.

Revisions

  1. rochacbruno created this gist Feb 9, 2024.
    6 changes: 6 additions & 0 deletions A.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # Delete whatch later videos from youtube

    - OPen youtube, change language to English
    - Go to your watch later playlist
    - OPen the inspect -> console
    - Paste the script and execute it
    37 changes: 37 additions & 0 deletions delete_youtube_watch_later.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    function deleteVideoFromWatchLater() {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];
    video.querySelector('#primary button[aria-label="Action menu"]').click();
    var things = document.evaluate(
    '//span[contains(text(),"Remove from")]',
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null
    );
    for (var i = 0; i < things.snapshotLength; i++) {
    things.snapshotItem(i).click();
    }
    }

    async function deleteWatchLater() {
    let batchSize = 200;
    let waitBetweenBatchesInMilliseconds = 1000 * 60 * 5
    let waitBetweenDeletionsInMilliseconds = 500;

    let totalWaitTime = ((5000 / batchSize) * (waitBetweenBatchesInMilliseconds / 1000 / 60)) + (5000 * (waitBetweenDeletionsInMilliseconds / 1000 / 60))
    console.log(`Deletion will take around ${totalWaitTime.toFixed(0)} minutes to run if the playlist is full.`);

    let count = 0;
    while (true) {
    await new Promise(resolve => setTimeout(resolve, waitBetweenDeletionsInMilliseconds));
    deleteVideoFromWatchLater();
    count++;

    if (count % batchSize === 0 && count !== 0) {
    console.log('Waiting for 5 minutes...');
    await new Promise(resolve => setTimeout(waitBetweenBatchesInMilliseconds));
    }
    }
    }

    deleteWatchLater();