SaveTube

Download videos from video sharing web sites.

当前为 2019-06-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SaveTube
  3. // @version 2019.06.05
  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') getObj = pObj.getElementsByTagNameNS(value, type);
  205. }
  206. chObj = (child >= 0) ? getObj[child] : getObj;
  207. if (content && chObj) {
  208. if (type == 'html' || type == 'body' || type == 'div' || type == 'option') coObj = chObj.innerHTML;
  209. else if (type == 'object') coObj = chObj.data;
  210. else coObj = chObj.textContent;
  211. return coObj;
  212. }
  213. else {
  214. return chObj;
  215. }
  216. }
  217.  
  218. function modifyMyElement(obj, type, content, clear) {
  219. if (content) {
  220. if (type == 'div') obj.innerHTML = content;
  221. else if (type == 'option') {
  222. obj.value = content;
  223. obj.innerHTML = content;
  224. }
  225. }
  226. if (clear) {
  227. if (obj.hasChildNodes()) {
  228. while (obj.childNodes.length >= 1) {
  229. obj.removeChild(obj.firstChild);
  230. }
  231. }
  232. }
  233. }
  234.  
  235. function styleMyElement(obj, styles) {
  236. for (var property in styles) {
  237. if (styles.hasOwnProperty(property)) obj.style[property] = styles[property];
  238. }
  239. }
  240.  
  241. function appendMyElement(parent, child) {
  242. parent.appendChild(child);
  243. }
  244.  
  245. function removeMyElement(parent, child) {
  246. parent.removeChild(child);
  247. }
  248.  
  249. function replaceMyElement(parent, orphan, child) {
  250. parent.replaceChild(orphan, child);
  251. }
  252.  
  253. function createMySaver() {
  254. /* Get My Options */
  255. getMyOptions();
  256.  
  257. /* The Panel */
  258. saver['saverPanel'] = createMyElement('div', '', '', '', '');
  259. 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'});
  260. appendMyElement(page.body, saver['saverPanel']);
  261.  
  262. /* Warnings */
  263. if (saver['warnMess']) {
  264. if (saver['warnContent']) showMyMessage(saver['warnMess'], saver['warnContent']);
  265. else showMyMessage(saver['warnMess']);
  266. return;
  267. }
  268.  
  269. /* Panel Items */
  270. saver['panelHeight'] = 18;
  271. var panelItemBorder = 1;
  272. var panelItemHeight = saver['panelHeight'] - panelItemBorder * 2;
  273.  
  274. /* Panel Logo */
  275. saver['panelLogo'] = createMyElement('div', userscript + ': ', 'click', 'logo', '');
  276. saver['panelLogo'].title = '{SaveTube: click to visit the script web page}';
  277. styleMyElement(saver['panelLogo'], {height: panelItemHeight + 'px', padding: '0px', display: 'inline', color: '#336699', fontSize: '12px', fontWeight: 'bold', textShadow: '0px 1px 1px #CCCCCC', cursor: 'pointer'});
  278. appendMyElement(saver['saverPanel'], saver['panelLogo']);
  279.  
  280. /* Panel Video Menu */
  281. saver['videoMenu'] = createMyElement('select', '', 'change', '', 'video');
  282. saver['videoMenu'].title = '{Videos: select the video format for download}';
  283. styleMyElement(saver['videoMenu'], {width: '200px', height: panelItemHeight + 'px', border: '1px solid transparent', padding: '0px', display: 'inline', backgroundColor: 'inherit', color: '#336699', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', verticalAlign: 'baseline', cursor: 'pointer'});
  284. appendMyElement(saver['saverPanel'], saver['videoMenu'] );
  285. for (var videoCode in saver['videoList']) {
  286. saver['videoItem'] = createMyElement('option', videoCode, '', '', '');
  287. styleMyElement(saver['videoItem'], {padding: '0px', display: 'block', color: '#336699', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', cursor: 'pointer'});
  288. if (videoCode.indexOf('Video') != -1 || videoCode.indexOf('Audio') != -1) styleMyElement(saver['videoItem'], {color: '#8F6B32'});
  289. if (saver['videoList'][videoCode] == 'DASH') styleMyElement(saver['videoItem'], {color: '#CF4913'});
  290. if (saver['videoList'][videoCode] != 'DASH' || option['dash']) appendMyElement(saver['videoMenu'], saver['videoItem']);
  291. else delete saver['videoList'][videoCode];
  292. }
  293.  
  294. /* Panel Get Button */
  295. saver['buttonGet'] = createMyElement('div', 'Get', 'click', 'get', '');
  296. saver['buttonGet'].title = '{Get: click to download the selected video format}';
  297. 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', cursor: 'pointer'});
  298. if (option['autoget']) styleMyElement(saver['buttonGet'], {display: 'none'});
  299. appendMyElement(saver['saverPanel'], saver['buttonGet']);
  300.  
  301. /* Panel Autoget Button */
  302. if (feature['autoget']) {
  303. saver['buttonAutoget'] = createMyElement('div', 'AG', 'click', 'autoget', '');
  304. saver['buttonAutoget'].title = '{Autoget: click to enable/disable auto download on page load}';
  305. styleMyElement(saver['buttonAutoget'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#CCCCCC', fontSize: '12px', cursor: 'pointer'});
  306. if (option['autoget']) styleMyElement(saver['buttonAutoget'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  307. appendMyElement(saver['saverPanel'], saver['buttonAutoget']);
  308. }
  309.  
  310. /* Panel Definition Button */
  311. if (feature['definition']) {
  312. saver['buttonDefinition'] = createMyElement('div', option['definition'], 'click', 'definition', '');
  313. saver['buttonDefinition'].title = '{Definition: click to change the preferred video definition}';
  314. 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', cursor: 'pointer'});
  315. appendMyElement(saver['saverPanel'], saver['buttonDefinition']);
  316. }
  317.  
  318. /* Panel Container Button */
  319. if (feature['container']) {
  320. saver['buttonContainer'] = createMyElement('div', option['container'], 'click', 'container', '');
  321. saver['buttonContainer'].title = '{Container: click to change the preferred video container}';
  322. 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', cursor: 'pointer'});
  323. appendMyElement(saver['saverPanel'], saver['buttonContainer']);
  324. }
  325.  
  326. /* Panel DASH Button */
  327. if (feature['dash']) {
  328. saver['buttonDASH'] = createMyElement('div', 'MD', 'click', 'dash', '');
  329. saver['buttonDASH'].title = '{MPEG-DASH: click to enable/disable DASH download using the SaveTube protocol}';
  330. styleMyElement(saver['buttonDASH'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#CCCCCC', fontSize: '12px', cursor: 'pointer'});
  331. if (option['dash']) styleMyElement(saver['buttonDASH'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  332. appendMyElement(saver['saverPanel'], saver['buttonDASH']);
  333. }
  334.  
  335. /* Panel Move Button */
  336. saver['buttonMove'] = createMyElement('div', '<', 'click', 'move', '');
  337. saver['buttonMove'].title = '{Move: click to toggle left/right panel position}';
  338. 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', cursor: 'pointer'});
  339. appendMyElement(saver['saverPanel'], saver['buttonMove']);
  340.  
  341. /* Disabled Features */
  342. if (!feature['autoget']) option['autoget'] = false;
  343. if (!feature['dash']) option['dash'] = false;
  344.  
  345. /* Select The Video */
  346. if (feature['definition'] || feature['container']) selectMyVideo();
  347.  
  348. /* Get The Video On Autoget */
  349. if (option['autoget']) getMyVideo();
  350. }
  351.  
  352. function selectMyVideo() {
  353. var vdoCont = (option['container'] != 'Any') ? [option['container']] : option['containers'];
  354. var vdoDef = option['definitions'];
  355. var vdoList = {};
  356. for (var vC = 0; vC < vdoCont.length; vC++) {
  357. if (vdoCont[vC] != 'Any') {
  358. for (var vD = 0; vD < vdoDef.length; vD++) {
  359. var format = vdoDef[vD] + ' ' + vdoCont[vC];
  360. if (!vdoList[vdoDef[vD]]) {
  361. for (var vL in saver['videoList']) {
  362. if (vL == format) {
  363. vdoList[vdoDef[vD]] = vL;
  364. break;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. if (option['definition'] == 'UHD') {
  372. if (vdoList['Ultra High Definition']) saver['videoSave'] = vdoList['Ultra High Definition'];
  373. else if (vdoList['Full High Definition']) saver['videoSave'] = vdoList['Full High Definition'];
  374. else if (vdoList['High Definition']) saver['videoSave'] = vdoList['High Definition'];
  375. else if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  376. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  377. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  378. }
  379. else if (option['definition'] == 'FHD') {
  380. if (vdoList['Full High Definition']) saver['videoSave'] = vdoList['Full High Definition'];
  381. else if (vdoList['High Definition']) saver['videoSave'] = vdoList['High Definition'];
  382. else if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  383. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  384. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  385. }
  386. else if (option['definition'] == 'HD') {
  387. if (vdoList['High Definition']) saver['videoSave'] = vdoList['High Definition'];
  388. else if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  389. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  390. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  391. }
  392. else if (option['definition'] == 'SD') {
  393. if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  394. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  395. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  396. }
  397. else if (option['definition'] == 'LD') {
  398. if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  399. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  400. }
  401. else if (option['definition'] == 'VLD') {
  402. if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  403. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  404. }
  405. saver['videoMenu'].value = saver['videoSave'];
  406. }
  407.  
  408. function getMyVideo() {
  409. var vdoURL = saver['videoList'][saver['videoSave']];
  410. var vdoDef = ' (' + saver['videoSave'].split(' ').slice(0, -1).join('').match(/[A-Z]/g).join('') + ')';
  411. var vdoExt = '.' + saver['videoSave'].split(' ').slice(-1).join('').toLowerCase();
  412. var vdoTle = (saver['videoTitle']) ? saver['videoTitle'] : '';
  413. if (feature['autoget'] && vdoTle && saver['videoSave'] == 'High Definition MP4') {
  414. page.win.location.href = vdoURL + '&title=' + vdoTle + vdoDef;
  415. }
  416. else {
  417. if (saver['videoList'][saver['videoSave']] == 'DASH') {
  418. if (saver['videoSave'].indexOf('MP4') != -1) {
  419. var vdoV = saver['videoList'][saver['videoSave'].replace(/MP4/, 'Video MP4')];
  420. if (saver['videoList']['High Bitrate Audio MP4']) {
  421. var vdoA = saver['videoList']['High Bitrate Audio MP4'];
  422. }
  423. else if (saver['videoList']['Medium Bitrate Audio MP4']) {
  424. var vdoA = saver['videoList']['Medium Bitrate Audio MP4'];
  425. }
  426. else {
  427. var vdoA = saver['videoList']['Low Bitrate Audio MP4'];
  428. }
  429. }
  430. else {
  431. var vdoV = saver['videoList'][saver['videoSave'].replace(/WebM/, 'Video WebM')];
  432. if (saver['videoList']['High Bitrate Audio Opus']) {
  433. var vdoA = saver['videoList']['High Bitrate Audio Opus'];
  434. }
  435. else if (saver['videoList']['Medium Bitrate Audio Opus']) {
  436. var vdoA = saver['videoList']['Medium Bitrate Audio Opus'];
  437. }
  438. else {
  439. var vdoA = saver['videoList']['Low Bitrate Audio Opus'];
  440. }
  441. }
  442. var vdoT = (vdoTle) ? vdoTle + vdoDef : page.site + vdoDef;
  443. vdoURL = 'savetube:' + vdoT + '=SAVETUBE=' + vdoV + '=SAVETUBE=' + vdoA;
  444. page.win.location.href = vdoURL;
  445. }
  446. else {
  447. var vdoLnk = '';
  448. if (vdoTle) {
  449. var vdoNme = vdoTle + vdoDef + vdoExt;
  450. vdoLnk = 'Get <a href="' + vdoURL + '" style="color:#00892C" download="' + vdoNme + '" target="_blank">Link</a>';
  451. }
  452. else {
  453. vdoLnk = 'Get <a href="' + vdoURL + '" style="color:#00892C" target="_blank">Link</a>';
  454. }
  455. modifyMyElement(saver['buttonGet'] , 'div', vdoLnk, false);
  456. }
  457. }
  458. }
  459.  
  460. function cleanMyContent(content, unesc) {
  461. var myNewContent = content;
  462. if (unesc) myNewContent = unescape(myNewContent);
  463. myNewContent = myNewContent.replace(/\\u0025/g, '%');
  464. myNewContent = myNewContent.replace(/\\u0026/g, '&');
  465. myNewContent = myNewContent.replace(/\\u002F/g, '/');
  466. myNewContent = myNewContent.replace(/\\/g, '');
  467. myNewContent = myNewContent.replace(/\n/g, '');
  468. return myNewContent;
  469. }
  470.  
  471. function getMyContent(url, pattern, clean) {
  472. var myPageContent, myVideosParse, myVideosContent;
  473. if (!sources[url]) {
  474. var xmlHTTP = new XMLHttpRequest();
  475. xmlHTTP.open('GET', url, false);
  476. xmlHTTP.send();
  477. sources[url] = (xmlHTTP.responseText) ? xmlHTTP.responseText : xmlHTTP.responseXML;
  478. //console.log('Request: ' + url + ' ' + pattern);
  479. }
  480. if (pattern == 'TEXT') {
  481. myVideosContent = sources[url];
  482. }
  483. else {
  484. myPageContent = (sources[url]) ? sources[url] : '';
  485. if (clean) myPageContent = cleanMyContent(myPageContent, true);
  486. myVideosParse = myPageContent.match(pattern);
  487. myVideosContent = (myVideosParse) ? myVideosParse[1] : null;
  488. }
  489. return myVideosContent;
  490. }
  491.  
  492. function setMyOptions(key, value) {
  493. key = page.site + '_' + userscript.toLowerCase() + '_' + key;
  494. try {
  495. localStorage.setItem(key, value);
  496. if (localStorage.getItem(key) == value) return;
  497. else throw false;
  498. }
  499. catch(e) {
  500. var date = new Date();
  501. date.setTime(date.getTime() + (356*24*60*60*1000));
  502. var expires = '; expires=' + date.toGMTString();
  503. page.doc.cookie = key + '=' + value + expires + '; path=/';
  504. }
  505. }
  506.  
  507. function getMyOptions() {
  508. for (var opt in option) {
  509. if (option.hasOwnProperty(opt)) {
  510. var key = page.site + '_' + userscript.toLowerCase() + '_' + opt;
  511. try {
  512. if (localStorage.getItem(key)) {
  513. option[opt] = localStorage.getItem(key);
  514. continue;
  515. }
  516. else throw false;
  517. }
  518. catch(e) {
  519. var cookies = page.doc.cookie.split(';');
  520. for (var i=0; i < cookies.length; i++) {
  521. var cookie = cookies[i];
  522. while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
  523. option[opt] = (cookie.indexOf(key) == 0) ? cookie.substring(key.length + 1, cookie.length) : option[opt];
  524. }
  525. }
  526. }
  527. }
  528. option['autoget'] = (option['autoget'] === true || option['autoget'] == 'true') ? true : false;
  529. option['dash'] = (option['dash'] === true || option['dash'] == 'true') ? true : false;
  530. }
  531.  
  532. function showMyMessage(cause, content) {
  533. styleMyElement(saver['saverPanel'], {color: '#AD0000', fontSize: '12px'});
  534. if (cause == '!content') {
  535. var myNoContentMess = '<b>SaveTube:</b> Couldn\'t get the videos content. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  536. modifyMyElement(saver['saverPanel'], 'div', myNoContentMess, false);
  537. }
  538. else if (cause == '!videos') {
  539. var myNoVideosMess = '<b>SaveTube:</b> Couldn\'t get any video. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  540. modifyMyElement(saver['saverPanel'], 'div', myNoVideosMess, false);
  541. }
  542. else if (cause == '!support') {
  543. var myNoSupportMess = '<b>SaveTube:</b> This video uses the RTMP protocol which is not supported.';
  544. modifyMyElement(saver['saverPanel'], 'div', myNoSupportMess, false);
  545. }
  546. else if (cause == 'embed') {
  547. var myEmbedMess = '<b>SaveTube:</b> This is an embedded video. You can get it <a href="' + content + '" style="color:#00892C">here</a>.';
  548. modifyMyElement(saver['saverPanel'], 'div', myEmbedMess, false);
  549. }
  550. else if (cause == 'other') {
  551. modifyMyElement(saver['saverPanel'], 'div', content, false);
  552. }
  553. }
  554.  
  555.  
  556. // ==========Websites========== //
  557.  
  558. function SaveTube() {
  559.  
  560. // =====YouTube===== //
  561.  
  562. if (page.url.indexOf('youtube.com/watch') != -1) {
  563.  
  564. /* Redirect Categories */
  565. if (page.url.indexOf('gaming.youtube.com') != -1) {
  566. page.win.location.href = page.url.replace('gaming', 'www');
  567. }
  568.  
  569. /* Video Availability */
  570. if (getMyContent(page.url, '"simpleText":"(This video is (private|unavailable|not available).)"', false)) return;
  571. var ytVideoUnavailable = getMyElement('', 'div', 'id', 'player-unavailable', -1, false);
  572. if (ytVideoUnavailable) {
  573. if (ytVideoUnavailable.className.indexOf('hid') == -1) {
  574. var ytAgeGateContent = getMyElement('', 'div', 'id', 'watch7-player-age-gate-content', -1, true);
  575. if (!ytAgeGateContent) return;
  576. else {
  577. if(ytAgeGateContent.indexOf('feature=private_video') != -1) return;
  578. }
  579. }
  580. }
  581.  
  582. /* Decrypt Signature */
  583. var ytScriptSrc;
  584. function ytDecryptSignature(s) {return null;}
  585. function ytDecryptFunction() {
  586. var ytSignFuncName, ytSignFuncBody, ytSwapFuncName, ytSwapFuncBody, ytFuncMatch;
  587. ytScriptSrc = ytScriptSrc.replace(/(\r\n|\n|\r)/gm, '');
  588. ytSignFuncName = ytScriptSrc.match(/"signature"\s*,\s*([^\)]*?)\(/);
  589. if (!ytSignFuncName) ytSignFuncName = ytScriptSrc.match(/d.set\(b,(?:encodeURIComponent\()?.*?([a-zA-Z0-9$]+)\(/);
  590. ytSignFuncName = (ytSignFuncName) ? ytSignFuncName[1] : null;
  591. if (ytSignFuncName) {
  592. ytFuncMatch = ytSignFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\}';
  593. ytSignFuncBody = ytScriptSrc.match(ytFuncMatch);
  594. ytSignFuncBody = (ytSignFuncBody) ? ytSignFuncBody[1] : null;
  595. if (ytSignFuncBody) {
  596. ytSwapFuncName = ytSignFuncBody.match(/((\$|_|\w)+)\.(\$|_|\w)+\(\w,[0-9]+\)/);
  597. ytSwapFuncName = (ytSwapFuncName) ? ytSwapFuncName[1] : null;
  598. if (ytSwapFuncName) {
  599. ytFuncMatch = 'var\\s+' + ytSwapFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};';
  600. ytSwapFuncBody = ytScriptSrc.match(ytFuncMatch);
  601. ytSwapFuncBody = (ytSwapFuncBody) ? ytSwapFuncBody[1] : null;
  602. }
  603. if (ytSwapFuncBody) ytSignFuncBody = 'var ' + ytSwapFuncName + '={' + ytSwapFuncBody + '};' + ytSignFuncBody;
  604. ytSignFuncBody = 'try {' + ytSignFuncBody + '} catch(e) {return null}';
  605. ytDecryptSignature = new Function('a', ytSignFuncBody);
  606. }
  607. }
  608. }
  609.  
  610. /* Get Video Title */
  611. var ytVideoTitle = getMyContent(page.url, '"title":"(.*?)"', false);
  612. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, '"videoPrimaryInfoRenderer":\\{"title":\\{"simpleText":"(.*?)"', false);
  613. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  614. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, 'meta\\s+itemprop="name"\\s+content="(.*?)"', false);
  615. if (ytVideoTitle) {
  616. ytVideoTitle = ytVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  617. ytVideoTitle = ytVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  618. ytVideoTitle = ytVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  619. ytVideoTitle = ytVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  620. ytVideoTitle = ytVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  621. }
  622.  
  623. /* Get Videos Content */
  624. var ytVideosEncodedFmts, ytVideosAdaptiveFmts, ytVideosContent, ytHLSVideos, ytHLSContent;
  625. ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  626. ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  627. if (!ytVideosAdaptiveFmts) {
  628. var ytDASHVideos, ytDASHContent;
  629. ytDASHVideos = getMyContent(page.url, '"dashmpd\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  630. if (ytDASHVideos) {
  631. ytDASHVideos = cleanMyContent(ytDASHVideos, false);
  632. ytDASHContent = getMyContent(ytDASHVideos + '?pacing=0', 'TEXT', false);
  633. if (ytDASHContent) {
  634. var ytDASHVideo, ytDASHVideoParts, ytDASHVideoServer, ytDASHVideoParams;
  635. ytDASHVideos = ytDASHContent.match(new RegExp('<BaseURL>.*?</BaseURL>', 'g'));
  636. if (ytDASHVideos) {
  637. ytVideosAdaptiveFmts = '';
  638. for (var i = 0; i < ytDASHVideos.length; i++) {
  639. ytDASHVideo = ytDASHVideos[i].replace('<BaseURL>', '').replace('</BaseURL>', '');
  640. if (ytDASHVideo.indexOf('source/youtube') == -1) continue;
  641. ytDASHVideoParts = ytDASHVideo.split('videoplayback/');
  642. ytDASHVideoServer = ytDASHVideoParts[0] + 'videoplayback?';
  643. ytDASHVideoParams = ytDASHVideoParts[1].split('/');
  644. ytDASHVideo = '';
  645. for (var p = 0; p < ytDASHVideoParams.length; p++) {
  646. if (p % 2) ytDASHVideo += ytDASHVideoParams[p] + '&';
  647. else ytDASHVideo += ytDASHVideoParams[p] + '=';
  648. }
  649. ytDASHVideo = encodeURIComponent(ytDASHVideoServer + ytDASHVideo);
  650. ytDASHVideo = ytDASHVideo.replace('itag%3D', 'itag=');
  651. ytVideosAdaptiveFmts += ytDASHVideo + ',';
  652. }
  653. }
  654. }
  655. }
  656. }
  657. if (ytVideosEncodedFmts) {
  658. ytVideosContent = ytVideosEncodedFmts;
  659. }
  660. else {
  661. ytHLSVideos = getMyContent(page.url, '"hls(?:vp|ManifestUrl)\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
  662. if (ytHLSVideos) {
  663. ytHLSVideos = cleanMyContent(ytHLSVideos, false);
  664. if (ytHLSVideos.indexOf('keepalive/yes/') != -1) ytHLSVideos = ytHLSVideos.replace('keepalive/yes/', '');
  665. }
  666. else {
  667. var ytVideoID = page.url.match(/(\?|&)v=(.*?)(&|$)/);
  668. ytVideoID = (ytVideoID) ? ytVideoID[2] : null;
  669. if (ytVideoID) {
  670. var ytVideoSts = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"sts"\\s*:\\s*(\\d+)', false);
  671. var ytVideosInfoURL = page.win.location.protocol + '//' + page.win.location.hostname + '/get_video_info?video_id=' + ytVideoID + '&eurl=https://youtube.googleapis.com/v/' + ytVideoID + '&sts=' + ytVideoSts;
  672. var ytVideosInfo = getMyContent(ytVideosInfoURL, 'TEXT', false);
  673. if (ytVideosInfo) {
  674. ytVideosEncodedFmts = ytVideosInfo.match(/url_encoded_fmt_stream_map=(.*?)&/);
  675. ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null;
  676. if (ytVideosEncodedFmts) {
  677. ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
  678. ytVideosContent = ytVideosEncodedFmts;
  679. }
  680. if (!ytVideosAdaptiveFmts) {
  681. ytVideosAdaptiveFmts = ytVideosInfo.match(/adaptive_fmts=(.*?)&/);
  682. ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null;
  683. if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
  684. }
  685. }
  686. }
  687. }
  688. }
  689. if (ytVideosAdaptiveFmts && !ytHLSVideos) {
  690. if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts;
  691. else ytVideosContent = ytVideosAdaptiveFmts;
  692. }
  693.  
  694. /* Create Saver */
  695. var ytDefaultVideo = 'Low Definition MP4';
  696. function ytSaver() {
  697. saver = {'videoList': ytVideoList, 'videoSave': ytDefaultVideo, 'videoTitle': ytVideoTitle};
  698. option['definitions'] = ['Ultra High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  699. option['containers'] = ['MP4', 'WebM', '3GP', 'Any'];
  700. }
  701.  
  702. /* Parse Videos */
  703. function ytVideos() {
  704. var ytVideoFormats = {
  705. '17': 'Very Low Definition 3GP',
  706. '18': 'Low Definition MP4',
  707. '22': 'High Definition MP4',
  708. '36': 'Low Definition 3GP',
  709. '43': 'Low Definition WebM',
  710. '135': 'Standard Definition Video MP4',
  711. '136': 'High Definition Video MP4',
  712. '137': 'Full High Definition Video MP4',
  713. '140': 'Medium Bitrate Audio MP4',
  714. '171': 'Medium Bitrate Audio WebM',
  715. '244': 'Standard Definition Video WebM',
  716. '247': 'High Definition Video WebM',
  717. '248': 'Full High Definition Video WebM',
  718. '249': 'Low Bitrate Audio Opus',
  719. '250': 'Medium Bitrate Audio Opus',
  720. '251': 'High Bitrate Audio Opus',
  721. '272': 'Ultra High Definition Video WebM',
  722. '298': 'High Definition Video MP4',
  723. '299': 'Full High Definition Video MP4',
  724. '302': 'High Definition Video WebM',
  725. '303': 'Full High Definition Video WebM',
  726. '313': 'Ultra High Definition Video WebM',
  727. '315': 'Ultra High Definition Video WebM',
  728. '333': 'Standard Definition Video WebM',
  729. '334': 'High Definition Video WebM',
  730. '335': 'Full High Definition Video WebM',
  731. '337': 'Ultra High Definition Video WebM'
  732. };
  733. var ytVideoFound = false;
  734. var ytVideos = ytVideosContent.split(',');
  735. var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo, ytSign, ytSignP;
  736. for (var i = 0; i < ytVideos.length; i++) {
  737. if (!ytVideos[i].match(/^url/)) {
  738. ytVideoParse = ytVideos[i].match(/(.*)(url=.*$)/);
  739. if (ytVideoParse) ytVideos[i] = ytVideoParse[2] + '&' + ytVideoParse[1];
  740. }
  741. ytVideoCodeParse = ytVideos[i].match(/itag=(\d{1,3})/);
  742. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  743. if (ytVideoCode) {
  744. myVideoCode = ytVideoFormats[ytVideoCode];
  745. if (myVideoCode) {
  746. ytVideo = cleanMyContent(ytVideos[i], true);
  747. ytVideo = ytVideo.replace(/url=/, '').replace(/&$/, '');
  748. if (ytVideo.match(/itag=/) && ytVideo.match(/itag=/g).length > 1) {
  749. if (ytVideo.match(/itag=\d{1,3}&/)) ytVideo = ytVideo.replace(/itag=\d{1,3}&/, '');
  750. else if (ytVideo.match(/&itag=\d{1,3}/)) ytVideo = ytVideo.replace(/&itag=\d{1,3}/, '');
  751. }
  752. if (ytVideo.match(/clen=/) && ytVideo.match(/clen=/g).length > 1) {
  753. if (ytVideo.match(/clen=\d+&/)) ytVideo = ytVideo.replace(/clen=\d+&/, '');
  754. else if (ytVideo.match(/&clen=\d+/)) ytVideo = ytVideo.replace(/&clen=\d+/, '');
  755. }
  756. if (ytVideo.match(/lmt=/) && ytVideo.match(/lmt=/g).length > 1) {
  757. if (ytVideo.match(/lmt=\d+&/)) ytVideo = ytVideo.replace(/lmt=\d+&/, '');
  758. else if (ytVideo.match(/&lmt=\d+/)) ytVideo = ytVideo.replace(/&lmt=\d+/, '');
  759. }
  760. if (ytVideo.match(/type=(video|audio).*?&/)) ytVideo = ytVideo.replace(/type=(video|audio).*?&/, '');
  761. else ytVideo = ytVideo.replace(/&type=(video|audio).*$/, '');
  762. if (ytVideo.match(/xtags=[^%=]*&/)) ytVideo = ytVideo.replace(/xtags=[^%=]*?&/, '');
  763. else if (ytVideo.match(/&xtags=[^%=]*$/)) ytVideo = ytVideo.replace(/&xtags=[^%=]*$/, '');
  764. if (ytVideo.match(/&sig=/) && !ytVideo.match(/&lsig=/)) ytVideo = ytVideo.replace(/&sig=/, '&signature=');
  765. else if (ytVideo.match(/&s=/)) {
  766. ytSign = ytVideo.match(/&s=(.*?)(&|$)/);
  767. ytSign = (ytSign) ? ytSign[1] : null;
  768. if (ytSign) {
  769. ytSign = ytDecryptSignature(ytSign);
  770. if (ytSign) {
  771. ytSignP = ytVideo.match(/&sp=(.*?)(&|$)/);
  772. ytSignP = (ytSignP) ? ytSignP[1] : ((ytVideo.match(/&lsig=/)) ? 'sig' : 'signature');
  773. ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&' + ytSignP + '=' + ytSign + '$1');
  774. }
  775. else ytVideo = '';
  776. }
  777. else ytVideo = '';
  778. }
  779. ytVideo = cleanMyContent(ytVideo, true);
  780. if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes';
  781. if (ytVideo && ytVideo.indexOf('http') == 0) {
  782. if (!ytVideoFound) ytVideoFound = true;
  783. ytVideoList[myVideoCode] = ytVideo;
  784. }
  785. }
  786. }
  787. }
  788.  
  789. if (ytVideoFound) {
  790. /* DASH */
  791. if (!ytVideoList['Standard Definition MP4'] && ytVideoList['Standard Definition Video MP4']) ytVideoList['Standard Definition MP4'] = 'DASH';
  792. if (!ytVideoList['High Definition MP4'] && ytVideoList['High Definition Video MP4']) ytVideoList['High Definition MP4'] = 'DASH';
  793. if (!ytVideoList['Full High Definition MP4'] && ytVideoList['Full High Definition Video MP4']) ytVideoList['Full High Definition MP4'] = 'DASH';
  794. if (!ytVideoList['Ultra High Definition MP4'] && ytVideoList['Ultra High Definition Video MP4']) ytVideoList['Ultra High Definition MP4'] = 'DASH';
  795. if (!ytVideoList['Standard Definition WebM'] && ytVideoList['Standard Definition Video WebM']) ytVideoList['Standard Definition WebM'] = 'DASH';
  796. if (!ytVideoList['High Definition WebM'] && ytVideoList['High Definition Video WebM']) ytVideoList['High Definition WebM'] = 'DASH';
  797. if (!ytVideoList['Full High Definition WebM'] && ytVideoList['Full High Definition Video WebM']) ytVideoList['Full High Definition WebM'] = 'DASH';
  798. if (!ytVideoList['Ultra High Definition WebM'] && ytVideoList['Ultra High Definition Video WebM']) ytVideoList['Ultra High Definition WebM'] = 'DASH';
  799. feature['dash'] = true;
  800.  
  801. /* Create Saver */
  802. feature['autoget'] = true;
  803. ytSaver();
  804. createMySaver();
  805. }
  806. else {
  807. saver = {};
  808. if (ytVideosContent.indexOf('conn=rtmp') != -1) saver['warnMess'] = '!support';
  809. else saver['warnMess'] = '!videos';
  810. createMySaver();
  811. }
  812. }
  813.  
  814. /* Parse HLS */
  815. function ytHLS() {
  816. var ytHLSFormats = {
  817. '92': 'Very Low Definition MP4',
  818. '93': 'Low Definition MP4',
  819. '94': 'Standard Definition MP4',
  820. '95': 'High Definition MP4',
  821. '96': 'Full High Definition MP4'
  822. };
  823. ytVideoList["Any Definition MP4"] = ytHLSVideos;
  824. if (ytHLSContent) {
  825. var ytHLSVideo, ytVideoCodeParse, ytVideoCode, myVideoCode;
  826. var ytHLSMatcher = new RegExp('(http.*?m3u8)', 'g');
  827. ytHLSVideos = ytHLSContent.match(ytHLSMatcher);
  828. if (ytHLSVideos) {
  829. for (var i = 0; i < ytHLSVideos.length; i++) {
  830. ytHLSVideo = ytHLSVideos[i];
  831. ytVideoCodeParse = ytHLSVideo.match(/\/itag\/(\d{1,3})\//);
  832. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  833. if (ytVideoCode) {
  834. myVideoCode = ytHLSFormats[ytVideoCode];
  835. if (myVideoCode && ytHLSVideo) {
  836. ytVideoList[myVideoCode] = ytHLSVideo;
  837. }
  838. }
  839. }
  840. }
  841. }
  842.  
  843. /* Create Saver */
  844. ytVideoTitle = null;
  845. ytDefaultVideo = 'Any Definition MP4';
  846. ytSaver();
  847. createMySaver();
  848. }
  849.  
  850. /* Get Videos */
  851. var ytVideoList = {};
  852. if (ytVideosContent) {
  853. if (ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/) || ytVideosContent.match(/u0026s=/)) {
  854. var ytScriptURL = getMyContent(page.url, '"js":\\s*"(.*?)"', true);
  855. if (!ytScriptURL) ytScriptURL = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"js":\\s*"(.*?)"', true);
  856. if (ytScriptURL) {
  857. ytScriptURL = page.win.location.protocol + '//' + page.win.location.hostname + ytScriptURL;
  858. ytScriptSrc = getMyContent(ytScriptURL, 'TEXT', false);
  859. if (ytScriptSrc) ytDecryptFunction();
  860. ytVideos();
  861. }
  862. else {
  863. saver = {
  864. 'warnMess': 'other',
  865. 'warnContent': '<b>SaveTube:</b> Couldn\'t get the signature link. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'
  866. };
  867. createMySaver();
  868. }
  869. }
  870. else {
  871. ytVideos();
  872. }
  873. }
  874. else {
  875. if (ytHLSVideos) {
  876. ytHLSContent = getMyContent(ytHLSVideos, 'TEXT', false);
  877. ytHLS();
  878. }
  879. else {
  880. saver = {'warnMess': '!content'};
  881. createMySaver();
  882. }
  883. }
  884.  
  885. }
  886.  
  887. // =====DailyMotion===== //
  888.  
  889. else if (page.url.indexOf('dailymotion.com/video') != -1) {
  890.  
  891. /* Get Video Title */
  892. var dmVideoTitle = getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"title":"(.*?)"', false);
  893. if (dmVideoTitle) {
  894. dmVideoTitle = dmVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  895. dmVideoTitle = dmVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  896. dmVideoTitle = dmVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  897. dmVideoTitle = dmVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  898. dmVideoTitle = dmVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  899. }
  900.  
  901. /* Get Videos Content */
  902. var dmVideosContent = getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"qualities":\\{(.*?)\\]\\},', false);
  903.  
  904. /* Get Videos */
  905. if (dmVideosContent) {
  906. var dmVideoFormats = {'auto': 'Low Definition MP4', '240': 'Very Low Definition MP4', '380': 'Low Definition MP4', '480': 'Standard Definition MP4',
  907. '720': 'High Definition MP4', '1080': 'Full High Definition MP4'};
  908. var dmVideoList = {};
  909. var dmVideoFound = false;
  910. var dmVideoParser, dmVideoParse, myVideoCode, dmVideo;
  911. for (var dmVideoCode in dmVideoFormats) {
  912. dmVideoParser = '"' + dmVideoCode + '".*?"type":"video.*?mp4","url":"(.*?)"';
  913. dmVideoParse = dmVideosContent.match(dmVideoParser);
  914. if (!dmVideoParse) {
  915. dmVideoParser = '"' + dmVideoCode + '".*?"type":"application.*?mpegURL","url":"(.*?)"';
  916. dmVideoParse = dmVideosContent.match(dmVideoParser);
  917. }
  918. dmVideo = (dmVideoParse) ? dmVideoParse[1] : null;
  919. if (dmVideo) {
  920. if (!dmVideoFound) dmVideoFound = true;
  921. dmVideo = cleanMyContent(dmVideo, true);
  922. myVideoCode = dmVideoFormats[dmVideoCode];
  923. if (!dmVideoList[myVideoCode]) dmVideoList[myVideoCode] = dmVideo;
  924. }
  925. }
  926.  
  927. if (dmVideoFound) {
  928. /* Create Saver */
  929. var dmDefaultVideo = 'Low Definition MP4';
  930. saver = {'videoList': dmVideoList, 'videoSave': dmDefaultVideo, 'videoTitle': dmVideoTitle};
  931. feature['container'] = false;
  932. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  933. option['containers'] = ['MP4'];
  934. createMySaver();
  935. }
  936. else {
  937. saver = {'warnMess': '!videos'};
  938. createMySaver();
  939. }
  940. }
  941. else {
  942. saver = {'warnMess': '!content'};
  943. createMySaver();
  944. }
  945.  
  946. }
  947.  
  948. // =====Vimeo===== //
  949.  
  950. else if (page.url.match(/vimeo.com\/\d+/) || page.url.match(/vimeo.com\/channels\/[^\/]*($|\/$|\/page|\/\d+)/) || page.url.match(/vimeo.com\/originals\/[^\/]*($|\/$|\/\d+)/) || page.url.match(/vimeo.com\/album\/\d+\/video\/\d+/) || page.url.match(/vimeo.com\/groups\/[^\/]*\/videos\/\d+/)) {
  951.  
  952. /* Multi Video Page */
  953. if (getMyElement('', 'div', 'class', 'player_container', -1, false).length > 1) return;
  954.  
  955. /* Get Video Title */
  956. var viVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  957. if (viVideoTitle) {
  958. viVideoTitle = viVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  959. viVideoTitle = viVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  960. viVideoTitle = viVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  961. viVideoTitle = viVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  962. viVideoTitle = viVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  963. viVideoTitle = viVideoTitle.replace(/on\sVimeo$/, '');
  964. }
  965.  
  966. /* Get Content Source */
  967. var viVideoSource = getMyContent(page.url, '"config_url":"(.*?)"', false);
  968. if (viVideoSource) viVideoSource = cleanMyContent(viVideoSource, false);
  969. else viVideoSource = getMyContent(page.url, 'data-config-url="(.*?)"', false).replace(/&amp;/g, '&');
  970.  
  971. /* Get Videos Content */
  972. var viVideosContent;
  973. if (viVideoSource) {
  974. viVideosContent = getMyContent(viVideoSource, '"progressive":\\[(.*?)\\]', false);
  975. }
  976.  
  977. /* Get Videos */
  978. if (viVideosContent) {
  979. var viVideoFormats = {'1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '480p': 'Standard Definition MP4', '360p': 'Low Definition MP4', '270p': 'Very Low Definition MP4'};
  980. var viVideoList = {};
  981. var viVideoFound = false;
  982. var viVideo, myVideoCode;
  983. var viVideos = viVideosContent.split('},');
  984. for (var i = 0; i < viVideos.length; i++) {
  985. for (var viVideoCode in viVideoFormats) {
  986. if (viVideos[i].indexOf('"quality":"' + viVideoCode + '"') != -1) {
  987. viVideo = viVideos[i].match(/"url":"(.*?)"/);
  988. viVideo = (viVideo) ? viVideo[1] : null;
  989. if (viVideo) {
  990. if (!viVideoFound) viVideoFound = true;
  991. myVideoCode = viVideoFormats[viVideoCode];
  992. viVideoList[myVideoCode] = viVideo;
  993. }
  994. }
  995. }
  996. }
  997.  
  998. if (viVideoFound) {
  999. /* Create Saver */
  1000. var viDefaultVideo = 'Low Definition MP4';
  1001. saver = {'videoList': viVideoList, 'videoSave': viDefaultVideo, 'videoTitle': viVideoTitle};
  1002. feature['container'] = false;
  1003. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1004. option['containers'] = ['MP4'];
  1005. createMySaver();
  1006. }
  1007. else {
  1008. saver = {'warnMess': '!videos'};
  1009. createMySaver();
  1010. }
  1011. }
  1012. else {
  1013. saver = {'warnMess': '!content'};
  1014. createMySaver();
  1015. }
  1016.  
  1017. }
  1018.  
  1019. // =====MetaCafe===== //
  1020.  
  1021. else if (page.url.indexOf('metacafe.com/watch') != -1) {
  1022.  
  1023. /* Get Videos Content */
  1024. var mcVideosContent = getMyContent(page.url, 'flashvars\\s*=\\s*\\{(.*?)\\};', false);
  1025.  
  1026. /* Get Videos */
  1027. if (mcVideosContent) {
  1028. var mcVideoList = {};
  1029. var mcVideoFound = false;
  1030. var mcVideoFormats = {'video_alt_url2': 'High Definition MP4', 'video_alt_url': 'Low Definition MP4', 'video_url': 'Very Low Definition MP4'};
  1031. var mcVideoFormatz = {'video_alt_url2': '_720p', 'video_alt_url': '_360p', 'video_url': '_240p'};
  1032. var mcVideoHLS = mcVideosContent.match(/"src":"(.*?)"/);
  1033. mcVideoHLS = (mcVideoHLS) ? cleanMyContent(mcVideoHLS[1], false) : null;
  1034. if (mcVideoHLS) {
  1035. var mcVideoParser, mcVideoParse, myVideoCode, mcVideo;
  1036. for (var mcVideoCode in mcVideoFormats) {
  1037. mcVideoParser = '"' + mcVideoCode + '":"(.*?)"';
  1038. mcVideoParse = mcVideosContent.match(mcVideoParser);
  1039. mcVideo = (mcVideoParse) ? mcVideoParse[1] : null;
  1040. if (mcVideo) {
  1041. if (!mcVideoFound) mcVideoFound = true;
  1042. myVideoCode = mcVideoFormats[mcVideoCode];
  1043. mcVideoList[myVideoCode] = mcVideoHLS.replace('.m3u8', mcVideoFormatz[mcVideoCode] + '.m3u8');
  1044. }
  1045. }
  1046. }
  1047.  
  1048. if (mcVideoFound) {
  1049. /* Create Saver */
  1050. var mcDefaultVideo = 'Low Definition MP4';
  1051. saver = {'videoList': mcVideoList, 'videoSave': mcDefaultVideo};
  1052. feature['container'] = false;
  1053. option['definitions'] = ['High Definition', 'Low Definition', 'Very Low Definition'];
  1054. option['containers'] = ['MP4'];
  1055. createMySaver();
  1056. }
  1057. else {
  1058. saver = {'warnMess': '!videos'};
  1059. createMySaver();
  1060. }
  1061. }
  1062. else {
  1063. saver = {};
  1064. var ytVideoId = page.url.match(/\/yt-(.*?)\//);
  1065. if (ytVideoId && ytVideoId[1]) {
  1066. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId[1];
  1067. saver['warnMess'] = 'embed';
  1068. saver['warnContent'] = ytVideoLink;
  1069. }
  1070. else saver['warnMess'] = '!videos';
  1071. createMySaver();
  1072. }
  1073.  
  1074. }
  1075.  
  1076. // =====Veoh===== //
  1077.  
  1078. else if (page.url.indexOf('veoh.com/watch') != -1) {
  1079.  
  1080. /* Get Video Availability */
  1081. if (getMyElement('', 'div', 'class', 'veoh-video-player-error', 0, false)) return;
  1082.  
  1083. /* Get Video Title */
  1084. var veVideoTitle = getMyContent(page.url, 'meta\\s+name="og:title"\\s+content="(.*?)"', false);
  1085. if (veVideoTitle) {
  1086. veVideoTitle = veVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1087. veVideoTitle = veVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1088. veVideoTitle = veVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1089. veVideoTitle = veVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1090. veVideoTitle = veVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1091. }
  1092.  
  1093. /* Get Videos Content */
  1094. var veVideosContent = getMyContent(page.url.replace(/\/watch\//, '/watch/getVideo/'), '"src"\\s*:\\s*\\{(.*?)\\}', false);
  1095.  
  1096. /* Get Videos */
  1097. if (veVideosContent) {
  1098. var veVideoFormats = {'Regular': 'Low Definition MP4', 'HQ': 'Standard Definition MP4'};
  1099. var veVideoList = {};
  1100. var veVideoFound = false;
  1101. var veVideoParser, veVideoParse, veVideo, myVideoCode;
  1102. for (var veVideoCode in veVideoFormats) {
  1103. veVideoParser = veVideoCode + '":"(.*?)"';
  1104. veVideoParse = veVideosContent.match(veVideoParser);
  1105. veVideo = (veVideoParse) ? veVideoParse[1] : null;
  1106. if (veVideo) {
  1107. if (!veVideoFound) veVideoFound = true;
  1108. myVideoCode = veVideoFormats[veVideoCode];
  1109. veVideoList[myVideoCode] = cleanMyContent(veVideo, false);
  1110. }
  1111. }
  1112.  
  1113. if (veVideoFound) {
  1114. /* Create Saver */
  1115. var veDefaultVideo = 'Low Definition MP4';
  1116. saver = {'videoList': veVideoList, 'videoSave': veDefaultVideo, 'videoTitle': veVideoTitle};
  1117. feature['container'] = false;
  1118. feature['fullsize'] = false;
  1119. option['definition'] = 'LD';
  1120. option['definitions'] = ['Standard Definition', 'Low Definition'];
  1121. option['containers'] = ['MP4'];
  1122. createMySaver();
  1123. }
  1124. else {
  1125. saver = {};
  1126. var ytVideoId = getMyContent(page.url, 'youtube.com/embed/(.*?)("|\\?)', false);
  1127. if (!ytVideoId) ytVideoId = getMyContent(page.url, '"videoId":"yapi-(.*?)"', false);
  1128. if (ytVideoId) {
  1129. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId;
  1130. saver['warnMess'] = 'embed';
  1131. saver['warnContent'] = ytVideoLink;
  1132. }
  1133. else saver['warnMess'] = '!videos';
  1134. createMySaver();
  1135. }
  1136. }
  1137. else {
  1138. saver = {'warnMess': '!content'};
  1139. createMySaver();
  1140. }
  1141.  
  1142. }
  1143.  
  1144. // =====Viki===== //
  1145.  
  1146. else if (page.url.indexOf('viki.com/videos') != -1) {
  1147.  
  1148. /* Get Video Title */
  1149. var vkVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1150. if (vkVideoTitle) {
  1151. vkVideoTitle = vkVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1152. vkVideoTitle = vkVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1153. vkVideoTitle = vkVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1154. vkVideoTitle = vkVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1155. vkVideoTitle = vkVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1156. }
  1157.  
  1158. /* Get Video ID */
  1159. var vkVideoID = page.url.match(/videos\/(\d+v)/);
  1160. vkVideoID = (vkVideoID) ? vkVideoID[1] : null;
  1161.  
  1162. /* Get Videos Content */
  1163. var vkVideosContent;
  1164. if (vkVideoID) {
  1165. /*
  1166. A JavaScript implementation of the SHA family of hashes, as
  1167. defined in FIPS PUB 180-4 and FIPS PUB 202, as well as the corresponding
  1168. HMAC implementation as defined in FIPS PUB 198a
  1169.  
  1170. Copyright Brian Turek 2008-2017
  1171. Distributed under the BSD License
  1172. See http://caligatio.github.com/jsSHA/ for more information
  1173.  
  1174. Several functions taken from Paul Johnston
  1175. */
  1176. 'use strict';(function(G){function r(d,b,c){var h=0,a=[],f=0,g,m,k,e,l,p,q,t,w=!1,n=[],u=[],v,r=!1;c=c||{};g=c.encoding||"UTF8";v=c.numRounds||1;if(v!==parseInt(v,10)||1>v)throw Error("numRounds must a integer >= 1");if("SHA-1"===d)l=512,p=z,q=H,e=160,t=function(a){return a.slice()};else throw Error("Chosen SHA variant is not supported");k=A(b,g);m=x(d);this.setHMACKey=function(a,f,b){var c;if(!0===w)throw Error("HMAC key already set");if(!0===r)throw Error("Cannot set HMAC key after calling update");
  1177. g=(b||{}).encoding||"UTF8";f=A(f,g)(a);a=f.binLen;f=f.value;c=l>>>3;b=c/4-1;if(c<a/8){for(f=q(f,a,0,x(d),e);f.length<=b;)f.push(0);f[b]&=4294967040}else if(c>a/8){for(;f.length<=b;)f.push(0);f[b]&=4294967040}for(a=0;a<=b;a+=1)n[a]=f[a]^909522486,u[a]=f[a]^1549556828;m=p(n,m);h=l;w=!0};this.update=function(b){var e,g,c,d=0,q=l>>>5;e=k(b,a,f);b=e.binLen;g=e.value;e=b>>>5;for(c=0;c<e;c+=q)d+l<=b&&(m=p(g.slice(c,c+q),m),d+=l);h+=d;a=g.slice(d>>>5);f=b%l;r=!0};this.getHash=function(b,g){var c,k,l,p;if(!0===
  1178. w)throw Error("Cannot call getHash after setting HMAC key");l=B(g);switch(b){case "HEX":c=function(a){return C(a,e,l)};break;case "B64":c=function(a){return D(a,e,l)};break;case "BYTES":c=function(a){return E(a,e)};break;case "ARRAYBUFFER":try{k=new ArrayBuffer(0)}catch(I){throw Error("ARRAYBUFFER not supported by this environment");}c=function(a){return F(a,e)};break;default:throw Error("format must be HEX, B64, BYTES, or ARRAYBUFFER");}p=q(a.slice(),f,h,t(m),e);for(k=1;k<v;k+=1)p=q(p,e,0,x(d),e);
  1179. return c(p)};this.getHMAC=function(b,g){var c,k,n,r;if(!1===w)throw Error("Cannot call getHMAC without first setting HMAC key");n=B(g);switch(b){case "HEX":c=function(a){return C(a,e,n)};break;case "B64":c=function(a){return D(a,e,n)};break;case "BYTES":c=function(a){return E(a,e)};break;case "ARRAYBUFFER":try{c=new ArrayBuffer(0)}catch(I){throw Error("ARRAYBUFFER not supported by this environment");}c=function(a){return F(a,e)};break;default:throw Error("outputFormat must be HEX, B64, BYTES, or ARRAYBUFFER");
  1180. }k=q(a.slice(),f,h,t(m),e);r=p(u,x(d));r=q(k,e,l,r,e);return c(r)}}function C(d,b,c){var h="";b/=8;var a,f;for(a=0;a<b;a+=1)f=d[a>>>2]>>>8*(3+a%4*-1),h+="0123456789abcdef".charAt(f>>>4&15)+"0123456789abcdef".charAt(f&15);return c.outputUpper?h.toUpperCase():h}function D(d,b,c){var h="",a=b/8,f,g,m;for(f=0;f<a;f+=3)for(g=f+1<a?d[f+1>>>2]:0,m=f+2<a?d[f+2>>>2]:0,m=(d[f>>>2]>>>8*(3+f%4*-1)&255)<<16|(g>>>8*(3+(f+1)%4*-1)&255)<<8|m>>>8*(3+(f+2)%4*-1)&255,g=0;4>g;g+=1)8*f+6*g<=b?h+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(m>>>
  1181. 6*(3-g)&63):h+=c.b64Pad;return h}function E(d,b){var c="",h=b/8,a,f;for(a=0;a<h;a+=1)f=d[a>>>2]>>>8*(3+a%4*-1)&255,c+=String.fromCharCode(f);return c}function F(d,b){var c=b/8,h,a=new ArrayBuffer(c),f;f=new Uint8Array(a);for(h=0;h<c;h+=1)f[h]=d[h>>>2]>>>8*(3+h%4*-1)&255;return a}function B(d){var b={outputUpper:!1,b64Pad:"=",shakeLen:-1};d=d||{};b.outputUpper=d.outputUpper||!1;!0===d.hasOwnProperty("b64Pad")&&(b.b64Pad=d.b64Pad);if("boolean"!==typeof b.outputUpper)throw Error("Invalid outputUpper formatting option");
  1182. if("string"!==typeof b.b64Pad)throw Error("Invalid b64Pad formatting option");return b}function A(d,b){var c;switch(b){case "UTF8":case "UTF16BE":case "UTF16LE":break;default:throw Error("encoding must be UTF8, UTF16BE, or UTF16LE");}switch(d){case "HEX":c=function(b,a,f){var g=b.length,c,d,e,l,p;if(0!==g%2)throw Error("String of HEX type must be in byte increments");a=a||[0];f=f||0;p=f>>>3;for(c=0;c<g;c+=2){d=parseInt(b.substr(c,2),16);if(isNaN(d))throw Error("String of HEX type contains invalid characters");
  1183. l=(c>>>1)+p;for(e=l>>>2;a.length<=e;)a.push(0);a[e]|=d<<8*(3+l%4*-1)}return{value:a,binLen:4*g+f}};break;case "TEXT":c=function(c,a,f){var g,d,k=0,e,l,p,q,t,n;a=a||[0];f=f||0;p=f>>>3;if("UTF8"===b)for(n=3,e=0;e<c.length;e+=1)for(g=c.charCodeAt(e),d=[],128>g?d.push(g):2048>g?(d.push(192|g>>>6),d.push(128|g&63)):55296>g||57344<=g?d.push(224|g>>>12,128|g>>>6&63,128|g&63):(e+=1,g=65536+((g&1023)<<10|c.charCodeAt(e)&1023),d.push(240|g>>>18,128|g>>>12&63,128|g>>>6&63,128|g&63)),l=0;l<d.length;l+=1){t=k+
  1184. p;for(q=t>>>2;a.length<=q;)a.push(0);a[q]|=d[l]<<8*(n+t%4*-1);k+=1}else if("UTF16BE"===b||"UTF16LE"===b)for(n=2,d="UTF16LE"===b&&!0||"UTF16LE"!==b&&!1,e=0;e<c.length;e+=1){g=c.charCodeAt(e);!0===d&&(l=g&255,g=l<<8|g>>>8);t=k+p;for(q=t>>>2;a.length<=q;)a.push(0);a[q]|=g<<8*(n+t%4*-1);k+=2}return{value:a,binLen:8*k+f}};break;case "B64":c=function(b,a,f){var c=0,d,k,e,l,p,q,n;if(-1===b.search(/^[a-zA-Z0-9=+\/]+$/))throw Error("Invalid character in base-64 string");k=b.indexOf("=");b=b.replace(/\=/g,
  1185. "");if(-1!==k&&k<b.length)throw Error("Invalid '=' found in base-64 string");a=a||[0];f=f||0;q=f>>>3;for(k=0;k<b.length;k+=4){p=b.substr(k,4);for(e=l=0;e<p.length;e+=1)d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(p[e]),l|=d<<18-6*e;for(e=0;e<p.length-1;e+=1){n=c+q;for(d=n>>>2;a.length<=d;)a.push(0);a[d]|=(l>>>16-8*e&255)<<8*(3+n%4*-1);c+=1}}return{value:a,binLen:8*c+f}};break;case "BYTES":c=function(b,a,c){var d,m,k,e,l;a=a||[0];c=c||0;k=c>>>3;for(m=0;m<b.length;m+=
  1186. 1)d=b.charCodeAt(m),l=m+k,e=l>>>2,a.length<=e&&a.push(0),a[e]|=d<<8*(3+l%4*-1);return{value:a,binLen:8*b.length+c}};break;case "ARRAYBUFFER":try{c=new ArrayBuffer(0)}catch(h){throw Error("ARRAYBUFFER not supported by this environment");}c=function(b,a,c){var d,m,k,e,l;a=a||[0];c=c||0;m=c>>>3;l=new Uint8Array(b);for(d=0;d<b.byteLength;d+=1)e=d+m,k=e>>>2,a.length<=k&&a.push(0),a[k]|=l[d]<<8*(3+e%4*-1);return{value:a,binLen:8*b.byteLength+c}};break;default:throw Error("format must be HEX, TEXT, B64, BYTES, or ARRAYBUFFER");
  1187. }return c}function n(d,b){return d<<b|d>>>32-b}function u(d,b){var c=(d&65535)+(b&65535);return((d>>>16)+(b>>>16)+(c>>>16)&65535)<<16|c&65535}function y(d,b,c,h,a){var f=(d&65535)+(b&65535)+(c&65535)+(h&65535)+(a&65535);return((d>>>16)+(b>>>16)+(c>>>16)+(h>>>16)+(a>>>16)+(f>>>16)&65535)<<16|f&65535}function x(d){var b=[];if("SHA-1"===d)b=[1732584193,4023233417,2562383102,271733878,3285377520];else throw Error("No SHA variants supported");return b}function z(d,b){var c=[],h,a,f,g,m,k,e;h=b[0];a=b[1];
  1188. f=b[2];g=b[3];m=b[4];for(e=0;80>e;e+=1)c[e]=16>e?d[e]:n(c[e-3]^c[e-8]^c[e-14]^c[e-16],1),k=20>e?y(n(h,5),a&f^~a&g,m,1518500249,c[e]):40>e?y(n(h,5),a^f^g,m,1859775393,c[e]):60>e?y(n(h,5),a&f^a&g^f&g,m,2400959708,c[e]):y(n(h,5),a^f^g,m,3395469782,c[e]),m=g,g=f,f=n(a,30),a=h,h=k;b[0]=u(h,b[0]);b[1]=u(a,b[1]);b[2]=u(f,b[2]);b[3]=u(g,b[3]);b[4]=u(m,b[4]);return b}function H(d,b,c,h){var a;for(a=(b+65>>>9<<4)+15;d.length<=a;)d.push(0);d[b>>>5]|=128<<24-b%32;b+=c;d[a]=b&4294967295;d[a-1]=b/4294967296|0;
  1189. b=d.length;for(a=0;a<b;a+=16)h=z(d.slice(a,a+16),h);return h}"function"===typeof define&&define.amd?define(function(){return r}):"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(module.exports=r),exports=r):G.jsSHA=r})(this);
  1190.  
  1191. var vkTimestamp = parseInt(Date.now() / 1000);
  1192. var vkQuery = "/v5/videos/" + vkVideoID + "/streams.json?app=100005a&t=" + vkTimestamp + "&site=www.viki.com"
  1193. var vkToken = "MM_d*yP@`&1@]@!AVrXf_o-HVEnoTnm$O-ti4[G~$JDI/Dc-&piU&z&5.;:}95\=Iad";
  1194. var shaObj = new jsSHA("SHA-1", "TEXT");
  1195. shaObj.setHMACKey(vkToken, "TEXT");
  1196. shaObj.update(vkQuery);
  1197. var vkSig = shaObj.getHMAC("HEX");
  1198. var vkSource = "https://api.viki.io" + vkQuery + "&sig=" + vkSig;
  1199. vkVideosContent = getMyContent(vkSource, 'TEXT', false);
  1200. }
  1201.  
  1202. /* Get Videos */
  1203. if (vkVideosContent) {
  1204. var vkVideoList = {};
  1205. var vkVideoFormats = {'720p': 'High Definition MP4', '480p': 'Standard Definition MP4', '360p': 'Low Definition MP4', '240p': 'Very Low Definition MP4'};
  1206. var vkVideoFound = false;
  1207. var vkVideoParser, vkVideoParse, vkVideo, myVideoCode;
  1208. for (var vkVideoCode in vkVideoFormats) {
  1209. vkVideoParser = '"' + vkVideoCode + '".*?"https":\{"url":"(.*?)"';
  1210. vkVideoParse = vkVideosContent.match(vkVideoParser);
  1211. vkVideo = (vkVideoParse) ? vkVideoParse[1] : null;
  1212. if (vkVideo) {
  1213. if (!vkVideoFound) vkVideoFound = true;
  1214. myVideoCode = vkVideoFormats[vkVideoCode];
  1215. vkVideoList[myVideoCode] = vkVideo;
  1216. }
  1217. }
  1218.  
  1219. /* Create Saver */
  1220. if (vkVideoFound) {
  1221. var vkDefaultVideo = 'Low Definition MP4';
  1222. saver = {'videoList': vkVideoList, 'videoSave': vkDefaultVideo, 'videoTitle': vkVideoTitle};
  1223. feature['container'] = false;
  1224. option['definition'] = 'LD';
  1225. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1226. option['containers'] = ['MP4'];
  1227. createMySaver();
  1228. }
  1229. else {
  1230. if (vkVideosContent.indexOf('unauth') != -1) {
  1231. saver = {
  1232. 'warnMess': 'other',
  1233. 'warnContent': '<b>SaveTube:</b> Authorization required!'
  1234. };
  1235. }
  1236. else saver = {'warnMess': '!videos'};
  1237. createMySaver();
  1238. }
  1239. }
  1240. else {
  1241. saver = {'warnMess': '!content'};
  1242. createMySaver();
  1243. }
  1244.  
  1245. }
  1246.  
  1247. // =====IMDB===== //
  1248.  
  1249. else if (page.url.indexOf('imdb.com') != -1) {
  1250.  
  1251. /* Redirect To Video Page */
  1252. if (page.url.indexOf('/video/') == -1 && page.url.indexOf('/videoplayer/') == -1) {
  1253. page.doc.addEventListener('click', function(e) {
  1254. var p = e.target.parentNode;
  1255. while (p) {
  1256. if (p.tagName === 'A' && p.href.indexOf('/video/imdb') != -1) {
  1257. page.win.location.href = p.href.replace(/imdb\/inline.*/, '');
  1258. }
  1259. p = p.parentNode;
  1260. }
  1261. }, false);
  1262. return;
  1263. }
  1264.  
  1265. /* Get Video Title */
  1266. var imdbVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1267. if (imdbVideoTitle) {
  1268. imdbVideoTitle = imdbVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1269. imdbVideoTitle = imdbVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1270. imdbVideoTitle = imdbVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1271. imdbVideoTitle = imdbVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1272. imdbVideoTitle = imdbVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1273. }
  1274.  
  1275. /* Get Video Id */
  1276. var imdbVideoId = page.url.replace(/.*videoplayer\//, '').replace(/(\/|\?).*/, '');
  1277.  
  1278. /* Get Videos Content */
  1279. var imdbVideosContent = getMyContent(page.url, '"' + imdbVideoId + '":\\{("aggregateUpVotes.*?videoId)', false);
  1280.  
  1281. /* Get Videos */
  1282. var imdbVideoList = {};
  1283. if (imdbVideosContent) {
  1284. var imdbVideoFormats = {'1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '480p': 'Standard Definition MP4', '360p': 'Low Definition MP4', 'SD': 'Low Definition MP4', '240p': 'Very Low Definition MP4'};
  1285. var imdbVideoFound = false;
  1286. var imdbVideoParser, imdbVideoParse, myVideoCode, imdbVideo;
  1287. for (var imdbVideoCode in imdbVideoFormats) {
  1288. imdbVideoParser = '"definition":"' + imdbVideoCode + '".*?"videoUrl":"(.*?)"';
  1289. imdbVideoParse = imdbVideosContent.match(imdbVideoParser);
  1290. imdbVideo = (imdbVideoParse) ? imdbVideoParse[1] : null;
  1291. if (imdbVideo) {
  1292. imdbVideo = cleanMyContent(imdbVideo, false);
  1293. if (!imdbVideoFound) imdbVideoFound = true;
  1294. myVideoCode = imdbVideoFormats[imdbVideoCode];
  1295. if (!imdbVideoList[myVideoCode]) imdbVideoList[myVideoCode] = imdbVideo;
  1296. }
  1297. }
  1298.  
  1299. if (imdbVideoFound) {
  1300. /* Create Saver */
  1301. var imdbDefaultVideo = 'Low Definition MP4';
  1302. saver = {'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'videoTitle': imdbVideoTitle};
  1303. feature['container'] = false;
  1304. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1305. option['containers'] = ['MP4'];
  1306. createMySaver();
  1307. }
  1308. else {
  1309. saver = {'warnMess': '!videos'};
  1310. createMySaver();
  1311. }
  1312. }
  1313. else {
  1314. imdbVideo = getMyContent(page.url, '"videoUrl":"(.*?)"', false);
  1315. if (imdbVideo) {
  1316. /* Create Saver */
  1317. imdbVideo = cleanMyContent(imdbVideo, false);
  1318. imdbVideoList[imdbDefaultVideo] = imdbVideo;
  1319. var imdbDefaultVideo = 'Low Definition MP4';
  1320. saver = {'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'videoTitle': imdbVideoTitle};
  1321. feature['container'] = false;
  1322. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1323. option['containers'] = ['MP4'];
  1324. createMySaver();
  1325. }
  1326. else {
  1327. saver = {'warnMess': '!content'};
  1328. createMySaver();
  1329. }
  1330. }
  1331.  
  1332. }
  1333.  
  1334. }
  1335.  
  1336.  
  1337. // ==========Run========== //
  1338.  
  1339. SaveTube();
  1340.  
  1341. page.win.setInterval(function() {
  1342. if (page.url != page.win.location.href) {
  1343. if (saver['saverPanel'] && saver['saverPanel'].parentNode) {
  1344. removeMyElement(saver['saverPanel'].parentNode, saver['saverPanel']);
  1345. }
  1346. page.doc = page.win.document;
  1347. page.body = page.doc.body;
  1348. page.url = page.win.location.href;
  1349. SaveTube();
  1350. }
  1351. }, 500);
  1352.  
  1353. })();