[peertube] use baseUrl instead of global instance url
This commit is contained in:
parent
8a7aa6b9a9
commit
4e0adbefbc
|
@ -3,7 +3,6 @@ package org.schabi.newpipe.extractor.services.peertube.extractors;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jsoup.helper.StringUtil;
|
import org.jsoup.helper.StringUtil;
|
||||||
import org.schabi.newpipe.extractor.ServiceList;
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
|
@ -35,9 +34,11 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
||||||
private long total;
|
private long total;
|
||||||
|
|
||||||
private JsonObject json;
|
private JsonObject json;
|
||||||
|
private final String baseUrl;
|
||||||
|
|
||||||
public PeertubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
public PeertubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
|
this.baseUrl = Utils.getBaseUrl(getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,7 +49,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
value = "/client/assets/images/default-avatar.png";
|
value = "/client/assets/images/default-avatar.png";
|
||||||
}
|
}
|
||||||
return ServiceList.PeerTube.getBaseUrl() + value;
|
return baseUrl + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,7 +91,6 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
||||||
throw new ParsingException("unable to extract channel streams", e);
|
throw new ParsingException("unable to extract channel streams", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
String baseUrl = Utils.getBaseUrl(getUrl());
|
|
||||||
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;
|
||||||
|
@ -183,7 +183,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOriginalUrl() throws ParsingException {
|
public String getOriginalUrl() throws ParsingException {
|
||||||
return ServiceList.PeerTube.getBaseUrl() + "/accounts/" + getId();
|
return baseUrl + "/accounts/" + getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
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.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
|
|
||||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
|
@ -18,10 +17,12 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||||
|
|
||||||
private final JsonObject item;
|
private final JsonObject item;
|
||||||
private final String url;
|
private final String url;
|
||||||
|
private final String baseUrl;
|
||||||
|
|
||||||
public PeertubeCommentsInfoItemExtractor(JsonObject item, String url) {
|
public PeertubeCommentsInfoItemExtractor(JsonObject item, String url) throws ParsingException {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
this.baseUrl = Utils.getBaseUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,7 +38,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
value = "/client/assets/images/default-avatar.png";
|
value = "/client/assets/images/default-avatar.png";
|
||||||
}
|
}
|
||||||
return ServiceList.PeerTube.getBaseUrl() + value;
|
return baseUrl + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,7 +59,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLikeCount() throws ParsingException {
|
public int getLikeCount() throws ParsingException {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,7 +87,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
value = "/client/assets/images/default-avatar.png";
|
value = "/client/assets/images/default-avatar.png";
|
||||||
}
|
}
|
||||||
return ServiceList.PeerTube.getBaseUrl() + value;
|
return baseUrl + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,8 +99,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||||
public String getAuthorEndpoint() throws ParsingException {
|
public String getAuthorEndpoint() throws ParsingException {
|
||||||
String name = JsonUtils.getString(item, "account.name");
|
String name = JsonUtils.getString(item, "account.name");
|
||||||
String host = JsonUtils.getString(item, "account.host");
|
String host = JsonUtils.getString(item, "account.host");
|
||||||
String baseUrl = Utils.getBaseUrl(url);
|
|
||||||
return ServiceList.PeerTube.getChannelLHFactory().fromId(name + "@" + host, baseUrl).getUrl();
|
return ServiceList.PeerTube.getChannelLHFactory().fromId(name + "@" + host, baseUrl).getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,11 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
private JsonObject json;
|
private JsonObject json;
|
||||||
private List<SubtitlesStream> subtitles = new ArrayList<>();
|
private List<SubtitlesStream> subtitles = new ArrayList<>();
|
||||||
|
private final String baseUrl;
|
||||||
|
|
||||||
public PeertubeStreamExtractor(StreamingService service, LinkHandler linkHandler) {
|
public PeertubeStreamExtractor(StreamingService service, LinkHandler linkHandler) throws ParsingException {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
|
this.baseUrl = Utils.getBaseUrl(getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +66,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getThumbnailUrl() throws ParsingException {
|
public String getThumbnailUrl() throws ParsingException {
|
||||||
return ServiceList.PeerTube.getBaseUrl() + JsonUtils.getString(json, "thumbnailPath");
|
return baseUrl + JsonUtils.getString(json, "thumbnailPath");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -115,7 +117,6 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
public String getUploaderUrl() throws ParsingException {
|
public String getUploaderUrl() throws ParsingException {
|
||||||
String name = JsonUtils.getString(json, "account.name");
|
String name = JsonUtils.getString(json, "account.name");
|
||||||
String host = JsonUtils.getString(json, "account.host");
|
String host = JsonUtils.getString(json, "account.host");
|
||||||
String baseUrl = Utils.getBaseUrl(getUrl());
|
|
||||||
return getService().getChannelLHFactory().fromId(name + "@" + host, baseUrl).getUrl();
|
return getService().getChannelLHFactory().fromId(name + "@" + host, baseUrl).getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
value = "/client/assets/images/default-avatar.png";
|
value = "/client/assets/images/default-avatar.png";
|
||||||
}
|
}
|
||||||
return ServiceList.PeerTube.getBaseUrl() + value;
|
return baseUrl + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -233,7 +234,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRelatedStreamsUrl(List<String> tags) throws UnsupportedEncodingException {
|
private String getRelatedStreamsUrl(List<String> tags) throws UnsupportedEncodingException {
|
||||||
String url = ServiceList.PeerTube.getBaseUrl() + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT;
|
String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT;
|
||||||
StringBuilder params = new StringBuilder();
|
StringBuilder params = new StringBuilder();
|
||||||
params.append("start=0&count=8&sort=-createdAt");
|
params.append("start=0&count=8&sort=-createdAt");
|
||||||
for(String tag : tags) {
|
for(String tag : tags) {
|
||||||
|
@ -267,7 +268,6 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
throw new ParsingException("unable to extract related videos", e);
|
throw new ParsingException("unable to extract related videos", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
String baseUrl = Utils.getBaseUrl(getUrl());
|
|
||||||
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;
|
||||||
|
@ -316,7 +316,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
for(Object c: captions) {
|
for(Object c: captions) {
|
||||||
if(c instanceof JsonObject) {
|
if(c instanceof JsonObject) {
|
||||||
JsonObject caption = (JsonObject)c;
|
JsonObject caption = (JsonObject)c;
|
||||||
String url = ServiceList.PeerTube.getBaseUrl() + JsonUtils.getString(caption, "captionPath");
|
String url = baseUrl + JsonUtils.getString(caption, "captionPath");
|
||||||
String languageCode = JsonUtils.getString(caption, "language.id");
|
String languageCode = JsonUtils.getString(caption, "language.id");
|
||||||
String ext = url.substring(url.lastIndexOf(".") + 1);
|
String ext = url.substring(url.lastIndexOf(".") + 1);
|
||||||
MediaFormat fmt = MediaFormat.getFromSuffix(ext);
|
MediaFormat fmt = MediaFormat.getFromSuffix(ext);
|
||||||
|
@ -336,7 +336,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOriginalUrl() throws ParsingException {
|
public String getOriginalUrl() throws ParsingException {
|
||||||
return ServiceList.PeerTube.getBaseUrl() + "/videos/watch/" + getId();
|
return baseUrl + "/videos/watch/" + getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@ import org.schabi.newpipe.extractor.ServiceList;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
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.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
|
|
||||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
|
@ -31,7 +29,7 @@ public class PeertubeStreamInfoItemExtractor implements StreamInfoItemExtractor
|
||||||
@Override
|
@Override
|
||||||
public String getThumbnailUrl() throws ParsingException {
|
public String getThumbnailUrl() throws ParsingException {
|
||||||
String value = JsonUtils.getString(item, "thumbnailPath");
|
String value = JsonUtils.getString(item, "thumbnailPath");
|
||||||
return ServiceList.PeerTube.getBaseUrl() + value;
|
return baseUrl + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class PeertubeCommentsExtractorTest {
|
||||||
assertFalse(StringUtil.isBlank(c.getTextualPublishedTime()));
|
assertFalse(StringUtil.isBlank(c.getTextualPublishedTime()));
|
||||||
assertFalse(StringUtil.isBlank(c.getThumbnailUrl()));
|
assertFalse(StringUtil.isBlank(c.getThumbnailUrl()));
|
||||||
assertFalse(StringUtil.isBlank(c.getUrl()));
|
assertFalse(StringUtil.isBlank(c.getUrl()));
|
||||||
assertFalse(c.getLikeCount() == -1);
|
assertFalse(c.getLikeCount() != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue