Add tests and rename SoundcloudGoPlusException to SoundcloudGoPlusContentException
This commit is contained in:
parent
771bb1a2cb
commit
3925204658
|
@ -0,0 +1,11 @@
|
|||
package org.schabi.newpipe.extractor.exceptions;
|
||||
|
||||
public class SoundCloudGoPlusContentException extends ContentNotAvailableException {
|
||||
public SoundCloudGoPlusContentException() {
|
||||
super("This track is a SoundCloud Go+ track");
|
||||
}
|
||||
|
||||
public SoundCloudGoPlusContentException(Throwable cause) {
|
||||
super("This track is a SoundCloud Go+ track", cause);
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package org.schabi.newpipe.extractor.exceptions;
|
||||
|
||||
public class SoundCloudGoPlusException extends ContentNotAvailableException {
|
||||
public SoundCloudGoPlusException() {
|
||||
super("This track is a SoundCloud Go+ track");
|
||||
}
|
||||
|
||||
public SoundCloudGoPlusException(Throwable cause) {
|
||||
super("This track is a SoundCloud Go+ track", cause);
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
|
|||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusException;
|
||||
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
||||
|
@ -46,7 +46,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
|||
String policy = track.getString("policy", EMPTY_STRING);
|
||||
if (!policy.equals("ALLOW") && !policy.equals("MONETIZE")) {
|
||||
if (policy.equals("SNIP")) {
|
||||
throw new SoundCloudGoPlusException();
|
||||
throw new SoundCloudGoPlusContentException();
|
||||
}
|
||||
if (policy.equals("BLOCK")) {
|
||||
throw new GeographicRestrictionException("This track is not available in user's country");
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
|
||||
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
|
@ -16,12 +19,33 @@ import javax.annotation.Nullable;
|
|||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
public class SoundcloudStreamExtractorTest {
|
||||
private static final String SOUNDCLOUD = "https://soundcloud.com/";
|
||||
|
||||
public static class SoundcloudNotAvailable {
|
||||
@Test(expected = GeographicRestrictionException.class)
|
||||
public void geoRestrictedContent() throws Exception {
|
||||
final String id = "one-touch";
|
||||
final String uploader = "jessglynne";
|
||||
final String url = SOUNDCLOUD + uploader + "/" + id;
|
||||
final StreamExtractor extractor = SoundCloud.getStreamExtractor(url);
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test(expected = SoundCloudGoPlusContentException.class)
|
||||
public void goPlusContent() throws Exception {
|
||||
final String id = "places";
|
||||
final String uploader = "martinsolveig";
|
||||
final String url = SOUNDCLOUD + uploader + "/" + id;
|
||||
final StreamExtractor extractor = SoundCloud.getStreamExtractor(url);
|
||||
extractor.fetchPage();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CreativeCommonsPlaysWellWithOthers extends DefaultStreamExtractorTest {
|
||||
private static final String ID = "plays-well-with-others-ep-2-what-do-an-army-of-ants-and-an-online-encyclopedia-have-in-common";
|
||||
private static final String UPLOADER = "https://soundcloud.com/wearecc";
|
||||
private static final String UPLOADER = "wearecc";
|
||||
private static final int TIMESTAMP = 69;
|
||||
private static final String URL = UPLOADER + "/" + ID + "#t=" + TIMESTAMP;
|
||||
private static final String URL = SOUNDCLOUD + UPLOADER + "/" + ID + "#t=" + TIMESTAMP;
|
||||
private static StreamExtractor extractor;
|
||||
|
||||
@BeforeClass
|
||||
|
|
|
@ -8,7 +8,11 @@ import org.schabi.newpipe.extractor.MetaInfo;
|
|||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.PaidContentException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.exceptions.PrivateContentException;
|
||||
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
|
||||
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
||||
import org.schabi.newpipe.extractor.stream.Description;
|
||||
|
@ -59,6 +63,13 @@ public class YoutubeStreamExtractorDefaultTest {
|
|||
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable"));
|
||||
}
|
||||
|
||||
@Test(expected = GeographicRestrictionException.class)
|
||||
public void geoRestrictedContent() throws Exception {
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "_PL2HJKxnOM");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test(expected = ContentNotAvailableException.class)
|
||||
public void nonExistentFetch() throws Exception {
|
||||
final StreamExtractor extractor =
|
||||
|
@ -72,6 +83,27 @@ public class YoutubeStreamExtractorDefaultTest {
|
|||
YouTube.getStreamExtractor(BASE_URL + "INVALID_ID_INVALID_ID");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test(expected = PaidContentException.class)
|
||||
public void paidContent() throws Exception {
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "ayI2iBwGdxw");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test(expected = PrivateContentException.class)
|
||||
public void privateContent() throws Exception {
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "8VajtrESJzA");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test(expected = YoutubeMusicPremiumContentException.class)
|
||||
public void youtubeMusicPremiumContent() throws Exception {
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "sMJ8bRN2dak");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DescriptionTestPewdiepie extends DefaultStreamExtractorTest {
|
||||
|
|
Loading…
Reference in New Issue