SaveTube

Download videos from video sharing web sites.

当前为 2015-04-02 提交的版本,查看 最新版本

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