DPlay Download Script (update 2018-09)

This script allows you download videos on DPlay

  1. // ==UserScript==
  2. // @name DPlay Download Script (update 2018-09)
  3. // @author Daniele Giudice
  4. // @namespace http://danielegiudice.altervista.org
  5. // @description This script allows you download videos on DPlay
  6. // @include http://*.dplay.com/*
  7. // @include https://*.dplay.com/*
  8. // @version 5.2.6
  9. // @require http://code.jquery.com/jquery-latest.min.js
  10. // @grant GM.xmlHttpRequest
  11. // @grant GM_xmlhttpRequest
  12. // @connect it.dplay.com
  13. // @connect dplayit.akamaized.net
  14. // @connect dplaysouth-vod.akamaized.net
  15. // @connect dplay-south-prod.disco-api.com
  16. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  17. // ==/UserScript==
  18.  
  19. /*
  20. Script originale: https://greasyfork.org/it/scripts/11108-dplay-download-script/
  21. Aggiornato al nuovo layout DPlay da Pizzacoder (https://greasyfork.org/en/users/211168-pizza-coder)
  22. */
  23. /*
  24. Thanks to Andrea Lazzarotto RSI Script
  25. Source: https://greasyfork.org/it/scripts/2131-rsi-direct-link/code
  26. */
  27.  
  28. /* Greasemonkey 4 wrapper */
  29. if (typeof GM !== "undefined" && !!GM.xmlHttpRequest){
  30. GM_xmlhttpRequest = GM.xmlHttpRequest;
  31. }
  32.  
  33. var preset = function()
  34. {
  35. $('.b-description-external-wrapper').prepend('<p id="save_box"><a>Salva</a></p>');
  36. $('.b-description-external-wrapper').prepend('<div id="download_box"></div>');
  37.  
  38. $('#save_box').css({
  39. 'width': '50%',
  40. 'margin': '0 auto',
  41. 'padding': '0.5em',
  42. 'border': '1px solid #ccc',
  43. 'background-color': '#FFFFFF',
  44. 'box-sizing': 'border-box',
  45. 'text-align': 'center',
  46. });
  47.  
  48. $('#save_box a').css({
  49. 'font-weight': 'bold',
  50. 'font-size': '20px',
  51. 'color': '#FF0000',
  52. 'cursor': 'pointer',
  53. });
  54.  
  55. $('#download_box').css({
  56. 'position': 'fixed',
  57. 'top': '30%',
  58. 'left': '20%',
  59. 'right': '20%',
  60. 'background-color': '#FFFFFF',
  61. 'color': '#000000',
  62. 'padding': '20px 20px 20px 20px',
  63. 'border': '2px solid #ccc',
  64. 'box-shadow': '0px 20px 150px 0px rgba(0, 0, 0, .95)',
  65. 'box-sizing': 'border-box',
  66. 'font-size': '20px',
  67. 'z-index': '9999',
  68. });
  69.  
  70. $('#download_box').hide();
  71. };
  72.  
  73. var fill_box = function(hls, hls_master)
  74. {
  75. var html_box = '';
  76.  
  77. if( hls_master.indexOf(',RESOLUTION=') == -1 )
  78. {
  79. html_box += '<p class="highlighted" style="text-align: center;">Download non disponibile!</p>';
  80. html_box += '<p class="dl_info">Per informazioni sul problema <a href="http://danielegiudice.altervista.org/scaricare-i-video-di-dplay-it/" target="_blank">andare qui</a>.</p>';
  81. html_box += '<p id="close_box"><a>Chiudi</a></p>';
  82. $('#download_box').append(html_box);
  83. }
  84. else
  85. {
  86. var renditions = [];
  87.  
  88. hls_master.split(',RESOLUTION=').forEach(function(item, index){
  89. if(index>0 && (item.indexOf('#EXT-X-STREAM-INF:') > -1 || item.indexOf(',FRAME-RATE=') > -1)) renditions.push(item.split(',')[0]);
  90. });
  91.  
  92. var ep_number = $('.dates').eq(0).text().replace('S.', 'S').replace('E.', 'E').split('-');
  93. var ep_title = location.pathname.substring(1, location.pathname.length-1).replace(/\-/g, '_').split('/');
  94.  
  95. var title = $('h1').eq(0).html().split('<br>')[0] + ' - ';
  96. title += (ep_number.length>=2 ? ep_number[ep_number.length-2] : ep_number[0]) + ' - ';
  97. title += ep_title[ep_title.length-1];
  98.  
  99. title = title.replace(/(\r\n|\n|\r)/gm, '').replace(/(^\s+|\s+$)/g, '').replace(/ +/g, ' ').replace(/ /g, "_").replace(/\"/g, '_').replace(/\'/g, '_').replace(/[.*+?^${}:()|[\]\\]/g, '');
  100. title += '_(<span id="quality_id""></span>)';
  101.  
  102. html_box += '<div class="flex_row" style="padding-bottom: 20px;"><span>Qualit&agrave; video: <select id="renditions_select"></select></span></div>';
  103. html_box += '<div class="text_dl">Per scaricare il video, usare <span class="highlighted">ffmpeg</span> con la seguente riga di comando:</div>';
  104. html_box += '<p class="highlighted">ffmpeg -i "' + hls + '" -v warning -stats -c copy -map 0:<span id="video_id"></span> -map 0:<span id="audio_id""></span> "' + title + '.mp4"</p>';
  105. html_box += '<p class="flex_row dl_info"><a href="http://danielegiudice.altervista.org/scaricare-i-video-di-dplay-it/" target="_blank">Informazioni script</a>';
  106. html_box += '<a href="http://danielegiudice.altervista.org/guida-al-download-dei-flussi-di-rete/" target="_blank">Guida al download</a></p><p id="close_box"><a>Chiudi</a></p>';
  107.  
  108. $('#download_box').append(html_box);
  109.  
  110. for( var i=0 ; i<renditions.length ; i++ )
  111. $('#renditions_select').append('<option value="' + i + '">' + renditions[i] + '</option>');
  112.  
  113. $('#renditions_select option:last-child').attr('selected','selected');
  114. $('#video_id').html((renditions.length-1)*2);
  115. $('#audio_id').html(((renditions.length-1)*2)+1);
  116. $('#quality_id').html(renditions[renditions.length-1]);
  117.  
  118. $('.flex_row').css({
  119. 'display': '-webkit-flex',
  120. 'display': 'flex',
  121. '-webkit-flex-direction': 'row',
  122. 'flex-direction': 'row',
  123. '-webkit-flex-wrap': 'nowrap',
  124. 'flex-wrap': 'nowrap',
  125. '-webkit-align-items': 'center',
  126. 'align-items': 'center',
  127. '-webkit-justify-content': 'space-around',
  128. 'justify-content': 'space-around',
  129. });
  130.  
  131. $('#renditions_select').css({
  132. 'width': 'auto',
  133. 'font-size': '16px',
  134. });
  135.  
  136. $('#renditions_select').change(function(){
  137. $('#video_id').html($('#renditions_select option:selected').val()*2);
  138. $('#audio_id').html(($('#renditions_select option:selected').val()*2)+1);
  139. $('#quality_id').html(renditions[$('#renditions_select option:selected').val()]);
  140. });
  141. }
  142.  
  143. $('.text_dl').css({
  144. 'font-size': '16px',
  145. 'padding-bottom': '10px',
  146. });
  147.  
  148. $('.highlighted').css({
  149. 'white-space': 'normal',
  150. 'word-break': 'break-word',
  151. 'margin': '.60em 0',
  152. 'padding': '.60em',
  153. 'border-radius': '15px',
  154. 'font-weight': 'bold',
  155. 'font-size': '18px',
  156. 'background-color': '#A1DBB2',
  157. 'color': '#9759BA',
  158. });
  159.  
  160. $('.dl_info a').css({
  161. 'font-size': '20px',
  162. 'font-weight': 'bold',
  163. 'color': '#74bfc1',
  164. 'text-decoration': 'underline',
  165. });
  166.  
  167. $('#close_box').css({
  168. 'text-align': 'center',
  169. });
  170.  
  171. $('#close_box a').css({
  172. 'color': '#FF0000',
  173. 'font-weight': 'bold',
  174. 'font-size': '22px',
  175. 'cursor': 'pointer',
  176. 'text-decoration': 'underline',
  177. });
  178.  
  179. $('#close_box a').click(function(){
  180. $('#download_box').hide();
  181. });
  182. };
  183.  
  184. $(document).ready(function()
  185. {
  186. if( !$('.dplayer').length ){
  187. return;
  188. }
  189.  
  190. preset();
  191.  
  192. $('#save_box a').click(function()
  193. {
  194. if( !$.trim($('#download_box').html()) )
  195. {
  196. var hls = 'https://' + unsafeWindow.location.hostname + unsafeWindow.config.playback_json_url;
  197.  
  198. GM_xmlhttpRequest({
  199. method: 'GET',
  200. url: hls,
  201. onload: function(response_playback)
  202. {
  203. var response_s = JSON.parse(response_playback.response);
  204. var playback_json = JSON.parse(response_s);
  205.  
  206. var url = playback_json.data.attributes.streaming.hls.url;
  207.  
  208. GM_xmlhttpRequest({
  209. method: 'GET',
  210. url: url,
  211. onload: function(response)
  212. {
  213. var response_s = response.response;
  214. fill_box(url, response_s);
  215. $('#download_box').show();
  216. }
  217. });
  218. }
  219. });
  220. }
  221. else
  222. $('#download_box').show();
  223. });
  224. });