SaveTube

Download videos from video sharing web sites.

当前为 2014-07-12 提交的版本,查看 最新版本

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