SaveTube

Download videos from video sharing web sites.

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

  1. // ==UserScript==
  2. // @name SaveTube
  3. // @version 2014.08.08
  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 ytSignFuncName, ytSignFuncBody, ytSwapFuncName, ytSwapFuncBody, ytFuncMatch;
  568. ytSignFuncName = ytScriptSrc.match(/\.signature\s*=\s*((\$|_|\w)+)\(\w+\)/);
  569. ytSignFuncName = (ytSignFuncName) ? ytSignFuncName[1] : null;
  570. if (ytSignFuncName) {
  571. ytFuncMatch = 'function\\s+' + ytSignFuncName.replace(/\$/, '\\$') + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\}';
  572. ytSignFuncBody = ytScriptSrc.match(ytFuncMatch);
  573. ytSignFuncBody = (ytSignFuncBody) ? ytSignFuncBody[1] : null;
  574. if (ytSignFuncBody) {
  575. ytSwapFuncName = ytSignFuncBody.match(/((\$|_|\w)+)\.(\$|_|\w)+\(\w,[0-9]+\)/);
  576. ytSwapFuncName = (ytSwapFuncName) ? ytSwapFuncName[1] : null;
  577. if (ytSwapFuncName) {
  578. ytFuncMatch = 'var\\s+' + ytSwapFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};';
  579. ytSwapFuncBody = ytScriptSrc.match(ytFuncMatch);
  580. ytSwapFuncBody = (ytSwapFuncBody) ? ytSwapFuncBody[1] : null;
  581. }
  582. if (ytSwapFuncBody) ytSignFuncBody = 'var ' + ytSwapFuncName + '={' + ytSwapFuncBody + '};' + ytSignFuncBody;
  583. ytSignFuncBody = 'try {' + ytSignFuncBody + '} catch(e) {return null}';
  584. ytDecryptSignature = new Function('a', ytSignFuncBody);
  585. }
  586. }
  587. }
  588.  
  589. /* Get Player Window */
  590. var ytFeatherBeta;
  591. var ytPlayerWindow = getMyElement ('', 'div', 'id', 'player', -1, false);
  592. if (!ytPlayerWindow) {
  593. ytPlayerWindow = getMyElement ('', 'div', 'id', 'p', -1, false);
  594. if (ytPlayerWindow) styleMyElement (ytPlayerWindow, {margin: '0px 0px 30px 0px'});
  595. ytFeatherBeta = true;
  596. }
  597.  
  598. if (!ytPlayerWindow) {
  599. showMyMessage ('!player');
  600. }
  601. else {
  602. /* Get Video Title */
  603. if (ytFeatherBeta) {
  604. var ytVideoTitle = page.doc.title;
  605. }
  606. else {
  607. var ytVideoTitle = getMyContent (page.url, 'meta\\s+itemprop="name"\\s+content="(.*?)"', false);
  608. if (!ytVideoTitle) ytVideoTitle = getMyContent (page.url, 'meta\\s+property="og:title"\\s+content="(.*?)"', false);
  609. if (!ytVideoTitle) ytVideoTitle = page.doc.title;
  610. }
  611. if (ytVideoTitle) {
  612. ytVideoTitle = ytVideoTitle.replace(/&quot;/g, '\'').replace(/&#34;/g, '\'').replace(/"/g, '\'');
  613. ytVideoTitle = ytVideoTitle.replace(/&#39;/g, '\'').replace(/'/g, '\'');
  614. ytVideoTitle = ytVideoTitle.replace(/&amp;/g, 'and').replace(/&/g, 'and');
  615. ytVideoTitle = ytVideoTitle.replace(/\?/g, '').replace(/[#:\*]/g, '-').replace(/\//g, '-');
  616. ytVideoTitle = ytVideoTitle.replace(/^\s+|\s+$/, '').replace(/\.+$/g, '');
  617. ytVideoTitle = ytVideoTitle.replace(/^YouTube\s-\s/, '');
  618. }
  619.  
  620. /* Get Videos Content */
  621. var ytVideosContent;
  622. var ytVideosEncodedFmts, ytVideosAdaptiveFmts;
  623. ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map":\\s+"(.*?)"', false);
  624. if (ytVideosEncodedFmts) ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, false);
  625. else {
  626. ytVideosEncodedFmts = getMyContent(page.url, 'url_encoded_fmt_stream_map=(.*?)&amp;', false);
  627. if (ytVideosEncodedFmts) ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
  628. }
  629. ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts":\\s+"(.*?)"', false);
  630. if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, false);
  631. else {
  632. ytVideosAdaptiveFmts = getMyContent(page.url, 'adaptive_fmts=(.*?)&amp;', false);
  633. if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
  634. }
  635. if (ytVideosEncodedFmts) {
  636. ytVideosContent = ytVideosEncodedFmts;
  637. }
  638. if (ytVideosAdaptiveFmts) {
  639. ytVideosAdaptiveFmts = ytVideosAdaptiveFmts.replace(/clen=\d+&/g, '').replace(/&clen=\d+/g, '');
  640. ytVideosAdaptiveFmts = ytVideosAdaptiveFmts.replace(/lmt=\d+&/g, '').replace(/&lmt=\d+/g, '');
  641. if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts;
  642. else ytVideosContent = ytVideosAdaptiveFmts;
  643. }
  644.  
  645. /* Get HLS Content */
  646. if (!ytVideosContent) {
  647. var ytHLSVideos, ytHLSContent;
  648. ytHLSVideos = getMyContent(page.url, '"hlsvp":\\s*"(.*?)"', false);
  649. if (ytHLSVideos) ytHLSVideos = cleanMyContent(ytHLSVideos, false);
  650. }
  651. /* Fix Sidebar */
  652. var ytSidebarWindow = getMyElement ('', 'div', 'id', 'watch7-sidebar', -1, false);
  653. if (ytSidebarWindow) styleMyElement(ytSidebarWindow, {marginTop: '-412px'});
  654. /* Create Saver */
  655. var ytDefaultVideo = 'Low Definition MP4';
  656. function ytSaver () {
  657. saver = {'saverSocket': ytPlayerWindow, 'videoList': ytVideoList, 'videoSave': ytDefaultVideo, 'videoTitle': ytVideoTitle, 'saverWidth': 640};
  658. option['definitions'] = ['Ultra High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  659. option['containers'] = ['MP4', 'WebM', 'FLV', '3GP', 'Any'];
  660. }
  661. /* Parse Videos */
  662. function ytVideos() {
  663. var ytVideoFormats = {
  664. '5': 'Very Low Definition FLV',
  665. '17': 'Very Low Definition 3GP',
  666. '18': 'Low Definition MP4',
  667. '22': 'High Definition MP4',
  668. '34': 'Low Definition FLV',
  669. '35': 'Standard Definition FLV',
  670. '36': 'Low Definition 3GP',
  671. '37': 'Full High Definition MP4',
  672. '38': 'Ultra High Definition MP4',
  673. '43': 'Low Definition WebM',
  674. '44': 'Standard Definition WebM',
  675. '45': 'High Definition WebM',
  676. '46': 'Full High Definition WebM',
  677. '82': 'Low Definition 3D MP4',
  678. '83': 'Standard Definition 3D MP4',
  679. '84': 'High Definition 3D MP4',
  680. '85': 'Full High Definition 3D MP4',
  681. '100': 'Low Definition 3D WebM',
  682. '101': 'Standard Definition 3D WebM',
  683. '102': 'High Definition 3D WebM',
  684. '135': 'Standard Definition Video MP4',
  685. '136': 'High Definition Video MP4',
  686. '137': 'Full High Definition Video MP4',
  687. '138': 'Ultra High Definition Video MP4',
  688. '139': 'Low Bitrate Audio MP4',
  689. '140': 'Medium Bitrate Audio MP4',
  690. '141': 'High Bitrate Audio MP4',
  691. '171': 'Medium Bitrate Audio WebM',
  692. '172': 'High Bitrate Audio WebM',
  693. '244': 'Standard Definition Video WebM',
  694. '247': 'High Definition Video WebM',
  695. '248': 'Full High Definition Video WebM'
  696. };
  697. var ytVideoFound = false;
  698. var ytVideos = ytVideosContent.split(',');
  699. var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo;
  700. for (var i = 0; i < ytVideos.length; i++) {
  701. if (!ytVideos[i].match(/^url/)) {
  702. ytVideoParse = ytVideos[i].match(/(.*)(url=.*$)/);
  703. if (ytVideoParse) ytVideos[i] = ytVideoParse[2] + '&' + ytVideoParse[1];
  704. }
  705. ytVideoCodeParse = ytVideos[i].match (/itag=(\d{1,3})/);
  706. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  707. if (ytVideoCode) {
  708. myVideoCode = ytVideoFormats[ytVideoCode];
  709. if (myVideoCode) {
  710. ytVideo = ytVideos[i].replace (/url=/, '').replace(/&$/, '').replace(/&itag=\d{1,3}/, '');
  711. if (ytVideo.match(/type=.*?&/)) ytVideo = ytVideo.replace(/type=.*?&/, '');
  712. else ytVideo = ytVideo.replace(/&type=.*$/, '');
  713. if (ytVideo.match(/&sig=/)) ytVideo = ytVideo.replace (/&sig=/, '&signature=');
  714. else if (ytVideo.match(/&s=/)) {
  715. var ytSig = ytVideo.match(/&s=(.*?)(&|$)/);
  716. if (ytSig) {
  717. var s = ytSig[1];
  718. s = ytDecryptSignature(s);
  719. if (s) ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&signature=' + s + '$1');
  720. else ytVideo = '';
  721. }
  722. else ytVideo = '';
  723. }
  724. ytVideo = cleanMyContent (ytVideo, true);
  725. if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes';
  726. if (ytVideo && ytVideo.indexOf('http') == 0) {
  727. if (!ytVideoFound) ytVideoFound = true;
  728. ytVideoList[myVideoCode] = ytVideo;
  729. }
  730. }
  731. }
  732. }
  733.  
  734. if (ytVideoFound) {
  735. /* Create Saver */
  736. feature['autoget'] = true;
  737. ytSaver();
  738. createMySaver();
  739. }
  740. else {
  741. saver = {'saverSocket': ytPlayerWindow, 'saverWidth': 640};
  742. if (ytVideosContent.indexOf('conn=rtmp') != -1) saver['warnMess'] = '!support';
  743. else saver['warnMess'] = '!videos';
  744. createMySaver();
  745. }
  746. }
  747. /* Parse HLS */
  748. function ytHLS() {
  749. var ytHLSFormats = {
  750. '92': 'Very Low Definition MP4',
  751. '93': 'Low Definition MP4',
  752. '94': 'Standard Definition MP4',
  753. '95': 'High Definition MP4'
  754. };
  755. ytVideoList["Any Definition MP4"] = ytHLSVideos;
  756. if (ytHLSContent) {
  757. var ytHLSVideo, ytVideoCodeParse, ytVideoCode, myVideoCode;
  758. var ytHLSMatcher = new RegExp('(http.*?m3u8)', 'g');
  759. ytHLSVideos = ytHLSContent.match(ytHLSMatcher);
  760. if (ytHLSVideos) {
  761. for (var i = 0; i < ytHLSVideos.length; i++) {
  762. ytHLSVideo = ytHLSVideos[i];
  763. ytVideoCodeParse = ytHLSVideo.match(/\/itag\/(\d{1,3})\//);
  764. ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null;
  765. if (ytVideoCode) {
  766. myVideoCode = ytHLSFormats[ytVideoCode];
  767. if (myVideoCode && ytHLSVideo) {
  768. ytVideoList[myVideoCode] = ytHLSVideo;
  769. }
  770. }
  771. }
  772. }
  773. }
  774.  
  775. /* Create Saver */
  776. ytVideoTitle = null;
  777. ytDefaultVideo = 'Any Definition MP4';
  778. ytSaver();
  779. createMySaver();
  780. }
  781.  
  782. /* Get Videos */
  783. var ytVideoList = {};
  784. if (ytVideosContent) {
  785. if (ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/)) {
  786. var ytScriptURL = getMyContent(page.url, '"js":\\s*"(.*?)"', true);
  787. if (ytScriptURL) {
  788. ytScriptURL = page.win.location.protocol + ytScriptURL;
  789. try {
  790. ytScriptSrc = getMyContent(ytScriptURL, 'TEXT', false);
  791. if (ytScriptSrc) ytDecryptFunction();
  792. ytVideos();
  793. }
  794. catch (e) {
  795. try {
  796. GM_xmlhttpRequest({
  797. method: 'GET',
  798. url: ytScriptURL,
  799. onload: function(response) {
  800. if (response.readyState === 4 && response.status === 200) {
  801. ytScriptSrc = response.responseText;
  802. }
  803. if (ytScriptSrc) ytDecryptFunction();
  804. ytVideos();
  805. }
  806. });
  807. }
  808. catch (e) {
  809. ytVideos();
  810. }
  811. }
  812. }
  813. else {
  814. ytVideos();
  815. }
  816. }
  817. else {
  818. ytVideos();
  819. }
  820. }
  821. else {
  822. if (ytHLSVideos) {
  823. try {
  824. ytHLSContent = getMyContent(ytHLSVideos, 'TEXT', false);
  825. ytHLS();
  826. }
  827. catch (e) {
  828. try {
  829. GM_xmlhttpRequest({
  830. method: 'GET',
  831. url: ytHLSVideos,
  832. onload: function(response) {
  833. if (response.readyState === 4 && response.status === 200) {
  834. ytHLSContent = response.responseText;
  835. }
  836. ytHLS();
  837. }
  838. });
  839. }
  840. catch (e) {
  841. ytHLS();
  842. }
  843. }
  844. }
  845. else {
  846. saver = {'saverSocket': ytPlayerWindow, 'saverWidth': 640, 'warnMess': '!content'};
  847. createMySaver ();
  848. }
  849. }
  850. }
  851.  
  852. }
  853.  
  854. // =====DailyMotion===== //
  855.  
  856. else if (page.url.indexOf('dailymotion.com/video') != -1) {
  857.  
  858. /* Get Player Window */
  859. var dmPlayerWindow = getMyElement ('', 'div', 'id', 'player_box', -1, false);
  860. if (!dmPlayerWindow) {
  861. showMyMessage ('!player');
  862. }
  863. else {
  864. /* My Saver Socket */
  865. var dmSaverSocket = createMyElement ('div', '', '', '', '');
  866. styleMyElement (dmSaverSocket, {width: '620px', textAlign: 'center', marginTop: '350px'});
  867. appendMyElement (dmPlayerWindow, dmSaverSocket);
  868.  
  869. /* Get Videos Content */
  870. var dmEmbed = page.url.replace(/\/video\//, "/embed/video/");
  871. dmVideosContent = getMyContent (dmEmbed, 'info\\s+=\\s+\\{(.*?)\\}', false);
  872.  
  873. /* Get Videos */
  874. if (dmVideosContent) {
  875. var dmVideoFormats = {'stream_h264_hd1080_url': 'Full High Definition MP4', 'stream_h264_hd_url': 'High Definition MP4',
  876. 'stream_h264_hq_url': 'Standard Definition MP4', 'stream_h264_url': 'Low Definition MP4',
  877. 'stream_h264_ld_url': 'Very Low Definition MP4', 'stream_live_hls_url': "Standard Definition Live M3U8"};
  878. var dmVideoList = {};
  879. var dmVideoFound = false;
  880. var dmVideoParser, dmVideoParse, myVideoCode, dmVideo;
  881. for (var dmVideoCode in dmVideoFormats) {
  882. dmVideoParser = '"' + dmVideoCode + '":"(.*?)"';
  883. dmVideoParse = dmVideosContent.match (dmVideoParser);
  884. dmVideo = (dmVideoParse) ? dmVideoParse[1] : null;
  885. if (dmVideo) {
  886. if (!dmVideoFound) dmVideoFound = true;
  887. dmVideo = cleanMyContent(dmVideo, true);
  888. myVideoCode = dmVideoFormats[dmVideoCode];
  889. if (!dmVideoList[myVideoCode]) dmVideoList[myVideoCode] = dmVideo;
  890. }
  891. }
  892. if (dmVideoFound) {
  893. /* Create Saver */
  894. var dmDefaultVideo = 'Low Definition MP4';
  895. saver = {'saverSocket': dmSaverSocket, 'videoList': dmVideoList, 'videoSave': dmDefaultVideo, 'saverWidth': 620};
  896. feature['container'] = false;
  897. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  898. option['containers'] = ['MP4'];
  899. createMySaver ();
  900. }
  901. else {
  902. saver = {'saverSocket': dmPlayerWindow, 'saverWidth': 620, 'warnMess': '!videos'};
  903. createMySaver ();
  904. }
  905. }
  906. else {
  907. saver = {'saverSocket': dmPlayerWindow, 'saverWidth': 620, 'warnMess': '!content'};
  908. createMySaver ();
  909. }
  910. }
  911. }
  912.  
  913. // =====Vimeo===== //
  914.  
  915. else if (page.url.match(/vimeo.com\/\d+/) || page.url.match(/vimeo.com\/channels\/[^\/]*($|\/page|\/\d+)/)) {
  916. /* Multi Video Page */
  917. if (getMyElement('', 'div', 'class', 'player_container', -1, false).length > 1) return;
  918.  
  919. /* Saver Width */
  920. var viSaverWidth = 960;
  921. if (page.url.indexOf('/channels/') != -1 && page.url.indexOf('/channels/staffpicks') == -1) {
  922. viSaverWidth = 630;
  923. }
  924.  
  925. /* Get Player Window */
  926. var viPlayerWindow = getMyElement ('', 'div', 'class', 'player_container', 0, false) || null;
  927. if (!viPlayerWindow) {
  928. showMyMessage ('!player');
  929. }
  930. else {
  931. /* Restyle Player Window */
  932. styleMyElement (viPlayerWindow, {margin: '0px 0px 20px 0px'});
  933.  
  934. /* Get Content Source */
  935. var viVideoSource = getMyContent (page.url, 'data-config-url="(.*?)"', false).replace(/&amp;/g, '&');
  936. /* Get Videos Content */
  937. var viVideosContent;
  938. if (viVideoSource) {
  939. viVideosContent = getMyContent(viVideoSource, '"h264":\\{(.*?)\\}\\}', false);
  940. if (!viVideosContent) viVideosContent = getMyContent(viVideoSource, '"vp6":\\{(.*?)\\}\\}', false);
  941. }
  942.  
  943. /* Get Videos */
  944. if (viVideosContent) {
  945. var viVideoFormats = {'hd': 'High Definition MP4', 'sd': 'Low Definition MP4', 'mobile': 'Very Low Definition MP4'};
  946. var viVideoList = {};
  947. var viVideoFound = false;
  948. var viPattern, viMatcher, viVideo, myVideoCode;
  949. for (var viVideoCode in viVideoFormats) {
  950. viPattern = '"' + viVideoCode + '":\\{.*?"url":"(.*?)"';
  951. viMatcher = viVideosContent.match(viPattern);
  952. viVideo = (viMatcher) ? viMatcher[1] : null;
  953. if (viVideo) {
  954. if (!viVideoFound) viVideoFound = true;
  955. myVideoCode = viVideoFormats[viVideoCode];
  956. viVideoList[myVideoCode] = viVideo;
  957. }
  958. }
  959.  
  960. if (viVideoFound) {
  961. /* Create Saver */
  962. var viDefaultVideo = 'Low Definition MP4';
  963. saver = {'saverSocket': viPlayerWindow, 'videoList': viVideoList, 'videoSave': viDefaultVideo, 'saverWidth': viSaverWidth};
  964. feature['container'] = false;
  965. option['definitions'] = ['High Definition', 'Low Definition', 'Very Low Definition'];
  966. option['containers'] = ['MP4'];
  967. createMySaver ();
  968. }
  969. else {
  970. saver = {'saverSocket': viPlayerWindow, 'saverWidth': viSaverWidth, 'warnMess': '!videos'};
  971. createMySaver ();
  972. }
  973. }
  974. else {
  975. saver = {'saverSocket': viPlayerWindow, 'saverWidth': viSaverWidth, 'warnMess': '!content'};
  976. createMySaver ();
  977. }
  978. }
  979. }
  980.  
  981. // =====MetaCafe===== //
  982.  
  983. else if (page.url.indexOf('metacafe.com/watch') != -1) {
  984.  
  985. /* Get Player Window */
  986. var mcPlayerWindow = getMyElement ('', 'div', 'id', 'FlashWrap', -1, false);
  987. if (!mcPlayerWindow) {
  988. showMyMessage ('!player');
  989. }
  990. else {
  991. /* Check Video Availability */
  992. var mcVideoAvailable = getMyElement ('', 'div', 'id', 'FlashWrap', -1, true);
  993. if (mcVideoAvailable.indexOf('This Video cannot be played on this device.') != -1) return;
  994. /* Restyle Player Window */
  995. styleMyElement (mcPlayerWindow, {margin: '0px 0px 30px 0px'});
  996. /* Get Videos Content */
  997. var mcVideosContent, mcVideoH5;
  998. var mcFlashVideo = getMyElement (mcPlayerWindow, 'embed', 'tag', '', 0, false) || getMyElement (mcPlayerWindow, 'object', 'tag', '', 0, false);
  999. if (mcFlashVideo) mcVideosContent = getMyContent (page.url, '"mediaData":"(.*?)"', false);
  1000. else mcVideoH5 = getMyContent (page.url, 'video\\s+src="(.*?)"', false);
  1001.  
  1002. /* Get Videos */
  1003. if (mcVideosContent || mcVideoH5) {
  1004. var mcVideoList = {};
  1005. var mcVideoFound = false;
  1006. if (mcVideosContent) {
  1007. mcVideosContent = cleanMyContent(mcVideosContent, true);
  1008. var mcVideoFormats = {'highDefinitionMP4': 'High Definition MP4', 'MP4': 'Low Definition MP4', 'flv': 'Low Definition FLV'};
  1009. var mcVideoParser, mcVideoParse, myVideoCode, mcVideoPath, mcVideoKey, mcVideo;
  1010. for (var mcVideoCode in mcVideoFormats) {
  1011. mcVideoParser = '"' + mcVideoCode + '":\\{.*?"mediaURL":"(.*?)","access":\\[\\{"key":"(.*?)","value":"(.*?)"\\}\\]\\}';
  1012. mcVideoParse = mcVideosContent.match (mcVideoParser);
  1013. mcVideoPath = (mcVideoParse) ? mcVideoParse[1] : null;
  1014. mcVideoKeyName = (mcVideoParse) ? mcVideoParse[2] : null;
  1015. mcVideoKeyValue = (mcVideoParse) ? mcVideoParse[3] : null;
  1016. if (mcVideoPath && mcVideoKeyName && mcVideoKeyValue) {
  1017. if (!mcVideoFound) mcVideoFound = true;
  1018. myVideoCode = mcVideoFormats[mcVideoCode];
  1019. mcVideo = mcVideoPath + '?' + mcVideoKeyName + '=' + mcVideoKeyValue;
  1020. mcVideoList[myVideoCode] = mcVideo;
  1021. }
  1022. }
  1023. }
  1024. else {
  1025. mcVideoList['Low Definition MP4'] = mcVideoH5;
  1026. mcVideoFound = true;
  1027. feature['definition'] = false;
  1028. feature['container'] = false;
  1029. }
  1030.  
  1031. if (mcVideoFound) {
  1032. /* Create Saver */
  1033. var mcDefaultVideo = (mcVideoList['Low Definition MP4']) ? 'Low Definition MP4' : 'Low Definition FLV';
  1034. saver = {'saverSocket': mcPlayerWindow, 'videoList': mcVideoList, 'videoSave': mcDefaultVideo, 'saverWidth': 640};
  1035. option['definitions'] = ['High Definition', 'Low Definition'];
  1036. option['containers'] = ['MP4', 'FLV', 'Any'];
  1037. createMySaver ();
  1038. }
  1039. else {
  1040. saver = {'saverSocket': mcPlayerWindow, 'saverWidth': 640, 'warnMess': '!videos'};
  1041. createMySaver ();
  1042. }
  1043. }
  1044. else {
  1045. saver = {'saverSocket': mcPlayerWindow, 'saverWidth': 640, 'warnMess': '!content'};
  1046. createMySaver ();
  1047. }
  1048. }
  1049. }
  1050.  
  1051. // =====Break===== //
  1052.  
  1053. else if (page.url.indexOf('break.com/video') != -1) {
  1054.  
  1055. /* Get Player Window */
  1056. var brPlayerWindow = getMyElement ('', 'div', 'id', 'video-player', -1, false);
  1057. if (!brPlayerWindow) {
  1058. showMyMessage ('!player');
  1059. }
  1060. else {
  1061. /* Saver Width */
  1062. var brWindowWidth = page.win.innerWidth || page.doc.documentElement.clientWidth;
  1063. var brSaverWidth;
  1064. if (brWindowWidth > 1400) brSaverWidth = 832;
  1065. else brSaverWidth = 592;
  1066.  
  1067. /* Get Video ID */
  1068. var brVideoID = page.url.match(/(\d+)$/);
  1069. brVideoID = (brVideoID) ? brVideoID[1] : null;
  1070.  
  1071. /* Get Videos Content */
  1072. var brSource = page.win.location.protocol + '//' + page.win.location.hostname + '/embed/' + brVideoID;
  1073. var brVideosContent = getMyContent (brSource, 'TEXT', false);
  1074. /* Get Videos */
  1075. if (brVideosContent) {
  1076. var brVideoList = {};
  1077. var brVideoFormats = {};
  1078. var brVideoFound = false;
  1079. var brVideoPath, brVideoToken, brVideoThumb, brVideo, myVideoCode;
  1080. brVideoPath = brVideosContent.match (/"videoUri":\s"(.*?)"/);
  1081. brVideoPath = (brVideoPath) ? brVideoPath[1] : null;
  1082. if (brVideoPath) {
  1083. if (brVideoPath.match(/.wmv$/)) {
  1084. brVideoFormats = {'.flv': 'Low Definition FLV', '.mp4': 'Low Definition MP4'};
  1085. brVideoPath = brVideoPath.replace(/.wmv$/, '');
  1086. }
  1087. else if (brVideoPath.match(/.flv$/)) {
  1088. 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'};
  1089. brVideoPath = brVideoPath.replace(/1.flv$/, '');
  1090. }
  1091. else if (brVideoPath.match(/kbps.mp4$/)) {
  1092. 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'};
  1093. brVideoPath = brVideoPath.replace(/496_kbps.mp4$/, '');
  1094. }
  1095. else if (brVideoPath.match(/.mp4$/)) {
  1096. brVideoFormats = {'240.mp4': 'Very Low Definition MP4', '360.mp4': 'Low Definition MP4', '480.mp4': 'Standard Definition MP4', '720.mp4': 'High Definition MP4'};
  1097. brVideoPath = brVideoPath.replace(/360.mp4$/, '');
  1098. }
  1099. else brVideoPath = null;
  1100. }
  1101. brVideoToken = brVideosContent.match (/"AuthToken":\s"(.*?)"/);
  1102. brVideoToken = (brVideoToken) ? brVideoToken[1] : null;
  1103. if (brVideoPath && brVideoToken) {
  1104. for (var brVideoCode in brVideoFormats) {
  1105. if (brVideosContent.match(brVideoPath + brVideoCode) || brVideosContent.match(brVideoPath + '.wmv')) {
  1106. if (!brVideoFound) brVideoFound = true;
  1107. myVideoCode = brVideoFormats[brVideoCode];
  1108. brVideo = brVideoPath + brVideoCode + '?' + brVideoToken;
  1109. brVideoList[myVideoCode] = brVideo;
  1110. }
  1111. }
  1112. }
  1113. if (brVideoFound) {
  1114. /* Create Saver */
  1115. var brDefaultVideo = 'Low Definition MP4';
  1116. saver = {'saverSocket': brPlayerWindow, 'videoList': brVideoList, 'videoSave': brDefaultVideo, 'saverWidth': brSaverWidth};
  1117. option['definitions'] = ['Very Low Definition', 'Low Definition', 'Standard Definition', 'High Definition'];
  1118. option['containers'] = ['MP4', 'FLV', 'Any'];
  1119. createMySaver ();
  1120. }
  1121. else {
  1122. saver = {'saverSocket': brPlayerWindow, 'saverWidth': brSaverWidth};
  1123. var ytVideoId = brVideosContent.match (/"youtubeId":\s"(.*?)"/);
  1124. if (ytVideoId && ytVideoId[1]) {
  1125. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId[1];
  1126. saver['warnMess'] = 'embed';
  1127. saver['warnContent'] = ytVideoLink;
  1128. }
  1129. else saver['warnMess'] = '!videos';
  1130. createMySaver ();
  1131. }
  1132. }
  1133. else {
  1134. saver = {'saverSocket': brPlayerWindow, 'saverWidth': brSaverWidth, 'warnMess': '!content'};
  1135. createMySaver ();
  1136. }
  1137. }
  1138. }
  1139.  
  1140. // =====FunnyOrDie===== //
  1141.  
  1142. else if (page.url.indexOf('funnyordie.com/videos') != -1) {
  1143.  
  1144. /* Get Player Window */
  1145. var fodPlayerWindow = getMyElement ('', 'div', 'class', 'video-content', 0, false);
  1146. if (!fodPlayerWindow) {
  1147. showMyMessage ('!player');
  1148. }
  1149. else {
  1150. /* My Saver Socket */
  1151. var fodSaverSocket = createMyElement ('div', '', '', '', '');
  1152. styleMyElement (fodSaverSocket, {width: '100%', height: '24px', textAlign: 'center', padding: '0px 100px 0px 100px', backgroundColor: '#F4F4F4'});
  1153. appendMyElement (fodPlayerWindow, fodSaverSocket);
  1154. /* Get Videos Content */
  1155. var fodVideosContent = getMyContent (page.url, '<video([\\s\\S]*?)video>', false);
  1156.  
  1157. /* Get Videos */
  1158. if (fodVideosContent) {
  1159. 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'};
  1160. var fodVideoList = {};
  1161. var fodVideoFound = false;
  1162. var fodVideoPath, fodVideoCodes, fodVideo, myVideoCode;
  1163. fodVideoPath = fodVideosContent.match(/src="(.*?)v\d+.mp4"/);
  1164. fodVideoPath = (fodVideoPath) ? fodVideoPath[1] : null;
  1165. fodVideoCodes = fodVideosContent.match (/v,(.*?),\./);
  1166. fodVideoCodes = (fodVideoCodes) ? fodVideoCodes[1] : '';
  1167. if (fodVideoPath) {
  1168. if (fodVideoCodes) {
  1169. for (var fodVideoCode in fodVideoFormats) {
  1170. if (fodVideoCodes.indexOf(fodVideoCode.replace(/v/, '').replace(/\..*/, '')) != -1) {
  1171. if (!fodVideoFound) fodVideoFound = true;
  1172. fodVideo = fodVideoPath + fodVideoCode;
  1173. myVideoCode = fodVideoFormats[fodVideoCode];
  1174. fodVideoList[myVideoCode] = fodVideo;
  1175. }
  1176. }
  1177. }
  1178. else {
  1179. for (var fodVideoCode in fodVideoFormats) {
  1180. fodVideo = fodVideoPath + fodVideoCode;
  1181. if (fodVideosContent.match(fodVideo)) {
  1182. if (!fodVideoFound) fodVideoFound = true;
  1183. myVideoCode = fodVideoFormats[fodVideoCode];
  1184. fodVideoList[myVideoCode] = fodVideo;
  1185. }
  1186. }
  1187. }
  1188. }
  1189. if (fodVideoFound) {
  1190. /* Create Saver */
  1191. fodDefaultVideo = 'Low Definition MP4';
  1192. saver = {'saverSocket': fodSaverSocket, 'videoList': fodVideoList, 'videoSave': fodDefaultVideo, 'saverWidth': 570};
  1193. feature['container'] = false;
  1194. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1195. option['containers'] = ['MP4'];
  1196. createMySaver ();
  1197. }
  1198. else {
  1199. saver = {'saverSocket': fodPlayerWindow, 'saverWidth': 570, 'warnMess': '!videos'};
  1200. createMySaver ();
  1201. }
  1202. }
  1203. else {
  1204. saver = {'saverSocket': fodPlayerWindow, 'saverWidth': 570, 'warnMess': '!content'};
  1205. createMySaver ();
  1206. }
  1207. }
  1208. }
  1209.  
  1210. // =====Videojug===== //
  1211.  
  1212. else if (page.url.indexOf('videojug.com/film') != -1) {
  1213.  
  1214. /* Get Player Window */
  1215. var vjPlayerWindow = getMyElement ('', 'div', 'id', 'player', -1, false);
  1216. if (!vjPlayerWindow) {
  1217. showMyMessage ('!player');
  1218. }
  1219. else {
  1220. /* Get Videos Content */
  1221. var vjVideosContent = getMyContent (page.url, 'new\\s+Player\\((.*?)\\)', true);
  1222.  
  1223. /* Get Videos */
  1224. if (vjVideosContent) {
  1225. vjVideosContent = vjVideosContent.replace(/'/g, '').replace(/\s/g, '');
  1226. var vjVideosParts = vjVideosContent.split(',');
  1227. var vjVideoToken = vjVideosParts[3];
  1228. var vjVideoToken2 = vjVideoToken.substring(0,2);
  1229. var vjVideoTitle = vjVideosParts[7];
  1230. var vjVideoProtocol = page.win.location.protocol;
  1231. var vjVideoSource = vjVideoProtocol + '//' + page.win.location.hostname + '/views/film/playlist.aspx?id=' + vjVideoToken;
  1232. var vjVideoShapes = getMyContent(vjVideoSource, '<Shapes>(.*?)<\/Shapes>', false);
  1233. 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'};
  1234. var vjVideoList = {};
  1235. var vjVideoFound = false;
  1236. var vjVideoPart, myVideoCode, vjVideo, vjVideoThumb, vjVideoCodePart, vjVideoPattern, vjVideoLocation;
  1237. if (vjVideoToken && vjVideoTitle && vjVideoShapes) {
  1238. vjVideoPart = vjVideoToken2 + '/' + vjVideoToken + '/' + vjVideoTitle;
  1239. for (var vjVideoCode in vjVideoFormats) {
  1240. if (vjVideoCode.indexOf('VJ') != -1) vjVideoCodePart = vjVideoCode.substring(0, 6);
  1241. else vjVideoCodePart = vjVideoCode.substring(0, 3);
  1242. vjVideoPattern = 'Code="' + vjVideoCodePart + '"\\s+Locations="(.*?),';
  1243. vjVideoLocation = vjVideoShapes.match(vjVideoPattern);
  1244. vjVideoLocation = (vjVideoLocation) ? vjVideoProtocol + '//' + vjVideoLocation[1] : null;
  1245. if (vjVideoLocation) {
  1246. if (!vjVideoFound) vjVideoFound = true;
  1247. vjVideo = vjVideoLocation + '/' + vjVideoPart + '__' + vjVideoCode;
  1248. myVideoCode = vjVideoFormats[vjVideoCode];
  1249. vjVideoList[myVideoCode] = vjVideo;
  1250. }
  1251. }
  1252. vjVideoThumb = 'http://content5.videojug.com/' + vjVideoPart + '.WidePlayer.jpg';
  1253. }
  1254. if (vjVideoFound) {
  1255. /* Create Saver */
  1256. var vjDefaultVideo = 'Low Definition MP4';
  1257. saver = {'saverSocket': vjPlayerWindow, 'videoList': vjVideoList, 'videoSave': vjDefaultVideo, 'saverWidth': 640};
  1258. option['definition'] = 'SD';
  1259. option['definitions'] = ['Standard Definition', 'Low Definition', 'Very Low Definition'];
  1260. option['containers'] = ['MP4', 'FLV', 'Any'];
  1261. createMySaver ();
  1262. }
  1263. else {
  1264. saver = {'saverSocket': vjPlayerWindow, 'saverWidth': 640, 'warnMess': '!videos'};
  1265. createMySaver ();
  1266. }
  1267. }
  1268. else {
  1269. saver = {'saverSocket': vjPlayerWindow, 'saverWidth': 640, 'warnMess': '!content'};
  1270. createMySaver ();
  1271. }
  1272. }
  1273. }
  1274.  
  1275. // =====Blip===== //
  1276.  
  1277. else if (page.url.indexOf('blip.tv') != -1) {
  1278.  
  1279. /* Get Page Type */
  1280. var blipPageType = getMyContent (page.url, 'meta.*?property="og:type".*?content="(.*?)"', false);
  1281. if (!blipPageType || blipPageType != 'video.episode') return;
  1282. /* Get Player Window */
  1283. var blipSaverWidth;
  1284. var blipPlayerWindow = getMyElement ('', 'div', 'class', 'Theater', 0, false) || getMyElement ('', 'div', 'id', 'ErrorWrap', -1, false);
  1285. if (!blipPlayerWindow) {
  1286. blipPlayerWindow = getMyElement ('', 'div', 'id', 'PlayerEmbed', -1, false);
  1287. blipSaverWidth = 596;
  1288. }
  1289. else {
  1290. blipSaverWidth = 960;
  1291. }
  1292. if (!blipPlayerWindow) {
  1293. showMyMessage ('!player');
  1294. }
  1295. else {
  1296. /* My Saver Socket */
  1297. var blipSaverSocket = createMyElement ('div', '', '', '', '');
  1298. styleMyElement (blipSaverSocket, {width: blipSaverWidth + 'px', textAlign: 'center', margin: '0px auto'});
  1299. appendMyElement (blipPlayerWindow, blipSaverSocket);
  1300.  
  1301. /* Get Videos Content */
  1302. var blipVideosContent = getMyContent(page.url + '?skin=json', '"additionalMedia":\\[(.*?)\\]', false);
  1303.  
  1304. /* Get Videos */
  1305. if (blipVideosContent) {
  1306. var blipVideoList = {};
  1307. var blipVideoFound = false;
  1308. var blipMimeTypes = {'video/x-m4v': 'M4V', 'video/quicktime': 'MOV', 'video/mp4': 'MP4', 'video/x-flv': 'FLV'};
  1309. var blipVideos = blipVideosContent.split(',{');
  1310. var blipVideoURL, blipVideoMime, blipVideoHeight, blipVideoRole, blipVideoDef, blipVideoCode;
  1311. var blipDefaultVideo = 'Low Definition MP4';
  1312. for (var blipV = 0; blipV < blipVideos.length; blipV++) {
  1313. blipVideoMime = blipVideos[blipV].match(/"primary_mime_type":"(.*?)"/);
  1314. blipVideoMime = (blipVideoMime) ? blipVideoMime[1] : null;
  1315. if (blipMimeTypes[blipVideoMime]) {
  1316. blipVideoURL = blipVideos[blipV].match(/"url":"(.*?)"/);
  1317. blipVideoURL = (blipVideoURL) ? blipVideoURL[1] : null;
  1318. blipVideoHeight = blipVideos[blipV].match(/"media_height":"(.*?)"/);
  1319. blipVideoHeight = (blipVideoHeight) ? blipVideoHeight[1] : null;
  1320. blipVideoRole = blipVideos[blipV].match(/"role":"(.*?)"/);
  1321. blipVideoRole = (blipVideoRole) ? blipVideoRole[1] : null;
  1322. if (blipVideoURL && blipVideoHeight && blipVideoRole) {
  1323. if (!blipVideoFound) blipVideoFound = true;
  1324. if (blipVideoHeight >= 200 && blipVideoHeight < 400) blipVideoDef = 'Low Definition';
  1325. else if (blipVideoHeight >= 400 && blipVideoHeight < 700) blipVideoDef = 'Standard Definition';
  1326. else if (blipVideoHeight >= 700) blipVideoDef = 'High Definition';
  1327. blipVideoCode = blipVideoDef + ' ' + blipMimeTypes[blipVideoMime];
  1328. blipVideoList[blipVideoCode] = blipVideoURL;
  1329. if (blipVideoRole == 'Source') blipDefaultVideo = blipVideoCode;
  1330. }
  1331. }
  1332. }
  1333.  
  1334. if (blipVideoFound) {
  1335. /* Create Saver */
  1336. saver = {'saverSocket': blipSaverSocket, 'videoList': blipVideoList, 'videoSave': blipDefaultVideo, 'saverWidth': blipSaverWidth};
  1337. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition'];
  1338. option['containers'] = ['MP4', 'M4V', 'MOV', 'FLV', 'Any'];
  1339. createMySaver ();
  1340. }
  1341. else {
  1342. saver = {'saverSocket': blipPlayerWindow, 'saverWidth': blipSaverWidth, 'warnMess': '!videos'};
  1343. createMySaver ();
  1344. }
  1345. }
  1346. else {
  1347. saver = {'saverSocket': blipPlayerWindow, 'saverWidth': blipSaverWidth, 'warnMess': '!content'};
  1348. createMySaver ();
  1349. }
  1350. }
  1351. }
  1352.  
  1353. // =====Veoh===== //
  1354.  
  1355. else if (page.url.indexOf('veoh.com/watch') != -1) {
  1356.  
  1357. /* Get Video Availability */
  1358. if (getMyElement ('', 'div', 'class', 'veoh-video-player-error', 0, false)) return;
  1359.  
  1360. /* Get Player Window */
  1361. var vePlayerWindow = getMyElement ('', 'div', 'id', 'videoPlayerContainer', -1, false);
  1362. if (!vePlayerWindow) {
  1363. showMyMessage ('!player');
  1364. }
  1365. else {
  1366. /* Get Videos Content */
  1367. var veVideosContent = getMyContent (page.url, '__watch.videoDetailsJSON = \'\\{(.*?)\\}', false);
  1368. veVideosContent = cleanMyContent (veVideosContent, true);
  1369. /* Restyle Player Window */
  1370. styleMyElement (vePlayerWindow, {margin: '0px 0px 20px 0px'});
  1371. /* Get Videos */
  1372. if (veVideosContent) {
  1373. var veVideoFormats = {'fullPreviewHashLowPath': 'Very Low Definition MP4', 'fullPreviewHashHighPath': 'Low Definition MP4'};
  1374. var veVideoList = {};
  1375. var veVideoFound = false;
  1376. var veVideoParser, veVideoParse, veVideo, myVideoCode;
  1377. for (var veVideoCode in veVideoFormats) {
  1378. veVideoParser = veVideoCode + '":"(.*?)"';
  1379. veVideoParse = veVideosContent.match (veVideoParser);
  1380. veVideo = (veVideoParse) ? veVideoParse[1] : null;
  1381. if (veVideo) {
  1382. if (!veVideoFound) veVideoFound = true;
  1383. myVideoCode = veVideoFormats[veVideoCode];
  1384. veVideoList[myVideoCode] = veVideo;
  1385. }
  1386. }
  1387.  
  1388. if (veVideoFound) {
  1389. /* Create Saver */
  1390. var veDefaultVideo = 'Low Definition MP4';
  1391. saver = {'saverSocket': vePlayerWindow, 'videoList': veVideoList, 'videoSave': veDefaultVideo, 'saverWidth': 640};
  1392. feature['container'] = false;
  1393. feature['fullsize'] = false;
  1394. option['definition'] = 'LD';
  1395. option['definitions'] = ['Low Definition', 'Very Low Definition'];
  1396. option['containers'] = ['MP4'];
  1397. createMySaver ();
  1398. }
  1399. else {
  1400. saver = {'saverSocket': vePlayerWindow, 'saverWidth': 640};
  1401. var veVideoSource = getMyContent(page.url, '"videoContentSource":"(.*?)"', false);
  1402. if (veVideoSource == 'YouTube') var ytVideoId = getMyContent(page.url, '"videoId":"yapi-(.*?)"', false);
  1403. if (ytVideoId) {
  1404. var ytVideoLink = 'http://youtube.com/watch?v=' + ytVideoId;
  1405. saver['warnMess'] = 'embed';
  1406. saver['warnContent'] = ytVideoLink;
  1407. styleMyElement(vePlayerWindow, {margin: '0px 0px 20px 0px'});
  1408. }
  1409. else saver['warnMess'] = '!videos';
  1410. createMySaver ();
  1411. }
  1412. }
  1413. else {
  1414. saver = {'saverSocket': vePlayerWindow, 'saverWidth': 640, 'warnMess': '!content'};
  1415. createMySaver ();
  1416. }
  1417. }
  1418. }
  1419.  
  1420. // =====Crackle===== //
  1421.  
  1422. else if (page.url.indexOf('crackle.com/') != -1) {
  1423. /* Get Page Type */
  1424. var crPageType = getMyContent (page.url, 'meta\\s+property="og:type"\\s+content="(.*?)"', false);
  1425. if (!crPageType || crPageType.indexOf('video') == -1) return;
  1426. /* Get Player Window */
  1427. var crPlayerWindow = getMyElement ('', 'div', 'class', 'player-stage-area1', 0, false);
  1428. if (!crPlayerWindow) {
  1429. showMyMessage ('!player');
  1430. }
  1431. else {
  1432. /* Restyle */
  1433. if (!getMyElement(crPlayerWindow, 'div', 'class', 'clearall', 0, false)) {
  1434. var myClearFix = createMyElement ('div', '', '', '', '');
  1435. styleMyElement (myClearFix, {clear: 'both'});
  1436. appendMyElement (crPlayerWindow, myClearFix);
  1437. }
  1438. var crContent = getMyElement ('', 'div', 'id', 'content', -1, false);
  1439. styleMyElement (crContent, {marginTop: '30px'});
  1440. var crPlayerImage = getMyElement ('', 'div', 'class', 'image-stage-area', 0, false);
  1441. if (crPlayerImage) removeMyElement (crPlayerImage.parentNode, crPlayerImage);
  1442. /* Get Videos Content */
  1443. var crVideoPath = getMyContent (page.url, 'images-us-am.crackle.com\/(.*?_)tnl', false);
  1444. if (!crVideoPath) {
  1445. var crVideoID = getMyContent (page.url, 'mediaId:\\s*(.*?),', false);
  1446. if (crVideoID) {
  1447. var crVidWallCache = page.win.location.protocol + '//' + page.win.location.hostname + '/app/vidwallcache.aspx?flags=-1&fm=' + crVideoID + '&partner=20';
  1448. crVideoPath = getMyContent (crVidWallCache, '\\sp="(.*?)"', false);
  1449. }
  1450. }
  1451. /* Get Videos */
  1452. if (crVideoPath) {
  1453. var crVideoList = {};
  1454. var crVideoFormats = {'360p.mp4': 'Low Definition MP4', '480p.mp4': 'Standard Definition MP4'};
  1455. var crVideoThumb, crVideo, myVideoCode;
  1456. for (var crVideoCode in crVideoFormats) {
  1457. crVideo = 'http://media-us-am.crackle.com/' + crVideoPath + crVideoCode;
  1458. myVideoCode = crVideoFormats[crVideoCode];
  1459. crVideoList[myVideoCode] = crVideo;
  1460. }
  1461.  
  1462. /* Create Saver */
  1463. var crDefaultVideo = 'Low Definition MP4';
  1464. saver = {'saverSocket': crPlayerWindow, 'videoList': crVideoList, 'videoSave': crDefaultVideo, 'saverWidth': 970};
  1465. feature['container'] = false;
  1466. option['definition'] = 'SD';
  1467. option['definitions'] = ['Standard Definition', 'Low Definition'];
  1468. option['containers'] = ['MP4'];
  1469. createMySaver ();
  1470. /* Fix Thumbnails */
  1471. var crThumbs = getMyElement('', 'div', 'class', 'thumbnail', -1, false);
  1472. for (var crT = 0; crT < crThumbs.length; crT++) {
  1473. if (crThumbs[crT].innerHTML.indexOf('AddObjectToQueue') != -1) {
  1474. var crLink = crThumbs[crT].innerHTML.match(/,\s+\d+,\s+'(.*?)'/);
  1475. crLink = (crLink) ? crLink[1] : null;
  1476. var crImg = crThumbs[crT].innerHTML.match(/src="(.*?)"/);
  1477. crImg = (crImg) ? crImg[1] : null;
  1478. crThumbs[crT].innerHTML = '<img src="' + crImg + '" onclick="window.location.href=\'' + crLink + '\'" style="cursor:pointer">';
  1479. }
  1480. }
  1481. }
  1482. else {
  1483. saver = {'saverSocket': crPlayerWindow, 'saverWidth': 970, 'warnMess': '!videos'};
  1484. createMySaver ();
  1485. }
  1486. }
  1487.  
  1488. }
  1489.  
  1490. // =====Viki===== //
  1491.  
  1492. else if (page.url.indexOf('viki.com/videos') != -1) {
  1493. /* Get Player Window */
  1494. var vkSaverWindow = getMyElement ('', 'div', 'class', 'watch-actions', 0, false);
  1495. if (!vkSaverWindow) {
  1496. showMyMessage ('!player');
  1497. }
  1498. else {
  1499. /* Get Video ID */
  1500. var vkVideoID = page.url.match(/videos\/(.*?)v/);
  1501. vkVideoID = (vkVideoID) ? vkVideoID[1] : null;
  1502. /* Get Videos Content */
  1503. var vkVideosContent;
  1504. if (vkVideoID) vkVideosContent = getMyContent (page.win.location.protocol + '//' + page.win.location.host + '/player5_fragment/' + vkVideoID + 'v.json', 'TEXT', false);
  1505.  
  1506. /* Style Fix */
  1507. var vkShowMain = getMyElement ('', 'div', 'class', 'show-main', 0, false);
  1508. styleMyElement (vkShowMain, {paddingTop: '20px'});
  1509. /* My Saver Socket */
  1510. var vkSaverSocket = createMyElement ('div', '', '', '', '');
  1511. styleMyElement (vkSaverSocket, {width: '950px', textAlign: 'center', margin: '0px auto'});
  1512. appendMyElement (vkSaverWindow, vkSaverSocket);
  1513. /* Get Videos */
  1514. if (vkVideosContent) {
  1515. var vkVideoList = {};
  1516. var vkVideo = vkVideosContent.match(/"video_url":"(.*?)"/);
  1517. vkVideo = (vkVideo) ? vkVideo[1] : null;
  1518. var vkVideoThumb = vkVideosContent.match(/"image_url":"(.*?)"/);
  1519. vkVideoThumb = (vkVideoThumb) ? vkVideoThumb[1] : null;
  1520.  
  1521. /* Create Saver */
  1522. if (vkVideo) {
  1523. var vkDefaultVideo = 'Low Definition MP4';
  1524. vkVideoList[vkDefaultVideo] = vkVideo
  1525. saver = {'saverSocket': vkSaverSocket, 'videoList': vkVideoList, 'videoSave': vkDefaultVideo, 'saverWidth': 950};
  1526. feature['definition'] = false;
  1527. feature['container'] = false;
  1528. option['definition'] = 'LD';
  1529. option['definitions'] = ['Low Definition'];
  1530. option['containers'] = ['MP4'];
  1531. createMySaver ();
  1532. }
  1533. else {
  1534. saver = {'saverSocket': vkPlayerWindow, 'saverWidth': 950, 'warnMess': '!videos'};
  1535. createMySaver ();
  1536. }
  1537. }
  1538. else {
  1539. saver = {'saverSocket': vkPlayerWindow, 'saverWidth': 950, 'warnMess': '!content'};
  1540. createMySaver ();
  1541. }
  1542. }
  1543. }
  1544.  
  1545. // =====IMDB===== //
  1546.  
  1547. else if (page.url.indexOf('imdb.com/video/') != -1) {
  1548. /* Get Player Window */
  1549. var imdbPlayerWindow = getMyElement ('', 'div', 'id', 'player-article', -1, false);
  1550. if (!imdbPlayerWindow) {
  1551. showMyMessage ('!player');
  1552. }
  1553. else {
  1554. /* Get Videos Content */
  1555. var imdbVideoList = {};
  1556. var imdbVideoFormats = {'1': 'Low Definition MP4', '2': 'Standard Definition MP4', '3': 'High Definition MP4'};
  1557. var imdbDefaultVideo, imdbURL, imdbVideo, myVideoCode;
  1558. var imdbVideoFound = false;
  1559. var imdbVideoRTMP = false;
  1560. var imdbPageURL = page.url.replace(/\?.*$/, '').replace(/\/$/, '');
  1561. for (var imdbVideoCode in imdbVideoFormats) {
  1562. imdbURL = imdbPageURL + '/player?uff=' + imdbVideoCode;
  1563. imdbVideo = getMyContent (imdbURL, 'so.addVariable\\("file",\\s+"(.*?)"\\);', true);
  1564. if (imdbVideo) {
  1565. if (imdbVideo.indexOf('rtmp') != -1) {
  1566. if (!imdbVideoRTMP) imdbVideoRTMP = true;
  1567. }
  1568. else {
  1569. if (!imdbVideoFound) imdbVideoFound = true;
  1570. myVideoCode = imdbVideoFormats[imdbVideoCode];
  1571. imdbVideoList[myVideoCode] = imdbVideo;
  1572. if (!imdbDefaultVideo) imdbDefaultVideo = myVideoCode;
  1573. }
  1574. }
  1575. }
  1576. if (imdbVideoFound) {
  1577. /* Create Saver */
  1578. saver = {'saverSocket': imdbPlayerWindow, 'videoList': imdbVideoList, 'videoSave': imdbDefaultVideo, 'saverWidth': 1010};
  1579. feature['container'] = false;
  1580. option['definitions'] = ['High Definition', 'Standard Definition', 'Low Definition'];
  1581. option['containers'] = ['MP4'];
  1582. createMySaver ();
  1583. }
  1584. else {
  1585. if (imdbVideoRTMP) {
  1586. saver = {'saverSocket': imdbPlayerWindow, 'saverWidth': 1010, 'warnMess': '!support'};
  1587. createMySaver ();
  1588. }
  1589. else {
  1590. saver = {'saverSocket': imdbPlayerWindow, 'saverWidth': 1010, 'warnMess': '!videos'};
  1591. createMySaver ();
  1592. }
  1593. }
  1594. }
  1595. }
  1596.  
  1597. // =====Facebook===== //
  1598.  
  1599. else if (page.url.indexOf('facebook.com/photo') != -1) {
  1600. /* Get Player Window */
  1601. var fbPlayerWindow = getMyElement ('', 'div', 'class', 'stageButtons', 0, false);
  1602. if (!fbPlayerWindow) {
  1603. showMyMessage ('!player');
  1604. }
  1605. else {
  1606. /* Get Videos Content */
  1607. var fbVideosContent = getMyContent(page.url, '"params","(.*?)"', false);
  1608. var fbPattern = /\\u([\d\w]{4})/gi;
  1609. fbVideosContent = fbVideosContent.replace(fbPattern, function (match, group) {
  1610. return String.fromCharCode(parseInt(group, 16));
  1611. });
  1612. fbVideosContent = unescape(fbVideosContent);
  1613. /* Get Videos */
  1614. if (fbVideosContent) {
  1615. var fbVideoList = {};
  1616. var fbVideoFormats = {'sd_src': 'Low Definition MP4', 'hd_src': 'High Definition MP4'};
  1617. var fbVideoFound = false;
  1618. var fbVideoPattern, fbVideo, myVideoCode, fbVideoThumb, fbDefaultVideo;
  1619. for (var fbVideoCode in fbVideoFormats) {
  1620. fbVideoPattern = '"' + fbVideoCode + '":"(.*?)"';
  1621. fbVideo = fbVideosContent.match(fbVideoPattern);
  1622. fbVideo = (fbVideo) ? fbVideo[1] : null;
  1623. if (fbVideo) {
  1624. fbVideo = cleanMyContent(fbVideo, false);
  1625. if (!fbVideoFound) fbVideoFound = true;
  1626. myVideoCode = fbVideoFormats[fbVideoCode];
  1627. if (fbVideo.indexOf('.flv') != -1) myVideoCode = myVideoCode.replace('MP4', 'FLV');
  1628. fbVideoList[myVideoCode] = fbVideo;
  1629. if (!fbDefaultVideo) fbDefaultVideo = myVideoCode;
  1630. }
  1631. }
  1632.  
  1633. if (fbVideoFound) {
  1634. /* Create Saver */
  1635. saver = {'saverSocket': fbPlayerWindow, 'videoList': fbVideoList, 'videoSave': fbDefaultVideo, 'saverWidth': 760};
  1636. option['definitions'] = ['High Definition', 'Low Definition'];
  1637. option['containers'] = ['MP4', 'FLV', 'Any'];
  1638. createMySaver ();
  1639. }
  1640. else {
  1641. saver = {'saverSocket': fbPlayerWindow, 'saverWidth': 760, 'warnMess': '!videos'};
  1642. createMySaver ();
  1643. }
  1644. }
  1645. else {
  1646. saver = {'saverSocket': fbPlayerWindow, 'saverWidth': 760, 'warnMess': '!content'};
  1647. createMySaver ();
  1648. }
  1649. }
  1650. }
  1651.  
  1652. // =====YahooScreen===== //
  1653.  
  1654. else if (page.url.indexOf('screen.yahoo.com') != -1) {
  1655. /* Get Player Window */
  1656. var ysPlayerWindow = getMyElement ('', 'div', 'class', 'video-container', 0, false);
  1657. if (!ysPlayerWindow) {
  1658. showMyMessage ('!player');
  1659. }
  1660. else {
  1661. /* Restyle Player Window */
  1662. styleMyElement (ysPlayerWindow, {height: '100%'});
  1663. /* Get Videos Content */
  1664. var ysVideosContent;
  1665. var ysVideoID = getMyContent (page.url, 'window.YVIDEO.prefetchedData\\s*=\\s*\\{"id":"(.*?)"', false);
  1666. if (ysVideoID) {
  1667. var ysVideoQuery = 'SELECT * FROM yahoo.media.video.streams WHERE id="' + ysVideoID + '" AND format="mp4" AND protocol="http" AND plrs="sdwpWXbKKUIgNzVhXSce__" AND region="US";';
  1668. var ysVideoRequest = 'https://video.query.yahoo.com/v1/public/yql?q=' + ysVideoQuery + '&env=prod&format=json';
  1669. ysVideosContent = getMyContent(ysVideoRequest, '"streams":\\[(.*?)\\]', false);
  1670. ysVideoQuery = 'SELECT * FROM yahoo.media.video.streams WHERE id="' + ysVideoID + '" AND format="webm" AND protocol="http" AND plrs="sdwpWXbKKUIgNzVhXSce__" AND region="US";';
  1671. ysVideoRequest = 'https://video.query.yahoo.com/v1/public/yql?q=' + ysVideoQuery + '&env=prod&format=json';
  1672. ysVideosContent += ',' + getMyContent(ysVideoRequest, '"streams":\\[(.*?)\\]', false);
  1673. }
  1674. else {
  1675. ysVideosContent = getMyContent(page.url, '"streams":\\[(.*?)\\]', false);
  1676. }
  1677. /* Get Videos */
  1678. if (ysVideosContent) {
  1679. var ysVideoList = {};
  1680. var ysVideoFormats = {'360': 'Low Definition', '432': 'Low Definition', '540': 'Standard Definition', '720': 'High Definition', '1080': 'Full High Definition'};
  1681. var ysVideoFound;
  1682. var ysVideoParts = ysVideosContent.split('},');
  1683. var ysVideoPart, ysVideoPath, ysVideoHost, ysVideoHeight, myVideoCode;
  1684. for (var i = 0; i < ysVideoParts.length; i++) {
  1685. ysVideoPart = ysVideoParts[i];
  1686. ysVideoPath = ysVideoPart.match(/"path":"(.*?)"/);
  1687. ysVideoPath = (ysVideoPath) ? ysVideoPath[1] : null;
  1688. ysVideoHost = ysVideoPart.match(/"host":"(.*?)"/);
  1689. ysVideoHost = (ysVideoHost) ? ysVideoHost[1] : null;
  1690. ysVideoHeight = ysVideoPart.match(/"height":(.*?)\.0/);
  1691. ysVideoHeight = (ysVideoHeight) ? ysVideoHeight[1] : null;
  1692. ysVideoType = ysVideoPart.match(/"mime_type":"(.*?)"/);
  1693. ysVideoType = (ysVideoType) ? ysVideoType[1] : null;
  1694. if (ysVideoPath && ysVideoHost && ysVideoHeight && ysVideoType) {
  1695. for (var ysVideoCode in ysVideoFormats) {
  1696. if (ysVideoCode == ysVideoHeight) {
  1697. if (!ysVideoFound) ysVideoFound = true;
  1698. myVideoCode = ysVideoFormats[ysVideoCode]
  1699. if (ysVideoType == 'video/mp4') myVideoCode += ' MP4';
  1700. else if (ysVideoType == 'video/webm') myVideoCode += ' WebM';
  1701. ysVideoList[myVideoCode] = ysVideoHost + ysVideoPath;
  1702. }
  1703. }
  1704. }
  1705. }
  1706. if (ysVideoFound) {
  1707. /* Create Saver */
  1708. var ysDefaultVideo = 'Low Definition MP4';
  1709. saver = {'saverSocket': ysPlayerWindow, 'videoList': ysVideoList, 'videoSave': ysDefaultVideo, 'saverWidth': 640};
  1710. option['definitions'] = ['Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition'];
  1711. option['containers'] = ['MP4', 'WebM', 'Any'];
  1712. createMySaver ();
  1713. styleMyElement(saver['saverPanel'], {padding: '0px 0px 7px 0px'});
  1714. }
  1715. else {
  1716. saver = {'saverSocket': ysPlayerWindow, 'saverWidth': 640, 'warnMess': '!videos'};
  1717. createMySaver ();
  1718. }
  1719. }
  1720. else {
  1721. saver = {'saverSocket': ysPlayerWindow, 'saverWidth': 640, 'warnMess': '!content'};
  1722. createMySaver ();
  1723. }
  1724. }
  1725.  
  1726. }
  1727.  
  1728.  
  1729. })();