This commit is contained in:
CypherpunkSamurai 2023-03-08 21:53:58 +05:30
parent d2d975d3cc
commit 65a31fd37c
3 changed files with 72 additions and 29 deletions

View File

@ -31,7 +31,6 @@ public class XhService extends StreamingService {
public final static String HOST = "xhamster18.desi";
public final static String BASE_URL = "https://" + HOST + "/";
// constructor
public XhService(final int id) {
super(id, NAME, Arrays.asList(VIDEO));
@ -41,7 +40,6 @@ public class XhService extends StreamingService {
super(id, NAME, Arrays.asList(VIDEO));
}
@Override
public String getBaseUrl() {
return BASE_URL;
@ -89,11 +87,12 @@ public class XhService extends StreamingService {
@Override
public KioskList getKioskList() throws ExtractionException {
final KioskList list = new KioskList(this);
// Return Empty List
// patch: if (kioskId == null) { return "" }
KioskList list = new KioskList(this);
return list;
}
@Override
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) throws ExtractionException {
return null;

View File

@ -15,7 +15,7 @@ import org.schabi.newpipe.extractor.stream.StreamType;
*
* @author Rakesh
*/
public abstract class XhStreamInfoItemExtractor implements StreamInfoItemExtractor {
public class XhStreamInfoItemExtractor implements StreamInfoItemExtractor {
XhVideo video;

View File

@ -5,8 +5,14 @@
*/
package org.schabi.newpipe.extractor.services.xh.extractors.items;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
/**
*
@ -30,8 +36,7 @@ public class XhVideo {
String authorThumb;
String authorPageURL;
Map<String, String> sources;
Map<String, String> sources = null;
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;
@ -96,7 +101,46 @@ public class XhVideo {
return authorPageURL;
}
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
final JsonObject mp4 = videoModel.getObject("sources").getObject("mp4");
if (!mp4.isEmpty()) {
final Object keys[] = mp4.keySet().toArray();
for (int i = 0; i < keys.length; i++) {
final String key = keys[i].toString();
streams.put(key, mp4.getString("key"));
}
}
return streams;
}
public Map<String, String> getSources() {
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();
}
}
}
return sources;
}