Skip to content

Instantly share code, notes, and snippets.

@TheOnlyWayUp
Last active June 26, 2024 13:40
Show Gist options
  • Save TheOnlyWayUp/4452b0a5c151740417c16f3518fb701e to your computer and use it in GitHub Desktop.
Save TheOnlyWayUp/4452b0a5c151740417c16f3518fb701e to your computer and use it in GitHub Desktop.
Like all songs in a Youtube Music Playlist

This script likes all the songs in a Youtube Music Playlist at once.

How to use:

  • Visit a Playlist's page on ytm (URL looks like: https://music.youtube.com/playlist?list=...
  • Press ctrl + shift + j. This opens the Developer Console.
  • Copy the script in this gist (That's in script.js)
  • Paste the code into the Developer Console on the ytm Tab, hit enter.
  • Great, you're done!

Star ⭐ this gist if it was useful. Follows to my GitHub Profile are appreciated.

Follow Badge


TheOnlyWayUp © 2024

// made by https://github.com/TheOnlyWayUp, if it helped, drop a follow!
// source: https://gist.github.com/TheOnlyWayUp/4452b0a5c151740417c16f3518fb701e
let interval = 10 // wait time between chunks in seconds
const chunk = size => array => array.reduce((result, item) => {
if (result[result.length - 1].length < size) {
result[result.length - 1].push(item);
} else {
result.push([item]);
}
return result;
}, [
[]
]); // Thanks https://stackoverflow.com/a/77372180
function likeall() {
let els = document.getElementById("contents").querySelectorAll(
"button[aria-pressed=false][aria-label='Like']")
console.log(`${els.length} to Like`)
let cels = chunk(5)(Array.from(els))
cels.forEach(function(items, index) {
setTimeout(function() {
console.log("start")
items.forEach(el => el.click())
console.log("end")
}, index *
interval * 1000); // Thanks https://stackoverflow.com/a/45500721
});
}
likeall()
@adiologydev
Copy link

Updated Version :) Now shows the progress!

let total = 0;
let left = 0;
let interval = 10  // wait time between chunks in seconds

const ytmLog = msg => console.log(`[YTM Liker] ${msg}`);

const chunk = size => array => array.reduce((result, item) => {
    if (result[result.length - 1].length < size) {
        result[result.length - 1].push(item);
    } else {
        result.push([item]);
    }
    return result;
}, [
    []
]);

function likeAll() {
    let els = document.getElementById("contents").querySelectorAll(
        "button[aria-pressed=false][aria-label='Like']");

    total = els.length; left = els.length;
    ytmLog(`Total Queue: ${total}`);

    let cels = chunk(5)(Array.from(els));
    cels.forEach(function(items, index) {
        setTimeout(function() {
            ytmLog('Liking next chunk.');
            items.forEach(el => el.click());
            left = left - 5;
            ytmLog('Chunk finished. Waiting to start the next.');
            ytmLog(`${left} songs left out of ${total}.`);
        }, index *
        interval * 1000);
    });
}

likeAll();

Haven't done enough testing so sometimes the numbers may be wrong, but it worked :)

Output:
image

@WhiteBearSpirit
Copy link

For those who get no songs by running this script: just check your language is set to English, so that YT music webpage has aria-label='Like' elements

@zamora
Copy link

zamora commented Jun 26, 2024

Be careful using this script. I used it when transferring my music to a new account, and my channel got suspended because YouTube thought I was doing "Fake Engagement" by automating likes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment