SaveTube

Download videos from video sharing web sites.

当前为 2016-01-06 提交的版本,查看 最新版本

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