SaveTube

Download videos from video sharing web sites.

当前为 2019-09-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SaveTube
  3. // @version 2019.09.21
  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://gaming.youtube.com*
  13. // @include https://gaming.youtube.com*
  14. // @include http://m.youtube.com*
  15. // @include https://m.youtube.com*
  16. // @include http://dailymotion.com*
  17. // @include http://www.dailymotion.com*
  18. // @include https://dailymotion.com*
  19. // @include https://www.dailymotion.com*
  20. // @include http://vimeo.com*
  21. // @include http://www.vimeo.com*
  22. // @include https://vimeo.com*
  23. // @include https://www.vimeo.com*
  24. // @include http://metacafe.com*
  25. // @include http://www.metacafe.com*
  26. // @include https://metacafe.com*
  27. // @include https://www.metacafe.com*
  28. // @include http://veoh.com*
  29. // @include http://www.veoh.com*
  30. // @include https://veoh.com*
  31. // @include https://www.veoh.com*
  32. // @include http://viki.com*
  33. // @include http://www.viki.com*
  34. // @include https://viki.com*
  35. // @include https://www.viki.com*
  36. // @include http://imdb.com*
  37. // @include http://www.imdb.com*
  38. // @include https://imdb.com*
  39. // @include https://www.imdb.com*
  40. // @noframes
  41. // @grant none
  42. // @run-at document-end
  43. // ==/UserScript==
  44.  
  45.  
  46. /*
  47.  
  48. Copyright (C) 2010 - 2019 Sebastian Luncan
  49.  
  50. This program is free software: you can redistribute it and/or modify
  51. it under the terms of the GNU General Public License as published by
  52. the Free Software Foundation, either version 3 of the License, or
  53. (at your option) any later version.
  54.  
  55. This program is distributed in the hope that it will be useful,
  56. but WITHOUT ANY WARRANTY; without even the implied warranty of
  57. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  58. GNU General Public License for more details.
  59.  
  60. You should have received a copy of the GNU General Public License
  61. along with this program. If not, see <http://www.gnu.org/licenses/>.
  62.  
  63. Website: http://sebaro.pro/savetube
  64. Contact: http://sebaro.pro/contact
  65.  
  66. */
  67.  
  68.  
  69. (function() {
  70.  
  71.  
  72. // Don't run on frames or iframes
  73. if (window.top != window.self) return;
  74.  
  75.  
  76. // ==========Variables========== //
  77.  
  78. // Userscript
  79. var userscript = 'SaveTube';
  80.  
  81. // Page
  82. var page = {win: window, doc: window.document, body: window.document.body, url: window.location.href, site: window.location.hostname.match(/([^.]+)\.[^.]+$/)[1]};
  83.  
  84. // Saver
  85. var saver = {};
  86. var feature = {'definition': true, 'container': true, 'autoget': false, 'dash': false};
  87. var option = {'definition': 'HD', 'container': 'MP4', 'autoget': false, 'dash': false};
  88. var sources = {};
  89.  
  90. // Links
  91. var website = 'http://sebaro.pro/savetube';
  92. var contact = 'http://sebaro.pro/contact';
  93.  
  94.  
  95. // ==========Functions========== //
  96.  
  97. function createMyElement(type, content, event, action, target) {
  98. var obj = page.doc.createElement(type);
  99. if (content) {
  100. if (type == 'div') obj.innerHTML = content;
  101. else if (type == 'option') {
  102. obj.value = content;
  103. obj.innerHTML = content;
  104. }
  105. }
  106. if (event == 'change') {
  107. if (target == 'video') {
  108. obj.addEventListener('change', function() {
  109. saver['videoSave'] = this.value;
  110. if (feature['autoget'] && saver['buttonGet'] == 'Get') {
  111. if (option['autoget']) getMyVideo();
  112. }
  113. else {
  114. modifyMyElement(saver['buttonGet'] , 'div', 'Get', false);
  115. }
  116. }, false);
  117. }
  118. }
  119. else if (event == 'click') {
  120. obj.addEventListener('click', function() {
  121. if (action == 'close') {
  122. removeMyElement(page.body, target);
  123. }
  124. else if (action == 'logo') {
  125. page.win.location.href = website;
  126. }
  127. else if (action == 'get') {
  128. getMyVideo();
  129. }
  130. else if (action == 'autoget') {
  131. option['autoget'] = (option['autoget']) ? false : true;
  132. if (option['autoget']) {
  133. styleMyElement(saver['buttonGet'], {display: 'none'});
  134. styleMyElement(saver['buttonAutoget'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  135. getMyVideo();
  136. }
  137. else {
  138. styleMyElement(saver['buttonGet'], {display: 'inline'});
  139. styleMyElement(saver['buttonAutoget'], {color: '#CCCCCC', textShadow: '0px 0px 0px'});
  140. }
  141. setMyOptions('autoget', option['autoget']);
  142. }
  143. else if (action == 'definition') {
  144. for (var itemDef = 0; itemDef < option['definitions'].length; itemDef++) {
  145. if (option['definitions'][itemDef].match(/[A-Z]/g).join('') == option['definition']) {
  146. var nextDef = (itemDef + 1 < option['definitions'].length) ? itemDef + 1 : 0;
  147. option['definition'] = option['definitions'][nextDef].match(/[A-Z]/g).join('');
  148. break;
  149. }
  150. }
  151. modifyMyElement(saver['buttonDefinition'], 'div', option['definition'], false);
  152. setMyOptions('definition', option['definition']);
  153. modifyMyElement(saver['buttonGet'] , 'div', 'Get', false);
  154. selectMyVideo();
  155. if (option['autoget']) getMyVideo();
  156. }
  157. else if (action == 'container') {
  158. for (var itemCont = 0; itemCont < option['containers'].length; itemCont++) {
  159. if (option['containers'][itemCont] == option['container']) {
  160. var nextCont = (itemCont + 1 < option['containers'].length) ? itemCont + 1 : 0;
  161. option['container'] = option['containers'][nextCont];
  162. break;
  163. }
  164. }
  165. modifyMyElement(saver['buttonContainer'], 'div', option['container'], false);
  166. setMyOptions('container', option['container']);
  167. modifyMyElement(saver['buttonGet'] , 'div', 'Get', false);
  168. selectMyVideo();
  169. if (option['autoget']) getMyVideo();
  170. }
  171. else if (action == 'dash') {
  172. option['dash'] = (option['dash']) ? false : true;
  173. if (option['dash']) {
  174. styleMyElement(saver['buttonDASH'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  175. }
  176. else {
  177. styleMyElement(saver['buttonDASH'], {color: '#CCCCCC', textShadow: '0px 0px 0px'});
  178. }
  179. setMyOptions('dash', option['dash']);
  180. }
  181. else if (action == 'move') {
  182. if (saver['saverPanel'].style.right == '25px') {
  183. styleMyElement(saver['saverPanel'], {left: '25px', right: 'auto'});
  184. modifyMyElement(saver['buttonMove'], 'div', '>', false);
  185. }
  186. else {
  187. styleMyElement(saver['saverPanel'], {left: 'auto', right: '25px'});
  188. modifyMyElement(saver['buttonMove'], 'div', '<', false);
  189. }
  190. }
  191. }, false);
  192. }
  193. return obj;
  194. }
  195.  
  196. function getMyElement(obj, type, from, value, child, content) {
  197. var getObj, chObj, coObj;
  198. var pObj = (!obj) ? page.doc : obj;
  199. if (type == 'body') getObj = pObj.body;
  200. else {
  201. if (from == 'id') getObj = pObj.getElementById(value);
  202. else if (from == 'class') getObj = pObj.getElementsByClassName(value);
  203. else if (from == 'tag') getObj = pObj.getElementsByTagName(type);
  204. else if (from == 'ns') {
  205. if (pObj.getElementsByTagNameNS) getObj = pObj.getElementsByTagNameNS(value, type);
  206. }
  207. else if (from == 'query') {
  208. if (child > 0) {
  209. if (pObj.querySelectorAll) getObj = pObj.querySelectorAll(value);
  210. }
  211. else {
  212. if (pObj.querySelector) getObj = pObj.querySelector(value);
  213. }
  214. }
  215. }
  216. chObj = (getObj && child >= 0) ? getObj[child] : getObj;
  217. if (content && chObj) {
  218. if (type == 'html' || type == 'body' || type == 'div' || type == 'option') coObj = chObj.innerHTML;
  219. else if (type == 'object') coObj = chObj.data;
  220. else if (type == 'img' || type == 'video' || type == 'embed') coObj = chObj.src;
  221. else coObj = chObj.textContent;
  222. return coObj;
  223. }
  224. else {
  225. return chObj;
  226. }
  227. }
  228.  
  229. function modifyMyElement(obj, type, content, clear) {
  230. if (content) {
  231. if (type == 'div') obj.innerHTML = content;
  232. else if (type == 'option') {
  233. obj.value = content;
  234. obj.innerHTML = content;
  235. }
  236. }
  237. if (clear) {
  238. if (obj.hasChildNodes()) {
  239. while (obj.childNodes.length >= 1) {
  240. obj.removeChild(obj.firstChild);
  241. }
  242. }
  243. }
  244. }
  245.  
  246. function styleMyElement(obj, styles) {
  247. for (var property in styles) {
  248. if (styles.hasOwnProperty(property)) obj.style[property] = styles[property];
  249. }
  250. }
  251.  
  252. function appendMyElement(parent, child) {
  253. parent.appendChild(child);
  254. }
  255.  
  256. function removeMyElement(parent, child) {
  257. parent.removeChild(child);
  258. }
  259.  
  260. function replaceMyElement(parent, orphan, child) {
  261. parent.replaceChild(orphan, child);
  262. }
  263.  
  264. function createMySaver() {
  265. /* Get My Options */
  266. getMyOptions();
  267.  
  268. /* The Panel */
  269. saver['saverPanel'] = createMyElement('div', '', '', '', '');
  270. styleMyElement(saver['saverPanel'], {position: 'fixed', backgroundColor: '#FFFFFF', padding: '5px 5px 10px 5px', bottom: '0px', right: '25px', zIndex: '2000000000', borderTop: '3px solid #EEEEEE', borderLeft: '3px solid #EEEEEE', borderRight: '3px solid #EEEEEE', borderRadius: '5px 5px 0px 0px'});
  271. appendMyElement(page.body, saver['saverPanel']);
  272.  
  273. /* Warnings */
  274. if (saver['warnMess']) {
  275. if (saver['warnContent']) showMyMessage(saver['warnMess'], saver['warnContent']);
  276. else showMyMessage(saver['warnMess']);
  277. return;
  278. }
  279.  
  280. /* Panel Items */
  281. var panelItemHeight = 18;
  282.  
  283. /* Panel Logo */
  284. saver['panelLogo'] = createMyElement('div', userscript, 'click', 'logo', '');
  285. saver['panelLogo'].title = '{SaveTube: click to visit the script web page}';
  286. styleMyElement(saver['panelLogo'], {height: panelItemHeight + 'px', border: '1px solid #32d132', borderRadius: '3px', padding: '0px 2px', marginRight: '3px', display: 'inline', color: '#32d132', fontSize: '12px', textShadow: '0px 1px 1px #AAAAAA', verticalAlign: 'middle', cursor: 'pointer'});
  287. appendMyElement(saver['saverPanel'], saver['panelLogo']);
  288.  
  289. /* Panel Video Menu */
  290. saver['videoMenu'] = createMyElement('select', '', 'change', '', 'video');
  291. saver['videoMenu'].title = '{Videos: select the video format for download}';
  292. styleMyElement(saver['videoMenu'], {width: '200px', height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px', display: 'inline', backgroundColor: 'inherit', color: '#336699', fontSize: '12px', textShadow: '1px 1px 1px #CCCCCC', verticalAlign: 'middle', cursor: 'pointer'});
  293. appendMyElement(saver['saverPanel'], saver['videoMenu'] );
  294. for (var videoCode in saver['videoList']) {
  295. saver['videoItem'] = createMyElement('option', videoCode, '', '', '');
  296. styleMyElement(saver['videoItem'], {padding: '0px', display: 'block', color: '#336699', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', cursor: 'pointer'});
  297. if (videoCode.indexOf('Video') != -1 || videoCode.indexOf('Audio') != -1) styleMyElement(saver['videoItem'], {color: '#8F6B32'});
  298. if (saver['videoList'][videoCode] == 'DASH') styleMyElement(saver['videoItem'], {color: '#CF4913'});
  299. if (saver['videoList'][videoCode] != 'DASH' || option['dash']) appendMyElement(saver['videoMenu'], saver['videoItem']);
  300. else delete saver['videoList'][videoCode];
  301. }
  302.  
  303. /* Panel Get Button */
  304. saver['buttonGet'] = createMyElement('div', 'Get', 'click', 'get', '');
  305. saver['buttonGet'].title = '{Get: click to download the selected video format}';
  306. styleMyElement(saver['buttonGet'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#C000C0', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', verticalAlign: 'middle', cursor: 'pointer'});
  307. if (option['autoget']) styleMyElement(saver['buttonGet'], {display: 'none'});
  308. appendMyElement(saver['saverPanel'], saver['buttonGet']);
  309.  
  310. /* Panel Autoget Button */
  311. if (feature['autoget']) {
  312. saver['buttonAutoget'] = createMyElement('div', 'AG', 'click', 'autoget', '');
  313. saver['buttonAutoget'].title = '{Autoget: click to enable/disable auto download on page load}';
  314. styleMyElement(saver['buttonAutoget'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#CCCCCC', fontSize: '12px', verticalAlign: 'middle', cursor: 'pointer'});
  315. if (option['autoget']) styleMyElement(saver['buttonAutoget'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  316. appendMyElement(saver['saverPanel'], saver['buttonAutoget']);
  317. }
  318.  
  319. /* Panel Definition Button */
  320. if (feature['definition']) {
  321. saver['buttonDefinition'] = createMyElement('div', option['definition'], 'click', 'definition', '');
  322. saver['buttonDefinition'].title = '{Definition: click to change the preferred video definition}';
  323. styleMyElement(saver['buttonDefinition'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#008000', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', verticalAlign: 'middle', cursor: 'pointer'});
  324. appendMyElement(saver['saverPanel'], saver['buttonDefinition']);
  325. }
  326.  
  327. /* Panel Container Button */
  328. if (feature['container']) {
  329. saver['buttonContainer'] = createMyElement('div', option['container'], 'click', 'container', '');
  330. saver['buttonContainer'].title = '{Container: click to change the preferred video container}';
  331. styleMyElement(saver['buttonContainer'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#008000', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', verticalAlign: 'middle', cursor: 'pointer'});
  332. appendMyElement(saver['saverPanel'], saver['buttonContainer']);
  333. }
  334.  
  335. /* Panel DASH Button */
  336. if (feature['dash']) {
  337. saver['buttonDASH'] = createMyElement('div', 'MD', 'click', 'dash', '');
  338. saver['buttonDASH'].title = '{MPEG-DASH: click to enable/disable DASH download using the SaveTube protocol}';
  339. styleMyElement(saver['buttonDASH'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#CCCCCC', fontSize: '12px', verticalAlign: 'middle', cursor: 'pointer'});
  340. if (option['dash']) styleMyElement(saver['buttonDASH'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  341. appendMyElement(saver['saverPanel'], saver['buttonDASH']);
  342. }
  343.  
  344. /* Panel Move Button */
  345. saver['buttonMove'] = createMyElement('div', '<', 'click', 'move', '');
  346. saver['buttonMove'].title = '{Move: click to toggle left/right panel position}';
  347. styleMyElement(saver['buttonMove'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#CCCCCC', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', verticalAlign: 'middle', cursor: 'pointer'});
  348. appendMyElement(saver['saverPanel'], saver['buttonMove']);
  349.  
  350. /* Disabled Features */
  351. if (!feature['autoget']) option['autoget'] = false;
  352. if (!feature['dash']) option['dash'] = false;
  353.  
  354. /* Select The Video */
  355. if (feature['definition'] || feature['container']) selectMyVideo();
  356.  
  357. /* Get The Video On Autoget */
  358. if (option['autoget']) getMyVideo();
  359. }
  360.  
  361. function selectMyVideo() {
  362. var vdoCont = (option['container'] != 'Any') ? [option['container']] : option['containers'];
  363. var vdoDef = option['definitions'];
  364. var vdoList = {};
  365. for (var vC = 0; vC < vdoCont.length; vC++) {
  366. if (vdoCont[vC] != 'Any') {
  367. for (var vD = 0; vD < vdoDef.length; vD++) {
  368. var format = vdoDef[vD] + ' ' + vdoCont[vC];
  369. if (!vdoList[vdoDef[vD]]) {
  370. for (var vL in saver['videoList']) {
  371. if (vL == format) {
  372. vdoList[vdoDef[vD]] = vL;
  373. break;
  374. }
  375. }
  376. }
  377. }
  378. }
  379. }
  380. var vdoDef2 = [];
  381. var keepDef = false;
  382. for (var vD = 0; vD < vdoDef.length; vD++) {
  383. var sD = vdoDef[vD].match(/[A-Z]/g).join('');
  384. if (sD == option['definition'] && keepDef == false) keepDef = true;
  385. if (keepDef == true) vdoDef2.push(vdoDef[vD])
  386. }
  387. for (var vD = 0; vD < vdoDef2.length; vD++) {
  388. if (vdoList[vdoDef2[vD]]) {
  389. saver['videoSave'] = vdoList[vdoDef2[vD]];
  390. break;
  391. }
  392. }
  393. saver['videoMenu'].value = saver['videoSave'];
  394. }
  395.  
  396. function getMyVideo() {
  397. var vdoURL = saver['videoList'][saver['videoSave']];
  398. var vdoDef = ' (' + saver['videoSave'].split(' ').slice(0, -1).join('').match(/[A-Z]/g).join('') + ')';
  399. var vdoExt = '.' + saver['videoSave'].split(' ').slice(-1).join('').toLowerCase();
  400. var vdoTle = (saver['videoTitle']) ? saver['videoTitle'] : '';
  401. if (feature['autoget'] && vdoTle && saver['videoSave'] == 'High Definition MP4') {
  402. page.win.location.href = vdoURL + '&title=' + vdoTle + vdoDef;
  403. }
  404. else {
  405. if (saver['videoList'][saver['videoSave']] == 'DASH') {
  406. var vdoV, vdoA;
  407. if (saver['videoSave'].indexOf('MP4') != -1) {
  408. vdoV = saver['videoList'][saver['videoSave'].replace('MP4', 'Video MP4')];
  409. vdoA = saver['videoList']['Medium Bitrate Audio MP4'] || saver['videoList'][saver['videoSave'].replace('MP4', 'Audio MP4')];
  410. }
  411. else {
  412. vdoV = saver['videoList'][saver['videoSave'].replace('WebM', 'Video WebM')];
  413. vdoA = saver['videoList']['High Bitrate Audio WebM'] || saver['videoList']['Medium Bitrate Audio WebM'] || saver['videoList']['Medium Bitrate Audio MP4'];
  414. }
  415. var vdoT = (vdoTle) ? vdoTle + vdoDef : page.site + vdoDef;
  416. vdoURL = 'savetube:' + vdoT + 'SEPARATOR' + vdoV + 'SEPARATOR' + vdoA;
  417. page.win.location.href = vdoURL;
  418. }
  419. else {
  420. var vdoLnk = '';
  421. if (vdoTle) {
  422. var vdoNme = vdoTle + vdoDef + vdoExt;
  423. vdoLnk = 'Get <a href="' + vdoURL + '" style="color:#00892C" download="' + vdoNme + '" target="_blank">Link</a>';
  424. }
  425. else {
  426. vdoLnk = 'Get <a href="' + vdoURL + '" style="color:#00892C" target="_blank">Link</a>';
  427. }
  428. modifyMyElement(saver['buttonGet'] , 'div', vdoLnk, false);
  429. }
  430. }
  431. }
  432.  
  433. function cleanMyContent(content, unesc, extra) {
  434. var myNewContent = content;
  435. if (unesc) myNewContent = unescape(myNewContent);
  436. myNewContent = myNewContent.replace(/\\u0025/g, '%');
  437. myNewContent = myNewContent.replace(/\\u0026/g, '&');
  438. myNewContent = myNewContent.replace(/\\u002F/g, '/');
  439. myNewContent = myNewContent.replace(/\\/g, '');
  440. myNewContent = myNewContent.replace(/\n/g, '');
  441. if (extra) {
  442. myNewContent = myNewContent.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/&#034;/g, '\'').replace(/"/g, '\'');
  443. myNewContent = myNewContent.replace(/&#39;/g, '\'').replace(/&#039;/g, '\'').replace(/'/g, '\'');
  444. myNewContent = myNewContent.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  445. myNewContent = myNewContent.replace(/[\/\|]/g, '-');
  446. myNewContent = myNewContent.replace(/[#:\*\?]/g, '');
  447. myNewContent = myNewContent.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  448. }
  449. return myNewContent;
  450. }
  451.  
  452. function getMyContent(url, pattern, clean) {
  453. var myPageContent, myVideosParse, myVideosContent;
  454. if (!sources[url]) {
  455. var xmlHTTP = new XMLHttpRequest();
  456. xmlHTTP.open('GET', url, false);
  457. xmlHTTP.send();
  458. sources[url] = (xmlHTTP.responseText) ? xmlHTTP.responseText : xmlHTTP.responseXML;
  459. //console.log('Request: ' + url + ' ' + pattern);
  460. }
  461. if (pattern == 'TEXT') {
  462. myVideosContent = sources[url];
  463. }
  464. else {
  465. myPageContent = (sources[url]) ? sources[url] : '';
  466. if (clean) myPageContent = cleanMyContent(myPageContent, true);
  467. myVideosParse = myPageContent.match(pattern);
  468. myVideosContent = (myVideosParse) ? myVideosParse[1] : null;
  469. }
  470. return myVideosContent;
  471. }
  472.  
  473. function setMyOptions(key, value) {
  474. key = page.site + '_' + userscript.toLowerCase() + '_' + key;
  475. try {
  476. localStorage.setItem(key, value);
  477. if (localStorage.getItem(key) == value) return;
  478. else throw false;
  479. }
  480. catch(e) {
  481. var date = new Date();
  482. date.setTime(date.getTime() + (356*24*60*60*1000));
  483. var expires = '; expires=' + date.toGMTString();
  484. page.doc.cookie = key + '=' + value + expires + '; path=/';
  485. }
  486. }
  487.  
  488. function getMyOptions() {
  489. for (var opt in option) {
  490. if (option.hasOwnProperty(opt)) {
  491. var key = page.site + '_' + userscript.toLowerCase() + '_' + opt;
  492. try {
  493. if (localStorage.getItem(key)) {
  494. option[opt] = localStorage.getItem(key);
  495. continue;
  496. }
  497. else throw false;
  498. }
  499. catch(e) {
  500. var cookies = page.doc.cookie.split(';');
  501. for (var i=0; i < cookies.length; i++) {
  502. var cookie = cookies[i];
  503. while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
  504. option[opt] = (cookie.indexOf(key) == 0) ? cookie.substring(key.length + 1, cookie.length) : option[opt];
  505. }
  506. }
  507. }
  508. }
  509. option['autoget'] = (option['autoget'] === true || option['autoget'] == 'true') ? true : false;
  510. option['dash'] = (option['dash'] === true || option['dash'] == 'true') ? true : false;
  511. }
  512.  
  513. function showMyMessage(cause, content) {
  514. styleMyElement(saver['saverPanel'], {color: '#AD0000', fontSize: '12px'});
  515. if (cause == '!content') {
  516. var myNoContentMess = '<b>SaveTube:</b> Couldn\'t get the videos content. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  517. modifyMyElement(saver['saverPanel'], 'div', myNoContentMess, false);
  518. }
  519. else if (cause == '!videos') {
  520. var myNoVideosMess = '<b>SaveTube:</b> Couldn\'t get any video. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  521. modifyMyElement(saver['saverPanel'], 'div', myNoVideosMess, false);
  522. }
  523. else if (cause == '!support') {
  524. var myNoSupportMess = '<b>SaveTube:</b> This video uses the RTMP protocol which is not supported.';
  525. modifyMyElement(saver['saverPanel'], 'div', myNoSupportMess, false);
  526. }
  527. else if (cause == 'embed') {
  528. var myEmbedMess = '<b>SaveTube:</b> This is an embedded video. You can get it <a href="' + content + '" style="color:#00892C">here</a>.';
  529. modifyMyElement(saver['saverPanel'], 'div', myEmbedMess, false);
  530. }
  531. else if (cause == 'other') {
  532. modifyMyElement(saver['saverPanel'], 'div', content, false);
  533. }
  534. }
  535.  
  536.  
  537. // ==========Websites========== //
  538.  
  539. function SaveTube() {
  540.  
  541. // =====YouTube===== //
  542.  
  543. if (page.url.indexOf('youtube.com/watch') != -1) {
  544.  
  545. /* Video Availability */
  546. if (getMyContent(page.url, '"playabilityStatus":\\{"status":"(ERROR|UNPLAYABLE)"', false)) return;
  547. var ytVideoUnavailable = getMyElement('', 'div', 'id', 'player-unavailable', -1, false);
  548. if (ytVideoUnavailable) {
  549. if (ytVideoUnavailable.className.indexOf('hid') == -1) {
  550. var ytAgeGateContent = getMyElement('', 'div', 'id', 'watch7-player-age-gate-content', -1, true);
  551. if (!ytAgeGateContent) return;
  552. else {
  553. if(ytAgeGateContent.indexOf('feature=private_video') != -1) return;
  554. }
  555. }
  556. }
  557.  
  558. /* Decrypt Signature */
  559. var ytScriptSrc;
  560. function ytDecryptSignature(s) {return null;}
  561. function ytDecryptFunction() {
  562. var ytSignFuncName, ytSignFuncBody, ytSwapFuncName, ytSwapFuncBody, ytFuncMatch;
  563. ytScriptSrc = ytScriptSrc.replace(/(\r\n|\n|\r)/gm, '');
  564. ytSignFuncName = ytScriptSrc.match(/"signature"\s*,\s*([^\)]*?)\(/);
  565. if (!ytSignFuncName) ytSignFuncName = ytScriptSrc.match(/c&&.\.set\(b,(?:encodeURIComponent\()?.*?([$a-zA-Z0-9]+)\(/);
  566. ytSignFuncName = (ytSignFuncName) ? ytSignFuncName[1] : null;
  567. if (ytSignFuncName) {
  568. ytFuncMatch = ytSignFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\}';
  569. ytSignFuncBody = ytScriptSrc.match(ytFuncMatch);
  570. ytSignFuncBody = (ytSignFuncBody) ? ytSignFuncBody[1] : null;
  571. if (ytSignFuncBody) {
  572. ytSwapFuncName = ytSignFuncBody.match(/((\$|_|\w)+)\.(\$|_|\w)+\(\w,[0-9]+\)/);
  573. ytSwapFuncName = (ytSwapFuncName) ? ytSwapFuncName[1] : null;
  574. if (ytSwapFuncName) {
  575. ytFuncMatch = 'var\\s+' + ytSwapFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};';
  576. ytSwapFuncBody = ytScriptSrc.match(ytFuncMatch);
  577. ytSwapFuncBody = (ytSwapFuncBody) ? ytSwapFuncBody[1] : null;
  578. }
  579. if (ytSwapFuncBody) ytSignFuncBody = 'var ' + ytSwapFuncName + '={' + ytSwapFuncBody + '};' + ytSignFuncBody;
  580. ytSignFuncBody = 'try {' + ytSignFuncBody + '} catch(e) {return null}';
  581. ytDecryptSignature = new Function('a', ytSignFuncBody);
  582. }
  583. }
  584. }
  585.  
  586. /* Get Video Title */
  587. var ytVideoTitle = getMyContent(page.url, '"videoDetails".*?"title":"((\\\\"|[^"])*?)"', false);
  588. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, '"title":\\{"runs":\\[\\{"text":"((\\\\"|[^"])*?)"', false);
  589. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  590. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, 'meta\\s+itemprop="name"\\s+content="(.*?)"', false);
  591. if (ytVideoTitle) {
  592. var ytVideoAuthor = getMyContent(page.url, '"(?:author|name)":\\s*"((\\\\"|[^"])*?)"', false);
  593. if (ytVideoAuthor) ytVideoTitle = ytVideoTitle + ' by ' + ytVideoAuthor;
  594. ytVideoTitle = cleanMyContent(ytVideoTitle, false, true);
  595. }
  596.  
  597. /* Get Videos Content */
  598. var ytVideosEncodedFmts, ytVideosEncodedFmtsNew, ytVideosAdaptiveFmts, ytVideosAdaptiveFmtsNew, ytVideosContent, ytHLSVideos, ytHLSContent;
  599. ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  600. if (!ytVideosEncodedFmts) {
  601. ytVideosEncodedFmtsNew = getMyContent(page.url, '"formats\\\\?":\\s*(\\[.*?\\])', false);
  602. if (ytVideosEncodedFmtsNew) {
  603. ytVideosEncodedFmts = '';
  604. ytVideosEncodedFmtsNew = cleanMyContent(ytVideosEncodedFmtsNew, false);
  605. ytVideosEncodedFmtsNew = ytVideosEncodedFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
  606. if (ytVideosEncodedFmtsNew) {
  607. for (var i = 0 ; i < ytVideosEncodedFmtsNew.length; i++) {
  608. ytVideosEncodedFmts += ytVideosEncodedFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
  609. }
  610. if (ytVideosEncodedFmts.indexOf('%3A%2F%2F') != -1) {
  611. ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
  612. }
  613. }
  614. }
  615. }
  616. ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  617. if (!ytVideosAdaptiveFmts) {
  618. ytVideosAdaptiveFmtsNew = getMyContent(page.url, '"adaptiveFormats\\\\?":\\s*(\\[.*?\\])', false);
  619. if (ytVideosAdaptiveFmtsNew) {
  620. ytVideosAdaptiveFmts = '';
  621. ytVideosAdaptiveFmtsNew = cleanMyContent(ytVideosAdaptiveFmtsNew, false);
  622. ytVideosAdaptiveFmtsNew = ytVideosAdaptiveFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
  623. if (ytVideosAdaptiveFmtsNew) {
  624. for (var i = 0 ; i < ytVideosAdaptiveFmtsNew.length; i++) {
  625. ytVideosAdaptiveFmts += ytVideosAdaptiveFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
  626. }
  627. if (ytVideosAdaptiveFmts.indexOf('%3A%2F%2F') != -1) {
  628. ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
  629. }
  630. }
  631. }
  632. }
  633. if (!ytVideosAdaptiveFmts) {
  634. var ytDASHVideos, ytDASHContent;
  635. ytDASHVideos = getMyContent(page.url, '"dash(?:mpd|ManifestUrl)\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  636. if (ytDASHVideos) {
  637. ytDASHVideos = cleanMyContent(ytDASHVideos, false);
  638. ytDASHContent = getMyContent(ytDASHVideos + '?pacing=0', 'TEXT', false);
  639. if (ytDASHContent) {
  640. var ytDASHVideo, ytDASHVideoParts, ytDASHVideoServer, ytDASHVideoParams;
  641. ytDASHVideos = ytDASHContent.match(new RegExp('<BaseURL>.*?</BaseURL>', 'g'));
  642. if (ytDASHVideos) {
  643. ytVideosAdaptiveFmts = '';
  644. for (var i = 0; i < ytDASHVideos.length; i++) {
  645. ytDASHVideo = ytDASHVideos[i].replace('<BaseURL>', '').replace('</BaseURL>', '');
  646. if (ytDASHVideo.indexOf('source/youtube') == -1) continue;
  647. ytDASHVideoParts = ytDASHVideo.split('videoplayback/');
  648. ytDASHVideoServer = ytDASHVideoParts[0] + 'videoplayback?';
  649. ytDASHVideoParams = ytDASHVideoParts[1].split('/');
  650. ytDASHVideo = '';
  651. for (var p = 0; p < ytDASHVideoParams.length; p++) {
  652. if (p % 2) ytDASHVideo += ytDASHVideoParams[p] + '&';
  653. else ytDASHVideo += ytDASHVideoParams[p] + '=';
  654. }
  655. ytDASHVideo = encodeURIComponent(ytDASHVideoServer + ytDASHVideo);
  656. ytDASHVideo = ytDASHVideo.replace('itag%3D', 'itag=');
  657. ytVideosAdaptiveFmts += ytDASHVideo + ',';
  658. }
  659. }
  660. }
  661. }
  662. }
  663. if (ytVideosEncodedFmts) {
  664. ytVideosContent = ytVideosEncodedFmts;
  665. }
  666. else {
  667. ytHLSVideos = getMyContent(page.url, '"hls(?:vp|ManifestUrl)\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  668. if (ytHLSVideos) {
  669. ytHLSVideos = cleanMyContent(ytHLSVideos, false);
  670. if (ytHLSVideos.indexOf('keepalive/yes/') != -1) ytHLSVideos = ytHLSVideos.replace('keepalive/yes/', '');
  671. }
  672. else {
  673. var ytVideoID = page.url.match(/(\?|&)v=(.*?)(&|$)/);
  674. ytVideoID = (ytVideoID) ? ytVideoID[2] : null;
  675. if (ytVideoID) {
  676. var ytVideosInfoPage = page.win.location.protocol + '//' + page.win.location.hostname + '/get_video_info?video_id=' + ytVideoID + '&eurl=https://youtube.googleapis.com/v/';
  677. ytVideosEncodedFmts = getMyContent(ytVideosInfoPage, 'url_encoded_fmt_stream_map=(.*?)&', false);
  678. if (ytVideosEncodedFmts) {
  679. ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
  680. ytVideosContent = ytVideosEncodedFmts;
  681. }
  682. else {
  683. ytVideosEncodedFmtsNew = getMyContent(ytVideosInfoPage, 'formats%22%3A(%5B.*?%5D)', false);
  684. if (ytVideosEncodedFmtsNew) {
  685. ytVideosEncodedFmts = '';
  686. ytVideosEncodedFmtsNew = cleanMyContent(ytVideosEncodedFmtsNew, true);
  687. ytVideosEncodedFmtsNew = ytVideosEncodedFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
  688. if (ytVideosEncodedFmtsNew) {
  689. for (var i = 0 ; i < ytVideosEncodedFmtsNew.length; i++) {
  690. ytVideosEncodedFmts += ytVideosEncodedFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
  691. }
  692. if (ytVideosEncodedFmts.indexOf('%3A%2F%2F') != -1) {
  693. ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
  694. }
  695. ytVideosContent = ytVideosEncodedFmts;
  696. }
  697. }
  698. }
  699. if (!ytVideosAdaptiveFmts) {
  700. ytVideosAdaptiveFmts = getMyContent(ytVideosInfoPage, 'adaptive_fmts=(.*?)&', false);
  701. if (ytVideosAdaptiveFmts) {
  702. ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
  703. }
  704. else {
  705. ytVideosAdaptiveFmtsNew = getMyContent(ytVideosInfoPage, 'adaptiveFormats%22%3A(%5B.*?%5D)', false);
  706. if (ytVideosAdaptiveFmtsNew) {
  707. ytVideosAdaptiveFmts = '';
  708. ytVideosAdaptiveFmtsNew = cleanMyContent(ytVideosAdaptiveFmtsNew, true);
  709. ytVideosAdaptiveFmtsNew = ytVideosAdaptiveFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
  710. if (ytVideosAdaptiveFmtsNew) {
  711. for (var i = 0 ; i < ytVideosAdaptiveFmtsNew.length; i++) {
  712. ytVideosAdaptiveFmts += ytVideosAdaptiveFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
  713. }
  714. if (ytVideosAdaptiveFmts.indexOf('%3A%2F%2F') != -1) {
  715. ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
  716. }
  717. }
  718. }
  719. }
  720. }
  721. }
  722. }
  723. }
  724. if (ytVideosAdaptiveFmts && !ytHLSVideos) {
  725. if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts;
  726. else ytVideosContent = ytVideosAdaptiveFmts;
  727. }
  728.  
  729. /* Create Saver */
  730. var ytDefaultVideo = 'Low Definition MP4';
  731. function ytSaver() {
  732. saver = {'videoList': ytVideoList, 'videoSave': ytDefaultVideo, 'videoTitle': ytVideoTitle};
  733. option['definitions'] = ['Ultra High Definition', 'Quad High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  734. option['containers'] = ['MP4', 'WebM', 'Any'];
  735. }
  736.  
  737. /* Parse Videos */
  738. function ytVideos() {
  739. var ytVideoFormats = {
  740. '18': 'Low Definition MP4',
  741. '22': 'High Definition MP4',
  742. '43': 'Low Definition WebM',
  743. '133': 'Very Low Definition Video MP4',
  744. '134': 'Low Definition Video MP4',
  745. '135': 'Standard Definition Video MP4',
  746. '136': 'High Definition Video MP4',
  747. '137': 'Full High Definition Video MP4',
  748. '140': 'Medium Bitrate Audio MP4',
  749. '242': 'Very Low Definition Video WebM',
  750. '243': 'Low Definition Video WebM',
  751. '244': 'Standard Definition Video WebM',
  752. '247': 'High Definition Video WebM',
  753. '248': 'Full High Definition Video WebM',
  754. '249': 'Low Bitrate Audio WebM',
  755. '250': 'Medium Bitrate Audio WebM',
  756. '251': 'High Bitrate Audio WebM',
  757. '264': 'Quad High Definition Video MP4',
  758. '271': 'Quad High Definition Video WebM',
  759. '272': 'Ultra High Definition Video WebM',
  760. '298': 'High Definition Video MP4',
  761. '299': 'Full High Definition Video MP4',
  762. '302': 'High Definition Video WebM',
  763. '303': 'Full High Definition Video WebM',
  764. '308': 'Quad High Definition Video WebM',
  765. '313': 'Ultra High Definition Video WebM',
  766. '315': 'Ultra High Definition Video WebM',
  767. '333': 'Standard Definition Video WebM',
  768. '334': 'High Definition Video WebM',
  769. '335': 'Full High Definition Video WebM',
  770. '337': 'Ultra High Definition Video WebM'
  771. };
  772. var ytVideoFound = false;
  773. var ytVideos = ytVideosContent.split(',');
  774. var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo, ytSign, ytSignP;
  775. for (var i = 0; i < ytVideos.length; i++) {
  776. ytVideo = ytVideos[i];
  777. ytVideoCodeParse = ytVideo.match(/itag=(\d{1,3})/);
  778. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  779. if (!ytVideoCode) continue;
  780. myVideoCode = ytVideoFormats[ytVideoCode];
  781. if (!myVideoCode) continue;
  782. if (!ytVideo.match(/^url/)) {
  783. ytVideoParse = ytVideo.match(/(.*)(url=.*$)/);
  784. if (ytVideoParse) ytVideo = ytVideoParse[2] + '&' + ytVideoParse[1];
  785. }
  786. ytVideo = cleanMyContent(ytVideo, true);
  787. if (myVideoCode.indexOf('Video') != -1) {
  788. if (ytVideo.indexOf('source=yt_otf') != -1) continue;
  789. }
  790. ytVideo = ytVideo.replace(/url=/, '').replace(/&$/, '');
  791. if (ytVideo.match(/itag=/) && ytVideo.match(/itag=/g).length > 1) {
  792. if (ytVideo.match(/itag=\d{1,3}&/)) ytVideo = ytVideo.replace(/itag=\d{1,3}&/, '');
  793. else if (ytVideo.match(/&itag=\d{1,3}/)) ytVideo = ytVideo.replace(/&itag=\d{1,3}/, '');
  794. }
  795. if (ytVideo.match(/clen=/) && ytVideo.match(/clen=/g).length > 1) {
  796. if (ytVideo.match(/clen=\d+&/)) ytVideo = ytVideo.replace(/clen=\d+&/, '');
  797. else if (ytVideo.match(/&clen=\d+/)) ytVideo = ytVideo.replace(/&clen=\d+/, '');
  798. }
  799. if (ytVideo.match(/lmt=/) && ytVideo.match(/lmt=/g).length > 1) {
  800. if (ytVideo.match(/lmt=\d+&/)) ytVideo = ytVideo.replace(/lmt=\d+&/, '');
  801. else if (ytVideo.match(/&lmt=\d+/)) ytVideo = ytVideo.replace(/&lmt=\d+/, '');
  802. }
  803. if (ytVideo.match(/type=(video|audio).*?&/)) ytVideo = ytVideo.replace(/type=(video|audio).*?&/, '');
  804. else ytVideo = ytVideo.replace(/&type=(video|audio).*$/, '');
  805. if (ytVideo.match(/xtags=[^%=]*&/)) ytVideo = ytVideo.replace(/xtags=[^%=]*?&/, '');
  806. else if (ytVideo.match(/&xtags=[^%=]*$/)) ytVideo = ytVideo.replace(/&xtags=[^%=]*$/, '');
  807. if (ytVideo.match(/&sig=/) && !ytVideo.match(/&lsig=/)) ytVideo = ytVideo.replace(/&sig=/, '&signature=');
  808. else if (ytVideo.match(/&s=/)) {
  809. ytSign = ytVideo.match(/&s=(.*?)(&|$)/);
  810. ytSign = (ytSign) ? ytSign[1] : null;
  811. if (ytSign) {
  812. ytSign = ytDecryptSignature(ytSign);
  813. if (ytSign) {
  814. ytSignP = ytVideo.match(/&sp=(.*?)(&|$)/);
  815. ytSignP = (ytSignP) ? ytSignP[1] : ((ytVideo.match(/&lsig=/)) ? 'sig' : 'signature');
  816. ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&' + ytSignP + '=' + ytSign + '$1');
  817. }
  818. else ytVideo = '';
  819. }
  820. else ytVideo = '';
  821. }
  822. ytVideo = cleanMyContent(ytVideo, true);
  823. if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes';
  824. if (ytVideo && ytVideo.indexOf('http') == 0) {
  825. if (!ytVideoFound) ytVideoFound = true;
  826. ytVideoList[myVideoCode] = ytVideo;
  827. }
  828. }
  829.  
  830. if (ytVideoFound) {
  831. /* DASH */
  832. if (ytVideoList['Medium Bitrate Audio MP4'] || ytVideoList['Medium Bitrate Audio WebM']) {
  833. for (var myVideoCode in ytVideoList) {
  834. if (myVideoCode.indexOf('Video') != -1) {
  835. if (!ytVideoList[myVideoCode.replace(' Video', '')]) {
  836. ytVideoList[myVideoCode.replace(' Video', '')] = 'DASH';
  837. }
  838. }
  839. }
  840. }
  841. feature['dash'] = true;
  842.  
  843. /* Create Saver */
  844. feature['autoget'] = true;
  845. ytSaver();
  846. createMySaver();
  847. }
  848. else {
  849. saver = {};
  850. if (ytVideosContent.indexOf('conn=rtmp') != -1) saver['warnMess'] = '!support';
  851. else saver['warnMess'] = '!videos';
  852. createMySaver();
  853. }
  854. }
  855.  
  856. /* Parse HLS */
  857. function ytHLS() {
  858. var ytHLSFormats = {
  859. '92': 'Very Low Definition MP4',
  860. '93': 'Low Definition MP4',
  861. '94': 'Standard Definition MP4',
  862. '95': 'High Definition MP4',
  863. '96': 'Full High Definition MP4'
  864. };
  865. ytVideoList["Any Definition MP4"] = ytHLSVideos;
  866. if (ytHLSContent) {
  867. var ytHLSVideo, ytVideoCodeParse, ytVideoCode, myVideoCode;
  868. var ytHLSMatcher = new RegExp('(http.*?m3u8)', 'g');
  869. ytHLSVideos = ytHLSContent.match(ytHLSMatcher);
  870. if (ytHLSVideos) {
  871. for (var i = 0; i < ytHLSVideos.length; i++) {
  872. ytHLSVideo = ytHLSVideos[i];
  873. ytVideoCodeParse = ytHLSVideo.match(/\/itag\/(\d{1,3})\//);
  874. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  875. if (ytVideoCode) {
  876. myVideoCode = ytHLSFormats[ytVideoCode];
  877. if (myVideoCode && ytHLSVideo) {
  878. ytVideoList[myVideoCode] = ytHLSVideo;
  879. }
  880. }
  881. }
  882. }
  883. }
  884.  
  885. /* Create Saver */
  886. ytVideoTitle = null;
  887. ytDefaultVideo = 'Any Definition MP4';
  888. ytSaver();
  889. createMySaver();
  890. }
  891.  
  892. /* Get Videos */
  893. var ytVideoList = {};
  894. if (ytVideosContent) {
  895. if (ytVideosContent.match(/^s=/) || ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/) || ytVideosContent.match(/u0026s=/)) {
  896. var ytScriptURL = getMyContent(page.url, '"js":\\s*"(.*?)"', true);
  897. if (!ytScriptURL) ytScriptURL = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"js":\\s*"(.*?)"', true);
  898. if (ytScriptURL) {
  899. ytScriptURL = page.win.location.protocol + '//' + page.win.location.hostname + ytScriptURL;
  900. ytScriptSrc = getMyContent(ytScriptURL, 'TEXT', false);
  901. if (ytScriptSrc) ytDecryptFunction();
  902. ytVideos();
  903. }
  904. else {
  905. saver = {
  906. 'warnMess': 'other',
  907. 'warnContent': '<b>SaveTube:</b> Couldn\'t get the signature link. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'
  908. };
  909. createMySaver();
  910. }
  911. }
  912. else {
  913. ytVideos();
  914. }
  915. }
  916. else {
  917. if (ytHLSVideos) {
  918. ytHLSContent = getMyContent(ytHLSVideos, 'TEXT', false);
  919. ytHLS();
  920. }
  921. else {
  922. saver = {'warnMess': '!content'};
  923. createMySaver();
  924. }
  925. }
  926.  
  927. }
  928.  
  929. // =====DailyMotion===== //
  930.  
  931. else if (page.url.indexOf('dailymotion.com/video') != -1) {
  932.  
  933. /* Video Availability */
  934. if (getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"error":\\{"title":"(.*?)"', false)) return;
  935. if (getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"error_title":"(.*?)"', false)) return;
  936.  
  937. /* Get Video Title */
  938. var dmVideoTitle = getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"title":"((\\\\"|[^"])*?)"', false);
  939. if (dmVideoTitle) {
  940. var dmVideoAuthor = getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"screenname":"((\\\\"|[^"])*?)"', false);
  941. if (dmVideoAuthor) dmVideoTitle = dmVideoTitle + ' by ' + dmVideoAuthor;
  942. dmVideoTitle = cleanMyContent(dmVideoTitle, false, true);
  943. }
  944.  
  945. /* Get Videos Content */
  946. var dmVideosContent = getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"qualities":\\{(.*?)\\]\\},', false);
  947.  
  948. /* Get Videos */
  949. if (dmVideosContent) {
  950. var dmVideoFormats = {'auto': 'Low Definition MP4', '240': 'Very Low Definition MP4', '380': 'Low Definition MP4',
  951. '480': 'Standard Definition MP4', '720': 'High Definition MP4', '1080': 'Full High Definition MP4'};
  952. var dmVideoList = {};
  953. var dmVideoFound = false;
  954. var dmVideoParser, dmVideoParse, myVideoCode, dmVideo;
  955. for (var dmVideoCode in dmVideoFormats) {
  956. dmVideoParser = '"' + dmVideoCode + '".*?"type":"video.*?mp4","url":"(.*?)"';
  957. dmVideoParse = dmVideosContent.match(dmVideoParser);
  958. if (!dmVideoParse) {
  959. dmVideoParser = '"' + dmVideoCode + '".*?"type":"application.*?mpegURL","url":"(.*?)"';
  960. dmVideoParse = dmVideosContent.match(dmVideoParser);
  961. }
  962. dmVideo = (dmVideoParse) ? dmVideoParse[1] : null;
  963. if (dmVideo) {
  964. if (!dmVideoFound) dmVideoFound = true;
  965. dmVideo = cleanMyContent(dmVideo, true);
  966. myVideoCode = dmVideoFormats[dmVideoCode];
  967. if (!dmVideoList[myVideoCode]) dmVideoList[myVideoCode] = dmVideo;
  968. }
  969. }
  970.  
  971. if (dmVideoFound) {
  972. /* Create Saver */
  973. var dmDefaultVideo = 'Low Definition MP4';
  974. saver = {'videoList': dmVideoList, 'videoSave': dmDefaultVideo, 'videoTitle': dmVideoTitle};
  975. feature['container'] = false;
  976. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  977. option['containers'] = ['MP4'];
  978. createMySaver();
  979. }
  980. else {
  981. saver = {'warnMess': '!videos'};
  982. createMySaver();
  983. }
  984. }
  985. else {
  986. saver = {'warnMess': '!content'};
  987. createMySaver();
  988. }
  989.  
  990. }
  991.  
  992. // =====Vimeo===== //
  993.  
  994. else if (page.url.indexOf('vimeo.com/') != -1) {
  995.  
  996. /* Page Type */
  997. var viPageType = getMyContent(page.url, 'meta\\s+property="og:type"\\s+content="(.*?)"', false);
  998. if (!viPageType || (viPageType != 'video' && viPageType != 'profile')) return;
  999.  
  1000. /* Get Video Title */
  1001. var viVideoTitle;
  1002. if (viPageType == 'video') {
  1003. viVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1004. }
  1005. else {
  1006. viVideoTitle = getMyContent(page.url, '"title":"((\\\\"|[^"])*?)"', false);
  1007. }
  1008. if (viVideoTitle) {
  1009. viVideoTitle = viVideoTitle.replace(/\s*on\s*Vimeo$/, '');
  1010. var viVideoAuthor = getMyContent(page.url, '"display_name":"((\\\\"|[^"])*?)"', false);
  1011. if (viVideoAuthor) viVideoTitle = viVideoTitle + ' by ' + viVideoAuthor;
  1012. viVideoTitle = cleanMyContent(viVideoTitle, false, true);
  1013. }
  1014.  
  1015. /* Get Content Source */
  1016. var viVideoSource = getMyContent(page.url, 'config_url":"(.*?)"', false);
  1017. if (viVideoSource) viVideoSource = cleanMyContent(viVideoSource, false);
  1018. else {
  1019. viVideoSource = getMyContent(page.url, 'data-config-url="(.*?)"', false);
  1020. if (viVideoSource) viVideoSource = viVideoSource.replace(/&amp;/g, '&');
  1021. }
  1022.  
  1023. /* Get Videos Content */
  1024. var viVideosContent;
  1025. if (viVideoSource) {
  1026. viVideosContent = getMyContent(viVideoSource, '"progressive":\\[(.*?)\\]', false);
  1027. }
  1028.  
  1029. /* Get Videos */
  1030. if (viVideosContent) {
  1031. var viVideoFormats = {'1440p': 'Quad High Definition MP4', '1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '540p': 'Standard Definition MP4',
  1032. '480p': 'Standard Definition MP4', '360p': 'Low Definition MP4', '270p': 'Very Low Definition MP4', '240p': 'Very Low Definition MP4'};
  1033. var viVideoList = {};
  1034. var viVideoFound = false;
  1035. var viVideo, myVideoCode;
  1036. var viVideos = viVideosContent.split('},');
  1037. for (var i = 0; i < viVideos.length; i++) {
  1038. for (var viVideoCode in viVideoFormats) {
  1039. if (viVideos[i].indexOf('"quality":"' + viVideoCode + '"') != -1) {
  1040. viVideo = viVideos[i].match(/"url":"(.*?)"/);
  1041. viVideo = (viVideo) ? viVideo[1] : null;
  1042. if (viVideo) {
  1043. if (!viVideoFound) viVideoFound = true;
  1044. myVideoCode = viVideoFormats[viVideoCode];
  1045. viVideoList[myVideoCode] = viVideo;
  1046. }
  1047. }
  1048. }
  1049. }
  1050.  
  1051. if (viVideoFound) {
  1052. /* Create Saver */
  1053. var viDefaultVideo = 'Low Definition MP4';
  1054. saver = {'videoList': viVideoList, 'videoSave': viDefaultVideo, 'videoTitle': viVideoTitle};
  1055. feature['container'] = false;
  1056. option['definitions'] = ['Quad High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1057. option['containers'] = ['MP4'];
  1058. createMySaver();
  1059. }
  1060. else {
  1061. saver = {'warnMess': '!videos'};
  1062. createMySaver();
  1063. }
  1064. }
  1065. else {
  1066. saver = {'warnMess': '!content'};
  1067. createMySaver();
  1068. }
  1069.  
  1070. }
  1071.  
  1072. // =====MetaCafe===== //
  1073.  
  1074. else if (page.url.indexOf('metacafe.com/watch') != -1) {
  1075.  
  1076. /* Get Video Title */
  1077. var mcVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1078. if (mcVideoTitle) mcVideoTitle = cleanMyContent(mcVideoTitle, false, true);
  1079.  
  1080. /* Get Videos Content */
  1081. var mcVideosContent = getMyContent(page.url, 'flashvars\\s*=\\s*\\{(.*?)\\};', false);
  1082.  
  1083. /* Get Videos */
  1084. if (mcVideosContent) {
  1085. var mcVideoList = {};
  1086. var mcVideoFound = false;
  1087. var mcVideoFormats = {'video_alt_url2': 'High Definition MP4', 'video_alt_url': 'Low Definition MP4', 'video_url': 'Very Low Definition MP4'};
  1088. var mcVideoFormatz = {'video_alt_url2': '_720p', 'video_alt_url': '_360p', 'video_url': '_240p'};
  1089. var mcVideoHLS = mcVideosContent.match(/"src":"(.*?)"/);
  1090. mcVideoHLS = (mcVideoHLS) ? cleanMyContent(mcVideoHLS[1], false) : null;
  1091. if (mcVideoHLS) {
  1092. var mcVideoParser, mcVideoParse, myVideoCode, mcVideo;
  1093. for (var mcVideoCode in mcVideoFormats) {
  1094. mcVideoParser = '"' + mcVideoCode + '":"(.*?)"';
  1095. mcVideoParse = mcVideosContent.match(mcVideoParser);
  1096. mcVideo = (mcVideoParse) ? mcVideoParse[1] : null;
  1097. if (mcVideo) {
  1098. if (!mcVideoFound) mcVideoFound = true;
  1099. myVideoCode = mcVideoFormats[mcVideoCode];
  1100. mcVideoList[myVideoCode] = mcVideoHLS.replace('.m3u8', mcVideoFormatz[mcVideoCode] + '.m3u8');
  1101. }
  1102. }
  1103. }
  1104.  
  1105. if (mcVideoFound) {
  1106. /* Create Saver */
  1107. var mcDefaultVideo = 'Low Definition MP4';
  1108. saver = {'videoList': mcVideoList, 'videoSave': mcDefaultVideo, 'videoTitle': mcVideoTitle};
  1109. feature['container'] = false;
  1110. option['definitions'] = ['High Definition', 'Low Definition', 'Very Low Definition'];
  1111. option['containers'] = ['MP4'];
  1112. createMySaver();
  1113. }
  1114. else {
  1115. saver = {'warnMess': '!videos'};
  1116. createMySaver();
  1117. }
  1118. }
  1119. else {
  1120. saver = {};
  1121. var ytVideoId = page.url.match(/\/yt-(.*?)\//);
  1122. if (ytVideoId && ytVideoId[1]) {
  1123. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId[1];
  1124. saver['warnMess'] = 'embed';
  1125. saver['warnContent'] = ytVideoLink;
  1126. }
  1127. else saver['warnMess'] = '!videos';
  1128. createMySaver();
  1129. }
  1130.  
  1131. }
  1132.  
  1133. // =====Veoh===== //
  1134.  
  1135. else if (page.url.indexOf('veoh.com/watch') != -1) {
  1136.  
  1137. /* Get Video Availability */
  1138. if (getMyElement('', 'div', 'class', 'veoh-video-player-error', 0, false)) return;
  1139.  
  1140. /* Get Video Title */
  1141. var veVideoTitle = getMyContent(page.url, 'meta\\s+name="og:title"\\s+content="(.*?)"', false);
  1142. if (!veVideoTitle) {
  1143. veVideoTitle = getMyContent(page.url.replace(/\/watch\//, '/watch/getVideo/'), '"title":"((\\\\"|[^"])*?)"', false);
  1144. }
  1145. if (veVideoTitle) veVideoTitle = cleanMyContent(veVideoTitle, false, true);
  1146.  
  1147. /* Get Videos Content */
  1148. var veVideosContent = getMyContent(page.url.replace(/\/watch\//, '/watch/getVideo/'), '"src"\\s*:\\s*\\{(.*?)\\}', false);
  1149.  
  1150. /* Get Videos */
  1151. if (veVideosContent) {
  1152. var veVideoFormats = {'Regular': 'Low Definition MP4', 'HQ': 'Standard Definition MP4'};
  1153. var veVideoList = {};
  1154. var veVideoFound = false;
  1155. var veVideoParser, veVideoParse, veVideo, myVideoCode;
  1156. for (var veVideoCode in veVideoFormats) {
  1157. veVideoParser = veVideoCode + '":"(.*?)"';
  1158. veVideoParse = veVideosContent.match(veVideoParser);
  1159. veVideo = (veVideoParse) ? veVideoParse[1] : null;
  1160. if (veVideo) {
  1161. if (!veVideoFound) veVideoFound = true;
  1162. myVideoCode = veVideoFormats[veVideoCode];
  1163. veVideoList[myVideoCode] = cleanMyContent(veVideo, false);
  1164. }
  1165. }
  1166.  
  1167. if (veVideoFound) {
  1168. /* Create Saver */
  1169. var veDefaultVideo = 'Low Definition MP4';
  1170. saver = {'videoList': veVideoList, 'videoSave': veDefaultVideo, 'videoTitle': veVideoTitle};
  1171. feature['container'] = false;
  1172. feature['fullsize'] = false;
  1173. option['definition'] = 'LD';
  1174. option['definitions'] = ['Standard Definition', 'Low Definition'];
  1175. option['containers'] = ['MP4'];
  1176. createMySaver();
  1177. }
  1178. else {
  1179. saver = {};
  1180. var ytVideoId = getMyContent(page.url, 'youtube.com/embed/(.*?)("|\\?)', false);
  1181. if (!ytVideoId) ytVideoId = getMyContent(page.url, '"videoId":"yapi-(.*?)"', false);
  1182. if (ytVideoId) {
  1183. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId;
  1184. saver['warnMess'] = 'embed';
  1185. saver['warnContent'] = ytVideoLink;
  1186. }
  1187. else saver['warnMess'] = '!videos';
  1188. createMySaver();
  1189. }
  1190. }
  1191. else {
  1192. saver = {'warnMess': '!content'};
  1193. createMySaver();
  1194. }
  1195.  
  1196. }
  1197.  
  1198. // =====Viki===== //
  1199.  
  1200. else if (page.url.indexOf('viki.com/videos') != -1) {
  1201.  
  1202. /* Get Video Title */
  1203. var vkVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1204. if (vkVideoTitle) vkVideoTitle = cleanMyContent(vkVideoTitle, false, true);
  1205.  
  1206. /* Get Video ID */
  1207. var vkVideoID = page.url.match(/videos\/(\d+v)/);
  1208. vkVideoID = (vkVideoID) ? vkVideoID[1] : null;
  1209.  
  1210. /* Get Videos Content */
  1211. var vkVideosContent;
  1212. if (vkVideoID) {
  1213. /* SHA-1
  1214. Copyright 2008-2018 Brian Turek, 1998-2009 Paul Johnston & Contributors
  1215. Distributed under the BSD License
  1216. See https://caligatio.github.com/jsSHA/ for more information
  1217. */
  1218. var SHA1FuncBody;
  1219. var SHA1Key = 'sha1js';
  1220. try {
  1221. if (localStorage.getItem(SHA1Key)) {
  1222. SHA1FuncBody = localStorage.getItem(SHA1Key);
  1223. }
  1224. else throw false;
  1225. }
  1226. catch(e) {
  1227. SHA1FuncBody = getMyContent('https://raw.githack.com/Caligatio/jsSHA/master/src/sha1.js', 'TEXT', false);
  1228. localStorage.setItem(SHA1Key, SHA1FuncBody);
  1229. }
  1230. var SHA1Func = new Function('a', SHA1FuncBody);
  1231. var SHA1 = new SHA1Func();
  1232. if (SHA1.jsSHA) {
  1233. var shaObj = new SHA1.jsSHA("SHA-1", "TEXT");
  1234. var vkTimestamp = parseInt(Date.now() / 1000);
  1235. var vkQuery = "/v5/videos/" + vkVideoID + "/streams.json?app=100005a&t=" + vkTimestamp + "&site=www.viki.com"
  1236. var vkToken = "MM_d*yP@`&1@]@!AVrXf_o-HVEnoTnm$O-ti4[G~$JDI/Dc-&piU&z&5.;:}95\=Iad";
  1237. shaObj.setHMACKey(vkToken, "TEXT");
  1238. shaObj.update(vkQuery);
  1239. var vkSig = shaObj.getHMAC("HEX");
  1240. var vkSource = "https://api.viki.io" + vkQuery + "&sig=" + vkSig;
  1241. vkVideosContent = getMyContent(vkSource, 'TEXT', false);
  1242. }
  1243. }
  1244.  
  1245. /* Get Videos */
  1246. if (vkVideosContent) {
  1247. var vkVideoList = {};
  1248. var vkVideoFormats = {'1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '480p': 'Standard Definition MP4',
  1249. '360p': 'Low Definition MP4', '240p': 'Very Low Definition MP4'};
  1250. var vkVideoFound = false;
  1251. var vkVideoParser, vkVideoParse, vkVideo, myVideoCode;
  1252. for (var vkVideoCode in vkVideoFormats) {
  1253. vkVideoParser = '"' + vkVideoCode + '".*?"https":\{"url":"(.*?)"';
  1254. vkVideoParse = vkVideosContent.match(vkVideoParser);
  1255. vkVideo = (vkVideoParse) ? vkVideoParse[1] : null;
  1256. if (vkVideo) {
  1257. if (!vkVideoFound) vkVideoFound = true;
  1258. myVideoCode = vkVideoFormats[vkVideoCode];
  1259. vkVideoList[myVideoCode] = vkVideo;
  1260. }
  1261. }
  1262.  
  1263. // Unauthorized
  1264. var vkUnauthorized = (vkVideosContent.indexOf('unauthorized') != -1) ? true : false;
  1265.  
  1266. // DASH/HLS/Subtitles
  1267. vkVideosContent = getMyContent(page.url.replace('/videos/', '/player5_fragment/'), 'TEXT', false);
  1268. if (vkVideosContent) {
  1269. vkVideoEncDASH = vkVideosContent.match(/dash\+xml".*?stream=(.*?)"/);
  1270. vkVideoEncDASH = (vkVideoEncDASH) ? vkVideoEncDASH[1] : null;
  1271. vkVideoEncHLS = vkVideosContent.match(/x-mpegURL".*?stream=(.*?)"/);
  1272. vkVideoEncHLS = (vkVideoEncHLS) ? vkVideoEncHLS[1] : null;
  1273. if (vkVideoEncDASH || vkVideoEncHLS) {
  1274. vkVideoEncKey = vkVideosContent.match(/chabi:\s*'(.*?)'/);
  1275. vkVideoEncKey = (vkVideoEncKey) ? vkVideoEncKey[1] : null;
  1276. vkVideoEncIV = vkVideosContent.match(/ecta:\s*'(.*?)'/);
  1277. vkVideoEncIV = (vkVideoEncIV) ? vkVideoEncIV[1] : null;
  1278. if (vkVideoEncKey && vkVideoEncIV) {
  1279. /* AES
  1280. Copyright 2015-2018 Richard Moore
  1281. MIT License.
  1282. See https://github.com/ricmoo/aes-js/ for more information
  1283. */
  1284. var AESFuncBody;
  1285. var AESKey = 'aesjs';
  1286. try {
  1287. if (localStorage.getItem(AESKey)) {
  1288. AESFuncBody = localStorage.getItem(AESKey);
  1289. }
  1290. else throw false;
  1291. }
  1292. catch(e) {
  1293. AESFuncBody = getMyContent('https://raw.githack.com/ricmoo/aes-js/master/index.js', 'TEXT', false);
  1294. localStorage.setItem(AESKey, AESFuncBody);
  1295. }
  1296. var AESFunc = new Function('a', AESFuncBody);
  1297. var AES = new AESFunc();
  1298. var AESKey = AES.aesjs.utils.utf8.toBytes(vkVideoEncKey);
  1299. var AESIV = AES.aesjs.utils.utf8.toBytes(vkVideoEncIV);
  1300. var encryptedBytes, decryptedBytes;
  1301. // HLS
  1302. encryptedBytes = AES.aesjs.utils.hex.toBytes(vkVideoEncHLS);
  1303. AESCBC = new AES.aesjs.ModeOfOperation.cbc(AESKey, AESIV);
  1304. decryptedBytes = AESCBC.decrypt(encryptedBytes);
  1305. var vkHLSManifest = AES.aesjs.utils.utf8.fromBytes(decryptedBytes);
  1306. if (vkHLSManifest) {
  1307. if (!vkVideoFound) vkVideoFound = true;
  1308. vkVideoList['Any Definition HLS'] = vkHLSManifest;
  1309. }
  1310. // DASH
  1311. encryptedBytes = AES.aesjs.utils.hex.toBytes(vkVideoEncDASH);
  1312. AESCBC = new AES.aesjs.ModeOfOperation.cbc(AESKey, AESIV);
  1313. decryptedBytes = AESCBC.decrypt(encryptedBytes);
  1314. var vkDASHManifest = AES.aesjs.utils.utf8.fromBytes(decryptedBytes);
  1315. if (vkDASHManifest) {
  1316. var vkDASHDomain = vkDASHManifest.split('/').splice(0, 5).join('/');
  1317. var vkDASHContent = getMyContent(vkDASHManifest, 'TEXT', false);
  1318. if (vkDASHContent) {
  1319. var vkDASHVideo;
  1320. var vkDASHVideos = vkDASHContent.match(new RegExp('<BaseURL>.*?</BaseURL>', 'g'));
  1321. if (vkDASHVideos) {
  1322. for (var i = 0; i < vkDASHVideos.length; i++) {
  1323. vkDASHVideo = vkDASHVideos[i].replace('<BaseURL>', '').replace('</BaseURL>', '');
  1324. if (vkDASHVideo.indexOf('http') != 0) vkDASHVideo = vkDASHDomain + '/' + vkDASHVideo;
  1325. for (var vkVideoCode in vkVideoFormats) {
  1326. if (vkDASHVideo.indexOf(vkVideoCode) != -1) {
  1327. myVideoCode = vkVideoFormats[vkVideoCode];
  1328. if (vkDASHVideo.indexOf('track1') != -1) {
  1329. if (!vkVideoFound) vkVideoFound = true;
  1330. if (!vkVideoList[myVideoCode]) {
  1331. vkVideoList[myVideoCode.replace('MP4', 'Video MP4')] = vkDASHVideo;
  1332. }
  1333. }
  1334. if (vkDASHVideo.indexOf('track2') != -1) {
  1335. if (!vkVideoList[myVideoCode]) {
  1336. vkVideoList[myVideoCode.replace('MP4', 'Audio MP4')] = vkDASHVideo;
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. }
  1343. for (var vkVideoCode in vkVideoFormats) {
  1344. myVideoCode = vkVideoFormats[vkVideoCode];
  1345. if (!vkVideoList[myVideoCode]) {
  1346. if (vkVideoList[myVideoCode.replace('MP4', 'Video MP4')] && vkVideoList[myVideoCode.replace('MP4', 'Audio MP4')]) {
  1347. vkVideoList[myVideoCode] = 'DASH';
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. // Subtitles
  1356. var vkSubtitles = vkVideosContent.match(/"srclang":"en".*?"src":"(.*?)"/);
  1357. vkSubtitles = (vkSubtitles) ? vkSubtitles[1] : null;
  1358. if (vkSubtitles) vkVideoList['EN Subtitles WebVTT'] = vkSubtitles;
  1359. }
  1360.  
  1361. /* Create Saver */
  1362. if (vkVideoFound) {
  1363. var vkDefaultVideo = 'Low Definition MP4';
  1364. saver = {'videoList': vkVideoList, 'videoSave': vkDefaultVideo, 'videoTitle': vkVideoTitle};
  1365. feature['container'] = false;
  1366. feature['dash'] = true;
  1367. option['definition'] = 'LD';
  1368. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1369. option['containers'] = ['MP4'];
  1370. createMySaver();
  1371. }
  1372. else {
  1373. if (vkUnauthorized) {
  1374. saver = {
  1375. 'warnMess': 'other',
  1376. 'warnContent': '<b>SaveTube:</b> Authorization required!'
  1377. };
  1378. }
  1379. else saver = {'warnMess': '!videos'};
  1380. createMySaver();
  1381. }
  1382. }
  1383. else {
  1384. saver = {'warnMess': '!content'};
  1385. createMySaver();
  1386. }
  1387.  
  1388. }
  1389.  
  1390. // =====IMDB===== //
  1391.  
  1392. else if (page.url.indexOf('imdb.com') != -1) {
  1393.  
  1394. /* Redirect To Video Page */
  1395. if (page.url.indexOf('/video/') == -1 && page.url.indexOf('/videoplayer/') == -1) {
  1396. page.doc.addEventListener('click', function(e) {
  1397. var p = e.target.parentNode;
  1398. while (p) {
  1399. if (p.tagName === 'A' && p.href.indexOf('/video/imdb') != -1) {
  1400. page.win.location.href = p.href.replace(/imdb\/inline.*/, '');
  1401. }
  1402. p = p.parentNode;
  1403. }
  1404. }, false);
  1405. return;
  1406. }
  1407.  
  1408. /* Get Video Title */
  1409. var imdbVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1410. if (imdbVideoTitle) imdbVideoTitle = cleanMyContent(imdbVideoTitle, false, true);
  1411.  
  1412. /* Get Video Id */
  1413. var imdbVideoId = page.url.replace(/.*videoplayer\//, '').replace(/(\/|\?).*/, '');
  1414.  
  1415. /* Get Videos Content */
  1416. var imdbVideosContent = getMyContent(page.url, '"' + imdbVideoId + '":\\{("aggregateUpVotes.*?videoId)', false);
  1417.  
  1418. /* Get Videos */
  1419. var imdbVideoList = {};
  1420. if (imdbVideosContent) {
  1421. var imdbVideoFormats = {'1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '480p': 'Standard Definition MP4',
  1422. '360p': 'Low Definition MP4', 'SD': 'Low Definition MP4', '240p': 'Very Low Definition MP4'};
  1423. var imdbVideoFound = false;
  1424. var imdbVideoParser, imdbVideoParse, myVideoCode, imdbVideo;
  1425. for (var imdbVideoCode in imdbVideoFormats) {
  1426. imdbVideoParser = '"definition":"' + imdbVideoCode + '".*?"videoUrl":"(.*?)"';
  1427. imdbVideoParse = imdbVideosContent.match(imdbVideoParser);
  1428. imdbVideo = (imdbVideoParse) ? imdbVideoParse[1] : null;
  1429. if (imdbVideo) {
  1430. imdbVideo = cleanMyContent(imdbVideo, false);
  1431. if (!imdbVideoFound) imdbVideoFound = true;
  1432. myVideoCode = imdbVideoFormats[imdbVideoCode];
  1433. if (!imdbVideoList[myVideoCode]) imdbVideoList[myVideoCode] = imdbVideo;
  1434. }
  1435. }
  1436.  
  1437. if (imdbVideoFound) {
  1438. /* Create Saver */
  1439. var imdbDefaultVideo = 'Low Definition MP4';
  1440. saver = {'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'videoTitle': imdbVideoTitle};
  1441. feature['container'] = false;
  1442. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1443. option['containers'] = ['MP4'];
  1444. createMySaver();
  1445. }
  1446. else {
  1447. saver = {'warnMess': '!videos'};
  1448. createMySaver();
  1449. }
  1450. }
  1451. else {
  1452. imdbVideo = getMyContent(page.url, '"videoUrl":"(.*?)"', false);
  1453. if (imdbVideo) {
  1454. /* Create Saver */
  1455. imdbVideo = cleanMyContent(imdbVideo, false);
  1456. imdbVideoList[imdbDefaultVideo] = imdbVideo;
  1457. var imdbDefaultVideo = 'Low Definition MP4';
  1458. saver = {'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'videoTitle': imdbVideoTitle};
  1459. feature['container'] = false;
  1460. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1461. option['containers'] = ['MP4'];
  1462. createMySaver();
  1463. }
  1464. else {
  1465. saver = {'warnMess': '!content'};
  1466. createMySaver();
  1467. }
  1468. }
  1469.  
  1470. }
  1471.  
  1472. }
  1473.  
  1474.  
  1475. // ==========Run========== //
  1476.  
  1477. SaveTube();
  1478.  
  1479. page.win.setInterval(function() {
  1480. if (page.url != page.win.location.href) {
  1481. if (saver['saverPanel'] && saver['saverPanel'].parentNode) {
  1482. removeMyElement(saver['saverPanel'].parentNode, saver['saverPanel']);
  1483. }
  1484. page.doc = page.win.document;
  1485. page.body = page.doc.body;
  1486. page.url = page.win.location.href;
  1487. SaveTube();
  1488. }
  1489. }, 500);
  1490.  
  1491. })();