Advertisement
Miksus

skrypt

Jul 3rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.68 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Skrypt umożliwiający pobieranie materiałów ze znanych serwisów VOD. Autor: Przemek
  3. // @namespace http://www.ipla.tv/
  4. // @include *www.ipla.tv/*
  5. // @include *getmedia.redefine.pl/*
  6. // @include *player.pl/*
  7. // @include *vod.pl/*
  8. // @include *tvp.pl/*
  9. // @include *www.cda.pl/*
  10. // @version 4.2
  11. // @description SKrypt umożliwiający pobieranie materiałów z serwisów Ipla.tv, Player.pl, Vod.pl
  12. // @author Przemek
  13. // @match http://www.ipla.tv/*
  14. // @grant none
  15. // ==/UserScript==
  16. //Ważne:
  17. //Skrypt opiera się na skryptach umieszczonych na stronie: miniskrypt.blogspot.com
  18. //oraz: miniskrypt.hubaiitv.pl. Moje rozszerzenie tylko i wyłącznie dodaje wygodne
  19. //w użyciu przyciski, jednak nie jestem autorem większości kodu.
  20. //Skrypt jest niepubliczny, a dostęp do niego mają tylko i wyłącznie osoby z linkiem.
  21. /////////////////////// KONFIGURACJA ////////////////////////
  22. Wlacz_skrypt = true; // true = skrypt włączony, false = skrypt wyłączony.
  23. //////////////////// KONIEC KONFIGURACJI ////////////////////
  24.  
  25. var SkryptKopiujText = "function copyText(e){function t(e){if(document.selection){var t=document.body.createTextRange();t.moveToElementText(e),t.select()}else if(window.getSelection){var t=document.createRange();t.selectNode(e),window.getSelection().removeAllRanges(),window.getSelection().addRange(t)}}var n=document.createElement(\"DIV\");n.textContent=e,document.body.appendChild(n),t(n),document.execCommand(\"copy\"),n.remove()} ";
  26. var StyleText = "<style>body{font-family: \"Segoe UI\";}.clicked{background-color: #7CFC00;}</style>";
  27.  
  28. function addEvent(obj, event, func) {
  29. if (obj.addEventListener) {
  30. obj.addEventListener(event, func, false);
  31. return true;
  32. } else if (obj.attachEvent) {
  33. obj.attachEvent('on' + event, func);
  34. } else {
  35. var f = obj['on' + event];
  36. obj['on' + event] = typeof f === 'function' ? function () {
  37. f();
  38. func();
  39. }
  40. : func;
  41. }
  42. }
  43.  
  44. function ShowPromptWithInfo(lol, info = null) {
  45. var infotext = 'Aby skopiować link, wciśnij: CTRL+C, potem: ENTER aby rozpocząć pobieranie, lub ESC aby zakończyć działanie skryptu';
  46. if(info !== null){
  47. infotext = infotext + ". " + info;
  48. }
  49. if (window.prompt(infotext, lol)) {
  50. document.location.href = lol;
  51. }
  52. }
  53.  
  54. function ShowPrompt(lol) {
  55. window.prompt('Aby skopiować link, wciśnij: CTRL+C, potem: ENTER', lol);
  56. }
  57.  
  58. function makeid()
  59. {
  60. var text = '';
  61. var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  62. for (var i = 0; i < 5; i++)
  63. text += possible.charAt(Math.floor(Math.random() * possible.length));
  64. return text;
  65. }
  66.  
  67. var DocumentWriteFirefoxFix = '';
  68. function fireNewTab() {
  69. function makeid2() {
  70. var text = '';
  71. var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  72. for (var i = 0; i < 5; i++)
  73. text += possible.charAt(Math.floor(Math.random() * possible.length));
  74. return text;
  75. }
  76. var randomText = makeid2();
  77. var newTab = window.open('about:blank', 'MsgWindow-' + randomText);
  78. newTab.document.write("DocumentWriteFirefoxFix");
  79. newTab.addEventListener('load', function () {
  80. alert('hi2');
  81. var destDoc = newTab.document;
  82. destDoc.open();
  83. destDoc.write("DocumentWriteFirefoxFix");
  84. destDoc.close();
  85. }, false
  86. );
  87. }
  88. function addslashes( str ) {
  89. return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
  90. }
  91.  
  92. function addJS_Node(text, s_URL, funcToRun, runOnLoad) {
  93. var D = document;
  94. var scriptNode = D.createElement('script');
  95. if (runOnLoad) {
  96. scriptNode.addEventListener('load', runOnLoad, false);
  97. }
  98. scriptNode.type = 'text/javascript';
  99. if (text) scriptNode.textContent = text;
  100. if (s_URL) scriptNode.src = s_URL;
  101. var str = funcToRun.toString();
  102. var tes = addslashes(DocumentWriteFirefoxFix);
  103. var res = str.replace("DocumentWriteFirefoxFix", tes);
  104. res = res.replace("DocumentWriteFirefoxFix", tes);
  105. if (funcToRun) scriptNode.textContent = '(' + res + ')()';
  106.  
  107. var targ = D.getElementsByTagName('head') [0] || D.body || D.documentElement;
  108. targ.appendChild(scriptNode);
  109. }
  110.  
  111. function PokazLinkTVNNowy() {
  112. try {
  113. try {
  114. n = document.querySelector("#detailEpisode").getAttribute("data-article-id");
  115. } catch (e) {
  116. var pageURL = window.location.href;
  117. var lastComma = pageURL.lastIndexOf(",");
  118. if (lastComma > - 1) {
  119. n = pageURL.substring(lastComma+1);
  120. n = parseInt(n);
  121. }
  122. }
  123. xmlhttp = new XMLHttpRequest();
  124. xmlhttp.open("GET", "/api/?platform=ConnectedTV&terminal=Panasonic&format=json&authKey=064fda5ab26dc1dd936f5c6e84b7d3c2&v=3.1&m=getItem&id=" + n, false);
  125. xmlhttp.send();
  126. o = JSON.parse(xmlhttp.responseText);
  127. lt = o.item.videos.main.video_content_license_type;
  128. dd = o.item.videos.main.video_content;
  129. title = o.item.serie_title + " - S" + o.item.season + "E" + o.item.episode;
  130. if (lt !== null) {
  131. alert('DRM lub brak materiału TV :(');
  132. return;
  133. }
  134. DocumentWriteFirefoxFix = "";
  135. var randomText = makeid();
  136. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + '<p>Tytuł: ' + title + '</p>';
  137. var HighestResolution = 0;
  138. var HighestResolutionLink = '';
  139. for (var j = 0, len = dd.length; j < len; j = j + 1) {
  140. HighestResolution = HighestResolution + 1;
  141. dlurl = dd[j].url;
  142. if(j < 2){
  143. HighestResolutionLink = dlurl;
  144. }
  145. pn = dd[j].profile_name;
  146. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + "<p>Jakość materiału: " + pn + "<br>";
  147. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + "Link do materiału: <button id=\"button-" + j + "\" type=\"button\">Kopiuj</button><br><a target=\"_blank\" href=\"" + dlurl + "\">" + dlurl + "</a></p>";
  148. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + "<script>var but = document.getElementById('button-"+j+"');but.addEventListener('click', function(){copyText(\""+ dlurl +"\");document.getElementById('button-"+j+"').setAttribute(\"class\", \"clicked\");})</script>";
  149. }
  150. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + StyleText + '<script type="application/javascript">function ShowPromptWithInfo(lol){if (window.prompt("Aby skopiować link, wciśnij: CTRL+C, potem: ENTER aby rozpocząć pobieranie, lub ESC aby zakończyć działanie skryptu", lol)){document.location.href=lol;}}setTimeout(function () {ShowPromptWithInfo("' + HighestResolutionLink + '");}, 1000);' + SkryptKopiujText + '</script>';
  151. addJS_Node(null, null, fireNewTab);
  152.  
  153. } catch (e) {}
  154. }
  155.  
  156. function PokazLinkPobieranieIpla() {
  157. //alert('ipla');
  158. nn = document.querySelector('pre').textContent;
  159. v = JSON.parse(nn);
  160. if (v.vod.drm == true) {
  161. alert('Niestety, ale materiał jest zabezpieczony DRM i prawdopodobnie nie będzie można go pobrać :(');
  162. }
  163. var QualityArray = [];
  164. var copies = v.vod.copies;
  165. if(copies !== null){
  166. if(copies.length > 0){
  167. for (var prop in copies) {
  168. var copy = copies[prop];
  169. var newArray = [copy.quality_p, copy.url];
  170. QualityArray.push(newArray);
  171. }
  172. if(QualityArray !== null){
  173. var countArray = QualityArray.length;
  174. if(countArray > 0){
  175. var countArrayElement = countArray - 1;
  176. var bestQuality = QualityArray[countArrayElement][0];
  177. var bestQualityLink = QualityArray[countArrayElement][1];
  178. ShowPromptWithInfo(bestQualityLink,"\nWybrana jakość materiału to: " + bestQuality + ".");
  179. }
  180. }
  181. }
  182. }
  183. }
  184.  
  185. function PokazLinkIpla() {
  186. if (location.href.match(/^http[s]?:\/\/www\.ipla\.tv\//)) {
  187. try {
  188. mid = document.querySelector('#vod-player').getAttribute('data-vod-json');
  189. idn = JSON.parse(mid).mid;
  190. document.location.href = 'http://getmedia.redefine.pl/vods/get_vod/?cpid=1&ua=mipla_ios/122&media_id=' + idn;
  191. } catch (e) {
  192. //alert("get from URL");
  193. var pageURL = window.location.href.split("?")[0];
  194. var pageURLTemp = pageURL.substring(0, pageURL.length - 3);
  195. var lastComma = pageURLTemp.lastIndexOf("/");
  196. if (lastComma > - 1) {
  197. n = pageURL.substring(lastComma+1);
  198. //alert(n);
  199. mid = n;
  200. document.location.href = 'http://getmedia.redefine.pl/vods/get_vod/?cpid=1&ua=mipla_ios/122&media_id=' + mid;
  201. }
  202. }
  203. }
  204.  
  205. }
  206.  
  207. function PokazLinkOnet() {
  208. m = dataLayer[0].mvpID;
  209. url = 'aHR0cHM6Ly9wbGF5ZXItYXBpLmRyZWFtbGFiLnBsLz9ib2R5W2lkXT0rbSsmYm9keVtqc29ucnBjXT0yLjAmYm9keVttZXRob2RdPWdldF9hc3NldF9kZXRhaWwmYm9keVtwYXJhbXNdW0lEX1B1Ymxpa2FjamldPSttKyZib2R5W3BhcmFtc11bU2VydmljZV09dm9kLm9uZXQucGwmY29udGVudC10eXBlPWFwcGxpY2F0aW9uL2pzb25wJngtb25ldC1hcHA9cGxheWVyLmZyb250Lm9uZXRhcGkucGwmY2FsbGJhY2s9';
  210. url = (atob(url)).replace(/\+m\+/g, m);
  211. xhr = new XMLHttpRequest();
  212. xhr.open('GET', url, false);
  213. xhr.send(null);
  214. v = JSON.parse(xhr.responseText);
  215. vc = v.result[0].formats.wideo.mp4;
  216. title = v.result[0].meta.title;
  217. if (!vc) {
  218. alert('materiał z drm :(');
  219. return;
  220. }
  221. for (var i = - 1, cc = [
  222. ], dd = [
  223. ], l = vc.length >>> 0; ++i !== l; null) {
  224. dd[i] = cc[i] = vc[i].video_bitrate;
  225. }
  226. dd.sort(function (a, b) {
  227. return b - a;
  228. });
  229. DocumentWriteFirefoxFix = "";
  230. var randomText = makeid();
  231. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + '<p>Tytuł: ' + title + '</p>';
  232. var HighestResolution = 0;
  233. var HighestResolutionLink = '';
  234. for (var j = 0, len = dd.length; j < len; j = j + 1) {
  235. dlurl = vc[cc.indexOf(dd[j])].url;
  236. bitrate = vc[cc.indexOf(dd[j])].video_bitrate;
  237. vertical_resolution = vc[cc.indexOf(dd[j])].vertical_resolution;
  238. if (vertical_resolution > HighestResolution) {
  239. HighestResolution = vertical_resolution;
  240. HighestResolutionLink = dlurl;
  241. }
  242. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + '<p>Bitrate: ' + bitrate + ' - Rozdzielczość pionowa: ' + vertical_resolution + '<br>';
  243. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + "Link do materiału: <button id=\"button-" + j + "\" type=\"button\">Kopiuj</button><br><a target=\"_blank\" href=\"" + dlurl + "\">" + dlurl + "</a></p>";
  244. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + "<script>var but = document.getElementById('button-"+j+"');but.addEventListener('click', function(){copyText(\""+ dlurl +"\");document.getElementById('button-"+j+"').setAttribute(\"class\", \"clicked\");})</script>";
  245. }
  246. if (HighestResolution > 0) {
  247. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + StyleText + '<script type="application/javascript">function ShowPromptWithInfo(lol){if (window.prompt("Aby skopiować link, wciśnij: CTRL+C, potem: ENTER aby rozpocząć pobieranie, lub ESC aby zakończyć działanie skryptu", lol)){document.location.href=lol;}}setTimeout(function () {ShowPromptWithInfo("' + HighestResolutionLink + '");}, 1000);' + SkryptKopiujText + '</script>';
  248. addJS_Node(null, null, fireNewTab);
  249. }
  250. }
  251.  
  252. function PokazLinkTvp() {
  253. if (location.href.match(/^http[s]?:\/\/vod\.tvp\.pl\/[\d]{0,8}/)) {
  254. i = document.body.innerHTML;
  255. m = i.match(/object_id=([\d]{0,8})/);
  256. var znalezionotytul = false;
  257. st = 'Nieznane';
  258. tt = 'Nieznane';
  259. i = document.querySelector('.movieWrapper');
  260. if (i !== null) {
  261. i = i.querySelector('iframe').contentWindow.document.head.innerHTML;
  262. if (i !== null) {
  263. st = i.match(/\{name: \x22SeriesTitle\x22\, value: \x22(.*)\x22\},/) [1];
  264. tt = i.match(/\{name: \x22Title\x22\, value: \x22(.*)\x22\},/) [1];
  265. znalezionotytul = true;
  266. }
  267. }
  268. title = st + ' - ' + tt;
  269. xmlhttp = new XMLHttpRequest();
  270. xmlhttp.open('GET', 'https://www.tvp.pl/shared/cdn/tokenizer_v2.php?object_id=' + m[1], false);
  271. xmlhttp.send();
  272. o = JSON.parse(xmlhttp.responseText);
  273. v = o.formats;
  274. vc = [];
  275. if(v != null){
  276. for (var i = - 1, vc = [
  277. ], l = v.length >>> 0; ++i !== l; null) {
  278. if (v[i].adaptive == false) {
  279. vc.push(v[i]);
  280. };
  281. };
  282. }
  283. if (vc.length == 0) {
  284. alert('Niestety, ale materiał jest zabezpieczony DRM i nie będzie można go pobrać :(');
  285. return;
  286. };
  287. for (var i = - 1, cc = [
  288. ], dd = [
  289. ], l = vc.length >>> 0; ++i !== l; null) {
  290. dd[i] = cc[i] = vc[i].totalBitrate;
  291. };
  292. dd.sort(function (a, b) {
  293. return b - a;
  294. });
  295. DocumentWriteFirefoxFix = '';
  296. if (znalezionotytul) {
  297. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + '<p>Tytuł: ' + title + '</p>';
  298. }
  299. for (var j = 0, len = dd.length; j < len; j = j + 1) {
  300. dlurl = vc[cc.indexOf(dd[j])].url;
  301. bitrate = vc[cc.indexOf(dd[j])].totalBitrate;
  302. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + '<p>Bitrate: ' + bitrate + '<br>';
  303. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + "Link do materiału: <button id=\"button-" + j + "\" type=\"button\">Kopiuj</button><br><a target=\"_blank\" href=\"" + dlurl + "\">" + dlurl + "</a></p>";
  304. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + "<script>var but = document.getElementById('button-"+j+"');but.addEventListener('click', function(){copyText(\""+ dlurl +"\");document.getElementById('button-"+j+"').setAttribute(\"class\", \"clicked\");})</script>";
  305. }
  306. for (var j = 0, len = dd.length; j < len; j = j + 1) {
  307. dlurlbest = vc[cc.indexOf(dd[j])].url;
  308. if (dlurlbest !== undefined) {
  309. break;
  310. }
  311. }
  312. DocumentWriteFirefoxFix = DocumentWriteFirefoxFix + StyleText + '<script type="application/javascript">function ShowPromptWithInfo(lol){if (window.prompt("Aby skopiować link, wciśnij: CTRL+C, potem: ENTER aby rozpocząć pobieranie, lub ESC aby zakończyć działanie skryptu", lol)){document.location.href=lol;}}setTimeout(function () {ShowPromptWithInfo("' + dlurlbest + '");}, 1000);' + SkryptKopiujText + '</script>';
  313. addJS_Node(null, null, fireNewTab);
  314. }
  315.  
  316. }
  317.  
  318. function PokazLinkCda() {
  319. if (typeof l === 'undefined') {
  320. var kolumny_list2 = 'pb-video-player';
  321. var list_czat = document.getElementsByClassName(kolumny_list2);
  322. if (list_czat.length > 0) {
  323. for (i = 0; i < list_czat.length; i++)
  324. {
  325. var vviideoo = list_czat[i].src;
  326. ShowPromptWithInfo(vviideoo);
  327. break;
  328. }
  329. }
  330. }
  331. else {
  332. ShowPromptWithInfo(l);
  333. }
  334. }
  335.  
  336. function SkryptDoPobieraniaStart() {
  337. if (Wlacz_skrypt) {
  338. var url = window.location.href;
  339. if (location.href.match(/^http[s]?:\/\/www\.ipla\.tv\//)) {
  340. var btnIpla = document.createElement('input');
  341. btnIpla.setAttribute('value', 'Pobierz video');
  342. btnIpla.setAttribute('type', 'button');
  343. btnIpla.setAttribute('id', 'btnIpla');
  344. btnIpla.setAttribute('style', 'position:fixed !important; left: 0px; top: 4px; width: 140px; height: 35px; background-color: #00a6ff; color: white; z-index: 1000000000;');
  345. document.getElementsByTagName('body') [0].appendChild(btnIpla);
  346. addEvent(document.getElementById('btnIpla'), 'click', function () {
  347. PokazLinkIpla();
  348. });
  349. }
  350. else if (url.indexOf('getmedia.redefine.pl') > - 1) {
  351. PokazLinkPobieranieIpla();
  352. }
  353. else if (location.href.match(/^http[s]?:\/\/(?:w{3}\.)?(?:tvn)?player\.pl\//)) {
  354. var btnTVNNowy = document.createElement('input');
  355. btnTVNNowy.setAttribute('value', 'Pobierz video');
  356. btnTVNNowy.setAttribute('type', 'button');
  357. btnTVNNowy.setAttribute('id', 'btnTVNNowy');
  358. btnTVNNowy.setAttribute('style', 'position:fixed !important; left: 0px; top: 1px; width: 115px; height: 30px; background-color: #00a6ff; color: white; z-index: 1000000000;');
  359. document.getElementsByTagName('body') [0].appendChild(btnTVNNowy);
  360. addEvent(document.getElementById('btnTVNNowy'), 'click', function () {
  361. PokazLinkTVNNowy();
  362. });
  363. }
  364. else if (location.href.match(/^http[s]?:\/\/vod\.pl\//)) {
  365. var btnOnet = document.createElement('input');
  366. btnOnet.setAttribute('value', 'Pobierz video');
  367. btnOnet.setAttribute('type', 'button');
  368. btnOnet.setAttribute('id', 'btnOnet');
  369. btnOnet.setAttribute('style', 'position:fixed !important; left: 0px; top: 2px; width: 110px; height: 25px; background-color: #2fd6ff; z-index: 1000000000;');
  370. document.getElementsByTagName('body') [0].appendChild(btnOnet);
  371. addEvent(document.getElementById('btnOnet'), 'click', function () {
  372. PokazLinkOnet();
  373. });
  374. }
  375. else if (location.href.match(/^http[s]?:\/\/vod\.tvp\.pl\/[\d]{0,8}/)) {
  376. i = document.body.innerHTML;
  377. m = i.match(/object_id=([\d]{0,8})/);
  378. if (m !== null) {
  379. if (url.indexOf('vod.tvp.pl/vod/slider') == - 1) {
  380. if (url.indexOf('tvp.pl/sess/tvplayer.php?') == - 1) {
  381. var btnTvp = document.createElement('input');
  382. btnTvp.setAttribute('value', 'Pobierz video');
  383. btnTvp.setAttribute('type', 'button');
  384. btnTvp.setAttribute('id', 'btnTvp');
  385. btnTvp.setAttribute('style', 'position:fixed !important; left: 0px; top: 10px; width: 100px; height: 35px; z-index: 1000000000;');
  386. document.getElementsByTagName('body') [0].appendChild(btnTvp);
  387. addEvent(document.getElementById('btnTvp'), 'click', function () {
  388. PokazLinkTvp();
  389. });
  390. }
  391. }
  392. }
  393. }
  394. else if (url.indexOf('www.cda.pl') > - 1) {
  395. var btnCda = document.createElement('input');
  396. btnCda.setAttribute('value', 'Pobierz video');
  397. btnCda.setAttribute('type', 'button');
  398. btnCda.setAttribute('id', 'btnCda');
  399. btnCda.setAttribute('style', 'position:fixed !important; left: 0px; top: 2px; width: 95px; height: 30px; z-index: 1000000000;');
  400. document.getElementsByTagName('body') [0].appendChild(btnCda);
  401. addEvent(document.getElementById('btnCda'), 'click', function () {
  402. PokazLinkCda();
  403. });
  404. }
  405. }
  406. }
  407. if(window.jQuery){
  408. $(document).ready(function() {
  409. SkryptDoPobieraniaStart();
  410. });
  411. }
  412. else{
  413. window.onload = SkryptDoPobieraniaStart();
  414. }
  415. /*document.addEventListener("DOMContentLoaded", function(event) {
  416. SkryptDoPobieraniaStart();
  417. });*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement