SaveTube

Download videos from video sharing web sites.

当前为 2019-12-17 提交的版本,查看 最新版本

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