From 57e7994c9e46d068ba53cb320c91c22ec24f76de Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 24 Oct 2020 21:17:58 +0200 Subject: [PATCH] Add some missing finals, nullables and comments --- .../extractors/MediaCCCParsingHelper.java | 4 ++-- .../extractors/MediaCCCStreamExtractor.java | 2 ++ .../extractors/PeertubeAccountExtractor.java | 6 +++-- .../extractors/PeertubeStreamExtractor.java | 22 ++++++++++++------- .../extractors/SoundcloudStreamExtractor.java | 2 ++ .../youtube/YoutubeParsingHelper.java | 4 ++-- .../extractors/YoutubeStreamExtractor.java | 5 ++++- .../extractor/stream/StreamExtractor.java | 1 + .../services/DefaultStreamExtractorTest.java | 3 +++ 9 files changed, 34 insertions(+), 15 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java index dfdceeadc..14ca5c52c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java @@ -12,9 +12,9 @@ public final class MediaCCCParsingHelper { private MediaCCCParsingHelper() { } public static Calendar parseDateFrom(final String textualUploadDate) throws ParsingException { - Date date; + final Date date; try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); date = sdf.parse(textualUploadDate); } catch (ParseException e) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java index 92a049c55..96b1a5cc7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Locale; import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class MediaCCCStreamExtractor extends StreamExtractor { private JsonObject data; @@ -217,6 +218,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor { return StreamType.VIDEO_STREAM; } + @Nullable @Override public StreamInfoItemsCollector getRelatedStreams() { return null; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java index 9f04ffc27..b41bf2057 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java @@ -96,7 +96,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor { } @Override - public InfoItemsPage getPage(final Page page) throws IOException, ExtractionException { + public InfoItemsPage getPage(final Page page) + throws IOException, ExtractionException { if (page == null || isNullOrEmpty(page.getUrl())) { throw new IllegalArgumentException("Page doesn't contain an URL"); } @@ -126,7 +127,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor { } @Override - public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { + public void onFetchPage(@Nonnull final Downloader downloader) + throws IOException, ExtractionException { String accountUrl = baseUrl + PeertubeChannelLinkHandlerFactory.API_ENDPOINT; if (getId().contains("accounts/")) { accountUrl += getId(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java index 7e1861f76..fa02d473a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.Locale; import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class PeertubeStreamExtractor extends StreamExtractor { private final String baseUrl; @@ -113,7 +114,7 @@ public class PeertubeStreamExtractor extends StreamExtractor { @Override public long getTimeStamp() throws ParsingException { - long timestamp = + final long timestamp = getTimestampSeconds("((#|&|\\?)start=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)"); if (timestamp == -2) { @@ -261,19 +262,24 @@ public class PeertubeStreamExtractor extends StreamExtractor { return StreamType.VIDEO_STREAM; } + @Nullable @Override public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { - final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); final List tags = getTags(); final String apiUrl; - if (!tags.isEmpty()) { - apiUrl = getRelatedStreamsUrl(tags); - - } else { + if (tags.isEmpty()) { apiUrl = getUploaderUrl() + "/videos?start=0&count=8"; + } else { + apiUrl = getRelatedStreamsUrl(tags); + } + + if (Utils.isBlank(apiUrl)) { + return null; + } else { + final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); + getStreamsFromApi(collector, apiUrl); + return collector; } - if (!Utils.isBlank(apiUrl)) getStreamsFromApi(collector, apiUrl); - return collector; } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java index c545ea805..bc1d59026 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.Locale; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; @@ -262,6 +263,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { return StreamType.AUDIO_STREAM; } + @Nullable @Override public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index cefab49d5..ac7db9855 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -183,9 +183,9 @@ public class YoutubeParsingHelper { } public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException { - Date date; + final Date date; try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); date = sdf.parse(textualUploadDate); } catch (ParseException e) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 8ae88c392..0077a163e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -576,11 +576,14 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } + @Nullable @Override public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException { assertPageFetched(); - if (getAgeLimit() != NO_AGE_LIMIT) return null; + if (getAgeLimit() != NO_AGE_LIMIT) { + return null; + } try { final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index f48bb913f..4e109bbab 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -321,6 +321,7 @@ public abstract class StreamExtractor extends Extractor { * @throws IOException * @throws ExtractionException */ + @Nullable public abstract StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException; /** diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java index 8ab642d93..a70b38a8a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java @@ -249,6 +249,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest