YouTube video metadata downloader

Saves the title, publishing date, creator, and description of a YouTube video to a text file.

  1. // ==UserScript==
  2. // @name YouTube video metadata downloader
  3. // @version 1.1
  4. // @description Saves the title, publishing date, creator, and description of a YouTube video to a text file.
  5. // @author DipshitDickinson
  6. // @match *://*.youtube.com/*
  7. // @require https://gitcdn.xyz/cdn/eligrey/FileSaver.js/9a0a1e4ae2732c2d8eedc0214ef1c0fa32d15150/src/FileSaver.js
  8. // @namespace https://greasyfork.org/users/256625
  9. // ==/UserScript==
  10.  
  11. var b = document.createElement("div");
  12.  
  13. b.id = "savetxtbtn";
  14. b.style = "padding-top: 8px; padding-bottom: 8px";
  15. b.innerHTML = "<paper-button class=\"style-scope ytd-subscribe-button-renderer\">SAVE METADATA AS .TXT</paper-button>";
  16.  
  17. var si = setInterval(function() {
  18. if (document.getElementById("count") && !document.getElementById("savetxtbtn")) {
  19. var toprow = document.querySelector("#top-row.style-scope.ytd-video-secondary-info-renderer");
  20. toprow.insertBefore(b, toprow.childNodes[1]);
  21. clearInterval(si);
  22. }
  23. }, 100);
  24.  
  25. b.onclick = function() {
  26. var title = document.querySelector("h1 yt-formatted-string").innerText;
  27. var pdate = document.querySelector("#date yt-formatted-string").innerText;
  28. var channel = document.querySelector("#upload-info a").innerText;
  29. var desc = document.querySelector("#description");
  30. var url = "https://www.youtube.com/watch?v=" + new URLSearchParams(new URL(window.location.href).search).get('v');
  31.  
  32. for (let a of desc.getElementsByTagName("a")) {
  33. var args = new URLSearchParams(new URL(a.href).search);
  34. if (args.has("q")) {
  35. a.href = args.get("q"); }
  36. if (a.innerHTML.endsWith("...")) {
  37. a.innerHTML = a.href; } }
  38.  
  39. var blob = new Blob([title + "\n" + pdate + "\n" + channel + "\n" + url + "\n\n" + desc.innerText], {type: "text/plain;charset=utf-8"});
  40.  
  41. saveAs(blob, title + ".txt")
  42. }