SaveTube

Download videos from video sharing web sites.

当前为 2018-06-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SaveTube
  3. // @version 2018.06.07
  4. // @description Download videos from video sharing web sites.
  5. // @author sebaro
  6. // @namespace http://sebaro.pro/savetube
  7. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  8. // @icon https://gitlab.com/sebaro/savetube/raw/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://sebaro.pro/savetube
  70. Contact: http://sebaro.pro/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, 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://sebaro.pro/savetube';
  98. var contact = 'http://sebaro.pro/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. var vdoDef = ' (' + saver['videoSave'].split(' ').slice(0, -1).join('').match(/[A-Z]/g).join('') + ')';
  417. var vdoExt = '.' + saver['videoSave'].split(' ').slice(-1).join('').toLowerCase();
  418. var vdoTle = (saver['videoTitle']) ? saver['videoTitle'] : '';
  419. if (feature['autoget'] && vdoTle && saver['videoSave'] == 'High Definition MP4') {
  420. page.win.location.href = vdoURL + '&title=' + vdoTle + vdoDef;
  421. }
  422. else {
  423. if (saver['videoList'][saver['videoSave']] == 'DASH') {
  424. if (saver['videoSave'].indexOf('MP4') != -1) {
  425. var vdoV = saver['videoList'][saver['videoSave'].replace(/MP4/, 'Video MP4')];
  426. if (saver['videoList']['High Bitrate Audio MP4']) {
  427. var vdoA = saver['videoList']['High Bitrate Audio MP4'];
  428. }
  429. else if (saver['videoList']['Medium Bitrate Audio MP4']) {
  430. var vdoA = saver['videoList']['Medium Bitrate Audio MP4'];
  431. }
  432. else {
  433. var vdoA = saver['videoList']['Low Bitrate Audio MP4'];
  434. }
  435. }
  436. else {
  437. var vdoV = saver['videoList'][saver['videoSave'].replace(/WebM/, 'Video WebM')];
  438. if (saver['videoList']['High Bitrate Audio Opus']) {
  439. var vdoA = saver['videoList']['High Bitrate Audio Opus'];
  440. }
  441. else if (saver['videoList']['Medium Bitrate Audio Opus']) {
  442. var vdoA = saver['videoList']['Medium Bitrate Audio Opus'];
  443. }
  444. else {
  445. var vdoA = saver['videoList']['Low Bitrate Audio Opus'];
  446. }
  447. }
  448. var vdoT = (vdoTle) ? vdoTle + vdoDef : page.site + vdoDef;
  449. vdoURL = 'savetube:' + vdoT + '=SAVETUBE=' + vdoV + '=SAVETUBE=' + vdoA;
  450. page.win.location.href = vdoURL;
  451. }
  452. else {
  453. var vdoLnk = '';
  454. if (vdoTle) {
  455. var vdoNme = vdoTle + vdoDef + vdoExt;
  456. vdoLnk = 'Get <a href="' + vdoURL + '" style="color:#00892C" download="' + vdoNme + '" target="_blank">Link</a>';
  457. }
  458. else {
  459. vdoLnk = 'Get <a href="' + vdoURL + '" style="color:#00892C" target="_blank">Link</a>';
  460. }
  461. modifyMyElement(saver['buttonGet'] , 'div', vdoLnk, false);
  462. }
  463. }
  464. }
  465.  
  466. function cleanMyContent(content, unesc) {
  467. var myNewContent = content;
  468. if (unesc) myNewContent = unescape(myNewContent);
  469. myNewContent = myNewContent.replace(/\\u0025/g,'%');
  470. myNewContent = myNewContent.replace(/\\u0026/g,'&');
  471. myNewContent = myNewContent.replace(/\\/g,'');
  472. myNewContent = myNewContent.replace(/\n/g,'');
  473. return myNewContent;
  474. }
  475.  
  476. function getMyContent(url, pattern, clean) {
  477. var myPageContent, myVideosParse, myVideosContent;
  478. if (!sources[url]) {
  479. var xmlHTTP = new XMLHttpRequest();
  480. xmlHTTP.open('GET', url, false);
  481. xmlHTTP.send();
  482. sources[url] = (xmlHTTP.responseText) ? xmlHTTP.responseText : xmlHTTP.responseXML;
  483. //console.log('Request: ' + url + ' ' + pattern);
  484. }
  485. if (pattern == 'TEXT') {
  486. myVideosContent = sources[url];
  487. }
  488. else {
  489. myPageContent = (sources[url]) ? sources[url] : '';
  490. if (clean) myPageContent = cleanMyContent(myPageContent, true);
  491. myVideosParse = myPageContent.match(pattern);
  492. myVideosContent = (myVideosParse) ? myVideosParse[1] : null;
  493. }
  494. return myVideosContent;
  495. }
  496.  
  497. function setMyOptions(key, value) {
  498. key = page.site + '_' + userscript.toLowerCase() + '_' + key;
  499. try {
  500. localStorage.setItem(key, value);
  501. if (localStorage.getItem(key) == value) return;
  502. else throw false;
  503. }
  504. catch(e) {
  505. var date = new Date();
  506. date.setTime(date.getTime() + (356*24*60*60*1000));
  507. var expires = '; expires=' + date.toGMTString();
  508. page.doc.cookie = key + '=' + value + expires + '; path=/';
  509. }
  510. }
  511.  
  512. function getMyOptions() {
  513. for (var opt in option) {
  514. if (option.hasOwnProperty(opt)) {
  515. var key = page.site + '_' + userscript.toLowerCase() + '_' + opt;
  516. try {
  517. if (localStorage.getItem(key)) {
  518. option[opt] = localStorage.getItem(key);
  519. continue;
  520. }
  521. else throw false;
  522. }
  523. catch(e) {
  524. var cookies = page.doc.cookie.split(';');
  525. for (var i=0; i < cookies.length; i++) {
  526. var cookie = cookies[i];
  527. while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
  528. option[opt] = (cookie.indexOf(key) == 0) ? cookie.substring(key.length + 1, cookie.length) : option[opt];
  529. }
  530. }
  531. }
  532. }
  533. option['autoget'] = (option['autoget'] === true || option['autoget'] == 'true') ? true : false;
  534. option['dash'] = (option['dash'] === true || option['dash'] == 'true') ? true : false;
  535. }
  536.  
  537. function showMyMessage(cause, content) {
  538. styleMyElement(saver['saverPanel'], {color: '#AD0000', fontSize: '12px'});
  539. if (cause == '!content') {
  540. var myNoContentMess = '<b>SaveTube:</b> Couldn\'t get the videos content. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  541. modifyMyElement(saver['saverPanel'], 'div', myNoContentMess, false);
  542. }
  543. else if (cause == '!videos') {
  544. var myNoVideosMess = '<b>SaveTube:</b> Couldn\'t get any video. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  545. modifyMyElement(saver['saverPanel'], 'div', myNoVideosMess, false);
  546. }
  547. else if (cause == '!support') {
  548. var myNoSupportMess = '<b>SaveTube:</b> This video uses the RTMP protocol which is not supported.';
  549. modifyMyElement(saver['saverPanel'], 'div', myNoSupportMess, false);
  550. }
  551. else if (cause == 'embed') {
  552. var myEmbedMess = '<b>SaveTube:</b> This is an embedded video. You can get it <a href="' + content + '" style="color:#00892C">here</a>.';
  553. modifyMyElement(saver['saverPanel'], 'div', myEmbedMess, false);
  554. }
  555. else if (cause == 'other') {
  556. modifyMyElement(saver['saverPanel'], 'div', content, false);
  557. }
  558. }
  559.  
  560.  
  561. // ==========Websites========== //
  562.  
  563. function SaveTube() {
  564.  
  565. // =====YouTube===== //
  566.  
  567. if (page.url.indexOf('youtube.com/watch') != -1) {
  568.  
  569. /* Redirect Categories */
  570. if (page.url.indexOf('gaming.youtube.com') != -1) {
  571. page.win.location.href = page.url.replace('gaming', 'www');
  572. }
  573.  
  574. /* Video Availability */
  575. if (getMyContent(page.url, '"simpleText":"(This video is (private|unavailable|not available).)"', false)) return;
  576. var ytVideoUnavailable = getMyElement('', 'div', 'id', 'player-unavailable', -1, false);
  577. if (ytVideoUnavailable) {
  578. if (ytVideoUnavailable.className.indexOf('hid') == -1) {
  579. var ytAgeGateContent = getMyElement('', 'div', 'id', 'watch7-player-age-gate-content', -1, true);
  580. if (!ytAgeGateContent) return;
  581. else {
  582. if(ytAgeGateContent.indexOf('feature=private_video') != -1) return;
  583. }
  584. }
  585. }
  586.  
  587. /* Decrypt Signature */
  588. var ytScriptSrc;
  589. function ytDecryptSignature(s) {return null;}
  590. function ytDecryptFunction() {
  591. var ytSignFuncName, ytSignFuncBody, ytSwapFuncName, ytSwapFuncBody, ytFuncMatch;
  592. ytScriptSrc = ytScriptSrc.replace(/(\r\n|\n|\r)/gm, '');
  593. ytSignFuncName = ytScriptSrc.match(/"signature"\s*,\s*([^\)]*?)\(/);
  594. ytSignFuncName = (ytSignFuncName) ? ytSignFuncName[1] : null;
  595. if (ytSignFuncName) {
  596. ytFuncMatch = ytSignFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\}';
  597. ytSignFuncBody = ytScriptSrc.match(ytFuncMatch);
  598. ytSignFuncBody = (ytSignFuncBody) ? ytSignFuncBody[1] : null;
  599. if (ytSignFuncBody) {
  600. ytSwapFuncName = ytSignFuncBody.match(/((\$|_|\w)+)\.(\$|_|\w)+\(\w,[0-9]+\)/);
  601. ytSwapFuncName = (ytSwapFuncName) ? ytSwapFuncName[1] : null;
  602. if (ytSwapFuncName) {
  603. ytFuncMatch = 'var\\s+' + ytSwapFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};';
  604. ytSwapFuncBody = ytScriptSrc.match(ytFuncMatch);
  605. ytSwapFuncBody = (ytSwapFuncBody) ? ytSwapFuncBody[1] : null;
  606. }
  607. if (ytSwapFuncBody) ytSignFuncBody = 'var ' + ytSwapFuncName + '={' + ytSwapFuncBody + '};' + ytSignFuncBody;
  608. ytSignFuncBody = 'try {' + ytSignFuncBody + '} catch(e) {return null}';
  609. ytDecryptSignature = new Function('a', ytSignFuncBody);
  610. }
  611. }
  612. }
  613.  
  614. /* Get Video Title */
  615. var ytVideoTitle = getMyContent(page.url, '"title":"(.*?)"', false);
  616. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, '"videoPrimaryInfoRenderer":\\{"title":\\{"simpleText":"(.*?)"', false);
  617. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  618. if (!ytVideoTitle) ytVideoTitle = getMyContent(page.url, 'meta\\s+itemprop="name"\\s+content="(.*?)"', false);
  619. if (ytVideoTitle) {
  620. ytVideoTitle = ytVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  621. ytVideoTitle = ytVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  622. ytVideoTitle = ytVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  623. ytVideoTitle = ytVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  624. ytVideoTitle = ytVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  625. }
  626.  
  627. /* Get Videos Content */
  628. var ytVideosEncodedFmts, ytVideosAdaptiveFmts, ytVideosContent, ytHLSVideos, ytHLSContent;
  629. ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map":\\s*"(.*?)"', false);
  630. if (!ytVideosEncodedFmts) ytVideosEncodedFmts = getMyContent(page.url, '\\\\"url_encoded_fmt_stream_map\\\\":\\s*\\\\"(.*?)\\\\"', false);
  631. ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts":\\s*"(.*?)"', false);
  632. if (!ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = getMyContent(page.url, '\\\\"adaptive_fmts\\\\":\\s*\\\\"(.*?)\\\\"', false);
  633. if (ytVideosEncodedFmts) {
  634. ytVideosContent = ytVideosEncodedFmts;
  635. }
  636. else {
  637. ytHLSVideos = getMyContent(page.url, '"hlsvp":\\s*"(.*?)"', false);
  638. if (!ytHLSVideos) ytHLSVideos = getMyContent(page.url, '\\\\"hlsvp\\\\":\\s*\\\\"(.*?)\\\\"', false);
  639. if (ytHLSVideos) {
  640. ytHLSVideos = cleanMyContent(ytHLSVideos, false);
  641. if (ytHLSVideos.indexOf('keepalive/yes/') != -1) ytHLSVideos = ytHLSVideos.replace('keepalive/yes/', '');
  642. }
  643. else {
  644. var ytVideoID = page.url.match(/(\?|&)v=(.*?)(&|$)/);
  645. ytVideoID = (ytVideoID) ? ytVideoID[2] : null;
  646. if (ytVideoID) {
  647. var ytVideoSts = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"sts"\\s*:\\s*(\\d+)', false);
  648. 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;
  649. var ytVideosInfo = getMyContent(ytVideosInfoURL, 'TEXT', false);
  650. if (ytVideosInfo) {
  651. ytVideosEncodedFmts = ytVideosInfo.match(/url_encoded_fmt_stream_map=(.*?)&/);
  652. ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null;
  653. if (ytVideosEncodedFmts) {
  654. ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
  655. ytVideosContent = ytVideosEncodedFmts;
  656. }
  657. if (!ytVideosAdaptiveFmts) {
  658. ytVideosAdaptiveFmts = ytVideosInfo.match(/adaptive_fmts=(.*?)&/);
  659. ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null;
  660. if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
  661. }
  662. }
  663. }
  664. }
  665. }
  666. if (ytVideosAdaptiveFmts && !ytHLSVideos) {
  667. if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts;
  668. else ytVideosContent = ytVideosAdaptiveFmts;
  669. }
  670.  
  671. /* Create Saver */
  672. var ytDefaultVideo = 'Low Definition MP4';
  673. function ytSaver() {
  674. saver = {'videoList': ytVideoList, 'videoSave': ytDefaultVideo, 'videoTitle': ytVideoTitle};
  675. option['definitions'] = ['Ultra High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  676. option['containers'] = ['MP4', 'WebM', '3GP', 'Any'];
  677. }
  678.  
  679. /* Parse Videos */
  680. function ytVideos() {
  681. var ytVideoFormats = {
  682. '17': 'Very Low Definition 3GP',
  683. '18': 'Low Definition MP4',
  684. '22': 'High Definition MP4',
  685. '36': 'Low Definition 3GP',
  686. '43': 'Low Definition WebM',
  687. '135': 'Standard Definition Video MP4',
  688. '136': 'High Definition Video MP4',
  689. '137': 'Full High Definition Video MP4',
  690. '140': 'Medium Bitrate Audio MP4',
  691. '171': 'Medium Bitrate Audio WebM',
  692. '244': 'Standard Definition Video WebM',
  693. '247': 'High Definition Video WebM',
  694. '248': 'Full High Definition Video WebM',
  695. '249': 'Low Bitrate Audio Opus',
  696. '250': 'Medium Bitrate Audio Opus',
  697. '251': 'High Bitrate Audio Opus',
  698. '272': 'Ultra High Definition Video WebM',
  699. '298': 'High Definition Video MP4',
  700. '299': 'Full High Definition Video MP4',
  701. '302': 'High Definition Video WebM',
  702. '303': 'Full High Definition Video WebM',
  703. '313': 'Ultra High Definition Video WebM',
  704. '315': 'Ultra High Definition Video WebM',
  705. '333': 'Standard Definition Video WebM',
  706. '334': 'High Definition Video WebM',
  707. '335': 'Full High Definition Video WebM',
  708. '337': 'Ultra High Definition Video WebM'
  709. };
  710. var ytVideoFound = false;
  711. var ytVideos = ytVideosContent.split(',');
  712. var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo;
  713. for (var i = 0; i < ytVideos.length; i++) {
  714. if (!ytVideos[i].match(/^url/)) {
  715. ytVideoParse = ytVideos[i].match(/(.*)(url=.*$)/);
  716. if (ytVideoParse) ytVideos[i] = ytVideoParse[2] + '&' + ytVideoParse[1];
  717. }
  718. ytVideoCodeParse = ytVideos[i].match(/itag=(\d{1,3})/);
  719. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  720. if (ytVideoCode) {
  721. myVideoCode = ytVideoFormats[ytVideoCode];
  722. if (myVideoCode) {
  723. ytVideo = cleanMyContent(ytVideos[i], true);
  724. ytVideo = ytVideo.replace(/url=/, '').replace(/&$/, '');
  725. if (ytVideo.match(/itag=/) && ytVideo.match(/itag=/g).length > 1) {
  726. if (ytVideo.match(/itag=\d{1,3}&/)) ytVideo = ytVideo.replace(/itag=\d{1,3}&/, '');
  727. else if (ytVideo.match(/&itag=\d{1,3}/)) ytVideo = ytVideo.replace(/&itag=\d{1,3}/, '');
  728. }
  729. if (ytVideo.match(/clen=/) && ytVideo.match(/clen=/g).length > 1) {
  730. if (ytVideo.match(/clen=\d+&/)) ytVideo = ytVideo.replace(/clen=\d+&/, '');
  731. else if (ytVideo.match(/&clen=\d+/)) ytVideo = ytVideo.replace(/&clen=\d+/, '');
  732. }
  733. if (ytVideo.match(/lmt=/) && ytVideo.match(/lmt=/g).length > 1) {
  734. if (ytVideo.match(/lmt=\d+&/)) ytVideo = ytVideo.replace(/lmt=\d+&/, '');
  735. else if (ytVideo.match(/&lmt=\d+/)) ytVideo = ytVideo.replace(/&lmt=\d+/, '');
  736. }
  737. if (ytVideo.match(/type=(video|audio).*?&/)) ytVideo = ytVideo.replace(/type=(video|audio).*?&/, '');
  738. else ytVideo = ytVideo.replace(/&type=(video|audio).*$/, '');
  739. if (ytVideo.match(/xtags=[^%=]*&/)) ytVideo = ytVideo.replace(/xtags=[^%=]*?&/, '');
  740. else if (ytVideo.match(/&xtags=[^%=]*$/)) ytVideo = ytVideo.replace(/&xtags=[^%=]*$/, '');
  741. if (ytVideo.match(/&sig=/)) ytVideo = ytVideo.replace (/&sig=/, '&signature=');
  742. else if (ytVideo.match(/&s=/)) {
  743. var ytSig = ytVideo.match(/&s=(.*?)(&|$)/);
  744. if (ytSig) {
  745. var s = ytSig[1];
  746. s = ytDecryptSignature(s);
  747. if (s) ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&signature=' + s + '$1');
  748. else ytVideo = '';
  749. }
  750. else ytVideo = '';
  751. }
  752. ytVideo = cleanMyContent(ytVideo, true);
  753. if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes';
  754. if (ytVideo && ytVideo.indexOf('http') == 0) {
  755. if (!ytVideoFound) ytVideoFound = true;
  756. ytVideoList[myVideoCode] = ytVideo;
  757. }
  758. }
  759. }
  760. }
  761.  
  762. if (ytVideoFound) {
  763. /* DASH */
  764. if (!ytVideoList['Standard Definition MP4'] && ytVideoList['Standard Definition Video MP4']) ytVideoList['Standard Definition MP4'] = 'DASH';
  765. if (!ytVideoList['High Definition MP4'] && ytVideoList['High Definition Video MP4']) ytVideoList['High Definition MP4'] = 'DASH';
  766. if (!ytVideoList['Full High Definition MP4'] && ytVideoList['Full High Definition Video MP4']) ytVideoList['Full High Definition MP4'] = 'DASH';
  767. if (!ytVideoList['Ultra High Definition MP4'] && ytVideoList['Ultra High Definition Video MP4']) ytVideoList['Ultra High Definition MP4'] = 'DASH';
  768. if (!ytVideoList['Standard Definition WebM'] && ytVideoList['Standard Definition Video WebM']) ytVideoList['Standard Definition WebM'] = 'DASH';
  769. if (!ytVideoList['High Definition WebM'] && ytVideoList['High Definition Video WebM']) ytVideoList['High Definition WebM'] = 'DASH';
  770. if (!ytVideoList['Full High Definition WebM'] && ytVideoList['Full High Definition Video WebM']) ytVideoList['Full High Definition WebM'] = 'DASH';
  771. if (!ytVideoList['Ultra High Definition WebM'] && ytVideoList['Ultra High Definition Video WebM']) ytVideoList['Ultra High Definition WebM'] = 'DASH';
  772. feature['dash'] = true;
  773.  
  774. /* Create Saver */
  775. feature['autoget'] = true;
  776. ytSaver();
  777. createMySaver();
  778. }
  779. else {
  780. saver = {};
  781. if (ytVideosContent.indexOf('conn=rtmp') != -1) saver['warnMess'] = '!support';
  782. else saver['warnMess'] = '!videos';
  783. createMySaver();
  784. }
  785. }
  786.  
  787. /* Parse HLS */
  788. function ytHLS() {
  789. var ytHLSFormats = {
  790. '92': 'Very Low Definition MP4',
  791. '93': 'Low Definition MP4',
  792. '94': 'Standard Definition MP4',
  793. '95': 'High Definition MP4',
  794. '96': 'Full High Definition MP4'
  795. };
  796. ytVideoList["Any Definition MP4"] = ytHLSVideos;
  797. if (ytHLSContent) {
  798. var ytHLSVideo, ytVideoCodeParse, ytVideoCode, myVideoCode;
  799. var ytHLSMatcher = new RegExp('(http.*?m3u8)', 'g');
  800. ytHLSVideos = ytHLSContent.match(ytHLSMatcher);
  801. if (ytHLSVideos) {
  802. for (var i = 0; i < ytHLSVideos.length; i++) {
  803. ytHLSVideo = ytHLSVideos[i];
  804. ytVideoCodeParse = ytHLSVideo.match(/\/itag\/(\d{1,3})\//);
  805. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  806. if (ytVideoCode) {
  807. myVideoCode = ytHLSFormats[ytVideoCode];
  808. if (myVideoCode && ytHLSVideo) {
  809. ytVideoList[myVideoCode] = ytHLSVideo;
  810. }
  811. }
  812. }
  813. }
  814. }
  815.  
  816. /* Create Saver */
  817. ytVideoTitle = null;
  818. ytDefaultVideo = 'Any Definition MP4';
  819. ytSaver();
  820. createMySaver();
  821. }
  822.  
  823. /* Get Videos */
  824. var ytVideoList = {};
  825. if (ytVideosContent) {
  826. if (ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/) || ytVideosContent.match(/u0026s=/)) {
  827. var ytScriptURL = getMyContent(page.url, '"js":\\s*"(.*?)"', true);
  828. if (!ytScriptURL) ytScriptURL = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"js":\\s*"(.*?)"', true);
  829. if (ytScriptURL) {
  830. ytScriptURL = page.win.location.protocol + '//' + page.win.location.hostname + ytScriptURL;
  831. ytScriptSrc = getMyContent(ytScriptURL, 'TEXT', false);
  832. if (ytScriptSrc) ytDecryptFunction();
  833. ytVideos();
  834. }
  835. else {
  836. saver = {
  837. 'warnMess': 'other',
  838. 'warnContent': '<b>SaveTube:</b> Couldn\'t get the signature link. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'
  839. };
  840. createMySaver();
  841. }
  842. }
  843. else {
  844. ytVideos();
  845. }
  846. }
  847. else {
  848. if (ytHLSVideos) {
  849. ytHLSContent = getMyContent(ytHLSVideos, 'TEXT', false);
  850. ytHLS();
  851. }
  852. else {
  853. saver = {'warnMess': '!content'};
  854. createMySaver();
  855. }
  856. }
  857.  
  858. }
  859.  
  860. // =====DailyMotion===== //
  861.  
  862. else if (page.url.indexOf('dailymotion.com/video') != -1) {
  863.  
  864. /* Get Video Title */
  865. var dmVideoTitle = getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"title":"(.*?)"', false);
  866. if (dmVideoTitle) {
  867. dmVideoTitle = dmVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  868. dmVideoTitle = dmVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  869. dmVideoTitle = dmVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  870. dmVideoTitle = dmVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  871. dmVideoTitle = dmVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  872. }
  873.  
  874. /* Get Videos Content */
  875. var dmVideosContent = getMyContent(page.url.replace(/\/video\//, "/embed/video/"), '"qualities":\\{(.*?)\\]\\},', false);
  876.  
  877. /* Get Videos */
  878. if (dmVideosContent) {
  879. var dmVideoFormats = {'auto': 'Low Definition MP4', '240': 'Very Low Definition MP4', '380': 'Low Definition MP4', '480': 'Standard Definition MP4',
  880. '720': 'High Definition MP4', '1080': 'Full High Definition MP4'};
  881. var dmVideoList = {};
  882. var dmVideoFound = false;
  883. var dmVideoParser, dmVideoParse, myVideoCode, dmVideo;
  884. for (var dmVideoCode in dmVideoFormats) {
  885. dmVideoParser = '"' + dmVideoCode + '".*?"type":"video.*?mp4","url":"(.*?)"';
  886. dmVideoParse = dmVideosContent.match(dmVideoParser);
  887. if (!dmVideoParse) {
  888. dmVideoParser = '"' + dmVideoCode + '".*?"type":"application.*?mpegURL","url":"(.*?)"';
  889. dmVideoParse = dmVideosContent.match(dmVideoParser);
  890. }
  891. dmVideo = (dmVideoParse) ? dmVideoParse[1] : null;
  892. if (dmVideo) {
  893. if (!dmVideoFound) dmVideoFound = true;
  894. dmVideo = cleanMyContent(dmVideo, true);
  895. myVideoCode = dmVideoFormats[dmVideoCode];
  896. if (!dmVideoList[myVideoCode]) dmVideoList[myVideoCode] = dmVideo;
  897. }
  898. }
  899.  
  900. if (dmVideoFound) {
  901. /* Create Saver */
  902. var dmDefaultVideo = 'Low Definition MP4';
  903. saver = {'videoList': dmVideoList, 'videoSave': dmDefaultVideo, 'videoTitle': dmVideoTitle};
  904. feature['container'] = false;
  905. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  906. option['containers'] = ['MP4'];
  907. createMySaver();
  908. }
  909. else {
  910. saver = {'warnMess': '!videos'};
  911. createMySaver();
  912. }
  913. }
  914. else {
  915. saver = {'warnMess': '!content'};
  916. createMySaver();
  917. }
  918.  
  919. }
  920.  
  921. // =====Vimeo===== //
  922.  
  923. 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+/)) {
  924.  
  925. /* Multi Video Page */
  926. if (getMyElement('', 'div', 'class', 'player_container', -1, false).length > 1) return;
  927.  
  928. /* Get Video Title */
  929. var viVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  930. if (viVideoTitle) {
  931. viVideoTitle = viVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  932. viVideoTitle = viVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  933. viVideoTitle = viVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  934. viVideoTitle = viVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  935. viVideoTitle = viVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  936. viVideoTitle = viVideoTitle.replace(/on\sVimeo$/, '');
  937. }
  938.  
  939. /* Get Content Source */
  940. var viVideoSource = getMyContent(page.url, '"config_url":"(.*?)"', false);
  941. if (viVideoSource) viVideoSource = cleanMyContent(viVideoSource, false);
  942. else viVideoSource = getMyContent(page.url, 'data-config-url="(.*?)"', false).replace(/&amp;/g, '&');
  943.  
  944. /* Get Videos Content */
  945. var viVideosContent;
  946. if (viVideoSource) {
  947. viVideosContent = getMyContent(viVideoSource, '"progressive":\\[(.*?)\\]', false);
  948. }
  949.  
  950. /* Get Videos */
  951. if (viVideosContent) {
  952. var viVideoFormats = {'1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '480p': 'Standard Definition MP4', '360p': 'Low Definition MP4', '270p': 'Very Low Definition MP4'};
  953. var viVideoList = {};
  954. var viVideoFound = false;
  955. var viVideo, myVideoCode;
  956. var viVideos = viVideosContent.split('},');
  957. for (var i = 0; i < viVideos.length; i++) {
  958. for (var viVideoCode in viVideoFormats) {
  959. if (viVideos[i].indexOf('"quality":"' + viVideoCode + '"') != -1) {
  960. viVideo = viVideos[i].match(/"url":"(.*?)"/);
  961. viVideo = (viVideo) ? viVideo[1] : null;
  962. if (viVideo) {
  963. if (!viVideoFound) viVideoFound = true;
  964. myVideoCode = viVideoFormats[viVideoCode];
  965. viVideoList[myVideoCode] = viVideo;
  966. }
  967. }
  968. }
  969. }
  970.  
  971. if (viVideoFound) {
  972. /* Create Saver */
  973. var viDefaultVideo = 'Low Definition MP4';
  974. saver = {'videoList': viVideoList, 'videoSave': viDefaultVideo, 'videoTitle': viVideoTitle};
  975. feature['container'] = false;
  976. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  977. option['containers'] = ['MP4'];
  978. createMySaver();
  979. }
  980. else {
  981. saver = {'warnMess': '!videos'};
  982. createMySaver();
  983. }
  984. }
  985. else {
  986. saver = {'warnMess': '!content'};
  987. createMySaver();
  988. }
  989.  
  990. }
  991.  
  992. // =====MetaCafe===== //
  993.  
  994. else if (page.url.indexOf('metacafe.com/watch') != -1) {
  995.  
  996. /* Get Videos Content */
  997. var mcVideosContent = getMyContent(page.url, 'flashvars\\s*=\\s*\\{(.*?)\\};', false);
  998.  
  999. /* Get Videos */
  1000. if (mcVideosContent) {
  1001. var mcVideoList = {};
  1002. var mcVideoFound = false;
  1003. var mcVideoFormats = {'video_alt_url2': 'High Definition MP4', 'video_alt_url': 'Low Definition MP4', 'video_url': 'Very Low Definition MP4'};
  1004. var mcVideoFormatz = {'video_alt_url2': '_720p', 'video_alt_url': '_360p', 'video_url': '_240p'};
  1005. var mcVideoHLS = mcVideosContent.match(/"src":"(.*?)"/);
  1006. mcVideoHLS = (mcVideoHLS) ? cleanMyContent(mcVideoHLS[1], false) : null;
  1007. if (mcVideoHLS) {
  1008. var mcVideoParser, mcVideoParse, myVideoCode, mcVideo;
  1009. for (var mcVideoCode in mcVideoFormats) {
  1010. mcVideoParser = '"' + mcVideoCode + '":"(.*?)"';
  1011. mcVideoParse = mcVideosContent.match(mcVideoParser);
  1012. mcVideo = (mcVideoParse) ? mcVideoParse[1] : null;
  1013. if (mcVideo) {
  1014. if (!mcVideoFound) mcVideoFound = true;
  1015. myVideoCode = mcVideoFormats[mcVideoCode];
  1016. mcVideoList[myVideoCode] = mcVideoHLS.replace('.m3u8', mcVideoFormatz[mcVideoCode] + '.m3u8');
  1017. }
  1018. }
  1019. }
  1020.  
  1021. if (mcVideoFound) {
  1022. /* Create Saver */
  1023. var mcDefaultVideo = 'Low Definition MP4';
  1024. saver = {'videoList': mcVideoList, 'videoSave': mcDefaultVideo};
  1025. feature['container'] = false;
  1026. option['definitions'] = ['High Definition', 'Low Definition', 'Very Low Definition'];
  1027. option['containers'] = ['MP4'];
  1028. createMySaver();
  1029. }
  1030. else {
  1031. saver = {'warnMess': '!videos'};
  1032. createMySaver();
  1033. }
  1034. }
  1035. else {
  1036. saver = {};
  1037. var ytVideoId = page.url.match(/\/yt-(.*?)\//);
  1038. if (ytVideoId && ytVideoId[1]) {
  1039. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId[1];
  1040. saver['warnMess'] = 'embed';
  1041. saver['warnContent'] = ytVideoLink;
  1042. }
  1043. else saver['warnMess'] = '!videos';
  1044. createMySaver();
  1045. }
  1046.  
  1047. }
  1048.  
  1049. // =====Break===== //
  1050.  
  1051. else if (page.url.indexOf('break.com/video') != -1) {
  1052.  
  1053. /* Get Video Title */
  1054. var brVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1055. if (brVideoTitle) {
  1056. brVideoTitle = brVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1057. brVideoTitle = brVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1058. brVideoTitle = brVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1059. brVideoTitle = brVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1060. brVideoTitle = brVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1061. brVideoTitle = brVideoTitle.replace(/\s\|\sVideo\s\|\sBreak$/, '');
  1062. }
  1063.  
  1064. /* Get Video */
  1065. var brVideo = getMyContent(page.url, '\\[\\{"url":"(.*?)"\\}\\]', false);
  1066. if (!brVideo) brVideo = getMyContent(page.url, 'youtube.com\/embed\/(.*?)(\\?|&|")', false);
  1067.  
  1068. /* Get Videos */
  1069. if (brVideo) {
  1070. if (brVideo.length == 11) {
  1071. var ytVideoLink = 'http://youtube.com/watch?v=' + brVideo;
  1072. showMyMessage('embed', ytVideoLink);
  1073. }
  1074. else {
  1075. /* Create Player */
  1076. var brDefaultVideo = 'Low Definition MP4';
  1077. var brVideoList = {};
  1078. brVideoList[brDefaultVideo] = brVideo;
  1079. saver = {'videoList': brVideoList, 'videoSave': brDefaultVideo, 'videoTitle': brVideoTitle};
  1080. option['definitions'] = ['Low Definition'];
  1081. option['containers'] = ['MP4'];
  1082. createMySaver();
  1083. }
  1084. }
  1085. else {
  1086. showMyMessage('!videos');
  1087. }
  1088.  
  1089. }
  1090.  
  1091. // =====FunnyOrDie===== //
  1092.  
  1093. else if (page.url.indexOf('funnyordie.com/videos') != -1) {
  1094.  
  1095. /* Get Video Title */
  1096. var fodVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1097. if (fodVideoTitle) {
  1098. fodVideoTitle = fodVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1099. fodVideoTitle = fodVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1100. fodVideoTitle = fodVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1101. fodVideoTitle = fodVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1102. fodVideoTitle = fodVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1103. }
  1104.  
  1105. /* Get Videos Content */
  1106. var fodVideosContent = getMyContent(page.url, '<video([\\s\\S]*?)video>', false);
  1107.  
  1108. /* Get Videos */
  1109. if (fodVideosContent) {
  1110. 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'};
  1111. var fodVideoList = {};
  1112. var fodVideoFound = false;
  1113. var fodVideoPath, fodVideoCodes, fodVideo, myVideoCode;
  1114. fodVideoPath = fodVideosContent.match(/src="(.*?)v\d+.*?\.mp4"/);
  1115. fodVideoPath = (fodVideoPath) ? fodVideoPath[1] : null;
  1116. fodVideoCodes = fodVideosContent.match(/v([^\/]*?)\/master/);
  1117. fodVideoCodes = (fodVideoCodes) ? fodVideoCodes[1] : '';
  1118. if (fodVideoPath) {
  1119. if (fodVideoCodes) {
  1120. for (var fodVideoCode in fodVideoFormats) {
  1121. if (fodVideoCodes.indexOf(fodVideoCode.replace(/v/, '').replace(/\..*/, '')) != -1) {
  1122. if (!fodVideoFound) fodVideoFound = true;
  1123. fodVideo = fodVideoPath + fodVideoCode;
  1124. myVideoCode = fodVideoFormats[fodVideoCode];
  1125. fodVideoList[myVideoCode] = fodVideo;
  1126. }
  1127. }
  1128. }
  1129. else {
  1130. for (var fodVideoCode in fodVideoFormats) {
  1131. fodVideo = fodVideoPath + fodVideoCode;
  1132. if (fodVideosContent.match(fodVideo)) {
  1133. if (!fodVideoFound) fodVideoFound = true;
  1134. myVideoCode = fodVideoFormats[fodVideoCode];
  1135. fodVideoList[myVideoCode] = fodVideo;
  1136. }
  1137. }
  1138. }
  1139. }
  1140.  
  1141. if (fodVideoFound) {
  1142. /* Create Saver */
  1143. fodDefaultVideo = 'Low Definition MP4';
  1144. saver = {'videoList': fodVideoList, 'videoSave': fodDefaultVideo, 'videoTitle': fodVideoTitle};
  1145. feature['container'] = false;
  1146. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1147. option['containers'] = ['MP4'];
  1148. createMySaver();
  1149. }
  1150. else {
  1151. saver = {'warnMess': '!videos'};
  1152. createMySaver();
  1153. }
  1154. }
  1155. else {
  1156. saver = {'warnMess': '!content'};
  1157. createMySaver();
  1158. }
  1159.  
  1160.  
  1161. }
  1162.  
  1163. // =====Veoh===== //
  1164.  
  1165. else if (page.url.indexOf('veoh.com/watch') != -1) {
  1166.  
  1167. /* Get Video Availability */
  1168. if (getMyElement('', 'div', 'class', 'veoh-video-player-error', 0, false)) return;
  1169.  
  1170. /* Get Video Title */
  1171. var veVideoTitle = getMyContent(page.url, 'meta\\s+name="og:title"\\s+content="(.*?)"', false);
  1172. if (veVideoTitle) {
  1173. veVideoTitle = veVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1174. veVideoTitle = veVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1175. veVideoTitle = veVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1176. veVideoTitle = veVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1177. veVideoTitle = veVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1178. }
  1179.  
  1180. /* Get Videos Content */
  1181. var veVideosContent = getMyContent(page.url, '__watch.videoDetailsJSON = \'\\{(.*?)\\}', false);
  1182. veVideosContent = cleanMyContent(veVideosContent, true);
  1183.  
  1184. /* Get Videos */
  1185. if (veVideosContent) {
  1186. var veVideoFormats = {'fullPreviewHashLowPath': 'Very Low Definition MP4', 'fullPreviewHashHighPath': 'Low Definition MP4'};
  1187. var veVideoList = {};
  1188. var veVideoFound = false;
  1189. var veVideoParser, veVideoParse, veVideo, myVideoCode;
  1190. for (var veVideoCode in veVideoFormats) {
  1191. veVideoParser = veVideoCode + '":"(.*?)"';
  1192. veVideoParse = veVideosContent.match(veVideoParser);
  1193. veVideo = (veVideoParse) ? veVideoParse[1] : null;
  1194. if (veVideo) {
  1195. if (!veVideoFound) veVideoFound = true;
  1196. myVideoCode = veVideoFormats[veVideoCode];
  1197. veVideoList[myVideoCode] = veVideo;
  1198. }
  1199. }
  1200.  
  1201. if (veVideoFound) {
  1202. /* Create Saver */
  1203. var veDefaultVideo = 'Low Definition MP4';
  1204. saver = {'videoList': veVideoList, 'videoSave': veDefaultVideo, 'videoTitle': veVideoTitle};
  1205. feature['container'] = false;
  1206. feature['fullsize'] = false;
  1207. option['definition'] = 'LD';
  1208. option['definitions'] = ['Low Definition', 'Very Low Definition'];
  1209. option['containers'] = ['MP4'];
  1210. createMySaver();
  1211. }
  1212. else {
  1213. saver = {};
  1214. var ytVideoId = getMyContent(page.url, 'youtube.com/embed/(.*?)("|\\?)', false);
  1215. if (!ytVideoId) ytVideoId = getMyContent(page.url, '"videoId":"yapi-(.*?)"', false);
  1216. if (ytVideoId) {
  1217. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId;
  1218. saver['warnMess'] = 'embed';
  1219. saver['warnContent'] = ytVideoLink;
  1220. }
  1221. else saver['warnMess'] = '!videos';
  1222. createMySaver();
  1223. }
  1224. }
  1225. else {
  1226. saver = {'warnMess': '!content'};
  1227. createMySaver();
  1228. }
  1229.  
  1230. }
  1231.  
  1232. // =====Viki===== //
  1233.  
  1234. else if (page.url.indexOf('viki.com/videos') != -1) {
  1235.  
  1236. /* Get Video Title */
  1237. var vkVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1238. if (vkVideoTitle) {
  1239. vkVideoTitle = vkVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1240. vkVideoTitle = vkVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1241. vkVideoTitle = vkVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1242. vkVideoTitle = vkVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1243. vkVideoTitle = vkVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1244. }
  1245.  
  1246. /* Get Video ID */
  1247. var vkVideoID = page.url.match(/videos\/(\d+v)/);
  1248. vkVideoID = (vkVideoID) ? vkVideoID[1] : null;
  1249.  
  1250. /* Get Videos Content */
  1251. var vkVideosContent;
  1252. if (vkVideoID) {
  1253. /*
  1254. A JavaScript implementation of the SHA family of hashes, as
  1255. defined in FIPS PUB 180-4 and FIPS PUB 202, as well as the corresponding
  1256. HMAC implementation as defined in FIPS PUB 198a
  1257.  
  1258. Copyright Brian Turek 2008-2017
  1259. Distributed under the BSD License
  1260. See http://caligatio.github.com/jsSHA/ for more information
  1261.  
  1262. Several functions taken from Paul Johnston
  1263. */
  1264. '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");
  1265. 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===
  1266. 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);
  1267. 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");
  1268. }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>>>
  1269. 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");
  1270. 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");
  1271. 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+
  1272. 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,
  1273. "");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+=
  1274. 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");
  1275. }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];
  1276. 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;
  1277. 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);
  1278.  
  1279. var vkTimestamp = parseInt(Date.now() / 1000);
  1280. var vkQuery = "/v5/videos/" + vkVideoID + "/streams.json?app=100005a&t=" + vkTimestamp + "&site=www.viki.com"
  1281. var vkToken = "MM_d*yP@`&1@]@!AVrXf_o-HVEnoTnm$O-ti4[G~$JDI/Dc-&piU&z&5.;:}95\=Iad";
  1282. var shaObj = new jsSHA("SHA-1", "TEXT");
  1283. shaObj.setHMACKey(vkToken, "TEXT");
  1284. shaObj.update(vkQuery);
  1285. var vkSig = shaObj.getHMAC("HEX");
  1286. var vkSource = "https://api.viki.io" + vkQuery + "&sig=" + vkSig;
  1287. vkVideosContent = getMyContent(vkSource, 'TEXT', false);
  1288. }
  1289.  
  1290. /* Get Videos */
  1291. if (vkVideosContent) {
  1292. var vkVideoList = {};
  1293. var vkVideoFormats = {'720p': 'High Definition MP4', '480p': 'Standard Definition MP4', '360p': 'Low Definition MP4', '240p': 'Very Low Definition MP4'};
  1294. var vkVideoFound = false;
  1295. var vkVideoParser, vkVideoParse, vkVideo, myVideoCode;
  1296. for (var vkVideoCode in vkVideoFormats) {
  1297. vkVideoParser = '"' + vkVideoCode + '".*?"https":\{"url":"(.*?)"';
  1298. vkVideoParse = vkVideosContent.match(vkVideoParser);
  1299. vkVideo = (vkVideoParse) ? vkVideoParse[1] : null;
  1300. if (vkVideo) {
  1301. if (!vkVideoFound) vkVideoFound = true;
  1302. myVideoCode = vkVideoFormats[vkVideoCode];
  1303. vkVideoList[myVideoCode] = vkVideo;
  1304. }
  1305. }
  1306.  
  1307. /* Create Saver */
  1308. if (vkVideo) {
  1309. var vkDefaultVideo = 'Low Definition MP4';
  1310. saver = {'videoList': vkVideoList, 'videoSave': vkDefaultVideo, 'videoTitle': vkVideoTitle};
  1311. feature['container'] = false;
  1312. option['definition'] = 'LD';
  1313. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1314. option['containers'] = ['MP4'];
  1315. createMySaver();
  1316. }
  1317. else {
  1318. if (vkVideosContent.indexOf('unauth') != -1) {
  1319. saver = {
  1320. 'warnMess': 'other',
  1321. 'warnContent': '<b>SaveTube:</b> Authorization required!'
  1322. };
  1323. }
  1324. else saver = {'warnMess': '!videos'};
  1325. createMySaver();
  1326. }
  1327. }
  1328. else {
  1329. saver = {'warnMess': '!content'};
  1330. createMySaver();
  1331. }
  1332.  
  1333. }
  1334.  
  1335. // =====IMDB===== //
  1336.  
  1337. else if (page.url.indexOf('imdb.com') != -1) {
  1338.  
  1339. /* Redirect To Video Page */
  1340. if (page.url.indexOf('/video/') == -1 && page.url.indexOf('/videoplayer/') == -1) {
  1341. page.doc.addEventListener('click', function(e) {
  1342. var p = e.target.parentNode;
  1343. while (p) {
  1344. if (p.tagName === 'A' && p.href.indexOf('/video/imdb') != -1) {
  1345. page.win.location.href = p.href.replace(/imdb\/inline.*/, '');
  1346. }
  1347. p = p.parentNode;
  1348. }
  1349. }, false);
  1350. return;
  1351. }
  1352.  
  1353. /* Get Video Title */
  1354. var imdbVideoTitle = getMyContent(page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  1355. if (imdbVideoTitle) {
  1356. imdbVideoTitle = imdbVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  1357. imdbVideoTitle = imdbVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  1358. imdbVideoTitle = imdbVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  1359. imdbVideoTitle = imdbVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  1360. imdbVideoTitle = imdbVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  1361. }
  1362.  
  1363. /* Get Video Id */
  1364. var imdbVideoId = page.url.replace(/.*videoplayer\//, '').replace(/(\/|\?).*/, '');
  1365.  
  1366. /* Get Videos Content */
  1367. var imdbVideosContent = getMyContent(page.url, '"' + imdbVideoId + '":\\{("aggregateUpVotes.*?videoId)', false);
  1368.  
  1369. /* Get Videos */
  1370. var imdbVideoList = {};
  1371. if (imdbVideosContent) {
  1372. var imdbVideoFormats = {'SD': 'Low Definition MP4', '480p': 'Standard Definition MP4', '720p': 'High Definition MP4', '1080p': 'Full High Definition MP4'};
  1373. var imdbVideoFound = false;
  1374. var imdbVideoParser, imdbVideoParse, myVideoCode, imdbVideo;
  1375. for (var imdbVideoCode in imdbVideoFormats) {
  1376. imdbVideoParser = '"definition":"' + imdbVideoCode + '".*?"videoUrl":"(.*?)"';
  1377. imdbVideoParse = imdbVideosContent.match(imdbVideoParser);
  1378. imdbVideo = (imdbVideoParse) ? imdbVideoParse[1] : null;
  1379. if (imdbVideo) {
  1380. if (!imdbVideoFound) imdbVideoFound = true;
  1381. myVideoCode = imdbVideoFormats[imdbVideoCode];
  1382. if (!imdbVideoList[myVideoCode]) imdbVideoList[myVideoCode] = imdbVideo;
  1383. }
  1384. }
  1385.  
  1386. if (imdbVideoFound) {
  1387. /* Create Saver */
  1388. var imdbDefaultVideo = 'Low Definition MP4';
  1389. saver = {'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'videoTitle': imdbVideoTitle};
  1390. feature['container'] = false;
  1391. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition'];
  1392. option['containers'] = ['MP4'];
  1393. createMySaver();
  1394. }
  1395. else {
  1396. saver = {'warnMess': '!videos'};
  1397. createMySaver();
  1398. }
  1399. }
  1400. else {
  1401. imdbVideo = getMyContent(page.url, '"videoUrl":"(.*?)"', false);
  1402. if (imdbVideo) {
  1403. /* Create Saver */
  1404. imdbVideoList[imdbDefaultVideo] = imdbVideo;
  1405. var imdbDefaultVideo = 'Low Definition MP4';
  1406. saver = {'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'videoTitle': imdbVideoTitle};
  1407. feature['container'] = false;
  1408. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition'];
  1409. option['containers'] = ['MP4'];
  1410. createMySaver();
  1411. }
  1412. else {
  1413. saver = {'warnMess': '!content'};
  1414. createMySaver();
  1415. }
  1416. }
  1417.  
  1418. }
  1419.  
  1420. }
  1421.  
  1422.  
  1423. // ==========Run========== //
  1424.  
  1425. SaveTube();
  1426.  
  1427. page.win.setInterval(function() {
  1428. if (page.url != page.win.location.href) {
  1429. if(saver['saverPanel']) removeMyElement(page.body, saver['saverPanel']);
  1430. page.doc = page.win.document;
  1431. page.body = page.doc.body;
  1432. page.url = page.win.location.href;
  1433. SaveTube();
  1434. }
  1435. }, 500);
  1436.  
  1437. })();