NewPipeExtractor/extractor/src/main/java/org/schabi/newpipe/extractor/services/xh/extractors/items/XhVideo.java

148 lines
3.7 KiB
Java
Raw Normal View History

2023-02-16 07:55:03 +00:00
/*
* 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 org.schabi.newpipe.extractor.services.xh.extractors.items;
2023-03-08 16:23:58 +00:00
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
import java.io.IOException;
2023-02-16 07:55:03 +00:00
import java.util.HashMap;
import java.util.Map;
2023-03-08 16:23:58 +00:00
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
2023-02-16 07:55:03 +00:00
/**
*
* @author Rakesh
*/
public class XhVideo {
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
int id;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
String title;
String description;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
int duration;
int created;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
String pageURL;
String thumbURL;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
int authorID;
String authorName;
String authorThumb;
String authorPageURL;
2023-03-08 16:23:58 +00:00
Map<String, String> sources = null;
2023-02-16 07:55:03 +00:00
public XhVideo(int id, String title, String description, int duration, int created, String pageURL, String thumbURL, int authorID, String authorName, String authorThumb, String authorPageURL, HashMap<String, String> streams) {
this.id = id;
this.title = title;
this.description = description;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
this.duration = duration;
this.created = created;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
this.pageURL = pageURL;
this.thumbURL = thumbURL;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
this.authorID = authorID;
this.authorName = authorName;
this.authorThumb = authorThumb;
this.authorPageURL = authorPageURL;
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
this.sources = streams;
}
public int getId() {
return id;
2023-03-08 16:23:58 +00:00
}
2023-02-16 07:55:03 +00:00
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public int getDuration() {
return duration;
}
public int getCreated() {
return created;
}
public String getPageURL() {
return pageURL;
}
public String getThumbURL() {
return thumbURL;
}
public int getAuthorID() {
return authorID;
}
public String getAuthorName() {
return authorName;
}
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
public String getAuthorThumb() {
return authorThumb;
}
public String getAuthorPageURL() {
return authorPageURL;
}
2023-03-08 16:23:58 +00:00
public Map<String, String> getSourceURLs() throws IOException, JsonParserException {
/*
Parse
*/
Document html = Jsoup.connect(this.pageURL).get();
// Parse Content
String content = html.selectFirst("#initials-script").html();
String info_cdn = content.substring(0, content.length() - 1).replace("window.initials=", "");
// Use NanoJSON to convert to VideoItem
final JsonObject json = JsonParser.object().from(info_cdn);
final JsonObject videoModel = json.getObject("videoModel");
HashMap<String, String> streams = new HashMap<>();
// iterate urls
2023-03-10 09:21:13 +00:00
JsonObject mp4 = videoModel.getObject("sources").getObject("mp4");
2023-03-08 16:23:58 +00:00
if (!mp4.isEmpty()) {
final Object keys[] = mp4.keySet().toArray();
for (int i = 0; i < keys.length; i++) {
final String key = keys[i].toString();
2023-03-10 09:21:13 +00:00
System.out.println(key);
2023-03-08 16:23:58 +00:00
}
}
return streams;
}
2023-02-16 07:55:03 +00:00
public Map<String, String> getSources() {
2023-03-10 09:21:13 +00:00
// if (sources.isEmpty() || sources == null) {
// // check if pageurl is set
// if (!pageURL.isBlank() || !pageURL.isEmpty()) {
// // parse the page
// try {
// this.sources = getSourceURLs();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
2023-02-16 07:55:03 +00:00
return sources;
}
2023-03-08 16:23:58 +00:00
2023-02-16 07:55:03 +00:00
}