Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package playerpremium;
  7.  
  8. import java.io.BufferedInputStream;
  9. import java.io.FileOutputStream;
  10. import java.io.IOException;
  11. import java.net.MalformedURLException;
  12. import java.net.URL;
  13. import java.net.URLConnection;
  14. import java.util.Calendar;
  15. import java.util.Timer;
  16. import java.util.TimerTask;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import java.util.prefs.BackingStoreException;
  20. import java.util.prefs.Preferences;
  21. import javafx.application.Platform;
  22. import javafx.collections.FXCollections;
  23. import javafx.collections.ObservableList;
  24. import javafx.scene.control.Alert;
  25. import javafx.scene.paint.Color;
  26. import javafx.stage.StageStyle;
  27. import org.json.JSONArray;
  28. import org.json.JSONException;
  29. import org.json.JSONObject;
  30. import org.jsoup.Connection;
  31. import org.jsoup.Jsoup;
  32. import org.jsoup.nodes.Document;
  33. import org.jsoup.nodes.Element;
  34. import org.jsoup.select.Elements;
  35.  
  36. /**
  37. *
  38. * @author Piotr
  39. */
  40. public class PlayerPremium {
  41.  
  42. /**
  43. * @param args the command line arguments
  44. */
  45. public static void main(String[] args) throws IOException {
  46.  
  47. Timer timer = new java.util.Timer();
  48.  
  49. String urlStary = "https://player.pl/seriale-online/19--odcinki,4814/odcinek-505,S06E505,172649";
  50.  
  51.  
  52. timer.schedule(new TimerTask() {
  53. public void run() {
  54.  
  55. try {
  56. String serial = "https://player.pl/seriale-online/19--odcinki,4814";
  57. Document doc = Jsoup.connect(serial).get();
  58. String e = doc.selectFirst(".seo-visible>a").attr("href");
  59. //System.out.println(e);
  60. //String e = "https://player.pl/seriale-online/19--odcinki,4814/odcinek-499,S06E499,170630";
  61.  
  62. if (!e.equals(urlStary)) {
  63. String t[] = e.split(",");
  64. String id = t[t.length - 1];
  65. //String id = "170627";
  66.  
  67. //System.out.println(e);
  68. // System.out.println(id);
  69. String link = "https://player.pl/api/?platform=ConnectedTV&terminal=Panasonic&format=json&authKey=064fda5ab26dc1dd936f5c6e84b7d3c2&v=3.1&m=getItem&id=" + id;
  70.  
  71. //Document doc1 = Jsoup.connect(link).ignoreContentType(true);
  72. String json = Jsoup.connect(link).ignoreContentType(true).execute().body();
  73. //System.out.println(doc.text());
  74. JSONObject d = new JSONObject(json);
  75. JSONObject item = d.getJSONObject("item");
  76. JSONObject videos = item.getJSONObject("videos");
  77. JSONObject main = videos.getJSONObject("main");
  78. JSONArray videocontent = main.getJSONArray("video_content");
  79. //for (int i = 0; i < videocontent.length(); i++) {
  80. // System.out.println(videocontent.getJSONObject(i).getString("url"));
  81. //System.out.println(videocontent.getJSONObject(i).get("profile_name").toString());
  82. // }
  83. // System.out.println(videocontent.length());
  84. if (videocontent.length() > 0) {
  85. System.out.println(videocontent.getJSONObject(3).get("profile_name").toString());
  86. String url = videocontent.getJSONObject(3).getString("url");
  87. System.out.println(url);
  88. timer.cancel();
  89. Calendar now = Calendar.getInstance();
  90. System.out.println(now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE));
  91. download(url, "src/" + t[t.length - 2] + ".mp4");
  92. } else {
  93. System.out.println("brak linku w jsonie");
  94. }
  95.  
  96. } else {
  97. System.out.println("brak nowego odc");
  98. }
  99. } catch (IOException ex) {
  100.  
  101. } catch (Exception ex) {
  102. System.out.println("exception");
  103. }
  104.  
  105. }
  106. }, 0, 10000);
  107.  
  108. }
  109.  
  110. public static void download(String remotePath, String localPath) {
  111. BufferedInputStream in = null;
  112. FileOutputStream out = null;
  113.  
  114. try {
  115. URL url = new URL(remotePath);
  116. URLConnection conn = url.openConnection();
  117. int size = conn.getContentLength();
  118.  
  119. if (size < 0) {
  120. System.out.println("Could not get the file size");
  121. } else {
  122. System.out.println("File size: " + size);
  123. }
  124.  
  125. in = new BufferedInputStream(url.openStream());
  126. out = new FileOutputStream(localPath);
  127. byte data[] = new byte[1024];
  128. int count;
  129. double sumCount = 0.0;
  130.  
  131. while ((count = in.read(data, 0, 1024)) != -1) {
  132. out.write(data, 0, count);
  133.  
  134. sumCount += count;
  135. if (size > 0) {
  136. //System.out.println("Rozmiar: " + sumCount + " z " + size);
  137. System.out.println("Percentace: " + (sumCount / size * 100.0) + "%");
  138. }
  139. }
  140.  
  141. } catch (MalformedURLException e1) {
  142. e1.printStackTrace();
  143. } catch (IOException e2) {
  144. e2.printStackTrace();
  145. } finally {
  146. if (in != null) {
  147. try {
  148. in.close();
  149. } catch (IOException e3) {
  150. e3.printStackTrace();
  151. }
  152. }
  153. if (out != null) {
  154. try {
  155. out.close();
  156. } catch (IOException e4) {
  157. e4.printStackTrace();
  158. }
  159. }
  160. }
  161. }
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement