Youtube Playlist 2 mp3

Makes script to download playlist and convert it to mp3 with number.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Youtube Playlist 2 mp3
// @description  Makes script to download playlist and convert it to mp3 with number.
// @namespace    https://greasyfork.org/users/3159
// @version      0.3
// @include      http*://www.youtube.com/playlist?list=*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function generateScript(){
        var playlist = document.getElementsByClassName('yt-simple-endpoint style-scope ytd-playlist-video-renderer');
        var allCode = [];

        for (var i = 0; i < playlist.length; i++) {
            if (playlist[i].getAttribute("href")){
                if (playlist[i].children[1].children[0].children[1].title != ("[Deleted video]" || "[Private video]")) {

                    var a=playlist[i].href.split('v=')[1].split('&')[0] // Video ID
                    var b=playlist[i].href.split('index=')[1].split('&')[0].padStart(3, "0") // Number
                    var c=playlist[i].children[1].children[0].children[1].title.replace(/\//g, "\\").replace(/\'/g, '"') // Name and remove '

                 allCode.push("youtube-dl -f 251 'https://www.youtube.com/watch?v=" + a + "' --id && ffmpeg -i '" + a + ".webm' '" + b + "_" + c + ".mp3'");
            }}
        }
        document.body.innerHTML = "select all and copy into terminal, remove webm waste when done<br /><br />";
        document.body.style.fontSize="1.3em"
        for (i = 0; i < allCode.length; i++) {
            document.body.innerHTML += allCode[i] + " && <br />";
        }
        document.body.innerHTML += "echo 'done! Remember to use kid3 to set track number if needed.'";
    }

    var css = 'p:hover{ background-color:red;color:white;border-radius: 3px; }p{ font-size:.75em;float:right;cursor:pointer }';
    var style = document.createElement('style');
    style.innerHTML = css;
    document.head.appendChild(style);

    var button = document.createElement('p');
    button.innerText = " ⇩ ";
    button.onclick = generateScript;
    document.getElementById('text-displayed').appendChild(button);
})();