Add some missing finals, nullables and comments

This commit is contained in:
Stypox 2020-10-24 21:17:58 +02:00
parent f11fe87688
commit 57e7994c9e
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
9 changed files with 34 additions and 15 deletions

View File

@ -12,9 +12,9 @@ public final class MediaCCCParsingHelper {
private MediaCCCParsingHelper() { } private MediaCCCParsingHelper() { }
public static Calendar parseDateFrom(final String textualUploadDate) throws ParsingException { public static Calendar parseDateFrom(final String textualUploadDate) throws ParsingException {
Date date; final Date date;
try { try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
date = sdf.parse(textualUploadDate); date = sdf.parse(textualUploadDate);
} catch (ParseException e) { } catch (ParseException e) {

View File

@ -30,6 +30,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class MediaCCCStreamExtractor extends StreamExtractor { public class MediaCCCStreamExtractor extends StreamExtractor {
private JsonObject data; private JsonObject data;
@ -217,6 +218,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
return StreamType.VIDEO_STREAM; return StreamType.VIDEO_STREAM;
} }
@Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() { public StreamInfoItemsCollector getRelatedStreams() {
return null; return null;

View File

@ -96,7 +96,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
} }
@Override @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())) { if (page == null || isNullOrEmpty(page.getUrl())) {
throw new IllegalArgumentException("Page doesn't contain an URL"); throw new IllegalArgumentException("Page doesn't contain an URL");
} }
@ -126,7 +127,8 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
} }
@Override @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; String accountUrl = baseUrl + PeertubeChannelLinkHandlerFactory.API_ENDPOINT;
if (getId().contains("accounts/")) { if (getId().contains("accounts/")) {
accountUrl += getId(); accountUrl += getId();

View File

@ -38,6 +38,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class PeertubeStreamExtractor extends StreamExtractor { public class PeertubeStreamExtractor extends StreamExtractor {
private final String baseUrl; private final String baseUrl;
@ -113,7 +114,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
@Override @Override
public long getTimeStamp() throws ParsingException { public long getTimeStamp() throws ParsingException {
long timestamp = final long timestamp =
getTimestampSeconds("((#|&|\\?)start=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)"); getTimestampSeconds("((#|&|\\?)start=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)");
if (timestamp == -2) { if (timestamp == -2) {
@ -261,19 +262,24 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return StreamType.VIDEO_STREAM; return StreamType.VIDEO_STREAM;
} }
@Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
final List<String> tags = getTags(); final List<String> tags = getTags();
final String apiUrl; final String apiUrl;
if (!tags.isEmpty()) { if (tags.isEmpty()) {
apiUrl = getRelatedStreamsUrl(tags);
} else {
apiUrl = getUploaderUrl() + "/videos?start=0&count=8"; 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 @Nonnull

View File

@ -33,6 +33,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull; 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.JsonUtils.EMPTY_STRING;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
@ -262,6 +263,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
return StreamType.AUDIO_STREAM; return StreamType.AUDIO_STREAM;
} }
@Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());

View File

@ -183,9 +183,9 @@ public class YoutubeParsingHelper {
} }
public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException { public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException {
Date date; final Date date;
try { try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
date = sdf.parse(textualUploadDate); date = sdf.parse(textualUploadDate);
} catch (ParseException e) { } catch (ParseException e) {

View File

@ -576,11 +576,14 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} }
} }
@Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException { public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException {
assertPageFetched(); assertPageFetched();
if (getAgeLimit() != NO_AGE_LIMIT) return null; if (getAgeLimit() != NO_AGE_LIMIT) {
return null;
}
try { try {
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());

View File

@ -321,6 +321,7 @@ public abstract class StreamExtractor extends Extractor {
* @throws IOException * @throws IOException
* @throws ExtractionException * @throws ExtractionException
*/ */
@Nullable
public abstract StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException; public abstract StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException;
/** /**

View File

@ -249,6 +249,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
assertFalse(stream.getResolution().isEmpty()); assertFalse(stream.getResolution().isEmpty());
final int formatId = stream.getFormatId(); final int formatId = stream.getFormatId();
// see MediaFormat: video stream formats range from 0 to 0x100
assertTrue("format id does not fit a video stream: " + formatId, assertTrue("format id does not fit a video stream: " + formatId,
0 <= formatId && formatId < 0x100); 0 <= formatId && formatId < 0x100);
} }
@ -270,6 +271,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
assertIsSecureUrl(stream.getUrl()); assertIsSecureUrl(stream.getUrl());
final int formatId = stream.getFormatId(); final int formatId = stream.getFormatId();
// see MediaFormat: video stream formats range from 0x100 to 0x1000
assertTrue("format id does not fit an audio stream: " + formatId, assertTrue("format id does not fit an audio stream: " + formatId,
0x100 <= formatId && formatId < 0x1000); 0x100 <= formatId && formatId < 0x1000);
} }
@ -291,6 +293,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
assertIsSecureUrl(stream.getUrl()); assertIsSecureUrl(stream.getUrl());
final int formatId = stream.getFormatId(); final int formatId = stream.getFormatId();
// see MediaFormat: video stream formats range from 0x1000 to 0x10000
assertTrue("format id does not fit a subtitles stream: " + formatId, assertTrue("format id does not fit a subtitles stream: " + formatId,
0x1000 <= formatId && formatId < 0x10000); 0x1000 <= formatId && formatId < 0x10000);
} }