SaveTube

Download videos from video sharing web sites.

当前为 2015-07-29 提交的版本,查看 最新版本

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