SaveTube

Download videos from video sharing web sites.

当前为 2018-01-11 提交的版本,查看 最新版本

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