Youtube Playlist 2 mp3

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

当前为 2020-05-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Playlist 2 mp3
  3. // @description Makes script to download playlist and convert it to mp3 with number.
  4. // @namespace https://greasyfork.org/users/3159
  5. // @version 0.3
  6. // @include http*://www.youtube.com/playlist?list=*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. function generateScript(){
  14. var playlist = document.getElementsByClassName('yt-simple-endpoint style-scope ytd-playlist-video-renderer');
  15. var allCode = [];
  16.  
  17. for (var i = 0; i < playlist.length; i++) {
  18. if (playlist[i].getAttribute("href")){
  19. if (playlist[i].children[1].children[0].children[1].title != ("[Deleted video]" || "[Private video]")) {
  20.  
  21. var a=playlist[i].href.split('v=')[1].split('&')[0] // Video ID
  22. var b=playlist[i].href.split('index=')[1].split('&')[0].padStart(3, "0") // Number
  23. var c=playlist[i].children[1].children[0].children[1].title.replace(/\//g, "\\").replace(/\'/g, '"') // Name and remove '
  24.  
  25. allCode.push("youtube-dl -f 251 'https://www.youtube.com/watch?v=" + a + "' --id && ffmpeg -i '" + a + ".webm' '" + b + "_" + c + ".mp3'");
  26. }}
  27. }
  28. document.body.innerHTML = "select all and copy into terminal, remove webm waste when done<br /><br />";
  29. document.body.style.fontSize="1.3em"
  30. for (i = 0; i < allCode.length; i++) {
  31. document.body.innerHTML += allCode[i] + " && <br />";
  32. }
  33. document.body.innerHTML += "echo 'done! Remember to use kid3 to set track number if needed.'";
  34. }
  35.  
  36. var css = 'p:hover{ background-color:red;color:white;border-radius: 3px; }p{ font-size:.75em;float:right;cursor:pointer }';
  37. var style = document.createElement('style');
  38. style.innerHTML = css;
  39. document.head.appendChild(style);
  40.  
  41. var button = document.createElement('p');
  42. button.innerText = " ⇩ ";
  43. button.onclick = generateScript;
  44. document.getElementById('text-displayed').appendChild(button);
  45. })();
  46.