Created
January 2, 2024 06:21
-
-
Save takehaya/2167bc4a642a69f7f436b8ae3e0898e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouTube Playlist Links Extractor | |
// @namespace https://twitter.com/takemioIO | |
// @version 0.0.1 | |
// @description Extract all video links from the current YouTube playlist after page load and format them.This is a plugin that outputs the command to change the youtube playlist to Jockie music playlist format to the console. | |
// @author takemioIO | |
// @match *://www.youtube.com/playlist?list=* | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function formatChannelName(name) { | |
return name.toLowerCase().split(' ').join('_'); | |
} | |
// Extract video links from the page's HTML | |
function extractVideoLinks() { | |
const videoIdRegex = /watch\?v=([a-zA-Z0-9_-]+)(?:&[a-zA-Z0-9_=]*)?/g; | |
let match; | |
let extractedLinks = new Set(); | |
while ((match = videoIdRegex.exec(document.body.innerHTML)) !== null) { | |
const videoUrl = `https://www.youtube.com/watch?v=${match[1]}`; | |
extractedLinks.add(videoUrl); | |
} | |
const channelAnchor = document.querySelector('a[href^="/channel"]'); | |
const channelName = formatChannelName(channelAnchor ? channelAnchor.textContent.trim() : 'playlist'); | |
console.log(`m!playlist create ${channelName}`); | |
// Format the links with the required prefix | |
const formattedOutput = `m!playlist add ${channelName} ` + Array.from(extractedLinks).join(" "); | |
console.log(formattedOutput); | |
} | |
// Wait for the window to load before extracting links | |
window.onload = function() { | |
extractVideoLinks(); | |
}; | |
})(); |
Author
takehaya
commented
Jan 2, 2024

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