added getBaseUrl method to linkhandler

This commit is contained in:
yausername 2019-11-23 00:05:49 +05:30
parent 279f175693
commit bc75c6603b
9 changed files with 26 additions and 18 deletions

View File

@ -1,5 +1,10 @@
package org.schabi.newpipe.extractor; package org.schabi.newpipe.extractor;
import java.io.IOException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.schabi.newpipe.extractor.downloader.Downloader; import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -8,11 +13,6 @@ import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.localization.TimeAgoParser; import org.schabi.newpipe.extractor.localization.TimeAgoParser;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.Serializable;
public abstract class Extractor{ public abstract class Extractor{
/** /**
* {@link StreamingService} currently related to this extractor.<br> * {@link StreamingService} currently related to this extractor.<br>
@ -93,6 +93,11 @@ public abstract class Extractor{
public String getUrl() throws ParsingException { public String getUrl() throws ParsingException {
return linkHandler.getUrl(); return linkHandler.getUrl();
} }
@Nonnull
public String getBaseUrl() throws ParsingException {
return linkHandler.getBaseUrl();
}
@Nonnull @Nonnull
public StreamingService getService() { public StreamingService getService() {

View File

@ -2,6 +2,9 @@ package org.schabi.newpipe.extractor.linkhandler;
import java.io.Serializable; import java.io.Serializable;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Utils;
public class LinkHandler implements Serializable { public class LinkHandler implements Serializable {
protected final String originalUrl; protected final String originalUrl;
protected final String url; protected final String url;
@ -28,4 +31,8 @@ public class LinkHandler implements Serializable {
public String getId() { public String getId() {
return id; return id;
} }
public String getBaseUrl() throws ParsingException {
return Utils.getBaseUrl(url);
}
} }

View File

@ -122,7 +122,7 @@ public class PeertubeService extends StreamingService {
return instance.getUrl(); return instance.getUrl();
} }
public void setInstance(PeertubeInstance instance) throws IOException { public void setInstance(PeertubeInstance instance) {
this.instance = instance; this.instance = instance;
this.getServiceInfo().setName(instance.getName()); this.getServiceInfo().setName(instance.getName());
} }

View File

@ -16,7 +16,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Parser.RegexException; import org.schabi.newpipe.extractor.utils.Parser.RegexException;
import org.schabi.newpipe.extractor.utils.Utils;
import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
@ -38,7 +37,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
public PeertubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException { public PeertubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException {
super(service, linkHandler); super(service, linkHandler);
this.baseUrl = Utils.getBaseUrl(getUrl()); this.baseUrl = getBaseUrl();
} }
@Override @Override

View File

@ -56,7 +56,7 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
for(Object c: contents) { for(Object c: contents) {
if(c instanceof JsonObject) { if(c instanceof JsonObject) {
final JsonObject item = (JsonObject) c; final JsonObject item = (JsonObject) c;
PeertubeCommentsInfoItemExtractor extractor = new PeertubeCommentsInfoItemExtractor(item, pageUrl); PeertubeCommentsInfoItemExtractor extractor = new PeertubeCommentsInfoItemExtractor(item, this);
collector.commit(extractor); collector.commit(extractor);
} }
} }

View File

@ -8,7 +8,6 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper; import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Utils;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
@ -19,10 +18,10 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
private final String url; private final String url;
private final String baseUrl; private final String baseUrl;
public PeertubeCommentsInfoItemExtractor(JsonObject item, String url) throws ParsingException { public PeertubeCommentsInfoItemExtractor(JsonObject item, PeertubeCommentsExtractor extractor) throws ParsingException {
this.item = item; this.item = item;
this.url = url; this.url = extractor.getUrl();
this.baseUrl = Utils.getBaseUrl(url); this.baseUrl = extractor.getBaseUrl();
} }
@Override @Override

View File

@ -17,7 +17,6 @@ import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Parser.RegexException; import org.schabi.newpipe.extractor.utils.Parser.RegexException;
import org.schabi.newpipe.extractor.utils.Utils;
import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
@ -59,7 +58,7 @@ public class PeertubeSearchExtractor extends SearchExtractor {
throw new ParsingException("unable to extract search info", e); throw new ParsingException("unable to extract search info", e);
} }
String baseUrl = Utils.getBaseUrl(getUrl()); String baseUrl = getBaseUrl();
for(Object c: contents) { for(Object c: contents) {
if(c instanceof JsonObject) { if(c instanceof JsonObject) {
final JsonObject item = (JsonObject) c; final JsonObject item = (JsonObject) c;

View File

@ -45,7 +45,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
public PeertubeStreamExtractor(StreamingService service, LinkHandler linkHandler) throws ParsingException { public PeertubeStreamExtractor(StreamingService service, LinkHandler linkHandler) throws ParsingException {
super(service, linkHandler); super(service, linkHandler);
this.baseUrl = Utils.getBaseUrl(getUrl()); this.baseUrl = getBaseUrl();
} }
@Override @Override

View File

@ -15,7 +15,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Parser.RegexException; import org.schabi.newpipe.extractor.utils.Parser.RegexException;
import org.schabi.newpipe.extractor.utils.Utils;
import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
@ -54,7 +53,7 @@ public class PeertubeTrendingExtractor extends KioskExtractor {
throw new ParsingException("unable to extract kiosk info", e); throw new ParsingException("unable to extract kiosk info", e);
} }
String baseUrl = Utils.getBaseUrl(getUrl()); String baseUrl = getBaseUrl();
for(Object c: contents) { for(Object c: contents) {
if(c instanceof JsonObject) { if(c instanceof JsonObject) {
final JsonObject item = (JsonObject) c; final JsonObject item = (JsonObject) c;