SaveTube

Download videos from video sharing web sites.

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

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