[Peertube] Fix checkstyle issues
This commit is contained in:
parent
9f7e06c817
commit
9ab32cb2e7
18 changed files with 377 additions and 242 deletions
|
@ -5,7 +5,6 @@ import com.grack.nanojson.JsonParser;
|
|||
import com.grack.nanojson.JsonParserException;
|
||||
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||
import org.schabi.newpipe.extractor.downloader.Response;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||
|
@ -18,14 +17,15 @@ public class PeertubeInstance {
|
|||
|
||||
private final String url;
|
||||
private String name;
|
||||
public static final PeertubeInstance defaultInstance = new PeertubeInstance("https://framatube.org", "FramaTube");
|
||||
public static final PeertubeInstance DEFAULT_INSTANCE
|
||||
= new PeertubeInstance("https://framatube.org", "FramaTube");
|
||||
|
||||
public PeertubeInstance(String url) {
|
||||
public PeertubeInstance(final String url) {
|
||||
this.url = url;
|
||||
this.name = "PeerTube";
|
||||
}
|
||||
|
||||
public PeertubeInstance(String url, String name) {
|
||||
public PeertubeInstance(final String url, final String name) {
|
||||
this.url = url;
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -35,11 +35,9 @@ public class PeertubeInstance {
|
|||
}
|
||||
|
||||
public void fetchInstanceMetaData() throws Exception {
|
||||
Downloader downloader = NewPipe.getDownloader();
|
||||
Response response = null;
|
||||
|
||||
final Response response;
|
||||
try {
|
||||
response = downloader.get(url + "/api/v1/config");
|
||||
response = NewPipe.getDownloader().get(url + "/api/v1/config");
|
||||
} catch (ReCaptchaException | IOException e) {
|
||||
throw new Exception("unable to configure instance " + url, e);
|
||||
}
|
||||
|
@ -49,7 +47,7 @@ public class PeertubeInstance {
|
|||
}
|
||||
|
||||
try {
|
||||
JsonObject json = JsonParser.object().from(response.responseBody());
|
||||
final JsonObject json = JsonParser.object().from(response.responseBody());
|
||||
this.name = JsonUtils.getString(json, "instance.name");
|
||||
} catch (JsonParserException | ParsingException e) {
|
||||
throw new Exception("unable to parse instance config", e);
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.time.OffsetDateTime;
|
|||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
public class PeertubeParsingHelper {
|
||||
public final class PeertubeParsingHelper {
|
||||
public static final String START_KEY = "start";
|
||||
public static final String COUNT_KEY = "count";
|
||||
public static final int ITEMS_PER_PAGE = 12;
|
||||
|
@ -33,10 +33,11 @@ public class PeertubeParsingHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static OffsetDateTime parseDateFrom(final String textualUploadDate) throws ParsingException {
|
||||
public static OffsetDateTime parseDateFrom(final String textualUploadDate)
|
||||
throws ParsingException {
|
||||
try {
|
||||
return OffsetDateTime.ofInstant(Instant.parse(textualUploadDate), ZoneOffset.UTC);
|
||||
} catch (DateTimeParseException e) {
|
||||
} catch (final DateTimeParseException e) {
|
||||
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e);
|
||||
}
|
||||
}
|
||||
|
@ -45,25 +46,31 @@ public class PeertubeParsingHelper {
|
|||
final String prevStart;
|
||||
try {
|
||||
prevStart = Parser.matchGroup1(START_PATTERN, prevPageUrl);
|
||||
} catch (Parser.RegexException e) {
|
||||
} catch (final Parser.RegexException e) {
|
||||
return null;
|
||||
}
|
||||
if (Utils.isBlank(prevStart)) return null;
|
||||
if (Utils.isBlank(prevStart)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final long nextStart;
|
||||
try {
|
||||
nextStart = Long.parseLong(prevStart) + ITEMS_PER_PAGE;
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (final NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (nextStart >= total) {
|
||||
return null;
|
||||
} else {
|
||||
return new Page(prevPageUrl.replace(START_KEY + "=" + prevStart, START_KEY + "=" + nextStart));
|
||||
return new Page(prevPageUrl.replace(
|
||||
START_KEY + "=" + prevStart, START_KEY + "=" + nextStart));
|
||||
}
|
||||
}
|
||||
|
||||
public static void collectStreamsFrom(final InfoItemsCollector collector, final JsonObject json, final String baseUrl) throws ParsingException {
|
||||
public static void collectStreamsFrom(final InfoItemsCollector collector,
|
||||
final JsonObject json,
|
||||
final String baseUrl) throws ParsingException {
|
||||
collectStreamsFrom(collector, json, baseUrl, false);
|
||||
}
|
||||
|
||||
|
@ -74,13 +81,15 @@ public class PeertubeParsingHelper {
|
|||
* @param json the file to retrieve data from
|
||||
* @param baseUrl the base Url of the instance
|
||||
* @param sepia if we should use PeertubeSepiaStreamInfoItemExtractor
|
||||
* @throws ParsingException
|
||||
*/
|
||||
public static void collectStreamsFrom(final InfoItemsCollector collector, final JsonObject json, final String baseUrl, boolean sepia) throws ParsingException {
|
||||
public static void collectStreamsFrom(final InfoItemsCollector collector,
|
||||
final JsonObject json,
|
||||
final String baseUrl,
|
||||
final boolean sepia) throws ParsingException {
|
||||
final JsonArray contents;
|
||||
try {
|
||||
contents = (JsonArray) JsonUtils.getValue(json, "data");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Unable to extract list info", e);
|
||||
}
|
||||
|
||||
|
@ -93,7 +102,7 @@ public class PeertubeParsingHelper {
|
|||
item = item.getObject("video");
|
||||
}
|
||||
|
||||
PeertubeStreamInfoItemExtractor extractor;
|
||||
final PeertubeStreamInfoItemExtractor extractor;
|
||||
if (sepia) {
|
||||
extractor = new PeertubeSepiaStreamInfoItemExtractor(item, baseUrl);
|
||||
} else {
|
||||
|
|
|
@ -1,35 +1,51 @@
|
|||
package org.schabi.newpipe.extractor.services.peertube;
|
||||
|
||||
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
|
||||
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
import org.schabi.newpipe.extractor.linkhandler.*;
|
||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
|
||||
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.*;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.*;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeAccountExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubePlaylistExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSearchExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeStreamExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSuggestionExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeCommentsLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubePlaylistLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeSearchQueryHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeTrendingLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
|
||||
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
|
||||
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
|
||||
|
||||
public class PeertubeService extends StreamingService {
|
||||
|
||||
private PeertubeInstance instance;
|
||||
|
||||
public PeertubeService(int id) {
|
||||
this(id, PeertubeInstance.defaultInstance);
|
||||
public PeertubeService(final int id) {
|
||||
this(id, PeertubeInstance.DEFAULT_INSTANCE);
|
||||
}
|
||||
|
||||
public PeertubeService(int id, PeertubeInstance instance) {
|
||||
public PeertubeService(final int id, final PeertubeInstance instance) {
|
||||
super(id, "PeerTube", asList(VIDEO, COMMENTS));
|
||||
this.instance = instance;
|
||||
}
|
||||
|
@ -60,13 +76,10 @@ public class PeertubeService extends StreamingService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) {
|
||||
public SearchExtractor getSearchExtractor(final SearchQueryHandler queryHandler) {
|
||||
final List<String> contentFilters = queryHandler.getContentFilters();
|
||||
boolean external = false;
|
||||
if (!contentFilters.isEmpty() && contentFilters.get(0).startsWith("sepia_")) {
|
||||
external = true;
|
||||
}
|
||||
return new PeertubeSearchExtractor(this, queryHandler, external);
|
||||
return new PeertubeSearchExtractor(this, queryHandler,
|
||||
!contentFilters.isEmpty() && contentFilters.get(0).startsWith("sepia_"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +93,7 @@ public class PeertubeService extends StreamingService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler)
|
||||
public ChannelExtractor getChannelExtractor(final ListLinkHandler linkHandler)
|
||||
throws ExtractionException {
|
||||
|
||||
if (linkHandler.getUrl().contains("/video-channels/")) {
|
||||
|
@ -91,19 +104,19 @@ public class PeertubeService extends StreamingService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler)
|
||||
public PlaylistExtractor getPlaylistExtractor(final ListLinkHandler linkHandler)
|
||||
throws ExtractionException {
|
||||
return new PeertubePlaylistExtractor(this, linkHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamExtractor getStreamExtractor(LinkHandler linkHandler)
|
||||
public StreamExtractor getStreamExtractor(final LinkHandler linkHandler)
|
||||
throws ExtractionException {
|
||||
return new PeertubeStreamExtractor(this, linkHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
|
||||
public CommentsExtractor getCommentsExtractor(final ListLinkHandler linkHandler)
|
||||
throws ExtractionException {
|
||||
return new PeertubeCommentsExtractor(this, linkHandler);
|
||||
}
|
||||
|
@ -117,34 +130,31 @@ public class PeertubeService extends StreamingService {
|
|||
return this.instance;
|
||||
}
|
||||
|
||||
public void setInstance(PeertubeInstance instance) {
|
||||
public void setInstance(final PeertubeInstance instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KioskList getKioskList() throws ExtractionException {
|
||||
KioskList.KioskExtractorFactory kioskFactory = new KioskList.KioskExtractorFactory() {
|
||||
@Override
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService,
|
||||
String url,
|
||||
String id)
|
||||
throws ExtractionException {
|
||||
return new PeertubeTrendingExtractor(PeertubeService.this,
|
||||
new PeertubeTrendingLinkHandlerFactory().fromId(id), id);
|
||||
}
|
||||
};
|
||||
final KioskList.KioskExtractorFactory kioskFactory = (streamingService, url, id) ->
|
||||
new PeertubeTrendingExtractor(
|
||||
PeertubeService.this,
|
||||
new PeertubeTrendingLinkHandlerFactory().fromId(id),
|
||||
id
|
||||
);
|
||||
|
||||
KioskList list = new KioskList(this);
|
||||
final KioskList list = new KioskList(this);
|
||||
|
||||
// add kiosks here e.g.:
|
||||
final PeertubeTrendingLinkHandlerFactory h = new PeertubeTrendingLinkHandlerFactory();
|
||||
try {
|
||||
list.addKioskEntry(kioskFactory, h, PeertubeTrendingLinkHandlerFactory.KIOSK_TRENDING);
|
||||
list.addKioskEntry(kioskFactory, h, PeertubeTrendingLinkHandlerFactory.KIOSK_MOST_LIKED);
|
||||
list.addKioskEntry(kioskFactory, h,
|
||||
PeertubeTrendingLinkHandlerFactory.KIOSK_MOST_LIKED);
|
||||
list.addKioskEntry(kioskFactory, h, PeertubeTrendingLinkHandlerFactory.KIOSK_RECENT);
|
||||
list.addKioskEntry(kioskFactory, h, PeertubeTrendingLinkHandlerFactory.KIOSK_LOCAL);
|
||||
list.setDefaultKiosk(PeertubeTrendingLinkHandlerFactory.KIOSK_TRENDING);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ExtractionException(e);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,10 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.*;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.ITEMS_PER_PAGE;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.START_KEY;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.collectStreamsFrom;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
public class PeertubeAccountExtractor extends ChannelExtractor {
|
||||
|
@ -31,7 +34,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
private final String baseUrl;
|
||||
private static final String ACCOUNTS = "accounts/";
|
||||
|
||||
public PeertubeAccountExtractor(final StreamingService service, final ListLinkHandler linkHandler) throws ParsingException {
|
||||
public PeertubeAccountExtractor(final StreamingService service,
|
||||
final ListLinkHandler linkHandler) throws ParsingException {
|
||||
super(service, linkHandler);
|
||||
this.baseUrl = getBaseUrl();
|
||||
}
|
||||
|
@ -41,7 +45,7 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
String value;
|
||||
try {
|
||||
value = JsonUtils.getString(json, "avatar.path");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = "/client/assets/images/default-avatar.png";
|
||||
}
|
||||
return baseUrl + value;
|
||||
|
@ -80,7 +84,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
subscribersCount += videoChannelJsonObject.getInt("followersCount");
|
||||
}
|
||||
} catch (final IOException | JsonParserException | ReCaptchaException ignored) {
|
||||
// something went wrong during video channels extraction, only return subscribers of ownerAccount
|
||||
// something went wrong during video channels extraction,
|
||||
// only return subscribers of ownerAccount
|
||||
}
|
||||
return subscribersCount;
|
||||
}
|
||||
|
@ -89,7 +94,7 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
public String getDescription() {
|
||||
try {
|
||||
return JsonUtils.getString(json, "description");
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
return "No description";
|
||||
}
|
||||
}
|
||||
|
@ -117,8 +122,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
@Nonnull
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
return getPage(new Page(
|
||||
baseUrl + "/api/v1/" + getId() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
return getPage(new Page(baseUrl + "/api/v1/" + getId() + "/videos?" + START_KEY + "=0&"
|
||||
+ COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,23 +135,24 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
|
||||
final Response response = getDownloader().get(page.getUrl());
|
||||
|
||||
JsonObject json = null;
|
||||
JsonObject pageJson = null;
|
||||
if (response != null && !Utils.isBlank(response.responseBody())) {
|
||||
try {
|
||||
json = JsonParser.object().from(response.responseBody());
|
||||
} catch (Exception e) {
|
||||
pageJson = JsonParser.object().from(response.responseBody());
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not parse json data for account info", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (json != null) {
|
||||
PeertubeParsingHelper.validate(json);
|
||||
final long total = json.getLong("total");
|
||||
if (pageJson != null) {
|
||||
PeertubeParsingHelper.validate(pageJson);
|
||||
final long total = pageJson.getLong("total");
|
||||
|
||||
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
collectStreamsFrom(collector, json, getBaseUrl());
|
||||
collectStreamsFrom(collector, pageJson, getBaseUrl());
|
||||
|
||||
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
return new InfoItemsPage<>(collector,
|
||||
PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
} else {
|
||||
throw new ExtractionException("Unable to get PeerTube account info");
|
||||
}
|
||||
|
@ -173,10 +179,12 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
private void setInitialData(final String responseBody) throws ExtractionException {
|
||||
try {
|
||||
json = JsonParser.object().from(responseBody);
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
throw new ExtractionException("Unable to extract PeerTube account data", e);
|
||||
}
|
||||
if (json == null) throw new ExtractionException("Unable to extract PeerTube account data");
|
||||
if (json == null) {
|
||||
throw new ExtractionException("Unable to extract PeerTube account data");
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -21,15 +21,18 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.*;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.ITEMS_PER_PAGE;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.START_KEY;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.collectStreamsFrom;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
|
||||
public class PeertubeChannelExtractor extends ChannelExtractor {
|
||||
private JsonObject json;
|
||||
private final String baseUrl;
|
||||
|
||||
public PeertubeChannelExtractor(final StreamingService service, final ListLinkHandler linkHandler) throws ParsingException {
|
||||
public PeertubeChannelExtractor(final StreamingService service,
|
||||
final ListLinkHandler linkHandler) throws ParsingException {
|
||||
super(service, linkHandler);
|
||||
this.baseUrl = getBaseUrl();
|
||||
}
|
||||
|
@ -39,7 +42,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
String value;
|
||||
try {
|
||||
value = JsonUtils.getString(json, "avatar.path");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = "/client/assets/images/default-avatar.png";
|
||||
}
|
||||
return baseUrl + value;
|
||||
|
@ -64,7 +67,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
public String getDescription() {
|
||||
try {
|
||||
return JsonUtils.getString(json, "description");
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
return "No description";
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +87,7 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
String value;
|
||||
try {
|
||||
value = JsonUtils.getString(json, "ownerAccount.avatar.path");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = "/client/assets/images/default-avatar.png";
|
||||
}
|
||||
return baseUrl + value;
|
||||
|
@ -98,45 +101,48 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
@Nonnull
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
return getPage(new Page(
|
||||
baseUrl + "/api/v1/" + getId() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
return getPage(new Page(baseUrl + "/api/v1/" + getId() + "/videos?" + START_KEY + "=0&"
|
||||
+ COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException, ExtractionException {
|
||||
public InfoItemsPage<StreamInfoItem> getPage(final Page page)
|
||||
throws IOException, ExtractionException {
|
||||
if (page == null || isNullOrEmpty(page.getUrl())) {
|
||||
throw new IllegalArgumentException("Page doesn't contain an URL");
|
||||
}
|
||||
|
||||
final Response response = getDownloader().get(page.getUrl());
|
||||
|
||||
JsonObject json = null;
|
||||
JsonObject pageJson = null;
|
||||
if (response != null && !Utils.isBlank(response.responseBody())) {
|
||||
try {
|
||||
json = JsonParser.object().from(response.responseBody());
|
||||
} catch (Exception e) {
|
||||
pageJson = JsonParser.object().from(response.responseBody());
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not parse json data for channel info", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (json != null) {
|
||||
PeertubeParsingHelper.validate(json);
|
||||
final long total = json.getLong("total");
|
||||
if (pageJson != null) {
|
||||
PeertubeParsingHelper.validate(pageJson);
|
||||
final long total = pageJson.getLong("total");
|
||||
|
||||
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
collectStreamsFrom(collector, json, getBaseUrl());
|
||||
collectStreamsFrom(collector, pageJson, getBaseUrl());
|
||||
|
||||
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
return new InfoItemsPage<>(collector,
|
||||
PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
} else {
|
||||
throw new ExtractionException("Unable to get PeerTube channel info");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(final Downloader downloader) throws IOException, ExtractionException {
|
||||
public void onFetchPage(final Downloader downloader)
|
||||
throws IOException, ExtractionException {
|
||||
final Response response = downloader.get(
|
||||
baseUrl + PeertubeChannelLinkHandlerFactory.API_ENDPOINT + getId());
|
||||
if (response != null ) {
|
||||
if (response != null) {
|
||||
setInitialData(response.responseBody());
|
||||
} else {
|
||||
throw new ExtractionException("Unable to extract PeerTube channel data");
|
||||
|
@ -146,10 +152,12 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
private void setInitialData(final String responseBody) throws ExtractionException {
|
||||
try {
|
||||
json = JsonParser.object().from(responseBody);
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
throw new ExtractionException("Unable to extract PeerTube channel data", e);
|
||||
}
|
||||
if (json == null) throw new ExtractionException("Unable to extract PeerTube channel data");
|
||||
if (json == null) {
|
||||
throw new ExtractionException("Unable to extract PeerTube channel data");
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -18,36 +18,41 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.*;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.ITEMS_PER_PAGE;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.START_KEY;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
public class PeertubeCommentsExtractor extends CommentsExtractor {
|
||||
public PeertubeCommentsExtractor(final StreamingService service, final ListLinkHandler uiHandler) {
|
||||
public PeertubeCommentsExtractor(final StreamingService service,
|
||||
final ListLinkHandler uiHandler) {
|
||||
super(service, uiHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoItemsPage<CommentsInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
final String pageUrl = getUrl() + "?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
|
||||
return getPage(new Page(pageUrl));
|
||||
public InfoItemsPage<CommentsInfoItem> getInitialPage()
|
||||
throws IOException, ExtractionException {
|
||||
return getPage(new Page(getUrl() + "?" + START_KEY + "=0&"
|
||||
+ COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
private void collectCommentsFrom(final CommentsInfoItemsCollector collector, final JsonObject json) throws ParsingException {
|
||||
private void collectCommentsFrom(final CommentsInfoItemsCollector collector,
|
||||
final JsonObject json) throws ParsingException {
|
||||
final JsonArray contents = json.getArray("data");
|
||||
|
||||
for (final Object c : contents) {
|
||||
if (c instanceof JsonObject) {
|
||||
final JsonObject item = (JsonObject) c;
|
||||
if (!item.getBoolean("isDeleted")) {
|
||||
final PeertubeCommentsInfoItemExtractor extractor = new PeertubeCommentsInfoItemExtractor(item, this);
|
||||
collector.commit(extractor);
|
||||
collector.commit(new PeertubeCommentsInfoItemExtractor(item, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoItemsPage<CommentsInfoItem> getPage(final Page page) throws IOException, ExtractionException {
|
||||
public InfoItemsPage<CommentsInfoItem> getPage(final Page page)
|
||||
throws IOException, ExtractionException {
|
||||
if (page == null || isNullOrEmpty(page.getUrl())) {
|
||||
throw new IllegalArgumentException("Page doesn't contain an URL");
|
||||
}
|
||||
|
@ -58,7 +63,7 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
|
|||
if (response != null && !Utils.isBlank(response.responseBody())) {
|
||||
try {
|
||||
json = JsonParser.object().from(response.responseBody());
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not parse json data for comments info", e);
|
||||
}
|
||||
}
|
||||
|
@ -67,15 +72,18 @@ public class PeertubeCommentsExtractor extends CommentsExtractor {
|
|||
PeertubeParsingHelper.validate(json);
|
||||
final long total = json.getLong("total");
|
||||
|
||||
final CommentsInfoItemsCollector collector = new CommentsInfoItemsCollector(getServiceId());
|
||||
final CommentsInfoItemsCollector collector
|
||||
= new CommentsInfoItemsCollector(getServiceId());
|
||||
collectCommentsFrom(collector, json);
|
||||
|
||||
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
return new InfoItemsPage<>(collector,
|
||||
PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
} else {
|
||||
throw new ExtractionException("Unable to get PeerTube kiosk info");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(Downloader downloader) { }
|
||||
public void onFetchPage(final Downloader downloader) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
|||
private final String url;
|
||||
private final String baseUrl;
|
||||
|
||||
public PeertubeCommentsInfoItemExtractor(final JsonObject item, final PeertubeCommentsExtractor extractor) throws ParsingException {
|
||||
public PeertubeCommentsInfoItemExtractor(final JsonObject item,
|
||||
final PeertubeCommentsExtractor extractor)
|
||||
throws ParsingException {
|
||||
this.item = item;
|
||||
this.url = extractor.getUrl();
|
||||
this.baseUrl = extractor.getBaseUrl();
|
||||
|
@ -35,7 +37,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
|||
String value;
|
||||
try {
|
||||
value = JsonUtils.getString(item, "account.avatar.path");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = "/client/assets/images/default-avatar.png";
|
||||
}
|
||||
return baseUrl + value;
|
||||
|
@ -63,7 +65,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
|||
try {
|
||||
final Document doc = Jsoup.parse(htmlText);
|
||||
return doc.body().text();
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
return htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", EMPTY_STRING);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +80,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
|||
String value;
|
||||
try {
|
||||
value = JsonUtils.getString(item, "account.avatar.path");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = "/client/assets/images/default-avatar.png";
|
||||
}
|
||||
return baseUrl + value;
|
||||
|
@ -86,13 +88,15 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
|||
|
||||
@Override
|
||||
public String getUploaderName() throws ParsingException {
|
||||
return JsonUtils.getString(item, "account.name") + "@" + JsonUtils.getString(item, "account.host");
|
||||
return JsonUtils.getString(item, "account.name") + "@"
|
||||
+ JsonUtils.getString(item, "account.host");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploaderUrl() throws ParsingException {
|
||||
final String name = JsonUtils.getString(item, "account.name");
|
||||
final String host = JsonUtils.getString(item, "account.host");
|
||||
return ServiceList.PeerTube.getChannelLHFactory().fromId("accounts/" + name + "@" + host, baseUrl).getUrl();
|
||||
return ServiceList.PeerTube.getChannelLHFactory()
|
||||
.fromId("accounts/" + name + "@" + host, baseUrl).getUrl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,17 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.*;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.ITEMS_PER_PAGE;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.START_KEY;
|
||||
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.collectStreamsFrom;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
public class PeertubePlaylistExtractor extends PlaylistExtractor {
|
||||
private JsonObject playlistInfo;
|
||||
|
||||
public PeertubePlaylistExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
|
||||
public PeertubePlaylistExtractor(final StreamingService service,
|
||||
final ListLinkHandler linkHandler) {
|
||||
super(service, linkHandler);
|
||||
}
|
||||
|
||||
|
@ -47,7 +51,8 @@ public class PeertubePlaylistExtractor extends PlaylistExtractor {
|
|||
|
||||
@Override
|
||||
public String getUploaderAvatarUrl() throws ParsingException {
|
||||
return getBaseUrl() + playlistInfo.getObject("ownerAccount").getObject("avatar").getString("path");
|
||||
return getBaseUrl()
|
||||
+ playlistInfo.getObject("ownerAccount").getObject("avatar").getString("path");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,17 +80,20 @@ public class PeertubePlaylistExtractor extends PlaylistExtractor {
|
|||
@Nonnull
|
||||
@Override
|
||||
public String getSubChannelAvatarUrl() throws ParsingException {
|
||||
return getBaseUrl() + playlistInfo.getObject("videoChannel").getObject("avatar").getString("path");
|
||||
return getBaseUrl()
|
||||
+ playlistInfo.getObject("videoChannel").getObject("avatar").getString("path");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
return getPage(new Page(getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
return getPage(new Page(getUrl() + "/videos?" + START_KEY + "=0&"
|
||||
+ COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException, ExtractionException {
|
||||
public InfoItemsPage<StreamInfoItem> getPage(final Page page)
|
||||
throws IOException, ExtractionException {
|
||||
if (page == null || isNullOrEmpty(page.getUrl())) {
|
||||
throw new IllegalArgumentException("Page doesn't contain an URL");
|
||||
}
|
||||
|
@ -96,7 +104,7 @@ public class PeertubePlaylistExtractor extends PlaylistExtractor {
|
|||
if (response != null && !Utils.isBlank(response.responseBody())) {
|
||||
try {
|
||||
json = JsonParser.object().from(response.responseBody());
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not parse json data for playlist info", e);
|
||||
}
|
||||
}
|
||||
|
@ -108,18 +116,20 @@ public class PeertubePlaylistExtractor extends PlaylistExtractor {
|
|||
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
collectStreamsFrom(collector, json, getBaseUrl());
|
||||
|
||||
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
return new InfoItemsPage<>(collector,
|
||||
PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
} else {
|
||||
throw new ExtractionException("Unable to get PeerTube playlist info");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||
public void onFetchPage(@Nonnull final Downloader downloader)
|
||||
throws IOException, ExtractionException {
|
||||
final Response response = downloader.get(getUrl());
|
||||
try {
|
||||
playlistInfo = JsonParser.object().from(response.responseBody());
|
||||
} catch (JsonParserException jpe) {
|
||||
} catch (final JsonParserException jpe) {
|
||||
throw new ExtractionException("Could not parse json", jpe);
|
||||
}
|
||||
PeertubeParsingHelper.validate(playlistInfo);
|
||||
|
|
|
@ -32,13 +32,16 @@ import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
|||
public class PeertubeSearchExtractor extends SearchExtractor {
|
||||
|
||||
// if we should use PeertubeSepiaStreamInfoItemExtractor
|
||||
private boolean sepia;
|
||||
private final boolean sepia;
|
||||
|
||||
public PeertubeSearchExtractor(StreamingService service, SearchQueryHandler linkHandler) {
|
||||
public PeertubeSearchExtractor(final StreamingService service,
|
||||
final SearchQueryHandler linkHandler) {
|
||||
this(service, linkHandler, false);
|
||||
}
|
||||
|
||||
public PeertubeSearchExtractor(StreamingService service, SearchQueryHandler linkHandler, boolean sepia) {
|
||||
public PeertubeSearchExtractor(final StreamingService service,
|
||||
final SearchQueryHandler linkHandler,
|
||||
final boolean sepia) {
|
||||
super(service, linkHandler);
|
||||
this.sepia = sepia;
|
||||
}
|
||||
|
@ -62,12 +65,13 @@ public class PeertubeSearchExtractor extends SearchExtractor {
|
|||
|
||||
@Override
|
||||
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
final String pageUrl = getUrl() + "&" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
|
||||
return getPage(new Page(pageUrl));
|
||||
return getPage(new Page(getUrl() + "&" + START_KEY + "=0&"
|
||||
+ COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException, ExtractionException {
|
||||
public InfoItemsPage<InfoItem> getPage(final Page page)
|
||||
throws IOException, ExtractionException {
|
||||
if (page == null || isNullOrEmpty(page.getUrl())) {
|
||||
throw new IllegalArgumentException("Page doesn't contain an URL");
|
||||
}
|
||||
|
@ -78,7 +82,7 @@ public class PeertubeSearchExtractor extends SearchExtractor {
|
|||
if (response != null && !Utils.isBlank(response.responseBody())) {
|
||||
try {
|
||||
json = JsonParser.object().from(response.responseBody());
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not parse json data for search info", e);
|
||||
}
|
||||
}
|
||||
|
@ -90,12 +94,15 @@ public class PeertubeSearchExtractor extends SearchExtractor {
|
|||
final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(getServiceId());
|
||||
collectStreamsFrom(collector, json, getBaseUrl(), sepia);
|
||||
|
||||
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
return new InfoItemsPage<>(collector,
|
||||
PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
} else {
|
||||
throw new ExtractionException("Unable to get PeerTube search info");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException { }
|
||||
public void onFetchPage(@Nonnull final Downloader downloader)
|
||||
throws IOException, ExtractionException {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.grack.nanojson.JsonObject;
|
|||
*/
|
||||
public class PeertubeSepiaStreamInfoItemExtractor extends PeertubeStreamInfoItemExtractor {
|
||||
|
||||
public PeertubeSepiaStreamInfoItemExtractor(JsonObject item, String baseUrl) {
|
||||
public PeertubeSepiaStreamInfoItemExtractor(final JsonObject item, final String baseUrl) {
|
||||
super(item, baseUrl);
|
||||
final String embedUrl = super.item.getString("embedUrl");
|
||||
final String embedPath = super.item.getString("embedPath");
|
||||
|
@ -15,8 +15,8 @@ public class PeertubeSepiaStreamInfoItemExtractor extends PeertubeStreamInfoItem
|
|||
setBaseUrl(itemBaseUrl);
|
||||
|
||||
// Usually, all videos, pictures and other content are hosted on the instance,
|
||||
// or can be accessed by the same URL path if the instance with baseUrl federates the one where the video is actually uploaded
|
||||
// But it can't be accessed with Sepiasearch, so we use the item's instance as base URL
|
||||
// or can be accessed by the same URL path if the instance with baseUrl federates the one
|
||||
// where the video is actually uploaded. But it can't be accessed with Sepiasearch, so we
|
||||
// use the item's instance as base URL.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package org.schabi.newpipe.extractor.services.peertube.extractors;
|
||||
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
import com.grack.nanojson.JsonArray;
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import com.grack.nanojson.JsonParser;
|
||||
import com.grack.nanojson.JsonParserException;
|
||||
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.MetaInfo;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||
|
@ -18,12 +21,17 @@ import org.schabi.newpipe.extractor.localization.DateWrapper;
|
|||
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeSearchQueryHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.stream.*;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.Description;
|
||||
import org.schabi.newpipe.extractor.stream.Stream;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
@ -32,15 +40,16 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PeertubeStreamExtractor extends StreamExtractor {
|
||||
private final String baseUrl;
|
||||
private JsonObject json;
|
||||
private final List<SubtitlesStream> subtitles = new ArrayList<>();
|
||||
|
||||
public PeertubeStreamExtractor(final StreamingService service, final LinkHandler linkHandler) throws ParsingException {
|
||||
public PeertubeStreamExtractor(final StreamingService service, final LinkHandler linkHandler)
|
||||
throws ParsingException {
|
||||
super(service, linkHandler);
|
||||
this.baseUrl = getBaseUrl();
|
||||
}
|
||||
|
@ -73,9 +82,10 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
String text;
|
||||
try {
|
||||
text = JsonUtils.getString(json, "description");
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
return Description.EMPTY_DESCRIPTION;
|
||||
}
|
||||
|
||||
if (text.length() == 250 && text.substring(247).equals("...")) {
|
||||
//if description is shortened, get full description
|
||||
final Downloader dl = NewPipe.getDownloader();
|
||||
|
@ -140,7 +150,8 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
public String getUploaderUrl() throws ParsingException {
|
||||
final String name = JsonUtils.getString(json, "account.name");
|
||||
final String host = JsonUtils.getString(json, "account.host");
|
||||
return getService().getChannelLHFactory().fromId("accounts/" + name + "@" + host, baseUrl).getUrl();
|
||||
return getService().getChannelLHFactory()
|
||||
.fromId("accounts/" + name + "@" + host, baseUrl).getUrl();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -155,7 +166,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
String value;
|
||||
try {
|
||||
value = JsonUtils.getString(json, "account.avatar.path");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = "/client/assets/images/default-avatar.png";
|
||||
}
|
||||
return baseUrl + value;
|
||||
|
@ -179,7 +190,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
String value;
|
||||
try {
|
||||
value = JsonUtils.getString(json, "channel.avatar.path");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = "/client/assets/images/default-avatar.png";
|
||||
}
|
||||
return baseUrl + value;
|
||||
|
@ -200,35 +211,41 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
public List<VideoStream> getVideoStreams() throws ExtractionException {
|
||||
assertPageFetched();
|
||||
final List<VideoStream> videoStreams = new ArrayList<>();
|
||||
|
||||
// mp4
|
||||
try {
|
||||
videoStreams.addAll(getVideoStreamsFromArray(json.getArray("files")));
|
||||
} catch (Exception ignored) { }
|
||||
} catch (final Exception ignored) { }
|
||||
|
||||
// HLS
|
||||
try {
|
||||
final JsonArray streamingPlaylists = json.getArray("streamingPlaylists");
|
||||
for (final Object p : streamingPlaylists) {
|
||||
if (!(p instanceof JsonObject)) continue;
|
||||
if (!(p instanceof JsonObject)) {
|
||||
continue;
|
||||
}
|
||||
final JsonObject playlist = (JsonObject) p;
|
||||
videoStreams.addAll(getVideoStreamsFromArray(playlist.getArray("files")));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not get video streams", e);
|
||||
}
|
||||
|
||||
if (getStreamType() == StreamType.LIVE_STREAM) {
|
||||
final String url = getHlsUrl();
|
||||
videoStreams.add(new VideoStream(url, MediaFormat.MPEG_4, "720p"));
|
||||
videoStreams.add(new VideoStream(getHlsUrl(), MediaFormat.MPEG_4, "720p"));
|
||||
}
|
||||
|
||||
return videoStreams;
|
||||
}
|
||||
|
||||
private List<VideoStream> getVideoStreamsFromArray(final JsonArray streams) throws ParsingException {
|
||||
private List<VideoStream> getVideoStreamsFromArray(final JsonArray streams)
|
||||
throws ParsingException {
|
||||
try {
|
||||
final List<VideoStream> videoStreams = new ArrayList<>();
|
||||
for (final Object s : streams) {
|
||||
if (!(s instanceof JsonObject)) continue;
|
||||
if (!(s instanceof JsonObject)) {
|
||||
continue;
|
||||
}
|
||||
final JsonObject stream = (JsonObject) s;
|
||||
final String url;
|
||||
if (stream.has("fileDownloadUrl")) {
|
||||
|
@ -240,13 +257,14 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
final String resolution = JsonUtils.getString(stream, "resolution.label");
|
||||
final String extension = url.substring(url.lastIndexOf(".") + 1);
|
||||
final MediaFormat format = MediaFormat.getFromSuffix(extension);
|
||||
final VideoStream videoStream = new VideoStream(url, torrentUrl, format, resolution);
|
||||
final VideoStream videoStream
|
||||
= new VideoStream(url, torrentUrl, format, resolution);
|
||||
if (!Stream.containSimilarStream(videoStream, videoStreams)) {
|
||||
videoStreams.add(videoStream);
|
||||
}
|
||||
}
|
||||
return videoStreams;
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not get video streams from array");
|
||||
}
|
||||
|
||||
|
@ -287,8 +305,8 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
final String apiUrl;
|
||||
if (tags.isEmpty()) {
|
||||
apiUrl = baseUrl + "/api/v1/accounts/" + JsonUtils.getString(json, "account.name")
|
||||
+ "@" + JsonUtils.getString(json, "account.host") +
|
||||
"/videos?start=0&count=8";
|
||||
+ "@" + JsonUtils.getString(json, "account.host")
|
||||
+ "/videos?start=0&count=8";
|
||||
} else {
|
||||
apiUrl = getRelatedItemsUrl(tags);
|
||||
}
|
||||
|
@ -313,7 +331,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
public String getSupportInfo() {
|
||||
try {
|
||||
return JsonUtils.getString(json, "support");
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -326,16 +344,17 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
params.append("&tagsOneOf=");
|
||||
params.append(URLEncoder.encode(tag, UTF_8));
|
||||
}
|
||||
return url + "?" + params.toString();
|
||||
return url + "?" + params;
|
||||
}
|
||||
|
||||
private void getStreamsFromApi(final StreamInfoItemsCollector collector, final String apiUrl) throws ReCaptchaException, IOException, ParsingException {
|
||||
private void getStreamsFromApi(final StreamInfoItemsCollector collector, final String apiUrl)
|
||||
throws ReCaptchaException, IOException, ParsingException {
|
||||
final Response response = getDownloader().get(apiUrl);
|
||||
JsonObject relatedVideosJson = null;
|
||||
if (response != null && !Utils.isBlank(response.responseBody())) {
|
||||
try {
|
||||
relatedVideosJson = JsonParser.object().from(response.responseBody());
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
throw new ParsingException("Could not parse json data for related videos", e);
|
||||
}
|
||||
}
|
||||
|
@ -345,27 +364,33 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
}
|
||||
}
|
||||
|
||||
private void collectStreamsFrom(final StreamInfoItemsCollector collector, final JsonObject json) throws ParsingException {
|
||||
private void collectStreamsFrom(final StreamInfoItemsCollector collector,
|
||||
final JsonObject jsonObject)
|
||||
throws ParsingException {
|
||||
final JsonArray contents;
|
||||
try {
|
||||
contents = (JsonArray) JsonUtils.getValue(json, "data");
|
||||
} catch (Exception e) {
|
||||
contents = (JsonArray) JsonUtils.getValue(jsonObject, "data");
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("unable to extract related videos", e);
|
||||
}
|
||||
|
||||
for (final Object c : contents) {
|
||||
if (c instanceof JsonObject) {
|
||||
final JsonObject item = (JsonObject) c;
|
||||
final PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor(item, baseUrl);
|
||||
final PeertubeStreamInfoItemExtractor extractor
|
||||
= new PeertubeStreamInfoItemExtractor(item, baseUrl);
|
||||
//do not add the same stream in related streams
|
||||
if (!extractor.getUrl().equals(getUrl())) collector.commit(extractor);
|
||||
if (!extractor.getUrl().equals(getUrl())) {
|
||||
collector.commit(extractor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(final Downloader downloader) throws IOException, ExtractionException {
|
||||
final Response response = downloader.get(baseUrl + PeertubeStreamLinkHandlerFactory.VIDEO_API_ENDPOINT + getId());
|
||||
final Response response = downloader.get(
|
||||
baseUrl + PeertubeStreamLinkHandlerFactory.VIDEO_API_ENDPOINT + getId());
|
||||
if (response != null) {
|
||||
setInitialData(response.responseBody());
|
||||
} else {
|
||||
|
@ -378,7 +403,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
private void setInitialData(final String responseBody) throws ExtractionException {
|
||||
try {
|
||||
json = JsonParser.object().from(responseBody);
|
||||
} catch (JsonParserException e) {
|
||||
} catch (final JsonParserException e) {
|
||||
throw new ExtractionException("Unable to extract PeerTube stream data", e);
|
||||
}
|
||||
if (json == null) {
|
||||
|
@ -402,11 +427,12 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
final String languageCode = JsonUtils.getString(caption, "language.id");
|
||||
final String ext = url.substring(url.lastIndexOf(".") + 1);
|
||||
final MediaFormat fmt = MediaFormat.getFromSuffix(ext);
|
||||
if (fmt != null && !isNullOrEmpty(languageCode))
|
||||
if (fmt != null && !isNullOrEmpty(languageCode)) {
|
||||
subtitles.add(new SubtitlesStream(fmt, languageCode, url, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
// ignore all exceptions
|
||||
}
|
||||
}
|
||||
|
@ -457,7 +483,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
public Locale getLanguageInfo() {
|
||||
try {
|
||||
return new Locale(JsonUtils.getString(json, "language.id"));
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelp
|
|||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
public class PeertubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
||||
public PeertubeTrendingExtractor(final StreamingService streamingService, final ListLinkHandler linkHandler, final String kioskId) {
|
||||
public PeertubeTrendingExtractor(final StreamingService streamingService,
|
||||
final ListLinkHandler linkHandler,
|
||||
final String kioskId) {
|
||||
super(streamingService, linkHandler, kioskId);
|
||||
}
|
||||
|
||||
|
@ -38,12 +40,13 @@ public class PeertubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
|||
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
final String pageUrl = getUrl() + "&" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
|
||||
return getPage(new Page(pageUrl));
|
||||
return getPage(new Page(getUrl() + "&" + START_KEY + "=0&"
|
||||
+ COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException, ExtractionException {
|
||||
public InfoItemsPage<StreamInfoItem> getPage(final Page page)
|
||||
throws IOException, ExtractionException {
|
||||
if (page == null || isNullOrEmpty(page.getUrl())) {
|
||||
throw new IllegalArgumentException("Page doesn't contain an URL");
|
||||
}
|
||||
|
@ -54,7 +57,7 @@ public class PeertubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
|||
if (response != null && !Utils.isBlank(response.responseBody())) {
|
||||
try {
|
||||
json = JsonParser.object().from(response.responseBody());
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new ParsingException("Could not parse json data for kiosk info", e);
|
||||
}
|
||||
}
|
||||
|
@ -66,12 +69,15 @@ public class PeertubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
|||
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
collectStreamsFrom(collector, json, getBaseUrl());
|
||||
|
||||
return new InfoItemsPage<>(collector, PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
return new InfoItemsPage<>(collector,
|
||||
PeertubeParsingHelper.getNextPage(page.getUrl(), total));
|
||||
} else {
|
||||
throw new ExtractionException("Unable to get PeerTube kiosk info");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException { }
|
||||
public void onFetchPage(@Nonnull final Downloader downloader)
|
||||
throws IOException, ExtractionException {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,39 +7,49 @@ import org.schabi.newpipe.extractor.utils.Parser;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
public final class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
|
||||
private static final PeertubeChannelLinkHandlerFactory instance = new PeertubeChannelLinkHandlerFactory();
|
||||
private static final PeertubeChannelLinkHandlerFactory INSTANCE
|
||||
= new PeertubeChannelLinkHandlerFactory();
|
||||
private static final String ID_PATTERN = "((accounts|a)|(video-channels|c))/([^/?&#]*)";
|
||||
public static final String API_ENDPOINT = "/api/v1/";
|
||||
|
||||
private PeertubeChannelLinkHandlerFactory() {
|
||||
}
|
||||
|
||||
public static PeertubeChannelLinkHandlerFactory getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
public String getId(final String url) throws ParsingException {
|
||||
return fixId(Parser.matchGroup(ID_PATTERN, url, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilters, String searchFilter) throws ParsingException {
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilters,
|
||||
final String searchFilter) throws ParsingException {
|
||||
return getUrl(id, contentFilters, searchFilter, ServiceList.PeerTube.getBaseUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilter, String sortFilter, String baseUrl)
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilter,
|
||||
final String sortFilter,
|
||||
final String baseUrl)
|
||||
throws ParsingException {
|
||||
if (id.matches(ID_PATTERN)) {
|
||||
return baseUrl + "/" + fixId(id);
|
||||
} else {
|
||||
// This is needed for compatibility with older versions were we didn't support video channels yet
|
||||
// This is needed for compatibility with older versions were we didn't support
|
||||
// video channels yet
|
||||
return baseUrl + "/accounts/" + id;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAcceptUrl(String url) {
|
||||
public boolean onAcceptUrl(final String url) {
|
||||
return url.contains("/accounts/") || url.contains("/a/")
|
||||
|| url.contains("/video-channels/") || url.contains("/c/");
|
||||
}
|
||||
|
@ -56,11 +66,11 @@ public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
* @param id the id to fix
|
||||
* @return the fixed id
|
||||
*/
|
||||
private String fixId(String id) {
|
||||
private String fixId(final String id) {
|
||||
if (id.startsWith("a/")) {
|
||||
id = "accounts" + id.substring(1);
|
||||
return "accounts" + id.substring(1);
|
||||
} else if (id.startsWith("c/")) {
|
||||
id = "video-channels" + id.substring(1);
|
||||
return "video-channels" + id.substring(1);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -4,21 +4,24 @@ import org.schabi.newpipe.extractor.ServiceList;
|
|||
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
public final class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
|
||||
private static final PeertubeCommentsLinkHandlerFactory instance = new PeertubeCommentsLinkHandlerFactory();
|
||||
private static final PeertubeCommentsLinkHandlerFactory INSTANCE
|
||||
= new PeertubeCommentsLinkHandlerFactory();
|
||||
private static final String COMMENTS_ENDPOINT = "/api/v1/videos/%s/comment-threads";
|
||||
|
||||
private PeertubeCommentsLinkHandlerFactory() {
|
||||
}
|
||||
|
||||
public static PeertubeCommentsLinkHandlerFactory getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException, IllegalArgumentException {
|
||||
public String getId(final String url) throws ParsingException, IllegalArgumentException {
|
||||
return PeertubeStreamLinkHandlerFactory.getInstance().getId(url); // the same id is needed
|
||||
}
|
||||
|
||||
|
@ -28,13 +31,17 @@ public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
|
||||
String baseUrl = ServiceList.PeerTube.getBaseUrl();
|
||||
return getUrl(id, contentFilter, sortFilter, baseUrl);
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilter,
|
||||
final String sortFilter) throws ParsingException {
|
||||
return getUrl(id, contentFilter, sortFilter, ServiceList.PeerTube.getBaseUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilter, String sortFilter, String baseUrl) throws ParsingException {
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilter,
|
||||
final String sortFilter,
|
||||
final String baseUrl) throws ParsingException {
|
||||
return baseUrl + String.format(COMMENTS_ENDPOINT, id);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,28 +8,36 @@ import org.schabi.newpipe.extractor.utils.Parser;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
public final class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
|
||||
private static final PeertubePlaylistLinkHandlerFactory instance = new PeertubePlaylistLinkHandlerFactory();
|
||||
private static final PeertubePlaylistLinkHandlerFactory INSTANCE
|
||||
= new PeertubePlaylistLinkHandlerFactory();
|
||||
private static final String ID_PATTERN = "(/videos/watch/playlist/|/w/p/)([^/?&#]*)";
|
||||
|
||||
private PeertubePlaylistLinkHandlerFactory() {
|
||||
}
|
||||
|
||||
public static PeertubePlaylistLinkHandlerFactory getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilters, String sortFilter) {
|
||||
String baseUrl = ServiceList.PeerTube.getBaseUrl();
|
||||
return getUrl(id, contentFilters, sortFilter, baseUrl);
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilters,
|
||||
final String sortFilter) {
|
||||
return getUrl(id, contentFilters, sortFilter, ServiceList.PeerTube.getBaseUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilters, String sortFilter, String baseUrl) {
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilters,
|
||||
final String sortFilter,
|
||||
final String baseUrl) {
|
||||
return baseUrl + "/api/v1/video-playlists/" + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
public String getId(final String url) throws ParsingException {
|
||||
return Parser.matchGroup(ID_PATTERN, url, 2);
|
||||
}
|
||||
|
||||
|
@ -38,7 +46,7 @@ public class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
try {
|
||||
getId(url);
|
||||
return true;
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,20 +10,25 @@ import java.util.List;
|
|||
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
||||
|
||||
public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
||||
public final class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
||||
|
||||
public static final String VIDEOS = "videos";
|
||||
public static final String SEPIA_VIDEOS = "sepia_videos"; // sepia is the global index
|
||||
public static final String SEPIA_BASE_URL = "https://sepiasearch.org";
|
||||
public static final String SEARCH_ENDPOINT = "/api/v1/search/videos";
|
||||
|
||||
private PeertubeSearchQueryHandlerFactory() {
|
||||
}
|
||||
|
||||
public static PeertubeSearchQueryHandlerFactory getInstance() {
|
||||
return new PeertubeSearchQueryHandlerFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String searchString, List<String> contentFilters, String sortFilter) throws ParsingException {
|
||||
String baseUrl;
|
||||
public String getUrl(final String searchString,
|
||||
final List<String> contentFilters,
|
||||
final String sortFilter) throws ParsingException {
|
||||
final String baseUrl;
|
||||
if (!contentFilters.isEmpty() && contentFilters.get(0).startsWith("sepia_")) {
|
||||
baseUrl = SEPIA_BASE_URL;
|
||||
} else {
|
||||
|
@ -33,10 +38,13 @@ public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String searchString, List<String> contentFilters, String sortFilter, String baseUrl) throws ParsingException {
|
||||
public String getUrl(final String searchString,
|
||||
final List<String> contentFilters,
|
||||
final String sortFilter,
|
||||
final String baseUrl) throws ParsingException {
|
||||
try {
|
||||
return baseUrl + SEARCH_ENDPOINT + "?search=" + URLEncoder.encode(searchString, UTF_8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new ParsingException("Could not encode query", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|||
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
|
||||
public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||
public final class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||
|
||||
private static final PeertubeStreamLinkHandlerFactory instance = new PeertubeStreamLinkHandlerFactory();
|
||||
private static final PeertubeStreamLinkHandlerFactory INSTANCE
|
||||
= new PeertubeStreamLinkHandlerFactory();
|
||||
private static final String ID_PATTERN = "(/w/|(/videos/(watch/|embed/)?))(?!p/)([^/?&#]*)";
|
||||
// we exclude p/ because /w/p/ is playlist, not video
|
||||
public static final String VIDEO_API_ENDPOINT = "/api/v1/videos/";
|
||||
|
@ -22,31 +23,33 @@ public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
}
|
||||
|
||||
public static PeertubeStreamLinkHandlerFactory getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id) {
|
||||
public String getUrl(final String id) {
|
||||
return getUrl(id, ServiceList.PeerTube.getBaseUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, String baseUrl) {
|
||||
public String getUrl(final String id, final String baseUrl) {
|
||||
return baseUrl + VIDEO_PATH + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException, IllegalArgumentException {
|
||||
public String getId(final String url) throws ParsingException, IllegalArgumentException {
|
||||
return Parser.matchGroup(ID_PATTERN, url, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAcceptUrl(final String url) throws FoundAdException {
|
||||
if (url.contains("/playlist/")) return false;
|
||||
if (url.contains("/playlist/")) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
getId(url);
|
||||
return true;
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
public final class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
|
||||
|
||||
private static final PeertubeTrendingLinkHandlerFactory instance = new PeertubeTrendingLinkHandlerFactory();
|
||||
private static final PeertubeTrendingLinkHandlerFactory INSTANCE
|
||||
= new PeertubeTrendingLinkHandlerFactory();
|
||||
|
||||
public static final Map<String, String> KIOSK_MAP;
|
||||
public static final Map<String, String> REVERSE_KIOSK_MAP;
|
||||
|
@ -22,49 +22,52 @@ public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
public static final String KIOSK_LOCAL = "Local";
|
||||
|
||||
static {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
map.put(KIOSK_TRENDING, "%s/api/v1/videos?sort=-trending");
|
||||
map.put(KIOSK_MOST_LIKED, "%s/api/v1/videos?sort=-likes");
|
||||
map.put(KIOSK_RECENT, "%s/api/v1/videos?sort=-publishedAt");
|
||||
map.put(KIOSK_LOCAL, "%s/api/v1/videos?sort=-publishedAt&filter=local");
|
||||
KIOSK_MAP = Collections.unmodifiableMap(map);
|
||||
|
||||
Map<String, String> reverseMap = new HashMap<>();
|
||||
for (Map.Entry<String, String> entry : KIOSK_MAP.entrySet()) {
|
||||
final Map<String, String> reverseMap = new HashMap<>();
|
||||
for (final Map.Entry<String, String> entry : KIOSK_MAP.entrySet()) {
|
||||
reverseMap.put(entry.getValue(), entry.getKey());
|
||||
}
|
||||
REVERSE_KIOSK_MAP = Collections.unmodifiableMap(reverseMap);
|
||||
}
|
||||
|
||||
public static PeertubeTrendingLinkHandlerFactory getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilters, String sortFilter) {
|
||||
String baseUrl = ServiceList.PeerTube.getBaseUrl();
|
||||
return getUrl(id, contentFilters, sortFilter, baseUrl);
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilters,
|
||||
final String sortFilter) {
|
||||
return getUrl(id, contentFilters, sortFilter, ServiceList.PeerTube.getBaseUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilters, String sortFilter, String baseUrl) {
|
||||
public String getUrl(final String id,
|
||||
final List<String> contentFilters,
|
||||
final String sortFilter,
|
||||
final String baseUrl) {
|
||||
return String.format(KIOSK_MAP.get(id), baseUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
String baseUrl = ServiceList.PeerTube.getBaseUrl();
|
||||
url = url.replace(baseUrl, "%s");
|
||||
if (url.contains("/videos/trending")) {
|
||||
public String getId(final String url) throws ParsingException {
|
||||
final String cleanUrl = url.replace(ServiceList.PeerTube.getBaseUrl(), "%s");
|
||||
if (cleanUrl.contains("/videos/trending")) {
|
||||
return KIOSK_TRENDING;
|
||||
} else if (url.contains("/videos/most-liked")) {
|
||||
} else if (cleanUrl.contains("/videos/most-liked")) {
|
||||
return KIOSK_MOST_LIKED;
|
||||
} else if (url.contains("/videos/recently-added")) {
|
||||
} else if (cleanUrl.contains("/videos/recently-added")) {
|
||||
return KIOSK_RECENT;
|
||||
} else if (url.contains("/videos/local")) {
|
||||
} else if (cleanUrl.contains("/videos/local")) {
|
||||
return KIOSK_LOCAL;
|
||||
} else if (REVERSE_KIOSK_MAP.containsKey(url)) {
|
||||
return REVERSE_KIOSK_MAP.get(url);
|
||||
} else if (REVERSE_KIOSK_MAP.containsKey(cleanUrl)) {
|
||||
return REVERSE_KIOSK_MAP.get(cleanUrl);
|
||||
} else {
|
||||
throw new ParsingException("no id found for this url");
|
||||
}
|
||||
|
@ -72,6 +75,8 @@ public class PeertubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
|
||||
@Override
|
||||
public boolean onAcceptUrl(final String url) {
|
||||
return url.contains("/videos?") || url.contains("/videos/trending") || url.contains("/videos/most-liked") || url.contains("/videos/recently-added") || url.contains("/videos/local");
|
||||
return url.contains("/videos?") || url.contains("/videos/trending")
|
||||
|| url.contains("/videos/most-liked") || url.contains("/videos/recently-added")
|
||||
|| url.contains("/videos/local");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue