[PeerTube] Fix link handler inconsistency providing API links
This commit is contained in:
parent
4349be13af
commit
7ae3cb6d07
8 changed files with 46 additions and 43 deletions
|
@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||
|
@ -20,6 +21,8 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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;
|
||||
|
@ -85,10 +88,11 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
final String pageUrl = getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
|
||||
return getPage(new Page(pageUrl));
|
||||
return getPage(new Page(
|
||||
getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,7 +127,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
|
||||
@Override
|
||||
public void onFetchPage(final Downloader downloader) throws IOException, ExtractionException {
|
||||
final Response response = downloader.get(getUrl());
|
||||
final Response response = downloader.get(
|
||||
baseUrl + PeertubeChannelLinkHandlerFactory.API_ENDPOINT + getId());
|
||||
if (response != null && response.responseBody() != null) {
|
||||
setInitialData(response.responseBody());
|
||||
} else {
|
||||
|
@ -140,13 +145,9 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
|
|||
if (json == null) throw new ExtractionException("Unable to extract PeerTube account data");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() throws ParsingException {
|
||||
return JsonUtils.getString(json, "displayName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalUrl() throws ParsingException {
|
||||
return baseUrl + "/" + getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
|
||||
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||
|
@ -20,6 +21,8 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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;
|
||||
|
@ -92,10 +95,11 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
return baseUrl + value;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
final String pageUrl = getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE;
|
||||
return getPage(new Page(pageUrl));
|
||||
return getPage(new Page(
|
||||
getUrl() + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,7 +134,8 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
|
||||
@Override
|
||||
public void onFetchPage(final Downloader downloader) throws IOException, ExtractionException {
|
||||
final Response response = downloader.get(getUrl());
|
||||
final Response response = downloader.get(
|
||||
baseUrl + PeertubeChannelLinkHandlerFactory.API_ENDPOINT + getId());
|
||||
if (response != null && response.responseBody() != null) {
|
||||
setInitialData(response.responseBody());
|
||||
} else {
|
||||
|
@ -147,13 +152,9 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
|
|||
if (json == null) throw new ExtractionException("Unable to extract PeerTube channel data");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() throws ParsingException {
|
||||
return JsonUtils.getString(json, "displayName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalUrl() throws ParsingException {
|
||||
return baseUrl + "/" + getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
|||
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.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.Description;
|
||||
import org.schabi.newpipe.extractor.stream.Stream;
|
||||
|
@ -83,7 +84,9 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
//if description is shortened, get full description
|
||||
final Downloader dl = NewPipe.getDownloader();
|
||||
try {
|
||||
final Response response = dl.get(getUrl() + "/description");
|
||||
final Response response = dl.get(baseUrl
|
||||
+ PeertubeStreamLinkHandlerFactory.VIDEO_API_ENDPOINT
|
||||
+ getId() + "/description");
|
||||
final JsonObject jsonObject = JsonParser.object().from(response.responseBody());
|
||||
text = JsonUtils.getString(jsonObject, "description");
|
||||
} catch (ReCaptchaException | IOException | JsonParserException e) {
|
||||
|
@ -338,7 +341,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
|
||||
@Override
|
||||
public void onFetchPage(final Downloader downloader) throws IOException, ExtractionException {
|
||||
final Response response = downloader.get(getUrl());
|
||||
final Response response = downloader.get(baseUrl + PeertubeStreamLinkHandlerFactory.VIDEO_API_ENDPOINT + getId());
|
||||
if (response != null && response.responseBody() != null) {
|
||||
setInitialData(response.responseBody());
|
||||
} else {
|
||||
|
@ -354,14 +357,18 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
} catch (JsonParserException e) {
|
||||
throw new ExtractionException("Unable to extract PeerTube stream data", e);
|
||||
}
|
||||
if (json == null) throw new ExtractionException("Unable to extract PeerTube stream data");
|
||||
if (json == null) {
|
||||
throw new ExtractionException("Unable to extract PeerTube stream data");
|
||||
}
|
||||
PeertubeParsingHelper.validate(json);
|
||||
}
|
||||
|
||||
private void loadSubtitles() {
|
||||
if (subtitles.isEmpty()) {
|
||||
try {
|
||||
final Response response = getDownloader().get(getUrl() + "/captions");
|
||||
final Response response = getDownloader().get(baseUrl
|
||||
+ PeertubeStreamLinkHandlerFactory.VIDEO_API_ENDPOINT
|
||||
+ getId() + "/captions");
|
||||
final JsonObject captionsJson = JsonParser.object().from(response.responseBody());
|
||||
final JsonArray captions = JsonUtils.getArray(captionsJson, "data");
|
||||
for (final Object c : captions) {
|
||||
|
@ -387,12 +394,6 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
|||
return JsonUtils.getString(json, "name");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getOriginalUrl() throws ParsingException {
|
||||
return baseUrl + "/videos/watch/" + getId();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getHost() throws ParsingException {
|
||||
|
|
|
@ -11,7 +11,7 @@ public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
|
||||
private static final PeertubeChannelLinkHandlerFactory instance = new PeertubeChannelLinkHandlerFactory();
|
||||
private static final String ID_PATTERN = "(accounts|video-channels)/([^/?&#]*)";
|
||||
private static final String API_ENDPOINT = "/api/v1/";
|
||||
public static final String API_ENDPOINT = "/api/v1/";
|
||||
|
||||
public static PeertubeChannelLinkHandlerFactory getInstance() {
|
||||
return instance;
|
||||
|
@ -31,12 +31,11 @@ public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
@Override
|
||||
public String getUrl(String id, List<String> contentFilter, String sortFilter, String baseUrl)
|
||||
throws ParsingException {
|
||||
|
||||
if (id.matches(ID_PATTERN)) {
|
||||
return baseUrl + API_ENDPOINT + id;
|
||||
return baseUrl + "/" + id;
|
||||
} else {
|
||||
// This is needed for compatibility with older versions were we didn't support video channels yet
|
||||
return baseUrl + API_ENDPOINT + "accounts/" + id;
|
||||
return baseUrl + "/accounts/" + id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
|
||||
private static final PeertubeStreamLinkHandlerFactory instance = new PeertubeStreamLinkHandlerFactory();
|
||||
private static final String ID_PATTERN = "/videos/(watch/|embed/)?([^/?&#]*)";
|
||||
private static final String VIDEO_ENDPOINT = "/api/v1/videos/";
|
||||
public static final String VIDEO_API_ENDPOINT = "/api/v1/videos/";
|
||||
private static final String VIDEO_PATH = "/videos/watch/";
|
||||
|
||||
private PeertubeStreamLinkHandlerFactory() {
|
||||
}
|
||||
|
@ -27,7 +28,7 @@ public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
|
||||
@Override
|
||||
public String getUrl(String id, String baseUrl) {
|
||||
return baseUrl + VIDEO_ENDPOINT + id;
|
||||
return baseUrl + VIDEO_PATH + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PeertubeAccountExtractorTest {
|
|||
// setting instance might break test when running in parallel
|
||||
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
|
||||
extractor = (PeertubeAccountExtractor) PeerTube
|
||||
.getChannelExtractor("https://peertube.mastodon.host/api/v1/accounts/kde");
|
||||
.getChannelExtractor("https://peertube.mastodon.host/accounts/kde");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class PeertubeAccountExtractorTest {
|
|||
|
||||
@Test
|
||||
public void testUrl() throws ParsingException {
|
||||
assertEquals("https://peertube.mastodon.host/api/v1/accounts/kde", extractor.getUrl());
|
||||
assertEquals("https://peertube.mastodon.host/accounts/kde", extractor.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -115,7 +115,7 @@ public class PeertubeAccountExtractorTest {
|
|||
// setting instance might break test when running in parallel
|
||||
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
|
||||
extractor = (PeertubeAccountExtractor) PeerTube
|
||||
.getChannelExtractor("https://peertube.mastodon.host/accounts/booteille");
|
||||
.getChannelExtractor("https://peertube.mastodon.host/api/v1/accounts/booteille");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
|
@ -150,12 +150,12 @@ public class PeertubeAccountExtractorTest {
|
|||
|
||||
@Test
|
||||
public void testUrl() throws ParsingException {
|
||||
assertEquals("https://peertube.mastodon.host/api/v1/accounts/booteille", extractor.getUrl());
|
||||
assertEquals("https://peertube.mastodon.host/accounts/booteille", extractor.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOriginalUrl() throws ParsingException {
|
||||
assertEquals("https://peertube.mastodon.host/accounts/booteille", extractor.getOriginalUrl());
|
||||
assertEquals("https://peertube.mastodon.host/api/v1/accounts/booteille", extractor.getOriginalUrl());
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -53,7 +53,7 @@ public class PeertubeChannelExtractorTest {
|
|||
|
||||
@Test
|
||||
public void testUrl() throws ParsingException {
|
||||
assertEquals("https://peertube.mastodon.host/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa", extractor.getUrl());
|
||||
assertEquals("https://peertube.mastodon.host/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa", extractor.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -130,7 +130,7 @@ public class PeertubeChannelExtractorTest {
|
|||
// setting instance might break test when running in parallel
|
||||
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
|
||||
extractor = (PeertubeChannelExtractor) PeerTube
|
||||
.getChannelExtractor("https://peertube.mastodon.host/video-channels/35080089-79b6-45fc-96ac-37e4d46a4457");
|
||||
.getChannelExtractor("https://peertube.mastodon.host/api/v1/video-channels/35080089-79b6-45fc-96ac-37e4d46a4457");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
|
@ -165,12 +165,12 @@ public class PeertubeChannelExtractorTest {
|
|||
|
||||
@Test
|
||||
public void testUrl() throws ParsingException {
|
||||
assertEquals("https://peertube.mastodon.host/api/v1/video-channels/35080089-79b6-45fc-96ac-37e4d46a4457", extractor.getUrl());
|
||||
assertEquals("https://peertube.mastodon.host/video-channels/35080089-79b6-45fc-96ac-37e4d46a4457", extractor.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOriginalUrl() throws ParsingException {
|
||||
assertEquals("https://peertube.mastodon.host/video-channels/35080089-79b6-45fc-96ac-37e4d46a4457", extractor.getOriginalUrl());
|
||||
assertEquals("https://peertube.mastodon.host/api/v1/video-channels/35080089-79b6-45fc-96ac-37e4d46a4457", extractor.getOriginalUrl());
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -53,7 +53,7 @@ public class PeertubeStreamExtractorTest {
|
|||
|
||||
@Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; }
|
||||
@Override public String expectedUploaderName() { return "Framasoft"; }
|
||||
@Override public String expectedUploaderUrl() { return "https://framatube.org/accounts/framasoft"; }
|
||||
@Override public String expectedUploaderUrl() { return "https://framatube.org/accounts/framasoft@framatube.org"; }
|
||||
@Override public List<String> expectedDescriptionContains() { // CRLF line ending
|
||||
return Arrays.asList("**[Want to help to translate this video?](https://weblate.framasoft.org/projects/what-is-peertube-video/)**\r\n"
|
||||
+ "\r\n"
|
||||
|
@ -108,7 +108,7 @@ public class PeertubeStreamExtractorTest {
|
|||
|
||||
@Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; }
|
||||
@Override public String expectedUploaderName() { return "Tomas Berezovskiy"; }
|
||||
@Override public String expectedUploaderUrl() { return "https://peertube.iriseden.eu/accounts/tomas_berezovskiy"; }
|
||||
@Override public String expectedUploaderUrl() { return "https://peertube.co.uk/accounts/tomas_berezovskiy@peertube.iriseden.eu"; }
|
||||
@Override public List<String> expectedDescriptionContains() { // LF line ending
|
||||
return Arrays.asList("https://en.informnapalm.org/dpr-combatant-describes-orders-given-russian-officers/ "
|
||||
+ " The InformNapalm team received another video of a separatist prisoner of war telling about his "
|
||||
|
|
Loading…
Reference in a new issue