SaveTube

Download videos from video sharing web sites.

当前为 2022-03-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SaveTube
  3. // @version 2022.02.06
  4. // @description Download videos from video sharing web sites.
  5. // @author sebaro
  6. // @namespace http://sebaro.pro/savetube
  7. // @icon https://gitlab.com/sebaro/savetube/raw/master/savetube.png
  8. // @include http://youtube.com*
  9. // @include http://www.youtube.com*
  10. // @include https://youtube.com*
  11. // @include https://www.youtube.com*
  12. // @include http://m.youtube.com*
  13. // @include https://m.youtube.com*
  14. // @include http://dailymotion.com*
  15. // @include http://www.dailymotion.com*
  16. // @include https://dailymotion.com*
  17. // @include https://www.dailymotion.com*
  18. // @include http://vimeo.com*
  19. // @include http://www.vimeo.com*
  20. // @include https://vimeo.com*
  21. // @include https://www.vimeo.com*
  22. // @include http://veoh.com*
  23. // @include http://www.veoh.com*
  24. // @include https://veoh.com*
  25. // @include https://www.veoh.com*
  26. // @include http://imdb.com*
  27. // @include http://www.imdb.com*
  28. // @include https://imdb.com*
  29. // @include https://www.imdb.com*
  30. // @noframes
  31. // @grant none
  32. // @run-at document-end
  33. // ==/UserScript==
  34.  
  35.  
  36. /*
  37.  
  38. Copyright (C) 2010 - 2022 Sebastian Luncan
  39.  
  40. This program is free software: you can redistribute it and/or modify
  41. it under the terms of the GNU General Public License as published by
  42. the Free Software Foundation, either version 3 of the License, or
  43. (at your option) any later version.
  44.  
  45. This program is distributed in the hope that it will be useful,
  46. but WITHOUT ANY WARRANTY; without even the implied warranty of
  47. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48. GNU General Public License for more details.
  49.  
  50. You should have received a copy of the GNU General Public License
  51. along with this program. If not, see <http://www.gnu.org/licenses/>.
  52.  
  53. Website: http://sebaro.pro/savetube
  54. Contact: http://sebaro.pro/contact
  55.  
  56. */
  57.  
  58.  
  59. (function() {
  60.  
  61.  
  62. // Don't run on frames or iframes
  63. if (window.top != window.self) return;
  64.  
  65.  
  66. // ==========Variables========== //
  67.  
  68. // Userscript
  69. var userscript = 'SaveTube';
  70. var website = 'http://sebaro.pro/savetube';
  71. var contact = 'http://sebaro.pro/contact';
  72.  
  73. // Page
  74. var page = {win: window, doc: window.document, body: window.document.body, url: window.location.href, site: window.location.hostname.match(/([^.]+)\.[^.]+$/)[1]};
  75.  
  76. // Saver
  77. var saver = {};
  78. var panelHeight = 30;
  79.  
  80. // Features/Options
  81. var feature = {'definition': true, 'container': true, 'openpagelink': true, 'autosave': true, 'savedash': false, 'showsavelink': true};
  82. var option = {'definition': 'High Definition', 'container': 'MP4', 'openpagelink': false, 'autosave': false, 'savedash': false, 'showsavelink': false, 'hidden': false};
  83.  
  84. // Media
  85. var mediatypes = {'MP4': 'video/mp4', 'WebM': 'video/webm', 'M3U8': 'application/x-mpegURL', 'WebVTT': 'text/vtt'};
  86.  
  87. // Sources
  88. var sources = {};
  89.  
  90.  
  91. // ==========Functions========== //
  92.  
  93. function createMyElement(type, properties, event, listener) {
  94. var obj = page.doc.createElement(type);
  95. for (var propertykey in properties) {
  96. if (propertykey == 'target') obj.setAttribute('target', properties[propertykey]);
  97. else obj[propertykey] = properties[propertykey];
  98. }
  99. if (event && listener) {
  100. obj.addEventListener(event, listener, false);
  101. }
  102. return obj;
  103. }
  104.  
  105. function modifyMyElement(obj, properties, event, listener) {
  106. for (var propertykey in properties) {
  107. if (propertykey == 'target') obj.setAttribute('target', properties[propertykey]);
  108. else obj[propertykey] = properties[propertykey];
  109. }
  110. if (event && listener) {
  111. obj.addEventListener(event, listener, false);
  112. }
  113. }
  114.  
  115. function styleMyElement(obj, styles) {
  116. for (var stylekey in styles) {
  117. obj.style[stylekey] = styles[stylekey];
  118. }
  119. }
  120.  
  121. function cleanMyElement(obj, hide) {
  122. if (hide) {
  123. for (var i = 0; i < obj.children.length; i++) {
  124. styleMyElement(obj.children[i], {display: 'none'});
  125. }
  126. }
  127. else {
  128. if (obj.hasChildNodes()) {
  129. while (obj.childNodes.length >= 1) {
  130. obj.removeChild(obj.firstChild);
  131. }
  132. }
  133. }
  134. }
  135.  
  136. function getMyElement(obj, type, from, value, child, content) {
  137. var getObj, chObj, coObj;
  138. var pObj = (!obj) ? page.doc : obj;
  139. if (type == 'body') {
  140. getObj = pObj.body;
  141. }
  142. else {
  143. if (from == 'id') getObj = pObj.getElementById(value);
  144. else if (from == 'class') getObj = pObj.getElementsByClassName(value);
  145. else if (from == 'tag') getObj = pObj.getElementsByTagName(type);
  146. else if (from == 'ns') {
  147. if (pObj.getElementsByTagNameNS) getObj = pObj.getElementsByTagNameNS(value, type);
  148. }
  149. else if (from == 'query') {
  150. if (child > 0) {
  151. if (pObj.querySelectorAll) getObj = pObj.querySelectorAll(value);
  152. }
  153. else {
  154. if (pObj.querySelector) getObj = pObj.querySelector(value);
  155. }
  156. }
  157. }
  158. chObj = (getObj && child >= 0) ? getObj[child] : getObj;
  159. if (content && chObj) {
  160. if (type == 'html' || type == 'body' || type == 'div' || type == 'option') coObj = chObj.innerHTML;
  161. else if (type == 'object') coObj = chObj.data;
  162. else if (type == 'img' || type == 'video' || type == 'embed') coObj = chObj.src;
  163. else coObj = chObj.textContent;
  164. return coObj;
  165. }
  166. else {
  167. return chObj;
  168. }
  169. }
  170.  
  171. function appendMyElement(parent, child) {
  172. parent.appendChild(child);
  173. }
  174.  
  175. function removeMyElement(parent, child) {
  176. parent.removeChild(child);
  177. }
  178.  
  179. function replaceMyElement(parent, orphan, child) {
  180. parent.replaceChild(orphan, child);
  181. }
  182.  
  183. function cleanMyContent(content, unesc, extra) {
  184. if (unesc) content = unescape(content);
  185. content = content.replace(/\\u0025/g, '%');
  186. content = content.replace(/\\u0026/g, '&');
  187. content = content.replace(/\\u002F/g, '/');
  188. content = content.replace(/\\/g, '');
  189. content = content.replace(/\n/g, '');
  190. if (extra) {
  191. content = content.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/&#034;/g, '\'').replace(/"/g, '\'');
  192. content = content.replace(/&#39;/g, '\'').replace(/&#039;/g, '\'').replace(/'/g, '\'');
  193. content = content.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  194. content = content.replace(/[\/\|]/g, '-');
  195. content = content.replace(/[#:\*\?]/g, '');
  196. content = content.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  197. }
  198. return content;
  199. }
  200.  
  201. function parseMyContent(content, pattern) {
  202. var parse, response;
  203. content = content.replace(/(\r\n|\n|\r)/gm, '');
  204. parse = content.match(pattern);
  205. if (parse) {
  206. response = (/g$/.test(pattern)) ? parse : parse[1];
  207. }
  208. return response;
  209. }
  210.  
  211. function getMyContent(url, pattern) {
  212. var urle, data, xhr, response;
  213. if (url.indexOf('|') != -1) {
  214. data = url.split('|')[1];
  215. url = url.split('|')[0];
  216. }
  217. if (data) {
  218. urle = btoa(data);
  219. if (!sources[urle]) {
  220. console.log('ViewTube: POST [' + pattern + '] ' + url);
  221. xhr = new XMLHttpRequest();
  222. xhr.open('POST', url, false);
  223. if (data.indexOf('{') != -1) {
  224. xhr.setRequestHeader('Content-Type', 'application/json');
  225. }
  226. else {
  227. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  228. }
  229. xhr.send(data);
  230. sources[urle] = (xhr.responseText) ? xhr.responseText : xhr.responseXML;
  231. }
  232. }
  233. else {
  234. urle = btoa(url);
  235. if (!sources[urle]) {
  236. console.log('ViewTube: GET [' + pattern + '] ' + url);
  237. xhr = new XMLHttpRequest();
  238. xhr.open('GET', url, false);
  239. xhr.send();
  240. sources[urle] = (xhr.responseText) ? xhr.responseText : xhr.responseXML;
  241. }
  242. }
  243. if (sources[urle]) {
  244. response = sources[urle];
  245. if (pattern) {
  246. response = parseMyContent(response, pattern);
  247. }
  248. }
  249. return response;
  250. }
  251.  
  252. function createMySaver() {
  253. /* The Panel */
  254. saver['saverPanel'] = createMyElement('div');
  255. styleMyElement(saver['saverPanel'], {position: 'fixed', fontFamily: 'sans-serif', fontSize: '10px', minHeight: panelHeight + 'px', lineHeight: panelHeight + 'px', backgroundColor: '#FFFFFF', padding: '0px 10px 5px 10px', bottom: '0px', right: '25px', zIndex: '2000000000', borderTop: '1px solid #CCCCCC', borderLeft: '1px solid #CCCCCC', borderRight: '1px solid #CCCCCC', borderRadius: '5px 5px 0px 0px', textAlign: 'center', boxSizing: 'content-box'});
  256. appendMyElement(page.body, saver['saverPanel']);
  257.  
  258. /* Panel Hide/Show Toggle Button */
  259. saver['buttonHide'] = createMyElement('div', {title: '{Hide/Show: click to hide/show this panel}'}, 'click', function() {
  260. toggleMySaver();
  261. });
  262. styleMyElement(saver['buttonHide'], {width: '0px', height: '0px', display: 'inline-block', borderTop: '8px solid transparent', borderBottom: '8px solid transparent', borderLeft: '15px solid #777777', borderRight: '0px solid #777777', lineHeight: 'normal', verticalAlign: 'middle', marginLeft: '5px', marginRight: '10px', cursor: 'pointer', boxSizing: 'content-box'});
  263. appendMyElement(saver['saverPanel'], saver['buttonHide']);
  264.  
  265. /* Panel Logo */
  266. saver['panelLogo'] = createMyElement('div', {title: '{SaveTube: click to visit the script wesite}', textContent: userscript}, 'click', function() {
  267. page.win.location.href = website;
  268. });
  269. styleMyElement(saver['panelLogo'], {display: 'inline-block', color: '#32D132', fontSize: '14px', fontWeight: 'bold', border: '1px solid #32D132', borderRadius: '3px', padding: '0px 4px', marginRight: '10px', lineHeight: 'normal', verticalAlign: 'middle', cursor: 'pointer', boxSizing: 'content-box'});
  270. appendMyElement(saver['saverPanel'], saver['panelLogo']);
  271.  
  272. /* Warnings */
  273. if (saver['warnMess']) {
  274. saver['saverMessage'] = createMyElement('div');
  275. styleMyElement(saver['saverMessage'], {display: 'inline-block', fontSize: '12px', color: '#AD0000'});
  276. appendMyElement(saver['saverPanel'], saver['saverMessage']);
  277. if (saver['warnContent']) showMyMessage(saver['warnMess'], saver['warnContent']);
  278. else showMyMessage(saver['warnMess']);
  279. return;
  280. }
  281.  
  282. /* Panel Video Menu */
  283. saver['videoMenu'] = createMyElement('select', {title: '{Videos: select the video format for download}'}, 'change', function() {
  284. saver['videoSave'] = this.value;
  285. if (saver['isShowingLink']) {
  286. cleanMyElement(saver['buttonSaveLink'], false);
  287. saver['isShowingLink'] = false;
  288. }
  289. if (option['autosave']) {
  290. saveMyVideo();
  291. }
  292. });
  293. styleMyElement(saver['videoMenu'], {display: 'inline-block', width: 'auto', height: '20px', fontFamily: 'inherit', fontSize: '14px', fontWeight: 'bold', padding: '0px 3px', overflow: 'hidden', border: '1px solid #CCCCCC', color: '#777777', backgroundColor: '#FFFFFF', lineHeight: 'normal', verticalAlign: 'middle', cursor: 'pointer', boxSizing: 'content-box'});
  294. appendMyElement(saver['saverPanel'], saver['videoMenu']);
  295. if (feature['openpagelink']) {
  296. saver['videoList']['Page Link'] = page.url;
  297. }
  298. var videosProgressive = [];
  299. var videosAdaptiveHLS = [];
  300. var videosAdaptiveDASHVideo = [];
  301. var videosAdaptiveDASHAudio = [];
  302. var videosAdaptiveDASHMuxed = [];
  303. var videosExtra = [];
  304. for (var videoCode in saver['videoList']) {
  305. if (videoCode.indexOf('Video') != -1) videosAdaptiveDASHVideo.push(videoCode);
  306. else if (videoCode.indexOf('Audio') != -1) videosAdaptiveDASHAudio.push(videoCode);
  307. else if (saver['videoList'][videoCode] == 'DASH') videosAdaptiveDASHMuxed.push(videoCode);
  308. else if (videoCode.indexOf('M3U8') != -1) videosAdaptiveHLS.push(videoCode);
  309. else if (videoCode.indexOf('MP4') != -1 || videoCode.indexOf('WebM') != -1) videosProgressive.push(videoCode);
  310. else videosExtra.push(videoCode);
  311. }
  312. if (videosProgressive.length > 0) {
  313. for (var i = 0; i < videosProgressive.length; i++) {
  314. saver['videoItem'] = createMyElement('option', {value: videosProgressive[i], textContent: videosProgressive[i]});
  315. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', cursor: 'pointer'});
  316. appendMyElement(saver['videoMenu'], saver['videoItem']);
  317. }
  318. }
  319. if (videosAdaptiveHLS.length > 0) {
  320. saver['videoItem'] = createMyElement('option', {value: 'HLS', textContent: 'HLS'});
  321. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', color: '#FF0000'});
  322. saver['videoItem'].disabled = 'disabled';
  323. appendMyElement(saver['videoMenu'], saver['videoItem']);
  324. for (var i = 0; i < videosAdaptiveHLS.length; i++) {
  325. saver['videoItem'] = createMyElement('option', {value: videosAdaptiveHLS[i], textContent: videosAdaptiveHLS[i]});
  326. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', cursor: 'pointer'});
  327. appendMyElement(saver['videoMenu'], saver['videoItem']);
  328. }
  329. }
  330. if (videosAdaptiveDASHVideo.length > 0) {
  331. saver['videoItem'] = createMyElement('option', {value: 'DASH (Video Only)', textContent: 'DASH (Video Only)'});
  332. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', color: '#FF0000'});
  333. saver['videoItem'].disabled = 'disabled';
  334. appendMyElement(saver['videoMenu'], saver['videoItem']);
  335. for (var i = 0; i < videosAdaptiveDASHVideo.length; i++) {
  336. saver['videoItem'] = createMyElement('option', {value: videosAdaptiveDASHVideo[i], textContent: videosAdaptiveDASHVideo[i]});
  337. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', cursor: 'pointer'});
  338. appendMyElement(saver['videoMenu'], saver['videoItem']);
  339. }
  340. }
  341. if (videosAdaptiveDASHAudio.length > 0) {
  342. saver['videoItem'] = createMyElement('option', {value: 'DASH (Audio Only)', textContent: 'DASH (Audio Only)'});
  343. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', color: '#FF0000'});
  344. saver['videoItem'].disabled = 'disabled';
  345. appendMyElement(saver['videoMenu'], saver['videoItem']);
  346. for (var i = 0; i < videosAdaptiveDASHAudio.length; i++) {
  347. saver['videoItem'] = createMyElement('option', {value: videosAdaptiveDASHAudio[i], textContent: videosAdaptiveDASHAudio[i]});
  348. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', cursor: 'pointer'});
  349. appendMyElement(saver['videoMenu'], saver['videoItem']);
  350. }
  351. }
  352. if (videosAdaptiveDASHMuxed.length > 0) {
  353. feature['savedash'] = true;
  354. if (option['savedash']) {
  355. saver['videoItem'] = createMyElement('option', {value: 'DASH (Video With Audio)', textContent: 'DASH (Video With Audio)'});
  356. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', color: '#FF0000'});
  357. saver['videoItem'].disabled = 'disabled';
  358. appendMyElement(saver['videoMenu'], saver['videoItem']);
  359. for (var i = 0; i < videosAdaptiveDASHMuxed.length; i++) {
  360. saver['videoItem'] = createMyElement('option', {value: videosAdaptiveDASHMuxed[i], textContent: videosAdaptiveDASHMuxed[i]});
  361. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', cursor: 'pointer'});
  362. appendMyElement(saver['videoMenu'], saver['videoItem']);
  363. }
  364. }
  365. else {
  366. for (var videoCode in saver['videoList']) {
  367. if (saver['videoList'][videoCode] == 'DASH') delete saver['videoList'][videoCode];
  368. }
  369. }
  370. }
  371. if (videosExtra.length > 0) {
  372. saver['videoItem'] = createMyElement('option', {value: 'Extra', textContent: 'Extra'});
  373. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', color: '#FF0000'});
  374. saver['videoItem'].disabled = 'disabled';
  375. appendMyElement(saver['videoMenu'], saver['videoItem']);
  376. for (var i = 0; i < videosExtra.length; i++) {
  377. saver['videoItem'] = createMyElement('option', {value: videosExtra[i], textContent: videosExtra[i]});
  378. styleMyElement(saver['videoItem'], {fontSize: '14px', fontWeight: 'bold', cursor: 'pointer'});
  379. appendMyElement(saver['videoMenu'], saver['videoItem']);
  380. }
  381. }
  382.  
  383. /* Panel Options Button */
  384. saver['buttonOptions'] = createMyElement('div', {title: '{Options: click to show the available options}'}, 'click', function() {
  385. if (saver['showsOptions']) {
  386. saver['showsOptions'] = false;
  387. styleMyElement(saver['optionsContent'], {display: 'none'})
  388. }
  389. else {
  390. saver['showsOptions'] = true;
  391. styleMyElement(saver['optionsContent'], {display: 'block'})
  392. }
  393. });
  394. styleMyElement(saver['buttonOptions'], {width: '1px', height: '14px', display: 'inline-block', paddingTop: '3px', borderLeft: '3px dotted #777777', lineHeight: 'normal', verticalAlign: 'middle', marginLeft: '20px', cursor: 'pointer', boxSizing: 'content-box'});
  395. appendMyElement(saver['saverPanel'], saver['buttonOptions']);
  396.  
  397. /* Panel Save Button */
  398. saver['buttonSave'] = createMyElement('div', {title: '{Save: click to download the selected video format}'}, 'click', function() {
  399. saveMyVideo();
  400. });
  401. styleMyElement(saver['buttonSave'], {width: '0px', height: '0px', display: 'inline-block', borderLeft: '8px solid transparent', borderRight: '8px solid transparent', borderTop: '15px solid #777777', borderBottom: '0px solid #777777', lineHeight: 'normal', verticalAlign: 'middle', marginTop: '2px', marginLeft: '20px', cursor: 'pointer', boxSizing: 'content-box'});
  402. appendMyElement(saver['saverPanel'], saver['buttonSave']);
  403.  
  404. /* Panel Save Button Link */
  405. saver['buttonSaveLink'] = createMyElement('div', {title: '{Save: right click & save as to download the selected video format}'});
  406. styleMyElement(saver['buttonSaveLink'], {display: 'inline-block', color: '#777777', fontSize: '14px', fontWeight: 'bold', lineHeight: 'normal', verticalAlign: 'middle', marginLeft: '5px', marginBottom: '2px', boxSizing: 'content-box'});
  407. appendMyElement(saver['saverPanel'], saver['buttonSaveLink']);
  408.  
  409. /* Disable Features */
  410. if (saver['videoDefinitions'].length < 2) feature['definition'] = false;
  411. if (saver['videoContainers'].length < 2) feature['container'] = false;
  412.  
  413. /* Select The Video */
  414. if (feature['definition'] || feature['container'] || feature['openpagelink']) {
  415. if (!option['definition'] || saver['videoDefinitions'].indexOf(option['definition']) == -1) option['definition'] = saver['videoSave'].replace(/Definition.*/, 'Definition');
  416. if (!option['container'] || saver['videoContainers'].indexOf(option['container']) == -1) option['container'] = saver['videoSave'].replace(/.*\s/, '');
  417. selectMyVideo();
  418. }
  419.  
  420. /* Save The Video On Autosave */
  421. if (option['autosave']) saveMyVideo();
  422.  
  423. /* Panel Options */
  424. saver['optionsContent'] = createMyElement('div');
  425. styleMyElement(saver['optionsContent'], {display: 'none', fontSize: '14px', fontWeight: 'bold', padding: '10px', textAlign: 'center', boxSizing: 'content-box'});
  426. appendMyElement(saver['saverPanel'], saver['optionsContent']);
  427.  
  428. /* Options Object => option: [label, options, new line, change video] */
  429. var options = {
  430. 'definition': ['Definition', saver['videoDefinitions'], true, true],
  431. 'container': ['Container', saver['videoContainers'], false, true],
  432. 'openpagelink': ['Open Page Link', ['On', 'Off'], true, true],
  433. 'autosave': ['Autosave', ['On', 'Off'], true, true],
  434. 'showsavelink': ['Show Save Link', ['On', 'Off'], false, true],
  435. 'savedash': ['Save DASH (Video With Audio)', ['On', 'Off'], true, false]
  436. };
  437.  
  438. /* Options */
  439. var optionsBox, optionBox, optionLabel, optionMenu, optionMenuItem;
  440. for (var o in options) {
  441. if (feature[o] === false) continue;
  442. if (options[o][2]) {
  443. optionsBox = createMyElement('div');
  444. styleMyElement(optionsBox, {display: 'block', padding: '5px 0px 5px 0px'});
  445. appendMyElement(saver['optionsContent'], optionsBox);
  446. }
  447. optionBox = createMyElement('div');
  448. styleMyElement(optionBox, {display: 'inline-block'});
  449. optionLabel = createMyElement('div', {textContent: options[o][0]});
  450. styleMyElement(optionLabel, {display: 'inline-block', color: '#777777', marginRight: '10px', verticalAlign: 'middle'});
  451. optionMenu = createMyElement('select', {id: 'savetube-option-' + o}, 'change', function() {
  452. var id = this.id.replace('savetube-option-', '');
  453. if (this.value == 'On' || this.value == 'Off') {
  454. option[id] = (this.value == 'On') ? true : false;
  455. }
  456. else {
  457. option[id] = this.value;
  458. }
  459. setMyOptions(id, option[id]);
  460. if (options[id][3]) {
  461. if (saver['isShowingLink']) {
  462. cleanMyElement(saver['buttonSaveLink'], false);
  463. saver['isShowingLink'] = false;
  464. }
  465. selectMyVideo();
  466. if (option['autosave']) {
  467. saveMyVideo();
  468. }
  469. }
  470. });
  471. styleMyElement(optionMenu, {display: 'inline-block', width: 'auto', height: '20px', color: '#777777', backgroundColor: '#FFFFFF', border: '1px solid #CCCCCC', fontFamily: 'inherit', fontSize: '14px', fontWeight: 'bold', marginRight: '10px', verticalAlign: 'middle'});
  472. appendMyElement(optionBox, optionLabel);
  473. appendMyElement(optionBox, optionMenu);
  474. appendMyElement(optionsBox, optionBox);
  475. for (var i = 0; i < options[o][1].length; i++) {
  476. optionMenuItem = createMyElement('option', {value: options[o][1][i], textContent: options[o][1][i]});
  477. styleMyElement(optionMenuItem, {fontSize: '14px', fontWeight: 'bold', cursor: 'pointer'});
  478. appendMyElement(optionMenu, optionMenuItem);
  479. }
  480. if (optionMenu.value == 'On' || optionMenu.value == 'Off') {
  481. if (option[o]) optionMenu.value = 'On';
  482. else optionMenu.value = 'Off';
  483. }
  484. else {
  485. optionMenu.value = option[o];
  486. }
  487. }
  488.  
  489. /* Hide */
  490. if (option['hidden']) {
  491. toggleMySaver('hide');
  492. }
  493. }
  494.  
  495. function toggleMySaver(toggle) {
  496. if (toggle == 'hide') {
  497. styleMyElement(saver['saverPanel'], {right: '-' + (saver['saverPanel'].offsetWidth - 40) + 'px', backgroundColor: 'transparent', borderColor: '#777777'});
  498. styleMyElement(saver['buttonHide'], {borderTop: '8px solid transparent', borderBottom: '8px solid transparent', borderLeft: '0px solid #777777', borderRight: '15px solid #777777'});
  499. }
  500. else {
  501. if (option['hidden']) {
  502. styleMyElement(saver['saverPanel'], {right: '25px', backgroundColor: '#FFFFFF', borderColor: '#CCCCCC', transition: 'right 2s, background-color 5s, border-color 5s'});
  503. styleMyElement(saver['buttonHide'], {borderTop: '8px solid transparent', borderBottom: '8px solid transparent', borderLeft: '15px solid #777777', borderRight: '0px solid #777777'});
  504. option['hidden'] = false;
  505. }
  506. else {
  507. styleMyElement(saver['saverPanel'], {right: '-' + (saver['saverPanel'].offsetWidth - 40) + 'px', backgroundColor: 'transparent', borderColor: '#777777', transition: 'right 2s, background-color 5s, border-color 5s'});
  508. styleMyElement(saver['buttonHide'], {borderTop: '8px solid transparent', borderBottom: '8px solid transparent', borderLeft: '0px solid #777777', borderRight: '15px solid #777777'});
  509. option['hidden'] = true;
  510. }
  511. setMyOptions('hidden', option['hidden']);
  512. }
  513. }
  514.  
  515. function setMyOptions(key, value) {
  516. key = page.site + '_' + userscript.toLowerCase() + '_' + key;
  517. try {
  518. localStorage.setItem(key, value);
  519. if (localStorage.getItem(key) == value) return;
  520. else throw false;
  521. }
  522. catch(e) {
  523. var date = new Date();
  524. date.setTime(date.getTime() + (356*24*60*60*1000));
  525. var expires = '; expires=' + date.toGMTString();
  526. page.doc.cookie = key + '=' + value + expires + '; path=/';
  527. }
  528. }
  529.  
  530. function getMyOptions() {
  531. for (var opt in option) {
  532. var key = page.site + '_' + userscript.toLowerCase() + '_' + opt;
  533. try {
  534. if (localStorage.getItem(key)) {
  535. option[opt] = localStorage.getItem(key);
  536. continue;
  537. }
  538. else throw false;
  539. }
  540. catch(e) {
  541. var cookies = page.doc.cookie.split(';');
  542. for (var i=0; i < cookies.length; i++) {
  543. var cookie = cookies[i];
  544. while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
  545. option[opt] = (cookie.indexOf(key) == 0) ? cookie.substring(key.length + 1, cookie.length) : option[opt];
  546. }
  547. }
  548. }
  549. var boolOptions = ['openpagelink', 'autosave', 'showsavelink', 'savedash', 'hidden'];
  550. for (var i = 0; i < boolOptions.length; i++) {
  551. option[boolOptions[i]] = (option[boolOptions[i]] === true || option[boolOptions[i]] == 'true') ? true : false;
  552. }
  553. }
  554.  
  555. function selectMyVideo() {
  556. if (option['openpagelink']) {
  557. saver['videoSave'] = 'Page Link';
  558. }
  559. else {
  560. var vdoCont = (option['container'] != 'Any') ? [option['container']] : saver['videoContainers'];
  561. var vdoDef = saver['videoDefinitions'];
  562. var vdoList = {};
  563. for (var vC = 0; vC < vdoCont.length; vC++) {
  564. if (vdoCont[vC] != 'Any') {
  565. for (var vD = 0; vD < vdoDef.length; vD++) {
  566. var format = vdoDef[vD] + ' ' + vdoCont[vC];
  567. if (!vdoList[vdoDef[vD]]) {
  568. for (var vL in saver['videoList']) {
  569. if (vL == format) {
  570. vdoList[vdoDef[vD]] = vL;
  571. break;
  572. }
  573. }
  574. }
  575. }
  576. }
  577. }
  578. var vdoDef2 = [];
  579. var keepDef = false;
  580. for (var vD = 0; vD < vdoDef.length; vD++) {
  581. if (vdoDef[vD] == option['definition'] && keepDef == false) keepDef = true;
  582. if (keepDef == true) vdoDef2.push(vdoDef[vD])
  583. }
  584. for (var vD = 0; vD < vdoDef2.length; vD++) {
  585. if (vdoList[vdoDef2[vD]]) {
  586. saver['videoSave'] = vdoList[vdoDef2[vD]];
  587. break;
  588. }
  589. }
  590. }
  591. saver['videoMenu'].value = saver['videoSave'];
  592. }
  593.  
  594. function saveMyVideo() {
  595. var vdoURL = saver['videoList'][saver['videoSave']];
  596. var vdoDef = ' (' + saver['videoSave'].split(' ').slice(0, -1).join('').match(/[A-Z]/g).join('') + ')';
  597. var vdoExt = saver['videoSave'].split(' ').slice(-1).join('');
  598. var vdoTle = (saver['videoTitle']) ? saver['videoTitle'] : page.url.replace(/https?:\/\//, '').replace(/[^0-9a-zA-Z]/g, '-');
  599. if (saver['videoSave'] == 'Page Link' || vdoURL == 'DASH' || (vdoExt == 'M3U8' && !option['showsavelink'])) {
  600. var vdoV, vdoA;
  601. if (saver['videoSave'] == 'Page Link' || vdoExt == 'M3U8') {
  602. vdoV = vdoURL;
  603. vdoA = '';
  604. vdoDef = '';
  605. }
  606. else {
  607. if (saver['videoSave'].indexOf('MP4') != -1) {
  608. vdoV = saver['videoList'][saver['videoSave'].replace('MP4', 'Video MP4')];
  609. vdoA = saver['videoList']['Medium Bitrate Audio MP4'] || saver['videoList'][saver['videoSave'].replace('MP4', 'Audio MP4')];
  610. }
  611. else {
  612. vdoV = saver['videoList'][saver['videoSave'].replace('WebM', 'Video WebM')];
  613. vdoA = saver['videoList']['High Bitrate Audio WebM'] || saver['videoList']['Medium Bitrate Audio WebM'] || saver['videoList']['Medium Bitrate Audio MP4'];
  614. }
  615. }
  616. var vdoT = vdoTle + vdoDef;
  617. page.win.location.href = 'savetube:' + vdoT + 'SEPARATOR' + vdoV + 'SEPARATOR' + vdoA;
  618. }
  619. else {
  620. var vdoLnk = createMyElement('a', {href: vdoURL, target: '_blank', textContent: '[Link]'});
  621. styleMyElement(vdoLnk, {color: '#777777', textDecoration: 'underline'});
  622. var vdoT = vdoTle + vdoDef;
  623. if (option['showsavelink'] || vdoExt == 'M3U8') {
  624. appendMyElement(saver['buttonSaveLink'], vdoLnk);
  625. saver['isShowingLink'] = true;
  626. if (page.site == 'youtube' && saver['videoSave'] == 'High Definition MP4') {
  627. if (!page.win.URL || !page.win.URL.createObjectURL) {
  628. page.win.location.href = vdoURL + '&title=' + vdoT;
  629. }
  630. }
  631. }
  632. else {
  633. if (!saver['isSaving']) {
  634. if (page.site == 'youtube' && saver['videoSave'] == 'High Definition MP4') {
  635. page.win.location.href = vdoURL + '&title=' + vdoT;
  636. }
  637. else {
  638. if (page.win.URL && page.win.URL.createObjectURL) {
  639. saver['isSaving'] = true;
  640. styleMyElement(saver['buttonSave'], {borderBottomWidth: '1px', cursor: 'none'});
  641. var vdoLnkBlob, vdoBlob, vdoBlobLnk;
  642. vdoLnkBlob = createMyElement('a');
  643. styleMyElement(vdoLnkBlob, {display: 'none'});
  644. appendMyElement(page.body, vdoLnkBlob);
  645. var XHRequest = new XMLHttpRequest();
  646. XHRequest.open('GET', vdoURL);
  647. XHRequest.responseType = 'arraybuffer';
  648. XHRequest.onload = function() {
  649. if (this.status === 200 && this.response) {
  650. vdoBlob = new Blob([this.response], {type: mediatypes[vdoExt]});
  651. vdoBlobLnk = page.win.URL.createObjectURL(vdoBlob);
  652. modifyMyElement(vdoLnkBlob, {href: vdoBlobLnk, target: '_blank', download: vdoT + '.' + vdoExt.toLowerCase()});
  653. vdoLnkBlob.click();
  654. page.win.URL.revokeObjectURL(vdoBlobLnk);
  655. removeMyElement(page.body, vdoLnkBlob);
  656. saver['isSaving'] = false;
  657. styleMyElement(saver['buttonSave'], {borderBottomWidth: '0px', cursor: 'pointer'});
  658. }
  659. else {
  660. saver['isSaving'] = false;
  661. styleMyElement(saver['buttonSave'], {borderBottomWidth: '0px', cursor: 'pointer'});
  662. if (!saver['isShowingLink']) {
  663. appendMyElement(saver['buttonSaveLink'], vdoLnk);
  664. saver['isShowingLink'] = true;
  665. }
  666. }
  667. }
  668. XHRequest.onerror = function() {
  669. saver['isSaving'] = false;
  670. styleMyElement(saver['buttonSave'], {borderBottomWidth: '0px', cursor: 'pointer'});
  671. if (!saver['isShowingLink']) {
  672. appendMyElement(saver['buttonSaveLink'], vdoLnk);
  673. saver['isShowingLink'] = true;
  674. }
  675. }
  676. XHRequest.send();
  677. }
  678. else {
  679. appendMyElement(saver['buttonSaveLink'], vdoLnk);
  680. saver['isShowingLink'] = true;
  681. }
  682. }
  683. }
  684. }
  685. }
  686. }
  687.  
  688. function showMyMessage(cause, content) {
  689. if (cause == '!content') {
  690. modifyMyElement(saver['saverMessage'], {innerHTML: 'Couldn\'t get the videos content. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'});
  691. }
  692. else if (cause == '!videos') {
  693. modifyMyElement(saver['saverMessage'], {innerHTML: 'Couldn\'t get any video. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'});
  694. }
  695. else if (cause == '!support') {
  696. modifyMyElement(saver['saverMessage'], {innerHTML: 'This video uses the RTMP protocol which is not supported.'});
  697. }
  698. else if (cause == 'embed') {
  699. modifyMyElement(saver['saverMessage'], {innerHTML: 'This is an embedded video. You can get it <a href="' + content + '" style="color:#00892C">here</a>.'});
  700. }
  701. else if (cause == 'other') {
  702. modifyMyElement(saver['saverMessage'], {innerHTML: content});
  703. }
  704. }
  705.  
  706.  
  707. // ==========Websites========== //
  708.  
  709. function SaveTube() {
  710.  
  711. // =====YouTube===== //
  712.  
  713. if (page.url.indexOf('youtube.com/watch') != -1) {
  714.  
  715. /* Video Availability */
  716. if (getMyContent(page.url, /"playabilityStatus":\{"status":"(ERROR|UNPLAYABLE)"/)) return;
  717.  
  718. /* Get Video ID */
  719. var ytVideoId = parseMyContent(page.url, /(?:\?|&)v=(.*?)(&|$)/);
  720.  
  721. /* Create Saver */
  722. var ytVideoList = {};
  723. var ytDefaultVideo = 'Low Definition MP4';
  724. function ytCreateSaver(data) {
  725. /* Get Title */
  726. var ytVideoTitle = getMyContent(page.url, /"videoDetails".*?"title":"(.*?)"/);
  727. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, /"title":\{"runs":\[\{"text":"(.*?)"/);
  728. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, /meta\s+property="og:title"\s+content="(.*?)"/);
  729. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, /meta\s+itemprop="name"\s+content="(.*?)"/);
  730. if (ytVideoTitle) {
  731. var ytVideoAuthor = getMyContent(page.url, /"(?:author|name)":\s*"(.*?)"/);
  732. if (ytVideoAuthor) ytVideoTitle = ytVideoTitle + ' by ' + ytVideoAuthor;
  733. ytVideoTitle = cleanMyContent(ytVideoTitle, false, true);
  734. }
  735. /* Create Saver */
  736. if (data) {
  737. saver = data;
  738. }
  739. else {
  740. saver = {
  741. 'videoList': ytVideoList,
  742. 'videoDefinitions': ['Ultra High Definition', 'Quad High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'],
  743. 'videoContainers': ['MP4', 'WebM', 'M3U8', 'Any'],
  744. 'videoSave': ytDefaultVideo,
  745. 'videoTitle': ytVideoTitle
  746. };
  747. }
  748. createMySaver();
  749. }
  750.  
  751. /* Parameter Unscrambler */
  752. var ytScriptUrl;
  753. var ytUnscrambleParam = {};
  754. function ytGetUnscrambleParamFunc() {
  755. var ytMainFuncName, ytMainFuncBody, ytExtraFuncName, ytExtraFuncBody;
  756. /* s */
  757. ytMainFuncName = getMyContent(ytScriptUrl, /c&&\([\w$]+=([\w$]+)\(decodeURIComponent/);
  758. if (ytMainFuncName) {
  759. ytMainFuncBody = getMyContent(ytScriptUrl, new RegExp(';' + ytMainFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\};'));
  760. if (ytMainFuncBody) {
  761. ytExtraFuncName = parseMyContent(ytMainFuncBody, /([\w$]+)\.[\w$]+\(\w,[0-9]+\)/);
  762. if (ytExtraFuncName) {
  763. ytExtraFuncBody = getMyContent(ytScriptUrl, new RegExp('var\\s+' + ytExtraFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};'));
  764. if (ytExtraFuncBody) {
  765. ytMainFuncBody = 'var ' + ytExtraFuncName + '={' + ytExtraFuncBody + '};' + ytMainFuncBody;
  766. ytMainFuncBody = 'try {' + ytMainFuncBody + '} catch(e) {return null}';
  767. ytUnscrambleParam['s'] = new Function('a', ytMainFuncBody);
  768. }
  769. }
  770. }
  771. }
  772. /* n */
  773. ytMainFuncName = getMyContent(ytScriptUrl, /&&\([\w$]+=([\w$]+)\(\w+\),\w+\.set\("n"/);
  774. if (!ytMainFuncName) ytMainFuncName = getMyContent(ytScriptUrl, /set\("n".*?\|\|([\w$]+)\(/);
  775. if (ytMainFuncName) {
  776. ytMainFuncBody = getMyContent(ytScriptUrl, new RegExp(';' + ytMainFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\};'));
  777. if (ytMainFuncBody) {
  778. ytMainFuncBody = 'try {' + ytMainFuncBody + '} catch(e) {return null}';
  779. ytUnscrambleParam['n'] = new Function('a', ytMainFuncBody);
  780. }
  781. }
  782. }
  783.  
  784. /* Get Videos Content */
  785. var ytVideosContent = {};
  786. var ytVideoInfoKey = 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8';
  787. var ytVideoInfoUrl = page.win.location.protocol + '//' + page.win.location.hostname + '/youtubei/v1/player?key=' + ytVideoInfoKey;
  788. var ytVideoInfoClientVersion = {'WEB': '2.11111111', 'ANDROID': '16.49'};
  789. var ytVideoInfoDataRequest = {};
  790. function ytGetVideos(api, client, embed) {
  791. if (api) {
  792. ytVideoInfoDataRequest = {};
  793. ytVideoInfoDataRequest['context'] = {};
  794. ytVideoInfoDataRequest['context']['client'] = {};
  795. ytVideoInfoDataRequest['context']['client']['clientName'] = client;
  796. ytVideoInfoDataRequest['context']['client']['clientVersion'] = ytVideoInfoClientVersion[client];
  797. if (embed) {
  798. ytVideoInfoDataRequest['context']['client']['clientScreen'] = 'EMBED';
  799. ytVideoInfoDataRequest['context']['thirdParty'] = {};
  800. ytVideoInfoDataRequest['context']['thirdParty']['embedUrl'] = 'https://www.youtube.com';
  801. }
  802. ytVideoInfoDataRequest['videoId'] = ytVideoId;
  803. ytVideosContent = getMyContent(ytVideoInfoUrl + '|' + JSON.stringify(ytVideoInfoDataRequest));
  804. }
  805. else {
  806. ytVideosContent = getMyContent(page.url, /ytInitialPlayerResponse\s*=\s*({.*?});/);
  807. }
  808. try {
  809. ytVideosContent = JSON.parse(ytVideosContent);
  810. }
  811. catch(e) {
  812. ytVideosContent = {};
  813. }
  814. ytVideosContent = (ytVideosContent['streamingData']) ? ytVideosContent['streamingData'] : {};
  815. }
  816.  
  817. /* Get Videos */
  818. ytGetVideos(true, 'ANDROID', false);
  819. if (!ytVideosContent['formats'] && ytVideosContent['hlsManifestUrl']) {
  820. var ytHLSFormats = {
  821. '92': 'Very Low Definition M3U8',
  822. '93': 'Low Definition M3U8',
  823. '94': 'Standard Definition M3U8',
  824. '95': 'High Definition M3U8',
  825. '96': 'Full High Definition M3U8'
  826. };
  827. ytVideoList["Multi Definition M3U8"] = ytVideosContent['hlsManifestUrl'];
  828. var ytHLSVideos, ytHLSVideo, ytVideoCode, myVideoCode;
  829. ytHLSVideos = getMyContent(ytVideosContent['hlsManifestUrl'], /(http.*?m3u8)/g);
  830. if (ytHLSVideos) {
  831. for (var i = 0; i < ytHLSVideos.length; i++) {
  832. ytHLSVideo = ytHLSVideos[i];
  833. ytVideoCode = parseMyContent(ytHLSVideo, /\/itag\/(\d{1,3})\//);
  834. if (ytVideoCode) {
  835. myVideoCode = ytHLSFormats[ytVideoCode];
  836. if (myVideoCode) {
  837. ytVideoList[myVideoCode] = ytHLSVideo;
  838. }
  839. }
  840. }
  841. }
  842. ytDefaultVideo = 'Multi Definition M3U8';
  843. ytCreateSaver();
  844. }
  845. else {
  846. if (!ytVideosContent['formats']) {
  847. ytGetVideos(true, 'ANDROID', true);
  848. }
  849. if (!ytVideosContent['formats']) {
  850. ytGetVideos(false, 'WEB', false);
  851. }
  852. if (ytVideosContent['formats']) {
  853. var ytVideoFormats = {
  854. '18': 'Low Definition MP4',
  855. '22': 'High Definition MP4',
  856. '43': 'Low Definition WebM',
  857. '133': 'Very Low Definition Video MP4',
  858. '134': 'Low Definition Video MP4',
  859. '135': 'Standard Definition Video MP4',
  860. '136': 'High Definition Video MP4',
  861. '137': 'Full High Definition Video MP4',
  862. '140': 'Medium Bitrate Audio MP4',
  863. '242': 'Very Low Definition Video WebM',
  864. '243': 'Low Definition Video WebM',
  865. '244': 'Standard Definition Video WebM',
  866. '247': 'High Definition Video WebM',
  867. '248': 'Full High Definition Video WebM',
  868. '249': 'Low Bitrate Audio WebM',
  869. '250': 'Medium Bitrate Audio WebM',
  870. '251': 'High Bitrate Audio WebM',
  871. '264': 'Quad High Definition Video MP4',
  872. '271': 'Quad High Definition Video WebM',
  873. '272': 'Ultra High Definition Video WebM',
  874. '298': 'High Definition Video MP4',
  875. '299': 'Full High Definition Video MP4',
  876. '302': 'High Definition Video WebM',
  877. '303': 'Full High Definition Video WebM',
  878. '308': 'Quad High Definition Video WebM',
  879. '313': 'Ultra High Definition Video WebM',
  880. '315': 'Ultra High Definition Video WebM',
  881. '333': 'Standard Definition Video WebM',
  882. '334': 'High Definition Video WebM',
  883. '335': 'Full High Definition Video WebM',
  884. '337': 'Ultra High Definition Video WebM'
  885. };
  886. var ytVideoFound = false;
  887. var ytVideos = (ytVideosContent['adaptiveFormats']) ? ytVideosContent['formats'].concat(ytVideosContent['adaptiveFormats']) : ytVideosContent['formats']
  888. var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo, ytSign, ytSignP;
  889. for (var i = 0; i < ytVideos.length; i++) {
  890. if (ytVideos[i]['signatureCipher'] || ytVideos[i]['cipher']) {
  891. if (!ytScriptUrl) {
  892. ytScriptUrl = getMyContent(page.url, /"js(?:Url)?":\s*"(.*?)"/);
  893. if (!ytScriptUrl) {
  894. ytScriptUrl = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), /"js(?:Url)?":\s*"(.*?)"/);
  895. }
  896. if (ytScriptUrl && ytScriptUrl.indexOf('//') == -1) {
  897. ytScriptUrl = page.win.location.protocol + '//' + page.win.location.hostname + ytScriptUrl;
  898. ytGetUnscrambleParamFunc();
  899. }
  900. else {
  901. ytCreateSaver({'warnMess': 'other', 'warnContent': '<b>SaveTube:</b> Couldn\'t get the signature link. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'});
  902. break;
  903. }
  904. }
  905. ytVideo = ytVideos[i]['signatureCipher'] || ytVideos[i]['cipher'];
  906. ytVideo = cleanMyContent(ytVideo, true);
  907. ytVideoParse = ytVideo.match(/(.*)(url=.*$)/);
  908. if (ytVideoParse) {
  909. ytVideo = ytVideoParse[2] + '&' + ytVideoParse[1];
  910. ytVideo = ytVideo.replace(/url=/, '').replace(/&$/, '');
  911. }
  912. ytSParam = parseMyContent(ytVideo, /&s=(.*?)(&|$)/);
  913. if (ytSParam && ytUnscrambleParam['s']) {
  914. ytSParam = ytUnscrambleParam['s'](ytSParam);
  915. if (ytSParam) {
  916. ytSParamName = parseMyContent(ytVideo, /&sp=(.*?)(&|$)/);
  917. ytSParamName = (ytSParamName) ? ytSParamName : ((/&lsig=/.test(ytVideo)) ? 'sig' : 'signature');
  918. ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&' + ytSParamName + '=' + ytSParam + '$1');
  919. }
  920. else ytVideo = '';
  921. }
  922. else ytVideo = '';
  923. }
  924. else {
  925. ytVideo = ytVideos[i]['url'];
  926. ytVideo = cleanMyContent(ytVideo, true);
  927. if (/&sig=/.test(ytVideo) && !/&lsig=/.test(ytVideo)) {
  928. ytVideo = ytVideo.replace(/&sig=/, '&signature=');
  929. }
  930. }
  931. ytVideoCode = ytVideos[i]['itag'];
  932. if (!ytVideoCode) continue;
  933. myVideoCode = ytVideoFormats[ytVideoCode];
  934. if (!myVideoCode) continue;
  935. if (myVideoCode.indexOf('Video') != -1) {
  936. if (ytVideo.indexOf('source=yt_otf') != -1) continue;
  937. }
  938. ytVideo = cleanMyContent(ytVideo, true);
  939. ytNParam = parseMyContent(ytVideo, /&n=(.*?)(&|$)/);
  940. if (ytNParam && ytUnscrambleParam['n']) {
  941. ytNParam = ytUnscrambleParam['n'](ytNParam);
  942. if (ytNParam) {
  943. ytVideo = ytVideo.replace(/&n=.*?(&|$)/, '&n=' + ytNParam + '$1');
  944. }
  945. }
  946. if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes';
  947. if (ytVideo && ytVideo.indexOf('http') == 0) {
  948. if (!ytVideoFound) ytVideoFound = true;
  949. ytVideoList[myVideoCode] = ytVideo;
  950. }
  951. }
  952. if (ytVideoFound) {
  953. /* DASH */
  954. if (ytVideoList['Medium Bitrate Audio MP4'] || ytVideoList['Medium Bitrate Audio WebM']) {
  955. for (var myVideoCode in ytVideoList) {
  956. if (myVideoCode.indexOf('Video') != -1) {
  957. if (!ytVideoList[myVideoCode.replace(' Video', '')]) {
  958. ytVideoList[myVideoCode.replace(' Video', '')] = 'DASH';
  959. }
  960. }
  961. }
  962. }
  963. ytCreateSaver();
  964. }
  965. else {
  966. ytCreateSaver({'warnMess': '!videos'});
  967. }
  968. }
  969. else {
  970. ytCreateSaver({'warnMess': '!content'});
  971. }
  972. }
  973.  
  974. }
  975.  
  976. // =====DailyMotion===== //
  977.  
  978. else if (page.url.indexOf('dailymotion.com/video') != -1) {
  979.  
  980. /* Video Source */
  981. var dmMetadataUrl = page.url.replace(/\/video\//, "/player/metadata/video/");
  982.  
  983. /* Video Availability */
  984. if (getMyContent(dmMetadataUrl, /"error":\{"title":"(.*?)"/)) return;
  985. if (getMyContent(dmMetadataUrl, /"error_title":"(.*?)"/)) return;
  986.  
  987. /* Get Video Title */
  988. var dmVideoTitle = getMyContent(dmMetadataUrl, /"title":"((\\"|[^"])*?)"/);
  989. if (dmVideoTitle) {
  990. var dmVideoAuthor = getMyContent(dmMetadataUrl, /"screenname":"((\\"|[^"])*?)"/);
  991. if (dmVideoAuthor) dmVideoTitle = dmVideoTitle + ' by ' + dmVideoAuthor;
  992. dmVideoTitle = cleanMyContent(dmVideoTitle, false, true);
  993. }
  994.  
  995. /* Get Videos Content */
  996. var dmVideosContent = getMyContent(dmMetadataUrl, /"qualities":\{(.*?)\]\},/);
  997.  
  998. /* Get Videos */
  999. if (dmVideosContent) {
  1000. var dmVideoFormats = {'auto': 'Low Definition MP4', '240': 'Very Low Definition MP4', '380': 'Low Definition MP4',
  1001. '480': 'Standard Definition MP4', '720': 'High Definition MP4', '1080': 'Full High Definition MP4'};
  1002. var dmVideoList = {};
  1003. var dmVideoFound = false;
  1004. var myVideoCode, dmVideo;
  1005. for (var dmVideoCode in dmVideoFormats) {
  1006. dmVideo = parseMyContent(dmVideosContent, new RegExp('"' + dmVideoCode + '".*?"type":"video.*?mp4","url":"(.*?)"'));
  1007. if (dmVideo) {
  1008. if (!dmVideoFound) dmVideoFound = true;
  1009. dmVideo = cleanMyContent(dmVideo, true);
  1010. myVideoCode = dmVideoFormats[dmVideoCode];
  1011. if (!dmVideoList[myVideoCode]) dmVideoList[myVideoCode] = dmVideo;
  1012. }
  1013. }
  1014. if (!dmVideoFound) {
  1015. var dmHLSManifest = parseMyContent(dmVideosContent, /"type":"application.*?mpegURL","url":"(.*?)"/);
  1016. if (dmHLSManifest) {
  1017. dmVideoFound = true;
  1018. dmHLSManifest = cleanMyContent(dmHLSManifest, true);
  1019. dmVideoList["Multi Definition M3U8"] = dmHLSManifest;
  1020. for (var dmVideoCode in dmVideoFormats) {
  1021. dmVideo = getMyContent(dmHLSManifest, new RegExp('NAME="' + dmVideoCode + '.*?",PROGRESSIVE-URI="(.*?)(#EXT|$)'));
  1022. if (dmVideo) {
  1023. myVideoCode = dmVideoFormats[dmVideoCode];
  1024. if (!dmVideoList[myVideoCode] && dmVideo.split('"')[0]) {
  1025. dmVideoList[myVideoCode] = dmVideo.split('"')[0];
  1026. }
  1027. myVideoCode = dmVideoFormats[dmVideoCode].replace('MP4', 'M3U8');
  1028. if (!dmVideoList[myVideoCode] && dmVideo.split('"')[1]) {
  1029. dmVideoList[myVideoCode] = dmVideo.split('"')[1];
  1030. }
  1031. }
  1032. }
  1033. }
  1034. }
  1035.  
  1036. if (dmVideoFound) {
  1037. /* Create Saver */
  1038. var dmDefaultVideo = 'Low Definition MP4';
  1039. if (!dmVideoList[dmDefaultVideo]) dmDefaultVideo = 'Low Definition M3U8';
  1040. saver = {
  1041. 'videoList': dmVideoList,
  1042. 'videoDefinitions': ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'],
  1043. 'videoContainers': ['MP4'],
  1044. 'videoSave': dmDefaultVideo,
  1045. 'videoTitle': dmVideoTitle
  1046. };
  1047. createMySaver();
  1048. }
  1049. else {
  1050. saver = {'warnMess': '!videos'};
  1051. createMySaver();
  1052. }
  1053. }
  1054. else {
  1055. saver = {'warnMess': '!content'};
  1056. createMySaver();
  1057. }
  1058.  
  1059. }
  1060.  
  1061. // =====Vimeo===== //
  1062.  
  1063. else if (page.url.indexOf('vimeo.com/') != -1) {
  1064.  
  1065. /* Page Type */
  1066. var viPageType = getMyContent(page.url, /meta\s+property="og:type"\s+content="(.*?)"/);
  1067. if (!viPageType || viPageType.indexOf('video') == -1) return;
  1068.  
  1069. /* Get Video Title */
  1070. var viVideoTitle;
  1071. if (viPageType.indexOf('video') != -1) {
  1072. viVideoTitle = getMyContent(page.url, /meta\s+property="og:title"\s+content="(.*?)"/);
  1073. }
  1074. else {
  1075. viVideoTitle = getMyContent(page.url, /"title":"((\\"|[^"])*?)"/);
  1076. }
  1077. if (viVideoTitle) {
  1078. viVideoTitle = viVideoTitle.replace(/\s*on\s*Vimeo$/, '');
  1079. var viVideoAuthor = getMyContent(page.url, /"display_name":"((\\"|[^"])*?)"/);
  1080. if (viVideoAuthor) viVideoTitle = viVideoTitle + ' by ' + viVideoAuthor;
  1081. viVideoTitle = cleanMyContent(viVideoTitle, false, true);
  1082. }
  1083.  
  1084. /* Get Content Source */
  1085. var viVideoSource = getMyContent(page.url, /config_url":"(.*?)"/);
  1086. if (viVideoSource) viVideoSource = cleanMyContent(viVideoSource, false);
  1087. else {
  1088. viVideoSource = getMyContent(page.url, /data-config-url="(.*?)"/);
  1089. if (viVideoSource) viVideoSource = viVideoSource.replace(/&amp;/g, '&');
  1090. }
  1091.  
  1092. /* Get Videos Content */
  1093. var viVideosContent;
  1094. if (viVideoSource) {
  1095. viVideosContent = getMyContent(viVideoSource, /"progressive":\[(.*?)\]/);
  1096. }
  1097.  
  1098. /* Get Videos */
  1099. if (viVideosContent) {
  1100. var viVideoFormats = {'1440p': 'Quad High Definition MP4', '1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '540p': 'Standard Definition MP4',
  1101. '480p': 'Standard Definition MP4', '360p': 'Low Definition MP4', '270p': 'Very Low Definition MP4', '240p': 'Very Low Definition MP4'};
  1102. var viVideoList = {};
  1103. var viVideoFound = false;
  1104. var viVideo, myVideoCode;
  1105. var viVideos = viVideosContent.split('},');
  1106. for (var i = 0; i < viVideos.length; i++) {
  1107. for (var viVideoCode in viVideoFormats) {
  1108. if (viVideos[i].indexOf('"quality":"' + viVideoCode + '"') != -1) {
  1109. viVideo = parseMyContent(viVideos[i], /"url":"(.*?)"/);
  1110. if (viVideo) {
  1111. if (!viVideoFound) viVideoFound = true;
  1112. myVideoCode = viVideoFormats[viVideoCode];
  1113. viVideoList[myVideoCode] = viVideo;
  1114. }
  1115. }
  1116. }
  1117. }
  1118.  
  1119. if (viVideoFound) {
  1120. /* Create Saver */
  1121. var viDefaultVideo = 'Low Definition MP4';
  1122. saver = {
  1123. 'videoList': viVideoList,
  1124. 'videoDefinitions': ['Quad High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'],
  1125. 'videoContainers': ['MP4'],
  1126. 'videoSave': viDefaultVideo,
  1127. 'videoTitle': viVideoTitle
  1128. };
  1129. createMySaver();
  1130. }
  1131. else {
  1132. saver = {'warnMess': '!videos'};
  1133. createMySaver();
  1134. }
  1135. }
  1136. else {
  1137. saver = {'warnMess': '!content'};
  1138. createMySaver();
  1139. }
  1140.  
  1141. }
  1142.  
  1143. // =====Veoh===== //
  1144.  
  1145. else if (page.url.indexOf('veoh.com/watch') != -1) {
  1146.  
  1147. /* Video Info */
  1148. var veVideoInfoUrl = page.url.replace(/\/watch\//, '/watch/getVideo/');
  1149.  
  1150. /* Get Video Availability */
  1151. if (getMyElement('', 'div', 'class', 'veoh-video-player-error', 0, false)) return;
  1152.  
  1153. /* Get Video Title */
  1154. var veVideoTitle = getMyContent(veVideoInfoUrl, /"title":"((\\"|[^"])*?)"/);
  1155. if (!veVideoTitle) {
  1156. veVideoTitle = getMyContent(page.url, /meta\s+name="og:title"\s+content="(.*?)"/);
  1157. }
  1158. if (veVideoTitle) veVideoTitle = cleanMyContent(veVideoTitle, false, true);
  1159.  
  1160. /* Get Videos Content */
  1161. var veVideosContent = getMyContent(veVideoInfoUrl, /"src"\s*:\s*\{(.*?)\}/);
  1162.  
  1163. /* Get Videos */
  1164. if (veVideosContent) {
  1165. var veVideoFormats = {'Regular': 'Low Definition MP4', 'HQ': 'Standard Definition MP4'};
  1166. var veVideoList = {};
  1167. var veVideoFound = false;
  1168. var veVideo, myVideoCode;
  1169. for (var veVideoCode in veVideoFormats) {
  1170. veVideo = parseMyContent(veVideosContent, new RegExp(veVideoCode + '":"(.*?)"'));
  1171. if (veVideo) {
  1172. if (!veVideoFound) veVideoFound = true;
  1173. myVideoCode = veVideoFormats[veVideoCode];
  1174. veVideoList[myVideoCode] = cleanMyContent(veVideo, false);
  1175. }
  1176. }
  1177.  
  1178. if (veVideoFound) {
  1179. /* Create Saver */
  1180. var veDefaultVideo = 'Low Definition MP4';
  1181. saver = {
  1182. 'videoList': veVideoList,
  1183. 'videoDefinitions': ['Standard Definition', 'Low Definition'],
  1184. 'videoContainers': ['MP4'],
  1185. 'videoSave': veDefaultVideo,
  1186. 'videoTitle': veVideoTitle
  1187. };
  1188. createMySaver();
  1189. }
  1190. else {
  1191. saver = {};
  1192. var ytVideoId = getMyContent(page.url, /youtube.com\/embed\/(.*?)("|\?)/);
  1193. if (!ytVideoId) ytVideoId = getMyContent(page.url, /"videoId":"yapi-(.*?)"/);
  1194. if (ytVideoId) {
  1195. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId;
  1196. saver['warnMess'] = 'embed';
  1197. saver['warnContent'] = ytVideoLink;
  1198. }
  1199. else saver['warnMess'] = '!videos';
  1200. createMySaver();
  1201. }
  1202. }
  1203. else {
  1204. saver = {'warnMess': '!content'};
  1205. createMySaver();
  1206. }
  1207.  
  1208. }
  1209.  
  1210. // =====IMDB===== //
  1211.  
  1212. else if (page.url.indexOf('imdb.com') != -1) {
  1213.  
  1214. /* Redirect To Video Page */
  1215. if (page.url.indexOf('/video/') == -1 && page.url.indexOf('/videoplayer/') == -1) {
  1216. page.doc.addEventListener('click', function(e) {
  1217. var p = e.target.parentNode;
  1218. while (p) {
  1219. if (p.tagName === 'A' && p.href.indexOf('/video/imdb') != -1) {
  1220. page.win.location.href = p.href.replace(/imdb\/inline.*/, '');
  1221. }
  1222. p = p.parentNode;
  1223. }
  1224. }, false);
  1225. return;
  1226. }
  1227.  
  1228. /* Get Video Title */
  1229. var imdbVideoTitle = getMyContent(page.url, /meta\s+property="og:title"\s+content="(.*?)"/);
  1230. if (imdbVideoTitle) imdbVideoTitle = cleanMyContent(imdbVideoTitle, false, true);
  1231.  
  1232. /* Get Data Key */
  1233. var imdbVideoId = page.url.replace(/^.*?\/(vi\d+).*/, '$1');
  1234. var imdbDataJSON = '{"type": "VIDEO_PLAYER", "subType": "FORCE_LEGACY", "id": "' + imdbVideoId + '"}';
  1235. var imdbDataKey = btoa(imdbDataJSON);
  1236.  
  1237. /* Get Videos Content */
  1238. var imdbVideosContent = getMyContent(page.url.replace(/video\/.*/, 've/data/VIDEO_PLAYBACK_DATA?key=' + imdbDataKey), '"videoLegacyEncodings":\\[(.*?)\\]', false);
  1239.  
  1240. /* Get Videos */
  1241. var imdbVideoList = {};
  1242. if (imdbVideosContent) {
  1243. var imdbVideoFormats = {'1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '480p': 'Standard Definition MP4',
  1244. '360p': 'Low Definition MP4', 'SD': 'Low Definition MP4', '240p': 'Very Low Definition MP4', 'AUTO': 'Multi Definition M3U8'};
  1245. var imdbVideoFound = false;
  1246. var myVideoCode, imdbVideo;
  1247. for (var imdbVideoCode in imdbVideoFormats) {
  1248. imdbVideo = parseMyContent(imdbVideosContent, new RegExp('"definition":"' + imdbVideoCode + '".*?"url":"(.*?)"'));
  1249. if (imdbVideo) {
  1250. imdbVideo = cleanMyContent(imdbVideo, false);
  1251. if (!imdbVideoFound) imdbVideoFound = true;
  1252. myVideoCode = imdbVideoFormats[imdbVideoCode];
  1253. if (!imdbVideoList[myVideoCode]) imdbVideoList[myVideoCode] = imdbVideo;
  1254. }
  1255. }
  1256.  
  1257. if (imdbVideoFound) {
  1258. /* Create Saver */
  1259. var imdbDefaultVideo = 'Low Definition MP4';
  1260. saver = {
  1261. 'videoList': imdbVideoList,
  1262. 'videoDefinitions': ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'],
  1263. 'videoContainers': ['MP4', 'M3U8', 'Any'],
  1264. 'videoSave': imdbDefaultVideo,
  1265. 'videoTitle': imdbVideoTitle
  1266. };
  1267. createMySaver();
  1268. }
  1269. else {
  1270. saver = {'warnMess': '!videos'};
  1271. createMySaver();
  1272. }
  1273. }
  1274. else {
  1275. saver = {'warnMess': '!content'};
  1276. createMySaver();
  1277. }
  1278.  
  1279. }
  1280.  
  1281. }
  1282.  
  1283.  
  1284. // ==========Run========== //
  1285.  
  1286. getMyOptions();
  1287. SaveTube();
  1288.  
  1289. page.win.setInterval(function() {
  1290. if (page.url != page.win.location.href.replace(page.win.location.hash, '')) {
  1291. if (saver['saverPanel'] && saver['saverPanel'].parentNode) {
  1292. removeMyElement(saver['saverPanel'].parentNode, saver['saverPanel']);
  1293. }
  1294. page.doc = page.win.document;
  1295. page.body = page.doc.body;
  1296. page.url = page.win.location.href.replace(page.win.location.hash, '');
  1297. SaveTube();
  1298. }
  1299. }, 500);
  1300.  
  1301. })();