Vimeo Download

Adds a download button to the Vimeo video player. This is a rewrite of "Vimeo Embed Download" originally created by aleixdev (https://greatest.deepsurf.us/en/scripts/376551).

  1. // ==UserScript==
  2. // @name Vimeo Download
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.2
  5. // @description Adds a download button to the Vimeo video player. This is a rewrite of "Vimeo Embed Download" originally created by aleixdev (https://greatest.deepsurf.us/en/scripts/376551).
  6. // @author You
  7. // @match https://vimeo.com/*
  8. // @match https://player.vimeo.com/video/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=vimeo.com
  10. // @unwrap
  11. // ==/UserScript==
  12. (function() {
  13. if (document.title === 'VimeUhOh') {
  14. return;
  15. }
  16.  
  17. // function getPlayer() {
  18. // if (window.playerConfig) {
  19. // return window.playerConfig;
  20. // }
  21. // const clips = window.vimeo.clips;
  22. // const videoId = Object.keys(clips).at();
  23. // if (!videoId) {
  24. // throw new Error('[Vimeo Download] Error retrieving video meta data:', clips);
  25. // }
  26. // return clips[videoId]
  27. // }
  28. // const { request, video } = getPlayer();
  29. // console.log(request.files);
  30. // const streams = request.files.progressive.sort((a, b) => b.width - a.width);
  31. // console.log(streams);
  32. // const { url, quality } = streams[0];
  33. const div = document.createElement('div');
  34. document.querySelectorAll('track[srclang]').forEach(subtitle => {
  35. const element = Object.assign(document.createElement('button'), {
  36. innerHTML: subtitle.srclang,
  37. title: subtitle.srclang,
  38. style: 'display: inline-block; font-size: 1.75em; margin: -0.25em 0 0 0.3em; color: rgb(68,187,255)',
  39. onclick: function() {
  40. this.disabled = true;
  41. this.innerText = 'Wait';
  42. fetch(subtitle.src)
  43. .then(response => response.blob())
  44. .then(file => {
  45. const tempUrl = URL.createObjectURL(file);
  46. const aTag = document.createElement("a");
  47. aTag.href = tempUrl;
  48. aTag.download = 'Subtitle ' + subtitle.srclang + '.vtt'
  49. document.body.appendChild(aTag);
  50. aTag.click();
  51. URL.revokeObjectURL(tempUrl);
  52. aTag.remove();
  53. }).finally(() => {
  54. this.disabled = false;
  55. this.innerText = subtitle.srclang
  56. });
  57. }
  58. })
  59. div.append(element);
  60. })
  61.  
  62. // const button = Object.assign(document.createElement('button'), {
  63. // innerHTML: 'Download',
  64. // title: 'Download ' + quality,
  65. // style: 'display: inline-block; font-size: 1.75em; margin: -0.25em 0 0 0.3em; color: rgb(68,187,255)',
  66. // onclick: function() {
  67. // console.log(url, quality);
  68. // this.disabled = true;
  69. // this.innerText = 'Wait';
  70. // fetch(url)
  71. // .then(response => response.blob())
  72. // .then(file => {
  73. // const tempUrl = URL.createObjectURL(file);
  74. // const aTag = document.createElement("a");
  75. // aTag.href = tempUrl;
  76. // aTag.download = name
  77. // document.body.appendChild(aTag);
  78. // aTag.click();
  79. // URL.revokeObjectURL(tempUrl);
  80. // aTag.remove();
  81. // }).finally(() => {
  82. // this.disabled = false;
  83. // this.innerText = 'Download'
  84. // });
  85. // }
  86. // })
  87. const interval = setInterval(function() {
  88. if (!document.querySelector('.vp-controls')) return;
  89. clearInterval(interval)
  90. document.querySelector('.vp-controls').append(/*button,*/ div);
  91. }, 100);
  92. })();