Vimeo Download

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

目前为 2023-06-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Vimeo Download
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.0
  5. // @description Adds a download button to the Vimeo video player. This is a rewrite of "Vimeo Embed Download" originally created by aleixdev (https://greasyfork.org/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 button = Object.assign(document.createElement('button'), {
  34. innerHTML: 'Download',
  35. title: 'Download ' + quality,
  36. style: 'display: inline-block; font-size: 1.75em; margin: -0.25em 0 0 0.3em; color: rgb(68,187,255)',
  37. onclick: function() {
  38. console.log(url, quality);
  39. this.disabled = true;
  40. this.innerText = 'Wait';
  41. fetch(url)
  42. .then(response => response.blob())
  43. .then(file => {
  44. const tempUrl = URL.createObjectURL(file);
  45. const aTag = document.createElement("a");
  46. aTag.href = tempUrl;
  47. aTag.download = name
  48. document.body.appendChild(aTag);
  49. aTag.click();
  50. URL.revokeObjectURL(tempUrl);
  51. aTag.remove();
  52. }).finally(() => {
  53. this.disabled = false;
  54. this.innerText = 'Download'
  55. });
  56. }
  57. })
  58. const interval = setInterval(function() {
  59. if (!document.querySelector('.vp-controls')) return;
  60. clearInterval(interval)
  61. document.querySelector('.vp-controls').appendChild(button);
  62. }, 100);
  63. })();