Fix wb9688 review comments

* Rename PeertubeUserExtractor to PeertubeAccountExtractor
* Add test for video-channels in PeertubeChannelLinkHandlerFactoryTest
* Compatibility support for older versions (use "accounts/" as default)
This commit is contained in:
Roy Yosef 2020-04-10 16:40:53 +03:00
parent b6e6f403a8
commit 2c9f1260eb
5 changed files with 22 additions and 13 deletions

View File

@ -78,9 +78,11 @@ public class PeertubeService extends StreamingService {
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler)
throws ExtractionException {
return linkHandler.getUrl().matches("^.*\\/accounts\\/[^\\/]*$") ?
new PeertubeUserExtractor(this, linkHandler) :
new PeertubeChannelExtractor(this, linkHandler);
if (linkHandler.getUrl().contains("/video-channels/")) {
return new PeertubeChannelExtractor(this, linkHandler);
} else {
return new PeertubeAccountExtractor(this, linkHandler);
}
}
@Override

View File

@ -21,7 +21,7 @@ import org.schabi.newpipe.extractor.utils.Parser.RegexException;
import java.io.IOException;
public class PeertubeUserExtractor extends ChannelExtractor {
public class PeertubeAccountExtractor extends ChannelExtractor {
private static final String START_KEY = "start";
private static final String COUNT_KEY = "count";
@ -34,7 +34,7 @@ public class PeertubeUserExtractor extends ChannelExtractor {
private JsonObject json;
private final String baseUrl;
public PeertubeUserExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException {
public PeertubeAccountExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException {
super(service, linkHandler);
this.baseUrl = getBaseUrl();
}

View File

@ -31,7 +31,13 @@ public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
@Override
public String getUrl(String id, List<String> contentFilter, String sortFilter, String baseUrl)
throws ParsingException {
return baseUrl + API_ENDPOINT + id;
if (id.matches(ID_PATTERN)) {
return baseUrl + API_ENDPOINT + id;
} else {
// This is needed for compatibility with older versions were we didn't support video channels yet
return baseUrl + API_ENDPOINT + "accounts/" + id;
}
}
@Override

View File

@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeUserExtractor;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeAccountExtractor;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
@ -16,18 +16,18 @@ import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
/**
* Test for {@link PeertubeUserExtractor}
* Test for {@link PeertubeAccountExtractor}
*/
public class PeertubeUserExtractorTest {
public class PeertubeAccountExtractorTest {
public static class KDE implements BaseChannelExtractorTest {
private static PeertubeUserExtractor extractor;
private static PeertubeAccountExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
// setting instance might break test when running in parallel
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
extractor = (PeertubeUserExtractor) PeerTube
extractor = (PeertubeAccountExtractor) PeerTube
.getChannelExtractor("https://peertube.mastodon.host/api/v1/accounts/kde");
extractor.fetchPage();
}
@ -107,14 +107,14 @@ public class PeertubeUserExtractorTest {
}
public static class Booteille implements BaseChannelExtractorTest {
private static PeertubeUserExtractor extractor;
private static PeertubeAccountExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
// setting instance might break test when running in parallel
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
extractor = (PeertubeUserExtractor) PeerTube
extractor = (PeertubeAccountExtractor) PeerTube
.getChannelExtractor("https://peertube.mastodon.host/accounts/booteille");
extractor.fetchPage();
}

View File

@ -32,5 +32,6 @@ public class PeertubeChannelLinkHandlerFactoryTest {
public void getIdFromUrl() throws ParsingException {
assertEquals("accounts/kranti@videos.squat.net", linkHandler.fromUrl("https://peertube.mastodon.host/accounts/kranti@videos.squat.net").getId());
assertEquals("accounts/kranti@videos.squat.net", linkHandler.fromUrl("https://peertube.mastodon.host/accounts/kranti@videos.squat.net/videos").getId());
assertEquals("video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa", linkHandler.fromUrl("https://peertube.mastodon.host/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa/videos").getId());
}
}