SaveTube

Download videos from video sharing web sites.

当前为 2016-03-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SaveTube
  3. // @version 2016.02.29
  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 http://s3.amazonaws.com/uso_ss/icon/130917/large.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://dailymotion.com*
  14. // @include http://www.dailymotion.com*
  15. // @include https://dailymotion.com*
  16. // @include https://www.dailymotion.com*
  17. // @include http://vimeo.com*
  18. // @include http://www.vimeo.com*
  19. // @include https://vimeo.com*
  20. // @include https://www.vimeo.com*
  21. // @include http://metacafe.com*
  22. // @include http://www.metacafe.com*
  23. // @include https://metacafe.com*
  24. // @include https://www.metacafe.com*
  25. // @include http://break.com*
  26. // @include http://www.break.com*
  27. // @include https://break.com*
  28. // @include https://www.break.com*
  29. // @include http://funnyordie.com*
  30. // @include http://www.funnyordie.com*
  31. // @include https://funnyordie.com*
  32. // @include https://www.funnyordie.com*
  33. // @include http://videojug.com*
  34. // @include http://www.videojug.com*
  35. // @include https://videojug.com*
  36. // @include https://www.videojug.com*
  37. // @include http://blip.tv*
  38. // @include http://www.blip.tv*
  39. // @include https://blip.tv*
  40. // @include https://www.blip.tv*
  41. // @include http://veoh.com*
  42. // @include http://www.veoh.com*
  43. // @include https://veoh.com*
  44. // @include https://www.veoh.com*
  45. // @include http://crackle.com*
  46. // @include http://www.crackle.com*
  47. // @include https://crackle.com*
  48. // @include https://www.crackle.com*
  49. // @include http://viki.com*
  50. // @include http://www.viki.com*
  51. // @include https://viki.com*
  52. // @include https://www.viki.com*
  53. // @include http://imdb.com*
  54. // @include http://www.imdb.com*
  55. // @include https://imdb.com*
  56. // @include https://www.imdb.com*
  57. // @include http://facebook.com*
  58. // @include http://www.facebook.com*
  59. // @include https://facebook.com*
  60. // @include https://www.facebook.com*
  61. // @grant GM_xmlhttpRequest
  62. // @grant GM_setValue
  63. // @grant GM_getValue
  64. // ==/UserScript==
  65.  
  66.  
  67. /*
  68.  
  69. Copyright (C) 2010 - 2016 Sebastian Luncan
  70.  
  71. This program is free software: you can redistribute it and/or modify
  72. it under the terms of the GNU General Public License as published by
  73. the Free Software Foundation, either version 3 of the License, or
  74. (at your option) any later version.
  75.  
  76. This program is distributed in the hope that it will be useful,
  77. but WITHOUT ANY WARRANTY; without even the implied warranty of
  78. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  79. GNU General Public License for more details.
  80.  
  81. You should have received a copy of the GNU General Public License
  82. along with this program. If not, see <http://www.gnu.org/licenses/>.
  83.  
  84. Website: http://isebaro.com/savetube
  85. Contact: http://isebaro.com/contact
  86.  
  87. */
  88.  
  89.  
  90. (function() {
  91.  
  92.  
  93. // Don't run on frames or iframes
  94. if (window.top != window.self) return;
  95.  
  96.  
  97. // ==========Variables========== //
  98.  
  99. // Userscript
  100. var userscript = 'SaveTube';
  101.  
  102. // Page
  103. var page = {win: window, doc: document, body: document.body, url: window.location.href, site: window.location.hostname.match(/([^.]+)\.[^.]+$/)[1]};
  104.  
  105. // Saver
  106. var saver = {};
  107. var feature = {'definition': true, 'container': true, 'autoget': false};
  108. var option = {'definition': 'HD', 'container': 'MP4', 'autoget': false};
  109.  
  110. // Links
  111. var website = 'http://isebaro.com/savetube/?ln=en';
  112. var contact = 'http://isebaro.com/contact/?ln=en&sb=savetube';
  113.  
  114.  
  115. // ==========Functions========== //
  116.  
  117. function createMyElement (type, content, event, action, target) {
  118. var obj = page.doc.createElement(type);
  119. if (content) {
  120. if (type == 'div') obj.innerHTML = content;
  121. else if (type == 'option') {
  122. obj.value = content;
  123. obj.innerHTML = content;
  124. }
  125. }
  126. if (event == 'change') {
  127. if (target == 'video') {
  128. obj.addEventListener ('change', function () {
  129. saver['videoSave'] = this.value;
  130. if (feature['autoget'] && saver['buttonGet'] == 'Get') {
  131. if (option['autoget']) getMyVideo();
  132. }
  133. else {
  134. modifyMyElement (saver['buttonGet'] , 'div', 'Get', false);
  135. }
  136. }, false);
  137. }
  138. }
  139. else if (event == 'click') {
  140. obj.addEventListener ('click', function () {
  141. if (action == 'close') {
  142. removeMyElement(page.body, target);
  143. }
  144. else if (action == 'logo') {
  145. page.win.location.href = website;
  146. }
  147. else if (action == 'get') {
  148. getMyVideo();
  149. }
  150. else if (action == 'autoget') {
  151. option['autoget'] = (option['autoget']) ? false : true;
  152. if (option['autoget']) {
  153. styleMyElement (saver['buttonGet'], {display: 'none'});
  154. styleMyElement (saver['buttonAutoget'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  155. getMyVideo();
  156. }
  157. else {
  158. styleMyElement (saver['buttonGet'], {display: 'inline'});
  159. styleMyElement (saver['buttonAutoget'], {color: '#CCCCCC', textShadow: '0px 0px 0px'});
  160. }
  161. setMyOptions ('autoget', option['autoget']);
  162. }
  163. else if (action == 'definition') {
  164. for (var itemDef = 0; itemDef < option['definitions'].length; itemDef++) {
  165. if (option['definitions'][itemDef].match(/[A-Z]/g).join('') == option['definition']) {
  166. var nextDef = (itemDef + 1 < option['definitions'].length) ? itemDef + 1 : 0;
  167. option['definition'] = option['definitions'][nextDef].match(/[A-Z]/g).join('');
  168. break;
  169. }
  170. }
  171. modifyMyElement (saver['buttonDefinition'], 'div', option['definition'], false);
  172. setMyOptions ('definition', option['definition']);
  173. modifyMyElement (saver['buttonGet'] , 'div', 'Get', false);
  174. selectMyVideo ();
  175. if (option['autoget']) getMyVideo();
  176. }
  177. else if (action == 'container') {
  178. for (var itemCont = 0; itemCont < option['containers'].length; itemCont++) {
  179. if (option['containers'][itemCont] == option['container']) {
  180. var nextCont = (itemCont + 1 < option['containers'].length) ? itemCont + 1 : 0;
  181. option['container'] = option['containers'][nextCont];
  182. break;
  183. }
  184. }
  185. modifyMyElement (saver['buttonContainer'], 'div', option['container'], false);
  186. setMyOptions ('container', option['container']);
  187. modifyMyElement (saver['buttonGet'] , 'div', 'Get', false);
  188. selectMyVideo ();
  189. if (option['autoget']) getMyVideo();
  190. }
  191. }, false);
  192. }
  193. return obj;
  194. }
  195.  
  196. function getMyElement (obj, type, from, value, child, content) {
  197. var getObj, chObj, coObj;
  198. var pObj = (!obj) ? page.doc : obj;
  199. if (type == 'body') getObj = pObj.body;
  200. else {
  201. if (from == 'id') getObj = pObj.getElementById(value);
  202. else if (from == 'class') getObj = pObj.getElementsByClassName(value);
  203. else if (from == 'tag') getObj = pObj.getElementsByTagName(type);
  204. else if (from == 'ns') getObj = pObj.getElementsByTagNameNS(value, type);
  205. }
  206. chObj = (child >= 0) ? getObj[child] : getObj;
  207. if (content && chObj) {
  208. if (type == 'html' || type == 'body' || type == 'div' || type == 'option') coObj = chObj.innerHTML;
  209. else if (type == 'object') coObj = chObj.data;
  210. else coObj = chObj.textContent;
  211. return coObj;
  212. }
  213. else {
  214. return chObj;
  215. }
  216. }
  217.  
  218. function modifyMyElement (obj, type, content, clear) {
  219. if (content) {
  220. if (type == 'div') obj.innerHTML = content;
  221. else if (type == 'option') {
  222. obj.value = content;
  223. obj.innerHTML = content;
  224. }
  225. }
  226. if (clear) {
  227. if (obj.hasChildNodes()) {
  228. while (obj.childNodes.length >= 1) {
  229. obj.removeChild(obj.firstChild);
  230. }
  231. }
  232. }
  233. }
  234.  
  235. function styleMyElement (obj, styles) {
  236. for (var property in styles) {
  237. if (styles.hasOwnProperty(property)) obj.style[property] = styles[property];
  238. }
  239. }
  240.  
  241. function appendMyElement (parent, child) {
  242. parent.appendChild(child);
  243. }
  244.  
  245. function removeMyElement (parent, child) {
  246. parent.removeChild(child);
  247. }
  248.  
  249. function replaceMyElement (parent, orphan, child) {
  250. parent.replaceChild(orphan, child);
  251. }
  252.  
  253. function createMySaver () {
  254. /* Get My Options */
  255. getMyOptions ();
  256.  
  257. /* Saver Settings */
  258. saver['panelHeight'] = 18;
  259. saver['panelPadding'] = 2;
  260.  
  261. /* The Panel */
  262. var panelWidth = saver['saverWidth'] - saver['panelPadding'] * 2;
  263. saver['saverPanel'] = createMyElement ('div', '', '', '', '');
  264. styleMyElement (saver['saverPanel'], {position: 'relative', width: panelWidth + 'px', height: saver['panelHeight'] + 'px', display: 'block', padding: saver['panelPadding'] + 'px', backgroundColor: '#F4F4F4', fontSize: '12px', textAlign: 'center'});
  265. appendMyElement (saver['saverSocket'], saver['saverPanel']);
  266.  
  267. /* Warnings */
  268. if (saver['warnMess']) {
  269. if (saver['warnContent']) showMyMessage (saver['warnMess'], saver['warnContent']);
  270. else showMyMessage (saver['warnMess']);
  271. return;
  272. }
  273.  
  274. /* Panel Items */
  275. var panelItemBorder = 1;
  276. var panelItemHeight = saver['panelHeight'] - panelItemBorder * 2;
  277.  
  278. /* Panel Logo */
  279. saver['panelLogo'] = createMyElement ('div', userscript + ': ', 'click', 'logo', '');
  280. saver['panelLogo'].title = '{SaveTube: click to visit the script web page}';
  281. styleMyElement (saver['panelLogo'], {height: panelItemHeight + 'px', padding: '0px', display: 'inline', color: '#336699', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', cursor: 'pointer'});
  282. appendMyElement (saver['saverPanel'], saver['panelLogo']);
  283.  
  284. /* Panel Video Menu */
  285. saver['videoMenu'] = createMyElement ('select', '', 'change', '', 'video');
  286. saver['videoMenu'].title = '{Videos: select the video format for download}';
  287. 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'});
  288. appendMyElement (saver['saverPanel'], saver['videoMenu'] );
  289. for (var videoCode in saver['videoList']) {
  290. saver['videoItem'] = createMyElement ('option', videoCode, '', '', '');
  291. styleMyElement (saver['videoItem'], {padding: '0px', display: 'block', color: '#336699', fontSize: '12px', textShadow: '0px 1px 1px #CCCCCC', cursor: 'pointer'});
  292. if (videoCode.indexOf('Video') != -1 || videoCode.indexOf('Audio') != -1) styleMyElement (saver['videoItem'], {color: '#8F6B32'});
  293. appendMyElement (saver['videoMenu'], saver['videoItem']);
  294. }
  295.  
  296. /* Panel Get Button */
  297. saver['buttonGet'] = createMyElement ('div', 'Get', 'click', 'get', '');
  298. saver['buttonGet'].title = '{Get: click to download the selected video format}';
  299. 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'});
  300. if (option['autoget']) styleMyElement (saver['buttonGet'], {display: 'none'});
  301. appendMyElement (saver['saverPanel'], saver['buttonGet']);
  302.  
  303. /* Panel Autoget Button */
  304. if (feature['autoget']) {
  305. saver['buttonAutoget'] = createMyElement ('div', 'Autoget', 'click', 'autoget', '');
  306. saver['buttonAutoget'].title = '{Get: click to enable/disable auto download on page load}';
  307. styleMyElement (saver['buttonAutoget'], {height: panelItemHeight + 'px', border: '1px solid #CCCCCC', borderRadius: '3px', padding: '0px 5px', display: 'inline', color: '#CCCCCC', fontSize: '12px', cursor: 'pointer'});
  308. if (option['autoget']) styleMyElement (saver['buttonAutoget'], {color: '#008080', textShadow: '0px 1px 1px #CCCCCC'});
  309. appendMyElement (saver['saverPanel'], saver['buttonAutoget']);
  310. }
  311.  
  312. /* Panel Definition Button */
  313. if (feature['definition']) {
  314. saver['buttonDefinition'] = createMyElement ('div', option['definition'], 'click', 'definition', '');
  315. saver['buttonDefinition'].title = '{Definition: click to change the preferred video definition}';
  316. 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'});
  317. appendMyElement (saver['saverPanel'], saver['buttonDefinition']);
  318. }
  319.  
  320. /* Panel Container Button */
  321. if (feature['container']) {
  322. saver['buttonContainer'] = createMyElement ('div', option['container'], 'click', 'container', '');
  323. saver['buttonContainer'].title = '{Container: click to change the preferred video container}';
  324. 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'});
  325. appendMyElement (saver['saverPanel'], saver['buttonContainer']);
  326. }
  327.  
  328. /* Select The Video */
  329. if (feature['definition'] || feature['container']) selectMyVideo ();
  330.  
  331. /* Get The Video On Autoget */
  332. if (option['autoget']) getMyVideo();
  333. }
  334.  
  335. function selectMyVideo () {
  336. var vdoCont = (option['container'] != 'Any') ? [option['container']] : option['containers'];
  337. var vdoDef = option['definitions'];
  338. var vdoList = {};
  339. for (var vC = 0; vC < vdoCont.length; vC++) {
  340. if (vdoCont[vC] != 'Any') {
  341. for (var vD = 0; vD < vdoDef.length; vD++) {
  342. var format = vdoDef[vD] + ' ' + vdoCont[vC];
  343. if (!vdoList[vdoDef[vD]]) {
  344. for (var vL in saver['videoList']) {
  345. if (vL == format) {
  346. vdoList[vdoDef[vD]] = vL;
  347. break;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. if (option['definition'] == 'UHD') {
  355. if (vdoList['Ultra High Definition']) saver['videoSave'] = vdoList['Ultra High Definition'];
  356. else if (vdoList['Full High Definition']) saver['videoSave'] = vdoList['Full High Definition'];
  357. else if (vdoList['High Definition']) saver['videoSave'] = vdoList['High Definition'];
  358. else if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  359. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  360. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  361. }
  362. else if (option['definition'] == 'FHD') {
  363. if (vdoList['Full High Definition']) saver['videoSave'] = vdoList['Full High Definition'];
  364. else if (vdoList['High Definition']) saver['videoSave'] = vdoList['High Definition'];
  365. else if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  366. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  367. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  368. }
  369. else if (option['definition'] == 'HD') {
  370. if (vdoList['High Definition']) saver['videoSave'] = vdoList['High Definition'];
  371. else if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  372. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  373. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  374. }
  375. else if (option['definition'] == 'SD') {
  376. if (vdoList['Standard Definition']) saver['videoSave'] = vdoList['Standard Definition'];
  377. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  378. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  379. }
  380. else if (option['definition'] == 'LD') {
  381. if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  382. else if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  383. }
  384. else if (option['definition'] == 'VLD') {
  385. if (vdoList['Very Low Definition']) saver['videoSave'] = vdoList['Very Low Definition'];
  386. else if (vdoList['Low Definition']) saver['videoSave'] = vdoList['Low Definition'];
  387. }
  388. saver['videoMenu'].value = saver['videoSave'];
  389. }
  390.  
  391. function getMyVideo () {
  392. var vdoURL = saver['videoList'][saver['videoSave']];
  393. if (saver['videoTitle']) {
  394. var vdoD = ' (' + saver['videoSave'] + ')';
  395. vdoD = vdoD.replace(/Ultra High Definition/, 'UHD');
  396. vdoD = vdoD.replace(/Full High Definition/, 'FHD');
  397. vdoD = vdoD.replace(/High Definition/, 'HD');
  398. vdoD = vdoD.replace(/Standard Definition/, 'SD');
  399. vdoD = vdoD.replace(/Very Low Definition/, 'VLD');
  400. vdoD = vdoD.replace(/Low Definition/, 'LD');
  401. vdoD = vdoD.replace(/\sFLV|\sMP4|\sWebM|\s3GP/g, '');
  402. vdoURL = vdoURL + '&title=' + saver['videoTitle'] + vdoD;
  403. }
  404. if (feature['autoget'] && !saver['videoSave'].match(/(Video|Audio)/)) page.win.location.href = vdoURL;
  405. else {
  406. var vdoLink = 'Get <a href="' + vdoURL + '" style="color:#00892C">Link</a>';
  407. modifyMyElement (saver['buttonGet'] , 'div', vdoLink, false);
  408. }
  409. }
  410.  
  411. function cleanMyContent (content, unesc) {
  412. var myNewContent = content;
  413. if (unesc) myNewContent = unescape (myNewContent);
  414. myNewContent = myNewContent.replace (/\\u0025/g,'%');
  415. myNewContent = myNewContent.replace (/\\u0026/g,'&');
  416. myNewContent = myNewContent.replace (/\\/g,'');
  417. myNewContent = myNewContent.replace (/\n/g,'');
  418. return myNewContent;
  419. }
  420.  
  421. function getMyContent (url, pattern, clean) {
  422. var myPageContent, myVideosParse, myVideosContent;
  423. var isIE = (navigator.appName.indexOf('Internet Explorer') != -1) ? true : false;
  424. var getMethod = (url != page.url || isIE) ? 'XHR' : 'DOM';
  425. if (getMethod == 'DOM') {
  426. myPageContent = getMyElement ('', 'html', 'tag', '', 0, true);
  427. if (!myPageContent) myPageContent = getMyElement ('', 'body', '', '', -1, true);
  428. if (clean) myPageContent = cleanMyContent (myPageContent, true);
  429. myVideosParse = myPageContent.match (pattern);
  430. myVideosContent = (myVideosParse) ? myVideosParse[1] : null;
  431. if (myVideosContent) return myVideosContent;
  432. else getMethod = 'XHR';
  433. }
  434. if (getMethod == 'XHR') {
  435. var xmlHTTP = new XMLHttpRequest();
  436. xmlHTTP.open('GET', url, false);
  437. xmlHTTP.send();
  438. if (pattern == 'XML') {
  439. myVideosContent = xmlHTTP.responseXML;
  440. }
  441. else if (pattern == 'TEXT') {
  442. myVideosContent = xmlHTTP.responseText;
  443. }
  444. else {
  445. myPageContent = xmlHTTP.responseText;
  446. if (clean) myPageContent = cleanMyContent (myPageContent, true);
  447. myVideosParse = myPageContent.match (pattern);
  448. myVideosContent = (myVideosParse) ? myVideosParse[1] : null;
  449. }
  450. return myVideosContent;
  451. }
  452. }
  453.  
  454. function setMyOptions (key, value) {
  455. key = page.site + '_' + userscript.toLowerCase() + '_' + key;
  456. if (typeof GM_setValue === 'function') {
  457. GM_setValue(key, value);
  458. if (typeof GM_getValue === 'function' && GM_getValue(key) == value) return;
  459. }
  460. try {
  461. localStorage.setItem(key, value);
  462. if (localStorage.getItem(key) == value) return;
  463. else throw false;
  464. }
  465. catch(e) {
  466. var date = new Date();
  467. date.setTime(date.getTime() + (356*24*60*60*1000));
  468. var expires = '; expires=' + date.toGMTString();
  469. page.doc.cookie = key + '=' + value + expires + '; path=/';
  470. }
  471. }
  472.  
  473. function getMyOptions () {
  474. for (var opt in option) {
  475. if (option.hasOwnProperty(opt)) {
  476. var key = page.site + '_' + userscript.toLowerCase() + '_' + opt;
  477. if (typeof GM_getValue === 'function') {
  478. if (GM_getValue(key)) {
  479. option[opt] = GM_getValue(key);
  480. continue;
  481. }
  482. }
  483. try {
  484. if (localStorage.getItem(key)) {
  485. option[opt] = localStorage.getItem(key);
  486. continue;
  487. }
  488. else throw false;
  489. }
  490. catch (e) {
  491. var cookies = page.doc.cookie.split(';');
  492. for (var i=0; i < cookies.length; i++) {
  493. var cookie = cookies[i];
  494. while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
  495. option[opt] = (cookie.indexOf(key) == 0) ? cookie.substring(key.length + 1, cookie.length) : option[opt];
  496. }
  497. }
  498. }
  499. }
  500. option['autoget'] = (option['autoget'] === true || option['autoget'] == 'true') ? true : false;
  501. }
  502.  
  503. function showMyMessage (cause, content) {
  504. var myScriptLogo = createMyElement ('div', userscript, '', '', '');
  505. styleMyElement (myScriptLogo, {margin: '0px auto', padding: '10px', color: '#666666', fontSize: '24px', textAlign: 'center', textShadow: '#FFFFFF -1px -1px 2px'});
  506. var myScriptMess = createMyElement ('div', '', '', '', '');
  507. styleMyElement (myScriptMess, {border: '1px solid #F4F4F4', margin: '5px auto 5px auto', padding: '10px', backgroundColor: '#FFFFFF', color: '#AD0000', textAlign: 'center'});
  508. if (cause == '!player') {
  509. var myScriptAlert = createMyElement ('div', '', '', '', '');
  510. styleMyElement (myScriptAlert, {position: 'absolute', top: '30%', left: '35%', border: '1px solid #F4F4F4', borderRadius: '3px', padding: '10px', backgroundColor: '#FFFFFF', fontSize: '14px', textAlign: 'center', zIndex: '99999'});
  511. appendMyElement (myScriptAlert, myScriptLogo);
  512. var myNoPlayerMess = 'Couldn\'t get the player element. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  513. modifyMyElement (myScriptMess, 'div', myNoPlayerMess, false);
  514. appendMyElement (myScriptAlert, myScriptMess);
  515. var myScriptAlertButton = createMyElement ('div', 'OK', 'click', 'close', myScriptAlert);
  516. styleMyElement (myScriptAlertButton, {width: '100px', border: '3px solid #EEEEEE', borderRadius: '5px', margin: '0px auto', backgroundColor: '#EEEEEE', color: '#666666', fontSize: '18px', textAlign: 'center', textShadow: '#FFFFFF -1px -1px 2px', cursor: 'pointer'});
  517. appendMyElement (myScriptAlert, myScriptAlertButton);
  518. appendMyElement (page.body, myScriptAlert);
  519. }
  520. else {
  521. styleMyElement (saver['saverPanel'], {color: '#AD0000'});
  522. if (cause == '!content') {
  523. var myNoContentMess = '<b>SaveTube:</b> Couldn\'t get the videos content. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  524. modifyMyElement (saver['saverPanel'], 'div', myNoContentMess, false);
  525. }
  526. else if (cause == '!videos') {
  527. var myNoVideosMess = '<b>SaveTube:</b> Couldn\'t get any video. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.';
  528. modifyMyElement (saver['saverPanel'], 'div', myNoVideosMess, false);
  529. }
  530. else if (cause == '!support') {
  531. var myNoSupportMess = '<b>SaveTube:</b> This video uses the RTMP protocol which is not supported.';
  532. modifyMyElement (saver['saverPanel'], 'div', myNoSupportMess, false);
  533. }
  534. else if (cause == 'embed') {
  535. var myEmbedMess = '<b>SaveTube:</b> This is an embedded video. You can get it <a href="' + content + '" style="color:#00892C">here</a>.';
  536. modifyMyElement (saver['saverPanel'], 'div', myEmbedMess, false);
  537. }
  538. else if (cause == 'other') {
  539. modifyMyElement (saver['saverPanel'], 'div', content, false);
  540. }
  541. }
  542. }
  543.  
  544.  
  545. // ==========Websites========== //
  546.  
  547. // Force page reload on href change
  548. page.win.setInterval(function() {
  549. nurl = page.win.location.href;
  550. if (page.url != nurl) {
  551. // YouTube
  552. if (nurl.indexOf('youtube.com') != -1) {
  553. if (nurl.indexOf('youtube.com/watch') != -1) page.win.location.href = nurl;
  554. }
  555. // Facebook
  556. else if (nurl.indexOf('facebook.com') != -1) {
  557. if (nurl.match('facebook.com/(video.php|.*/videos/)')) {
  558. page.win.location.href = nurl.replace('&theater', '');
  559. }
  560. }
  561. // Others
  562. else {
  563. page.win.location.href = nurl;
  564. }
  565. }
  566. }, 500);
  567.  
  568. // =====YouTube===== //
  569.  
  570. if (page.url.indexOf('youtube.com/watch') != -1) {
  571.  
  572. /* Video Availability */
  573. var ytVideoUnavailable = getMyElement ('', 'div', 'id', 'player-unavailable', -1, false);
  574. if (ytVideoUnavailable) {
  575. if (ytVideoUnavailable.className.indexOf('hid') == -1) {
  576. var ytAgeGateContent = getMyElement ('', 'div', 'id', 'watch7-player-age-gate-content', -1, true);
  577. if (!ytAgeGateContent) return;
  578. else {
  579. if(ytAgeGateContent.indexOf('feature=private_video') != -1) return;
  580. }
  581. }
  582. }
  583.  
  584. /* Decrypt Signature */
  585. var ytScriptSrc;
  586. function ytDecryptSignature (s) {return null;}
  587. function ytDecryptFunction () {
  588. var ytSignFuncName, ytSignFuncBody, ytSwapFuncName, ytSwapFuncBody, ytFuncMatch;
  589. ytScriptSrc = ytScriptSrc.replace(/(\r\n|\n|\r)/gm, '');
  590. ytSignFuncName = ytScriptSrc.match(/"signature"\s*,\s*(.*?)\(/);
  591. ytSignFuncName = (ytSignFuncName) ? ytSignFuncName[1] : null;
  592. if (ytSignFuncName) {
  593. ytFuncMatch = ytSignFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\}';
  594. ytSignFuncBody = ytScriptSrc.match(ytFuncMatch);
  595. ytSignFuncBody = (ytSignFuncBody) ? ytSignFuncBody[1] : null;
  596. if (ytSignFuncBody) {
  597. ytSwapFuncName = ytSignFuncBody.match(/((\$|_|\w)+)\.(\$|_|\w)+\(\w,[0-9]+\)/);
  598. ytSwapFuncName = (ytSwapFuncName) ? ytSwapFuncName[1] : null;
  599. if (ytSwapFuncName) {
  600. ytFuncMatch = 'var\\s+' + ytSwapFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};';
  601. ytSwapFuncBody = ytScriptSrc.match(ytFuncMatch);
  602. ytSwapFuncBody = (ytSwapFuncBody) ? ytSwapFuncBody[1] : null;
  603. }
  604. if (ytSwapFuncBody) ytSignFuncBody = 'var ' + ytSwapFuncName + '={' + ytSwapFuncBody + '};' + ytSignFuncBody;
  605. ytSignFuncBody = 'try {' + ytSignFuncBody + '} catch(e) {return null}';
  606. ytDecryptSignature = new Function('a', ytSignFuncBody);
  607. }
  608. }
  609. }
  610.  
  611. /* Get Player Window */
  612. var ytPlayerWindow = getMyElement ('', 'div', 'id', 'placeholder-player', -1, false);
  613. if (!ytPlayerWindow) {
  614. showMyMessage ('!player');
  615. }
  616. else {
  617. /* Get Video Title */
  618. var ytVideoTitle = getMyContent (page.url, 'meta\\s+itemprop="name"\\s+content="(.*?)"', false);
  619. if (!ytVideoTitle) ytVideoTitle = getMyContent (page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  620. if (!ytVideoTitle) ytVideoTitle = page.doc.title;
  621. if (ytVideoTitle) {
  622. ytVideoTitle = ytVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  623. ytVideoTitle = ytVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  624. ytVideoTitle = ytVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  625. ytVideoTitle = ytVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  626. ytVideoTitle = ytVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  627. ytVideoTitle = ytVideoTitle.replace(/^YouTube\s-\s/, '');
  628. }
  629.  
  630. /* Get Videos Content */
  631. var ytVideosContent, ytHLSContent;
  632. var ytVideosEncodedFmts, ytVideosAdaptiveFmts;
  633. ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map":\\s*"(.*?)"', false);
  634. ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts":\\s*"(.*?)"', false);
  635. if (ytVideosEncodedFmts) {
  636. ytVideosContent = ytVideosEncodedFmts;
  637. }
  638. else {
  639. if (!ytVideoID) {
  640. var ytVideoID = page.url.match (/(\?|&)v=(.*?)(&|$)/);
  641. ytVideoID = (ytVideoID) ? ytVideoID[2] : null;
  642. }
  643. if (ytVideoID) {
  644. var ytVideoSts = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"sts"\\s*:\\s*(\\d+)', false);
  645. 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;
  646. var ytVideosInfo = getMyContent(ytVideosInfoURL, 'TEXT', false);
  647. if (ytVideosInfo) {
  648. ytVideosEncodedFmts = ytVideosInfo.match(/url_encoded_fmt_stream_map=(.*?)&/);
  649. ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null;
  650. if (ytVideosEncodedFmts) {
  651. ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
  652. ytVideosContent = ytVideosEncodedFmts;
  653. }
  654. if (!ytVideosAdaptiveFmts) {
  655. ytVideosAdaptiveFmts = ytVideosInfo.match(/adaptive_fmts=(.*?)&/);
  656. ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null;
  657. if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
  658. }
  659. }
  660. }
  661. }
  662. if (ytVideosAdaptiveFmts) {
  663. if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts;
  664. else ytVideosContent = ytVideosAdaptiveFmts;
  665. }
  666.  
  667. /* Get HLS Content */
  668. if (!ytVideosContent) {
  669. var ytHLSVideos, ytHLSContent;
  670. ytHLSVideos = getMyContent(page.url, '"hlsvp":\\s*"(.*?)"', false);
  671. if (ytHLSVideos) ytHLSVideos = cleanMyContent(ytHLSVideos, false);
  672. }
  673.  
  674. /* Fix Sidebar */
  675. //var ytSidebarWindow = getMyElement ('', 'div', 'id', 'watch7-sidebar', -1, false);
  676. //if (ytSidebarWindow) styleMyElement(ytSidebarWindow, {marginTop: '-412px'});
  677.  
  678. /* Create Saver */
  679. var ytDefaultVideo = 'Low Definition MP4';
  680. function ytSaver () {
  681. saver = {'saverSocket': ytPlayerWindow, 'videoList': ytVideoList, 'videoSave': ytDefaultVideo, 'videoTitle': ytVideoTitle, 'saverWidth': 640};
  682. option['definitions'] = ['Ultra High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  683. option['containers'] = ['MP4', 'WebM', 'FLV', '3GP', 'Any'];
  684. }
  685.  
  686. /* Parse Videos */
  687. function ytVideos() {
  688. var ytVideoFormats = {
  689. '5': 'Very Low Definition FLV',
  690. '17': 'Very Low Definition 3GP',
  691. '18': 'Low Definition MP4',
  692. '22': 'High Definition MP4',
  693. '34': 'Low Definition FLV',
  694. '35': 'Standard Definition FLV',
  695. '36': 'Low Definition 3GP',
  696. '37': 'Full High Definition MP4',
  697. '38': 'Ultra High Definition MP4',
  698. '43': 'Low Definition WebM',
  699. '44': 'Standard Definition WebM',
  700. '45': 'High Definition WebM',
  701. '46': 'Full High Definition WebM',
  702. '82': 'Low Definition 3D MP4',
  703. '83': 'Standard Definition 3D MP4',
  704. '84': 'High Definition 3D MP4',
  705. '85': 'Full High Definition 3D MP4',
  706. '100': 'Low Definition 3D WebM',
  707. '101': 'Standard Definition 3D WebM',
  708. '102': 'High Definition 3D WebM',
  709. '135': 'Standard Definition Video MP4',
  710. '136': 'High Definition Video MP4',
  711. '137': 'Full High Definition Video MP4',
  712. '138': 'Ultra High Definition Video MP4',
  713. '139': 'Low Bitrate Audio MP4',
  714. '140': 'Medium Bitrate Audio MP4',
  715. '141': 'High Bitrate Audio MP4',
  716. '171': 'Medium Bitrate Audio WebM',
  717. '172': 'High Bitrate Audio WebM',
  718. '244': 'Standard Definition Video WebM',
  719. '247': 'High Definition Video WebM',
  720. '248': 'Full High Definition Video WebM',
  721. '249': 'Low Bitrate Audio Opus',
  722. '250': 'Medium Bitrate Audio Opus',
  723. '251': 'High Bitrate Audio Opus',
  724. '266': 'Ultra High Definition Video MP4',
  725. '272': 'Ultra High Definition Video WebM',
  726. '298': 'High Definition Video MP4',
  727. '299': 'Full High Definition Video MP4',
  728. '302': 'High Definition Video WebM',
  729. '303': 'Full High Definition Video WebM',
  730. '313': 'Ultra High Definition Video WebM'
  731. };
  732. var ytVideoFound = false;
  733. var ytVideos = ytVideosContent.split(',');
  734. var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo;
  735. for (var i = 0; i < ytVideos.length; i++) {
  736. if (!ytVideos[i].match(/^url/)) {
  737. ytVideoParse = ytVideos[i].match(/(.*)(url=.*$)/);
  738. if (ytVideoParse) ytVideos[i] = ytVideoParse[2] + '&' + ytVideoParse[1];
  739. }
  740. ytVideoCodeParse = ytVideos[i].match (/itag=(\d{1,3})/);
  741. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  742. if (ytVideoCode) {
  743. myVideoCode = ytVideoFormats[ytVideoCode];
  744. if (myVideoCode) {
  745. ytVideo = cleanMyContent(ytVideos[i], true);
  746. ytVideo = ytVideo.replace (/url=/, '').replace(/&$/, '');
  747. if (ytVideo.match(/itag=/) && ytVideo.match(/itag=/g).length > 1) {
  748. if (ytVideo.match(/itag=\d{1,3}&/)) ytVideo = ytVideo.replace(/itag=\d{1,3}&/, '');
  749. else if (ytVideo.match(/&itag=\d{1,3}/)) ytVideo = ytVideo.replace(/&itag=\d{1,3}/, '');
  750. }
  751. if (ytVideo.match(/clen=/) && ytVideo.match(/clen=/g).length > 1) {
  752. if (ytVideo.match(/clen=\d+&/)) ytVideo = ytVideo.replace(/clen=\d+&/, '');
  753. else if (ytVideo.match(/&clen=\d+/)) ytVideo = ytVideo.replace(/&clen=\d+/, '');
  754. }
  755. if (ytVideo.match(/lmt=/) && ytVideo.match(/lmt=/g).length > 1) {
  756. if (ytVideo.match(/lmt=\d+&/)) ytVideo = ytVideo.replace(/lmt=\d+&/, '');
  757. else if (ytVideo.match(/&lmt=\d+/)) ytVideo = ytVideo.replace(/&lmt=\d+/, '');
  758. }
  759. if (ytVideo.match(/type=(video|audio).*?&/)) ytVideo = ytVideo.replace(/type=(video|audio).*?&/, '');
  760. else ytVideo = ytVideo.replace(/&type=(video|audio).*$/, '');
  761. if (ytVideo.match(/&sig=/)) ytVideo = ytVideo.replace (/&sig=/, '&signature=');
  762. else if (ytVideo.match(/&s=/)) {
  763. var ytSig = ytVideo.match(/&s=(.*?)(&|$)/);
  764. if (ytSig) {
  765. var s = ytSig[1];
  766. s = ytDecryptSignature(s);
  767. if (s) ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&signature=' + s + '$1');
  768. else ytVideo = '';
  769. }
  770. else ytVideo = '';
  771. }
  772. ytVideo = cleanMyContent (ytVideo, true);
  773. if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes';
  774. if (ytVideo && ytVideo.indexOf('http') == 0) {
  775. if (!ytVideoFound) ytVideoFound = true;
  776. ytVideoList[myVideoCode] = ytVideo;
  777. }
  778. }
  779. }
  780. }
  781.  
  782. if (ytVideoFound) {
  783. /* Create Saver */
  784. feature['autoget'] = true;
  785. ytSaver();
  786. createMySaver();
  787. }
  788. else {
  789. saver = {'saverSocket': ytPlayerWindow, 'saverWidth': 640};
  790. if (ytVideosContent.indexOf('conn=rtmp') != -1) saver['warnMess'] = '!support';
  791. else saver['warnMess'] = '!videos';
  792. createMySaver();
  793. }
  794. }
  795.  
  796. /* Parse HLS */
  797. function ytHLS() {
  798. var ytHLSFormats = {
  799. '92': 'Very Low Definition MP4',
  800. '93': 'Low Definition MP4',
  801. '94': 'Standard Definition MP4',
  802. '95': 'High Definition MP4',
  803. '96': 'Full High Definition MP4'
  804. };
  805. ytVideoList["Any Definition MP4"] = ytHLSVideos;
  806. if (ytHLSContent) {
  807. var ytHLSVideo, ytVideoCodeParse, ytVideoCode, myVideoCode;
  808. var ytHLSMatcher = new RegExp('(http.*?m3u8)', 'g');
  809. ytHLSVideos = ytHLSContent.match(ytHLSMatcher);
  810. if (ytHLSVideos) {
  811. for (var i = 0; i < ytHLSVideos.length; i++) {
  812. ytHLSVideo = ytHLSVideos[i];
  813. ytVideoCodeParse = ytHLSVideo.match(/\/itag\/(\d{1,3})\//);
  814. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  815. if (ytVideoCode) {
  816. myVideoCode = ytHLSFormats[ytVideoCode];
  817. if (myVideoCode && ytHLSVideo) {
  818. ytVideoList[myVideoCode] = ytHLSVideo;
  819. }
  820. }
  821. }
  822. }
  823. }
  824.  
  825. /* Create Saver */
  826. ytVideoTitle = null;
  827. ytDefaultVideo = 'Any Definition MP4';
  828. ytSaver();
  829. createMySaver();
  830. }
  831.  
  832. /* Get Videos */
  833. var ytVideoList = {};
  834. if (ytVideosContent) {
  835. if (ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/) || ytVideosContent.match(/u0026s=/)) {
  836. var ytScriptURL = getMyContent(page.url, '"js":\\s*"(.*?)"', true);
  837. if (!ytScriptURL) ytScriptURL = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"js":\\s*"(.*?)"', true);
  838. if (ytScriptURL) {
  839. ytScriptURL = page.win.location.protocol + ytScriptURL;
  840. try {
  841. ytScriptSrc = getMyContent(ytScriptURL, 'TEXT', false);
  842. if (ytScriptSrc) ytDecryptFunction();
  843. ytVideos();
  844. }
  845. catch (e) {
  846. try {
  847. GM_xmlhttpRequest({
  848. method: 'GET',
  849. url: ytScriptURL,
  850. onload: function(response) {
  851. if (response.readyState === 4 && response.status === 200 && response.responseText) {
  852. ytScriptSrc = response.responseText;
  853. ytDecryptFunction();
  854. ytVideos();
  855. }
  856. else {
  857. saver = {
  858. 'saverSocket': ytPlayerWindow,
  859. 'saverWidth': 640,
  860. 'warnMess': 'other',
  861. 'warnContent': '<b>SaveTube:</b> Couldn\'t get the signature content. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'
  862. };
  863. createMySaver ();
  864. }
  865. },
  866. onerror: function() {
  867. saver = {
  868. 'saverSocket': ytPlayerWindow,
  869. 'saverWidth': 640,
  870. 'warnMess': 'other',
  871. 'warnContent': '<b>SaveTube:</b> Couldn\'t make the request. Make sure your browser user scripts extension supports cross-domain requests.'
  872. };
  873. createMySaver ();
  874. }
  875. });
  876. }
  877. catch (e) {
  878. saver = {
  879. 'saverSocket': ytPlayerWindow,
  880. 'saverWidth': 640,
  881. 'warnMess': 'other',
  882. 'warnContent': '<b>SaveTube:</b> Couldn\'t make the request. Make sure your browser user scripts extension supports cross-domain requests.'
  883. };
  884. createMySaver ();
  885. }
  886. }
  887. }
  888. else {
  889. saver = {
  890. 'saverSocket': ytPlayerWindow,
  891. 'saverWidth': 640,
  892. 'warnMess': 'other',
  893. 'warnContent': '<b>SaveTube:</b> Couldn\'t get the signature link. Please report it <a href="' + contact + '" style="color:#00892C">here</a>.'
  894. };
  895. createMySaver ();
  896. }
  897. }
  898. else {
  899. ytVideos();
  900. }
  901. }
  902. else {
  903. if (ytHLSVideos) {
  904. try {
  905. ytHLSContent = getMyContent(ytHLSVideos, 'TEXT', false);
  906. ytHLS();
  907. }
  908. catch (e) {
  909. try {
  910. GM_xmlhttpRequest({
  911. method: 'GET',
  912. url: ytHLSVideos,
  913. onload: function(response) {
  914. if (response.readyState === 4 && response.status === 200 && response.responseText) {
  915. ytHLSContent = response.responseText;
  916. }
  917. ytHLS();
  918. },
  919. onerror: function() {
  920. ytHLS();
  921. }
  922. });
  923. }
  924. catch (e) {
  925. ytHLS();
  926. }
  927. }
  928. }
  929. else {
  930. saver = {'saverSocket': ytPlayerWindow, 'saverWidth': 640, 'warnMess': '!content'};
  931. createMySaver ();
  932. }
  933. }
  934. }
  935.  
  936. }
  937.  
  938. // =====DailyMotion===== //
  939.  
  940. else if (page.url.indexOf('dailymotion.com/video') != -1 || page.url.indexOf('dailymotion.com/playlist') != -1) {
  941.  
  942. /* Redirect Playlist To Video */
  943. if (page.url.indexOf('dailymotion.com/playlist') != -1 && page.url.indexOf('#video=') != -1) {
  944. page.win.location.href = page.url.replace(/playlist.*#/, '').replace("=", "/");
  945. }
  946.  
  947. /* Get Player Window */
  948. var dmPlayerWindow = getMyElement ('', 'div', 'class', 'player-container', 0, false);
  949. if (!dmPlayerWindow) {
  950. showMyMessage ('!player');
  951. }
  952. else {
  953. /* Get Videos Content */
  954. var dmEmbed;
  955. if (page.url.indexOf('dailymotion.com/video') != -1) dmEmbed = page.url.replace(/\/video\//, "/embed/video/");
  956. else dmEmbed = page.url.replace(/playlist.*=/, "embed/video/");
  957. dmVideosContent = getMyContent (dmEmbed, '"qualities":\\{(.*?)\\]\\},', false);
  958.  
  959. /* Get Videos */
  960. if (dmVideosContent) {
  961. var dmVideoFormats = {'240': 'Very Low Definition MP4', '380': 'Low Definition MP4', '480': 'Standard Definition MP4',
  962. '720': 'High Definition MP4', '1080': 'Full High Definition MP4'};
  963. var dmVideoList = {};
  964. var dmVideoFound = false;
  965. var dmVideoParser, dmVideoParse, myVideoCode, dmVideo;
  966. for (var dmVideoCode in dmVideoFormats) {
  967. dmVideoParser = '"' + dmVideoCode + '".*?"url":"(.*?)"';
  968. dmVideoParse = dmVideosContent.match (dmVideoParser);
  969. dmVideo = (dmVideoParse) ? dmVideoParse[1] : null;
  970. if (dmVideo) {
  971. if (!dmVideoFound) dmVideoFound = true;
  972. dmVideo = cleanMyContent(dmVideo, true);
  973. myVideoCode = dmVideoFormats[dmVideoCode];
  974. if (!dmVideoList[myVideoCode]) dmVideoList[myVideoCode] = dmVideo;
  975. }
  976. }
  977.  
  978. if (dmVideoFound) {
  979. /* Create Saver */
  980. var dmDefaultVideo = 'Low Definition MP4';
  981. saver = {'saverSocket': dmPlayerWindow, 'videoList': dmVideoList, 'videoSave': dmDefaultVideo, 'saverWidth': 800};
  982. feature['container'] = false;
  983. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  984. option['containers'] = ['MP4'];
  985. createMySaver ();
  986. }
  987. else {
  988. saver = {'saverSocket': dmPlayerWindow, 'saverWidth': 800, 'warnMess': '!videos'};
  989. createMySaver ();
  990. }
  991. }
  992. else {
  993. saver = {'saverSocket': dmPlayerWindow, 'saverWidth': 800, 'warnMess': '!content'};
  994. createMySaver ();
  995. }
  996. }
  997.  
  998. }
  999.  
  1000. // =====Vimeo===== //
  1001.  
  1002. 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+/)) {
  1003.  
  1004. /* Multi Video Page */
  1005. if (getMyElement('', 'div', 'class', 'player_container', -1, false).length > 1) return;
  1006.  
  1007. /* Video Page Type */
  1008. var viVideoPage = (page.url.match(/vimeo.com\/\d+/) || page.url.match(/vimeo.com\/album\/\d+\/video\/\d+/) || page.url.match(/vimeo.com\/groups\/[^\/]*\/videos\/\d+/)) ? true : false;
  1009.  
  1010. /* Saver Width */
  1011. var viSaverWidth = 960;
  1012. if (page.url.indexOf('/channels/') != -1 && page.url.indexOf('/channels/staffpicks') == -1) {
  1013. viSaverWidth = 630;
  1014. }
  1015. if (viVideoPage) viSaverWidth = 700;
  1016.  
  1017. /* Get Player Window */
  1018. var viPlayerWindow;
  1019. if (viVideoPage) viPlayerWindow = getMyElement ('', 'div', 'class', 'clip_info-actions', 0, false);
  1020. else viPlayerWindow = getMyElement ('', 'div', 'class', 'player_container', 0, false);
  1021. if (!viPlayerWindow) {
  1022. showMyMessage ('!player');
  1023. }
  1024. else {
  1025. /* Restyle Player Window */
  1026. if (!viVideoPage) styleMyElement (viPlayerWindow, {margin: '0px 0px 20px 0px'});
  1027.  
  1028. /* Get Content Source */
  1029. var viVideoSource = getMyContent (page.url, '"config_url":"(.*?)"', false);
  1030. if (viVideoSource) viVideoSource = cleanMyContent(viVideoSource, false);
  1031. else viVideoSource = getMyContent (page.url, 'data-config-url="(.*?)"', false).replace(/&amp;/g, '&');
  1032.  
  1033. /* Get Videos Content */
  1034. var viVideosContent;
  1035. if (viVideoSource) {
  1036. viVideosContent = getMyContent(viVideoSource, '"progressive":\\[(.*?)\\]', false);
  1037. }
  1038.  
  1039. /* Get Videos */
  1040. if (viVideosContent) {
  1041. var viVideoFormats = {'1080p': 'Full High Definition MP4', '720p': 'High Definition MP4', '360p': 'Low Definition MP4', '270p': 'Very Low Definition MP4'};
  1042. var viVideoList = {};
  1043. var viVideoFound = false;
  1044. var viVideo, myVideoCode;
  1045. var viVideos = viVideosContent.split('},');
  1046. for (var i = 0; i < viVideos.length; i++) {
  1047. for (var viVideoCode in viVideoFormats) {
  1048. if (viVideos[i].indexOf('"quality":"' + viVideoCode + '"') != -1) {
  1049. viVideo = viVideos[i].match(/"url":"(.*?)"/);
  1050. viVideo = (viVideo) ? viVideo[1] : null;
  1051. if (viVideo) {
  1052. if (!viVideoFound) viVideoFound = true;
  1053. myVideoCode = viVideoFormats[viVideoCode];
  1054. viVideoList[myVideoCode] = viVideo;
  1055. }
  1056. }
  1057. }
  1058. }
  1059.  
  1060. if (viVideoFound) {
  1061. /* Create Saver */
  1062. var viDefaultVideo = 'Low Definition MP4';
  1063. saver = {'saverSocket': viPlayerWindow, 'videoList': viVideoList, 'videoSave': viDefaultVideo, 'saverWidth': viSaverWidth};
  1064. feature['container'] = false;
  1065. option['definitions'] = ['High Definition', 'Low Definition', 'Very Low Definition'];
  1066. option['containers'] = ['MP4'];
  1067. createMySaver ();
  1068. }
  1069. else {
  1070. saver = {'saverSocket': viPlayerWindow, 'saverWidth': viSaverWidth, 'warnMess': '!videos'};
  1071. createMySaver ();
  1072. }
  1073. }
  1074. else {
  1075. saver = {'saverSocket': viPlayerWindow, 'saverWidth': viSaverWidth, 'warnMess': '!content'};
  1076. createMySaver ();
  1077. }
  1078. }
  1079.  
  1080. }
  1081.  
  1082. // =====MetaCafe===== //
  1083.  
  1084. else if (page.url.indexOf('metacafe.com/watch') != -1) {
  1085.  
  1086. /* Get Player Window */
  1087. mcPlayerWindow = getMyElement ('', 'div', 'class', 'mc-video-player', 0, false);
  1088. if (!mcPlayerWindow) {
  1089. showMyMessage ('!player');
  1090. }
  1091. else {
  1092. /* Restyle Player Window */
  1093. styleMyElement (mcPlayerWindow, {margin: '0px 0px 10px 0px'});
  1094.  
  1095. /* Get Videos Content */
  1096. var mcVideosContent = getMyContent (page.url, 'flashvars\\s*=\\s*\\{(.*?)\\};', false);
  1097.  
  1098. /* Get Videos */
  1099. if (mcVideosContent) {
  1100. var mcVideoList = {};
  1101. var mcVideoFound = false;
  1102. var mcVideoFormats = {'video_alt_url2': 'High Definition MP4', 'video_alt_url': 'Low Definition MP4', 'video_url': 'Very Low Definition MP4'};
  1103. var mcVideoFormatz = {'video_alt_url2': '_720p', 'video_alt_url': '_360p', 'video_url': '_240p'};
  1104. var mcVideoHLS = mcVideosContent.match (/"src":"(.*?)"/);
  1105. mcVideoHLS = (mcVideoHLS) ? cleanMyContent(mcVideoHLS[1], false) : null;
  1106. if (mcVideoHLS) {
  1107. var mcVideoParser, mcVideoParse, myVideoCode, mcVideo;
  1108. for (var mcVideoCode in mcVideoFormats) {
  1109. mcVideoParser = '"' + mcVideoCode + '":"(.*?)"';
  1110. mcVideoParse = mcVideosContent.match (mcVideoParser);
  1111. mcVideo = (mcVideoParse) ? mcVideoParse[1] : null;
  1112. if (mcVideo) {
  1113. if (!mcVideoFound) mcVideoFound = true;
  1114. myVideoCode = mcVideoFormats[mcVideoCode];
  1115. mcVideoList[myVideoCode] = mcVideoHLS.replace('.m3u8', mcVideoFormatz[mcVideoCode] + '.m3u8');
  1116. }
  1117. }
  1118. }
  1119.  
  1120. if (mcVideoFound) {
  1121. /* Create Saver */
  1122. var mcDefaultVideo = 'Low Definition MP4';
  1123. saver = {'saverSocket': mcPlayerWindow, 'videoList': mcVideoList, 'videoSave': mcDefaultVideo, 'saverWidth': 640};
  1124. feature['container'] = false;
  1125. option['definitions'] = ['High Definition', 'Low Definition', 'Very Low Definition'];
  1126. option['containers'] = ['MP4'];
  1127. createMySaver ();
  1128. }
  1129. else {
  1130. saver = {'saverSocket': mcPlayerWindow, 'saverWidth': 640, 'warnMess': '!videos'};
  1131. createMySaver ();
  1132. }
  1133. }
  1134. else {
  1135. saver = {'saverSocket': mcPlayerWindow, 'saverWidth': 640};
  1136. var ytVideoId = page.url.match (/\/yt-(.*?)\//);
  1137. if (ytVideoId && ytVideoId[1]) {
  1138. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId[1];
  1139. saver['warnMess'] = 'embed';
  1140. saver['warnContent'] = ytVideoLink;
  1141. }
  1142. else saver['warnMess'] = '!videos';
  1143. createMySaver ();
  1144. }
  1145. }
  1146.  
  1147. }
  1148.  
  1149. // =====Break===== //
  1150.  
  1151. else if (page.url.indexOf('break.com/video') != -1 || page.url.indexOf('break.com/movies') != -1) {
  1152.  
  1153. /* Get Player Window */
  1154. var brPlayerWindow = getMyElement ('', 'div', 'id', 'video-player', -1, false);
  1155. if (!brPlayerWindow) {
  1156. showMyMessage ('!player');
  1157. }
  1158. else {
  1159. /* Saver Width */
  1160. var brWindowWidth = page.win.innerWidth || page.doc.documentElement.clientWidth;
  1161. var brSaverWidth;
  1162. if (page.url.indexOf('break.com/movies') != -1) {
  1163. if (brWindowWidth >= 1400) brSaverWidth = 1152;
  1164. else brSaverWidth = 912;
  1165. }
  1166. else {
  1167. if (brWindowWidth >= 1400) brSaverWidth = 832;
  1168. else brSaverWidth = 592;
  1169. }
  1170.  
  1171. /* Get Video ID */
  1172. var brVideoID = page.url.match(/-(\d+)($|\?)/);
  1173. brVideoID = (brVideoID) ? brVideoID[1] : null;
  1174.  
  1175. /* Get Videos Content */
  1176. var brSource = page.win.location.protocol + '//' + page.win.location.hostname + '/embed/' + brVideoID;
  1177. var brVideosContent = getMyContent (brSource, 'TEXT', false);
  1178.  
  1179. /* Get Videos */
  1180. if (brVideosContent) {
  1181. var brVideoList = {};
  1182. var brVideoFormats = {};
  1183. var brVideoFound = false;
  1184. 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'};
  1185. var brVideoPath, brVideoToken, brVideoThumb, brVideo, myVideoCode;
  1186. brVideoPath = brVideosContent.match (/"videoUri":\s"(.*?)496_kbps/);
  1187. brVideoPath = (brVideoPath) ? brVideoPath[1] : null;
  1188. brVideoToken = brVideosContent.match (/"AuthToken":\s"(.*?)"/);
  1189. brVideoToken = (brVideoToken) ? brVideoToken[1] : null;
  1190. if (brVideoPath && brVideoToken) {
  1191. for (var brVideoCode in brVideoFormats) {
  1192. if (brVideosContent.match(brVideoPath + brVideoCode)) {
  1193. if (!brVideoFound) brVideoFound = true;
  1194. myVideoCode = brVideoFormats[brVideoCode];
  1195. brVideo = brVideoPath + brVideoCode + '?' + brVideoToken;
  1196. brVideoList[myVideoCode] = brVideo;
  1197. }
  1198. }
  1199. }
  1200.  
  1201. if (brVideoFound) {
  1202. /* Create Saver */
  1203. var brDefaultVideo = 'Low Definition MP4';
  1204. saver = {'saverSocket': brPlayerWindow, 'videoList': brVideoList, 'videoSave': brDefaultVideo, 'saverWidth': brSaverWidth};
  1205. option['definitions'] = ['Very Low Definition', 'Low Definition', 'Standard Definition', 'High Definition', 'Full High Definition'];
  1206. option['containers'] = ['MP4', 'FLV', 'Any'];
  1207. createMySaver ();
  1208. }
  1209. else {
  1210. saver = {'saverSocket': brPlayerWindow, 'saverWidth': brSaverWidth};
  1211. var ytVideoId = brVideosContent.match (/"youtubeId":\s"(.*?)"/);
  1212. if (ytVideoId && ytVideoId[1]) {
  1213. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId[1];
  1214. saver['warnMess'] = 'embed';
  1215. saver['warnContent'] = ytVideoLink;
  1216. }
  1217. else saver['warnMess'] = '!videos';
  1218. createMySaver ();
  1219. }
  1220. }
  1221. else {
  1222. saver = {'saverSocket': brPlayerWindow, 'saverWidth': brSaverWidth, 'warnMess': '!content'};
  1223. createMySaver ();
  1224. }
  1225. }
  1226.  
  1227. }
  1228.  
  1229. // =====FunnyOrDie===== //
  1230.  
  1231. else if (page.url.indexOf('funnyordie.com/videos') != -1) {
  1232.  
  1233. /* Get Player Window */
  1234. var fodPlayerWindow = getMyElement ('', 'div', 'class', 'video-content', 0, false);
  1235. if (!fodPlayerWindow) {
  1236. showMyMessage ('!player');
  1237. }
  1238. else {
  1239. /* My Saver Socket */
  1240. var fodSaverSocket = createMyElement ('div', '', '', '', '');
  1241. styleMyElement (fodSaverSocket, {width: '100%', height: '24px', textAlign: 'center', padding: '0px 100px 0px 100px', backgroundColor: '#F4F4F4'});
  1242. appendMyElement (fodPlayerWindow, fodSaverSocket);
  1243.  
  1244. /* Get Videos Content */
  1245. var fodVideosContent = getMyContent (page.url, '<video([\\s\\S]*?)video>', false);
  1246.  
  1247. /* Get Videos */
  1248. if (fodVideosContent) {
  1249. 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'};
  1250. var fodVideoList = {};
  1251. var fodVideoFound = false;
  1252. var fodVideoPath, fodVideoCodes, fodVideo, myVideoCode;
  1253. fodVideoPath = fodVideosContent.match(/src="(.*?)v\d+.*?\.mp4"/);
  1254. fodVideoPath = (fodVideoPath) ? fodVideoPath[1] : null;
  1255. fodVideoCodes = fodVideosContent.match (/v([^\/]*?)\/master/);
  1256. fodVideoCodes = (fodVideoCodes) ? fodVideoCodes[1] : '';
  1257. if (fodVideoPath) {
  1258. if (fodVideoCodes) {
  1259. for (var fodVideoCode in fodVideoFormats) {
  1260. if (fodVideoCodes.indexOf(fodVideoCode.replace(/v/, '').replace(/\..*/, '')) != -1) {
  1261. if (!fodVideoFound) fodVideoFound = true;
  1262. fodVideo = fodVideoPath + fodVideoCode;
  1263. myVideoCode = fodVideoFormats[fodVideoCode];
  1264. fodVideoList[myVideoCode] = fodVideo;
  1265. }
  1266. }
  1267. }
  1268. else {
  1269. for (var fodVideoCode in fodVideoFormats) {
  1270. fodVideo = fodVideoPath + fodVideoCode;
  1271. if (fodVideosContent.match(fodVideo)) {
  1272. if (!fodVideoFound) fodVideoFound = true;
  1273. myVideoCode = fodVideoFormats[fodVideoCode];
  1274. fodVideoList[myVideoCode] = fodVideo;
  1275. }
  1276. }
  1277. }
  1278. }
  1279.  
  1280. if (fodVideoFound) {
  1281. /* Create Saver */
  1282. fodDefaultVideo = 'Low Definition MP4';
  1283. saver = {'saverSocket': fodSaverSocket, 'videoList': fodVideoList, 'videoSave': fodDefaultVideo, 'saverWidth': 570};
  1284. feature['container'] = false;
  1285. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1286. option['containers'] = ['MP4'];
  1287. createMySaver ();
  1288. }
  1289. else {
  1290. saver = {'saverSocket': fodPlayerWindow, 'saverWidth': 570, 'warnMess': '!videos'};
  1291. createMySaver ();
  1292. }
  1293. }
  1294. else {
  1295. saver = {'saverSocket': fodPlayerWindow, 'saverWidth': 570, 'warnMess': '!content'};
  1296. createMySaver ();
  1297. }
  1298. }
  1299.  
  1300. }
  1301.  
  1302. // =====Videojug===== //
  1303.  
  1304. else if (page.url.indexOf('videojug.com/') != -1) {
  1305.  
  1306. /* Get Player Window */
  1307. var vjPlayerWindow = getMyElement ('', 'div', 'id', 'player_shadow', -1, false);
  1308. var vjPlayerWidth;
  1309. if (page.url.indexOf("videojug.com/film") != -1) vjPlayerWidth = 640;
  1310. else if (page.url.indexOf("videojug.com/series") != -1) vjPlayerWidth = 768;
  1311. else return;
  1312. if (!vjPlayerWindow) {
  1313. showMyMessage ('!player');
  1314. }
  1315. else {
  1316. /* Get Videos Content */
  1317. var vjVideoID = getMyContent (page.url, 'data-videoid="(.*?)"', true);
  1318. var vjVideoTitle = getMyContent (page.url, 'data-filenameprefix="(.*?)"', true);
  1319.  
  1320. /* Get Videos */
  1321. if (vjVideoID && vjVideoTitle) {
  1322. var vjVideoID2 = vjVideoID.substring(0,2);
  1323. var vjVideoProtocol = page.win.location.protocol;
  1324. var vjVideoSource = vjVideoProtocol + '//' + page.win.location.hostname + '/views/film/playlist.aspx?id=' + vjVideoID;
  1325. var vjVideoShapes = getMyContent(vjVideoSource, '<Shapes>(.*?)<\/Shapes>', false);
  1326. var vjVideoFormats = {'VJ480PENG.mp4': 'Standard Definition MP4', 'VJ360PENG.mp4': 'Low Definition MP4', 'PHOENG.mp4': 'Very Low Definition MP4', 'FW8ENG.flv': 'Low Definition FLV', 'FS8ENG.flv': 'Very Low Definition FLV'};
  1327. var vjVideoList = {};
  1328. var vjVideoFound = false;
  1329. var vjVideoPart, myVideoCode, vjVideo, vjVideoCodePart, vjVideoPattern, vjVideoLocation;
  1330. if (vjVideoShapes) {
  1331. vjVideoPart = vjVideoID2 + '/' + vjVideoID + '/' + vjVideoTitle;
  1332. for (var vjVideoCode in vjVideoFormats) {
  1333. if (vjVideoCode.indexOf('VJ') != -1) vjVideoCodePart = vjVideoCode.substring(0, 6);
  1334. else vjVideoCodePart = vjVideoCode.substring(0, 3);
  1335. vjVideoPattern = 'Code="' + vjVideoCodePart + '"\\s+Locations="(.*?),';
  1336. vjVideoLocation = vjVideoShapes.match(vjVideoPattern);
  1337. vjVideoLocation = (vjVideoLocation) ? vjVideoProtocol + '//' + vjVideoLocation[1] : null;
  1338. if (vjVideoLocation) {
  1339. if (!vjVideoFound) vjVideoFound = true;
  1340. vjVideo = vjVideoLocation + '/' + vjVideoPart + '__' + vjVideoCode;
  1341. myVideoCode = vjVideoFormats[vjVideoCode];
  1342. vjVideoList[myVideoCode] = vjVideo;
  1343. }
  1344. }
  1345. }
  1346.  
  1347. if (vjVideoFound) {
  1348. /* Create Saver */
  1349. var vjDefaultVideo = 'Low Definition MP4';
  1350. saver = {'saverSocket': vjPlayerWindow, 'videoList': vjVideoList, 'videoSave': vjDefaultVideo, 'saverWidth': vjPlayerWidth};
  1351. option['definition'] = 'SD';
  1352. option['definitions'] = ['Standard Definition', 'Low Definition', 'Very Low Definition'];
  1353. option['containers'] = ['MP4', 'FLV', 'Any'];
  1354. createMySaver ();
  1355. }
  1356. else {
  1357. saver = {'saverSocket': vjPlayerWindow, 'saverWidth': vjPlayerWidth, 'warnMess': '!videos'};
  1358. createMySaver ();
  1359. }
  1360. }
  1361. else {
  1362. saver = {'saverSocket': vjPlayerWindow, 'saverWidth': vjPlayerWidth, 'warnMess': '!content'};
  1363. createMySaver ();
  1364. }
  1365. }
  1366. if (saver['saverPanel'] && vjPlayerWidth == 768) {
  1367. styleMyElement(saver['saverPanel'], {marginTop: '10px'});
  1368. }
  1369.  
  1370. }
  1371.  
  1372. // =====Blip===== //
  1373.  
  1374. else if (page.url.indexOf('blip.tv') != -1) {
  1375.  
  1376. /* Get Page Type */
  1377. var blipPageType = getMyContent (page.url, 'meta\\s+property="video:tag"\\s+content="(.*?)"', false);
  1378. if (!blipPageType || blipPageType.indexOf('episode') == -1) return;
  1379.  
  1380. /* Get Player Window */
  1381. var blipSaverWidth;
  1382. var blipPlayerWindow = getMyElement ('', 'div', 'class', 'Theater', 0, false) || getMyElement ('', 'div', 'id', 'ErrorWrap', -1, false);
  1383. if (!blipPlayerWindow) {
  1384. blipPlayerWindow = getMyElement ('', 'div', 'id', 'PlayerEmbed', -1, false);
  1385. blipSaverWidth = 596;
  1386. }
  1387. else {
  1388. blipSaverWidth = 960;
  1389. }
  1390. if (!blipPlayerWindow) {
  1391. showMyMessage ('!player');
  1392. }
  1393. else {
  1394. /* My Saver Socket */
  1395. var blipSaverSocket = createMyElement ('div', '', '', '', '');
  1396. styleMyElement (blipSaverSocket, {width: blipSaverWidth + 'px', textAlign: 'center', margin: '0px auto'});
  1397. appendMyElement (blipPlayerWindow, blipSaverSocket);
  1398.  
  1399. /* Get Videos Content */
  1400. var blipVideosContent = getMyContent(page.url + '?skin=json', '"additionalMedia":\\[(.*?)\\]', false);
  1401.  
  1402. /* Get Videos */
  1403. if (blipVideosContent) {
  1404. var blipVideoList = {};
  1405. var blipVideoFound = false;
  1406. var blipMimeTypes = {'video/x-m4v': 'M4V', 'video/quicktime': 'MOV', 'video/mp4': 'MP4', 'video/x-flv': 'FLV'};
  1407. var blipVideos = blipVideosContent.split(',{');
  1408. var blipVideoURL, blipVideoMime, blipVideoHeight, blipVideoRole, blipVideoDef, blipVideoCode;
  1409. var blipDefaultVideo = 'Low Definition MP4';
  1410. for (var blipV = 0; blipV < blipVideos.length; blipV++) {
  1411. blipVideoMime = blipVideos[blipV].match(/"primary_mime_type":"(.*?)"/);
  1412. blipVideoMime = (blipVideoMime) ? blipVideoMime[1] : null;
  1413. if (blipMimeTypes[blipVideoMime]) {
  1414. blipVideoURL = blipVideos[blipV].match(/"url":"(.*?)"/);
  1415. blipVideoURL = (blipVideoURL) ? blipVideoURL[1] : null;
  1416. blipVideoHeight = blipVideos[blipV].match(/"media_height":"(.*?)"/);
  1417. blipVideoHeight = (blipVideoHeight) ? blipVideoHeight[1] : null;
  1418. blipVideoRole = blipVideos[blipV].match(/"role":"(.*?)"/);
  1419. blipVideoRole = (blipVideoRole) ? blipVideoRole[1] : null;
  1420. if (blipVideoURL && blipVideoHeight && blipVideoRole) {
  1421. if (!blipVideoFound) blipVideoFound = true;
  1422. if (blipVideoHeight >= 200 && blipVideoHeight < 400) blipVideoDef = 'Low Definition';
  1423. else if (blipVideoHeight >= 400 && blipVideoHeight < 700) blipVideoDef = 'Standard Definition';
  1424. else if (blipVideoHeight >= 700) blipVideoDef = 'High Definition';
  1425. blipVideoCode = blipVideoDef + ' ' + blipMimeTypes[blipVideoMime];
  1426. blipVideoList[blipVideoCode] = blipVideoURL;
  1427. if (blipVideoRole == 'Source') blipDefaultVideo = blipVideoCode;
  1428. }
  1429. }
  1430. }
  1431.  
  1432. if (blipVideoFound) {
  1433. /* Create Saver */
  1434. saver = {'saverSocket': blipSaverSocket, 'videoList': blipVideoList, 'videoSave': blipDefaultVideo, 'saverWidth': blipSaverWidth};
  1435. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition'];
  1436. option['containers'] = ['MP4', 'M4V', 'MOV', 'FLV', 'Any'];
  1437. createMySaver ();
  1438. }
  1439. else {
  1440. saver = {'saverSocket': blipPlayerWindow, 'saverWidth': blipSaverWidth, 'warnMess': '!videos'};
  1441. createMySaver ();
  1442. }
  1443. }
  1444. else {
  1445. saver = {'saverSocket': blipPlayerWindow, 'saverWidth': blipSaverWidth, 'warnMess': '!content'};
  1446. createMySaver ();
  1447. }
  1448. }
  1449.  
  1450. }
  1451.  
  1452. // =====Veoh===== //
  1453.  
  1454. else if (page.url.indexOf('veoh.com/watch') != -1) {
  1455.  
  1456. /* Get Video Availability */
  1457. if (getMyElement ('', 'div', 'class', 'veoh-video-player-error', 0, false)) return;
  1458.  
  1459. /* Get Player Window */
  1460. var vePlayerWindow = getMyElement ('', 'div', 'id', 'videoPlayerContainer', -1, false);
  1461. if (!vePlayerWindow) {
  1462. showMyMessage ('!player');
  1463. }
  1464. else {
  1465. /* Get Videos Content */
  1466. var veVideosContent = getMyContent (page.url, '__watch.videoDetailsJSON = \'\\{(.*?)\\}', false);
  1467. veVideosContent = cleanMyContent (veVideosContent, true);
  1468.  
  1469. /* Restyle Player Window */
  1470. styleMyElement (vePlayerWindow, {margin: '0px 0px 20px 0px'});
  1471.  
  1472. /* Get Videos */
  1473. if (veVideosContent) {
  1474. var veVideoFormats = {'fullPreviewHashLowPath': 'Very Low Definition MP4', 'fullPreviewHashHighPath': 'Low Definition MP4'};
  1475. var veVideoList = {};
  1476. var veVideoFound = false;
  1477. var veVideoParser, veVideoParse, veVideo, myVideoCode;
  1478. for (var veVideoCode in veVideoFormats) {
  1479. veVideoParser = veVideoCode + '":"(.*?)"';
  1480. veVideoParse = veVideosContent.match (veVideoParser);
  1481. veVideo = (veVideoParse) ? veVideoParse[1] : null;
  1482. if (veVideo) {
  1483. if (!veVideoFound) veVideoFound = true;
  1484. myVideoCode = veVideoFormats[veVideoCode];
  1485. veVideoList[myVideoCode] = veVideo;
  1486. }
  1487. }
  1488.  
  1489. if (veVideoFound) {
  1490. /* Create Saver */
  1491. var veDefaultVideo = 'Low Definition MP4';
  1492. saver = {'saverSocket': vePlayerWindow, 'videoList': veVideoList, 'videoSave': veDefaultVideo, 'saverWidth': 640};
  1493. feature['container'] = false;
  1494. feature['fullsize'] = false;
  1495. option['definition'] = 'LD';
  1496. option['definitions'] = ['Low Definition', 'Very Low Definition'];
  1497. option['containers'] = ['MP4'];
  1498. createMySaver ();
  1499. }
  1500. else {
  1501. saver = {'saverSocket': vePlayerWindow, 'saverWidth': 640};
  1502. var veVideoSource = getMyContent(page.url, '"videoContentSource":"(.*?)"', false);
  1503. if (veVideoSource == 'YouTube') var ytVideoId = getMyContent(page.url, '"videoId":"yapi-(.*?)"', false);
  1504. if (ytVideoId) {
  1505. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId;
  1506. saver['warnMess'] = 'embed';
  1507. saver['warnContent'] = ytVideoLink;
  1508. styleMyElement(vePlayerWindow, {margin: '0px 0px 20px 0px'});
  1509. }
  1510. else saver['warnMess'] = '!videos';
  1511. createMySaver ();
  1512. }
  1513. }
  1514. else {
  1515. saver = {'saverSocket': vePlayerWindow, 'saverWidth': 640, 'warnMess': '!content'};
  1516. createMySaver ();
  1517. }
  1518. }
  1519.  
  1520. }
  1521.  
  1522. // =====Crackle===== //
  1523.  
  1524. else if (page.url.indexOf('crackle.com/') != -1) {
  1525.  
  1526. /* Get Page Type */
  1527. var crPageType = getMyContent (page.url, 'meta\\s+property="og:type"\\s+content="(.*?)"', false);
  1528. if (!crPageType || crPageType.indexOf('video') == -1) return;
  1529.  
  1530. /* Get Player Window */
  1531. var crPlayerWindow = getMyElement ('', 'div', 'class', 'player-stage-area1', 0, false);
  1532. if (!crPlayerWindow) {
  1533. showMyMessage ('!player');
  1534. }
  1535. else {
  1536. /* Restyle */
  1537. if (!getMyElement(crPlayerWindow, 'div', 'class', 'clearall', 0, false)) {
  1538. var myClearFix = createMyElement ('div', '', '', '', '');
  1539. styleMyElement (myClearFix, {clear: 'both'});
  1540. appendMyElement (crPlayerWindow, myClearFix);
  1541. }
  1542. var crContent = getMyElement ('', 'div', 'id', 'content', -1, false);
  1543. styleMyElement (crContent, {marginTop: '30px'});
  1544. var crPlayerImage = getMyElement ('', 'div', 'class', 'image-stage-area', 0, false);
  1545. if (crPlayerImage) removeMyElement (crPlayerImage.parentNode, crPlayerImage);
  1546.  
  1547. /* Get Videos Content */
  1548. var crVideoPath = getMyContent (page.url, 'images-us-am.crackle.com\/(.*?_)tnl', false);
  1549. if (!crVideoPath) {
  1550. var crVideoID = getMyContent (page.url, 'mediaId:\\s*(.*?),', false);
  1551. if (crVideoID) {
  1552. var crVidWallCache = page.win.location.protocol + '//' + page.win.location.hostname + '/app/vidwallcache.aspx?flags=-1&fm=' + crVideoID + '&partner=20';
  1553. crVideoPath = getMyContent (crVidWallCache, '\\sp="(.*?)"', false);
  1554. }
  1555. }
  1556.  
  1557. /* Get Videos */
  1558. if (crVideoPath) {
  1559. var crVideoList = {};
  1560. var crVideoFormats = {'360p.mp4': 'Low Definition MP4', '480p.mp4': 'Standard Definition MP4'};
  1561. var crVideoThumb, crVideo, myVideoCode;
  1562. for (var crVideoCode in crVideoFormats) {
  1563. crVideo = 'http://media-us-am.crackle.com/' + crVideoPath + crVideoCode;
  1564. myVideoCode = crVideoFormats[crVideoCode];
  1565. crVideoList[myVideoCode] = crVideo;
  1566. }
  1567.  
  1568. /* Create Saver */
  1569. var crDefaultVideo = 'Low Definition MP4';
  1570. saver = {'saverSocket': crPlayerWindow, 'videoList': crVideoList, 'videoSave': crDefaultVideo, 'saverWidth': 970};
  1571. feature['container'] = false;
  1572. option['definition'] = 'SD';
  1573. option['definitions'] = ['Standard Definition', 'Low Definition'];
  1574. option['containers'] = ['MP4'];
  1575. createMySaver ();
  1576.  
  1577. /* Fix Thumbnails */
  1578. var crThumbs = getMyElement('', 'div', 'class', 'thumbnail', -1, false);
  1579. for (var crT = 0; crT < crThumbs.length; crT++) {
  1580. if (crThumbs[crT].innerHTML.indexOf('AddObjectToQueue') != -1) {
  1581. var crLink = crThumbs[crT].innerHTML.match(/,\s+\d+,\s+'(.*?)'/);
  1582. crLink = (crLink) ? crLink[1] : null;
  1583. var crImg = crThumbs[crT].innerHTML.match(/src="(.*?)"/);
  1584. crImg = (crImg) ? crImg[1] : null;
  1585. crThumbs[crT].innerHTML = '<img src="' + crImg + '" onclick="window.location.href=\'' + crLink + '\'" style="cursor:pointer">';
  1586. }
  1587. }
  1588. }
  1589. else {
  1590. saver = {'saverSocket': crPlayerWindow, 'saverWidth': 970, 'warnMess': '!videos'};
  1591. createMySaver ();
  1592. }
  1593.  
  1594. }
  1595.  
  1596. }
  1597.  
  1598. // =====Viki===== //
  1599.  
  1600. else if (page.url.indexOf('viki.com/videos') != -1) {
  1601.  
  1602. /* Get Player Window */
  1603. var vkSaverWindow = getMyElement ('', 'div', 'class', 'card-content', 0, false);
  1604. if (!vkSaverWindow) {
  1605. showMyMessage ('!player');
  1606. }
  1607. else {
  1608. /* Get Video ID */
  1609. var vkVideoID = page.url.match(/videos\/(.*?)v/);
  1610. vkVideoID = (vkVideoID) ? vkVideoID[1] : null;
  1611.  
  1612. /* Get Videos Content */
  1613. var vkVideosContent;
  1614. if (vkVideoID) vkVideosContent = getMyContent (page.win.location.protocol + '//' + page.win.location.host + '/player5_fragment/' + vkVideoID + 'v.json', 'TEXT', false);
  1615.  
  1616. /* Saver Width*/
  1617. var vkSaverWith = parseInt(vkSaverWindow.clientWidth) - 20;
  1618.  
  1619. /* Get Videos */
  1620. if (vkVideosContent) {
  1621. var vkVideoList = {};
  1622. var vkVideo = vkVideosContent.match(/"video_url":"(.*?)"/);
  1623. vkVideo = (vkVideo) ? vkVideo[1] : null;
  1624.  
  1625. /* Create Saver */
  1626. if (vkVideo) {
  1627. var vkDefaultVideo = 'Low Definition MP4';
  1628. vkVideoList[vkDefaultVideo] = vkVideo
  1629. saver = {'saverSocket': vkSaverWindow, 'videoList': vkVideoList, 'videoSave': vkDefaultVideo, 'saverWidth': vkSaverWith};
  1630. feature['definition'] = false;
  1631. feature['container'] = false;
  1632. option['definition'] = 'LD';
  1633. option['definitions'] = ['Low Definition'];
  1634. option['containers'] = ['MP4'];
  1635. createMySaver ();
  1636. }
  1637. else {
  1638. saver = {'saverSocket': vkPlayerWindow, 'saverWidth': vkSaverWith, 'warnMess': '!videos'};
  1639. createMySaver ();
  1640. }
  1641. }
  1642. else {
  1643. saver = {'saverSocket': vkPlayerWindow, 'saverWidth': vkSaverWith, 'warnMess': '!content'};
  1644. createMySaver ();
  1645. }
  1646. }
  1647.  
  1648. }
  1649.  
  1650. // =====IMDB===== //
  1651.  
  1652. else if (page.url.indexOf('imdb.com') != -1) {
  1653.  
  1654. /* Redirect To Video Page */
  1655. if (page.url.indexOf('imdb.com/video/') == -1) {
  1656. page.doc.addEventListener('click', function(e) {
  1657. var p = e.target.parentNode;
  1658. while (p) {
  1659. if (p.tagName === 'A' && p.href.indexOf('/video/imdb') != -1) {
  1660. page.win.location.href = p.href.replace(/imdb\/inline.*/, '');
  1661. }
  1662. p = p.parentNode;
  1663. }
  1664. }, false);
  1665. return;
  1666. }
  1667.  
  1668. /* Get Player Window */
  1669. var imdbPlayerWindow = getMyElement ('', 'div', 'id', 'player-article', -1, false);
  1670. if (!imdbPlayerWindow) {
  1671. showMyMessage ('!player');
  1672. }
  1673. else {
  1674. /* Get Videos Content */
  1675. var imdbVideoList = {};
  1676. var imdbVideoFormats = {'1': 'Low Definition MP4', '2': 'Standard Definition MP4', '3': 'High Definition MP4'};
  1677. var imdbDefaultVideo, imdbURL, imdbVideo, myVideoCode;
  1678. var imdbVideoFound = false;
  1679. var imdbVideoRTMP = false;
  1680. var imdbPageURL = page.url.replace(/\?.*$/, '').replace(/\/$/, '');
  1681. for (var imdbVideoCode in imdbVideoFormats) {
  1682. imdbURL = imdbPageURL + '/player?uff=' + imdbVideoCode;
  1683. imdbVideo = getMyContent (imdbURL, 'so.addVariable\\("file",\\s+"(.*?)"\\);', true);
  1684. if (imdbVideo) {
  1685. if (imdbVideo.indexOf('rtmp') != -1) {
  1686. if (!imdbVideoRTMP) imdbVideoRTMP = true;
  1687. }
  1688. else {
  1689. if (!imdbVideoFound) imdbVideoFound = true;
  1690. myVideoCode = imdbVideoFormats[imdbVideoCode];
  1691. imdbVideoList[myVideoCode] = imdbVideo;
  1692. if (!imdbDefaultVideo) imdbDefaultVideo = myVideoCode;
  1693. }
  1694. }
  1695. }
  1696.  
  1697. if (imdbVideoFound) {
  1698. /* Create Saver */
  1699. saver = {'saverSocket': imdbPlayerWindow, 'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'saverWidth': 1010};
  1700. feature['container'] = false;
  1701. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition'];
  1702. option['containers'] = ['MP4'];
  1703. createMySaver ();
  1704. }
  1705. else {
  1706. if (imdbVideoRTMP) {
  1707. saver = {'saverSocket': imdbPlayerWindow, 'saverWidth': 1010, 'warnMess': '!support'};
  1708. createMySaver ();
  1709. }
  1710. else {
  1711. saver = {'saverSocket': imdbPlayerWindow, 'saverWidth': 1010, 'warnMess': '!videos'};
  1712. createMySaver ();
  1713. }
  1714. }
  1715. }
  1716.  
  1717. }
  1718.  
  1719. // =====Facebook===== //
  1720.  
  1721. else if (page.url.match('facebook.com/(video.php|.*/videos/)')) {
  1722.  
  1723. /* Get Player Window */
  1724. var fbPlayerWindow = getMyElement ('', 'div', 'class', 'stageButtons', 0, false);
  1725. if (!fbPlayerWindow) {
  1726. showMyMessage ('!player');
  1727. }
  1728. else {
  1729. /* Get Videos Content */
  1730. var fbVideosContent = getMyContent(page.url, '"params","(.*?)"', false);
  1731. var fbPattern = /\\u([\d\w]{4})/gi;
  1732. fbVideosContent = fbVideosContent.replace(fbPattern, function (match, group) {
  1733. return String.fromCharCode(parseInt(group, 16));
  1734. });
  1735. fbVideosContent = unescape(fbVideosContent);
  1736.  
  1737. /* Get Videos */
  1738. if (fbVideosContent) {
  1739. var fbVideoList = {};
  1740. var fbVideoFormats = {'sd_src': 'Low Definition MP4', 'hd_src': 'High Definition MP4'};
  1741. var fbVideoFound = false;
  1742. var fbVideoPattern, fbVideo, myVideoCode, fbVideoThumb, fbDefaultVideo;
  1743. for (var fbVideoCode in fbVideoFormats) {
  1744. fbVideoPattern = '"' + fbVideoCode + '":"(.*?)"';
  1745. fbVideo = fbVideosContent.match(fbVideoPattern);
  1746. fbVideo = (fbVideo) ? fbVideo[1] : null;
  1747. if (fbVideo) {
  1748. fbVideo = cleanMyContent(fbVideo, false);
  1749. if (!fbVideoFound) fbVideoFound = true;
  1750. myVideoCode = fbVideoFormats[fbVideoCode];
  1751. if (fbVideo.indexOf('.flv') != -1) myVideoCode = myVideoCode.replace('MP4', 'FLV');
  1752. fbVideoList[myVideoCode] = fbVideo;
  1753. if (!fbDefaultVideo) fbDefaultVideo = myVideoCode;
  1754. }
  1755. }
  1756.  
  1757. if (fbVideoFound) {
  1758. /* Create Saver */
  1759. saver = {'saverSocket': fbPlayerWindow, 'videoList': fbVideoList, 'videoSave': fbDefaultVideo, 'saverWidth': 760};
  1760. option['definitions'] = ['High Definition', 'Low Definition'];
  1761. option['containers'] = ['MP4', 'FLV', 'Any'];
  1762. createMySaver ();
  1763. }
  1764. else {
  1765. saver = {'saverSocket': fbPlayerWindow, 'saverWidth': 760, 'warnMess': '!videos'};
  1766. createMySaver ();
  1767. }
  1768. }
  1769. else {
  1770. saver = {'saverSocket': fbPlayerWindow, 'saverWidth': 760, 'warnMess': '!content'};
  1771. createMySaver ();
  1772. }
  1773. }
  1774.  
  1775. }
  1776.  
  1777. })();