Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package playerpremium;
- import java.io.BufferedInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.Calendar;
- import java.util.Timer;
- import java.util.TimerTask;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import java.util.prefs.BackingStoreException;
- import java.util.prefs.Preferences;
- import javafx.application.Platform;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.scene.control.Alert;
- import javafx.scene.paint.Color;
- import javafx.stage.StageStyle;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import org.jsoup.Connection;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- /**
- *
- * @author Piotr
- */
- public class PlayerPremium {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- Timer timer = new java.util.Timer();
- String urlStary = "https://player.pl/seriale-online/19--odcinki,4814/odcinek-505,S06E505,172649";
- timer.schedule(new TimerTask() {
- public void run() {
- try {
- String serial = "https://player.pl/seriale-online/19--odcinki,4814";
- Document doc = Jsoup.connect(serial).get();
- String e = doc.selectFirst(".seo-visible>a").attr("href");
- //System.out.println(e);
- //String e = "https://player.pl/seriale-online/19--odcinki,4814/odcinek-499,S06E499,170630";
- if (!e.equals(urlStary)) {
- String t[] = e.split(",");
- String id = t[t.length - 1];
- //String id = "170627";
- //System.out.println(e);
- // System.out.println(id);
- String link = "https://player.pl/api/?platform=ConnectedTV&terminal=Panasonic&format=json&authKey=064fda5ab26dc1dd936f5c6e84b7d3c2&v=3.1&m=getItem&id=" + id;
- //Document doc1 = Jsoup.connect(link).ignoreContentType(true);
- String json = Jsoup.connect(link).ignoreContentType(true).execute().body();
- //System.out.println(doc.text());
- JSONObject d = new JSONObject(json);
- JSONObject item = d.getJSONObject("item");
- JSONObject videos = item.getJSONObject("videos");
- JSONObject main = videos.getJSONObject("main");
- JSONArray videocontent = main.getJSONArray("video_content");
- //for (int i = 0; i < videocontent.length(); i++) {
- // System.out.println(videocontent.getJSONObject(i).getString("url"));
- //System.out.println(videocontent.getJSONObject(i).get("profile_name").toString());
- // }
- // System.out.println(videocontent.length());
- if (videocontent.length() > 0) {
- System.out.println(videocontent.getJSONObject(3).get("profile_name").toString());
- String url = videocontent.getJSONObject(3).getString("url");
- System.out.println(url);
- timer.cancel();
- Calendar now = Calendar.getInstance();
- System.out.println(now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE));
- download(url, "src/" + t[t.length - 2] + ".mp4");
- } else {
- System.out.println("brak linku w jsonie");
- }
- } else {
- System.out.println("brak nowego odc");
- }
- } catch (IOException ex) {
- } catch (Exception ex) {
- System.out.println("exception");
- }
- }
- }, 0, 10000);
- }
- public static void download(String remotePath, String localPath) {
- BufferedInputStream in = null;
- FileOutputStream out = null;
- try {
- URL url = new URL(remotePath);
- URLConnection conn = url.openConnection();
- int size = conn.getContentLength();
- if (size < 0) {
- System.out.println("Could not get the file size");
- } else {
- System.out.println("File size: " + size);
- }
- in = new BufferedInputStream(url.openStream());
- out = new FileOutputStream(localPath);
- byte data[] = new byte[1024];
- int count;
- double sumCount = 0.0;
- while ((count = in.read(data, 0, 1024)) != -1) {
- out.write(data, 0, count);
- sumCount += count;
- if (size > 0) {
- //System.out.println("Rozmiar: " + sumCount + " z " + size);
- System.out.println("Percentace: " + (sumCount / size * 100.0) + "%");
- }
- }
- } catch (MalformedURLException e1) {
- e1.printStackTrace();
- } catch (IOException e2) {
- e2.printStackTrace();
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e3) {
- e3.printStackTrace();
- }
- }
- if (out != null) {
- try {
- out.close();
- } catch (IOException e4) {
- e4.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement