File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,9 +12,9 @@ public final class MediaCCCParsingHelper {
1212 private MediaCCCParsingHelper () { }
1313
1414 public static Calendar parseDateFrom (final String textualUploadDate ) throws ParsingException {
15- Date date ;
15+ final Date date ;
1616 try {
17- SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" );
17+ final SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" );
1818 sdf .setTimeZone (TimeZone .getTimeZone ("GMT" ));
1919 date = sdf .parse (textualUploadDate );
2020 } catch (ParseException e ) {
Original file line number Diff line number Diff line change 3030import java .util .Locale ;
3131
3232import javax .annotation .Nonnull ;
33+ import javax .annotation .Nullable ;
3334
3435public class MediaCCCStreamExtractor extends StreamExtractor {
3536 private JsonObject data ;
@@ -217,6 +218,7 @@ public StreamType getStreamType() {
217218 return StreamType .VIDEO_STREAM ;
218219 }
219220
221+ @ Nullable
220222 @ Override
221223 public StreamInfoItemsCollector getRelatedStreams () {
222224 return null ;
Original file line number Diff line number Diff line change @@ -96,7 +96,8 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, Extrac
9696 }
9797
9898 @ Override
99- public InfoItemsPage <StreamInfoItem > getPage (final Page page ) throws IOException , ExtractionException {
99+ public InfoItemsPage <StreamInfoItem > getPage (final Page page )
100+ throws IOException , ExtractionException {
100101 if (page == null || isNullOrEmpty (page .getUrl ())) {
101102 throw new IllegalArgumentException ("Page doesn't contain an URL" );
102103 }
@@ -126,7 +127,8 @@ public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException
126127 }
127128
128129 @ Override
129- public void onFetchPage (@ Nonnull Downloader downloader ) throws IOException , ExtractionException {
130+ public void onFetchPage (@ Nonnull final Downloader downloader )
131+ throws IOException , ExtractionException {
130132 String accountUrl = baseUrl + PeertubeChannelLinkHandlerFactory .API_ENDPOINT ;
131133 if (getId ().contains ("accounts/" )) {
132134 accountUrl += getId ();
Original file line number Diff line number Diff line change 3838import java .util .Locale ;
3939
4040import javax .annotation .Nonnull ;
41+ import javax .annotation .Nullable ;
4142
4243public class PeertubeStreamExtractor extends StreamExtractor {
4344 private final String baseUrl ;
@@ -113,7 +114,7 @@ public long getLength() {
113114
114115 @ Override
115116 public long getTimeStamp () throws ParsingException {
116- long timestamp =
117+ final long timestamp =
117118 getTimestampSeconds ("((#|&|\\ ?)start=\\ d{0,3}h?\\ d{0,3}m?\\ d{1,3}s?)" );
118119
119120 if (timestamp == -2 ) {
@@ -261,19 +262,24 @@ public StreamType getStreamType() {
261262 return StreamType .VIDEO_STREAM ;
262263 }
263264
265+ @ Nullable
264266 @ Override
265267 public StreamInfoItemsCollector getRelatedStreams () throws IOException , ExtractionException {
266- final StreamInfoItemsCollector collector = new StreamInfoItemsCollector (getServiceId ());
267268 final List <String > tags = getTags ();
268269 final String apiUrl ;
269- if (!tags .isEmpty ()) {
270+ if (tags .isEmpty ()) {
271+ apiUrl = getUploaderUrl () + "/videos?start=0&count=8" ;
272+ } else {
270273 apiUrl = getRelatedStreamsUrl (tags );
274+ }
271275
276+ if (Utils .isBlank (apiUrl )) {
277+ return null ;
272278 } else {
273- apiUrl = getUploaderUrl () + "/videos?start=0&count=8" ;
279+ final StreamInfoItemsCollector collector = new StreamInfoItemsCollector (getServiceId ());
280+ getStreamsFromApi (collector , apiUrl );
281+ return collector ;
274282 }
275- if (!Utils .isBlank (apiUrl )) getStreamsFromApi (collector , apiUrl );
276- return collector ;
277283 }
278284
279285 @ Nonnull
Original file line number Diff line number Diff line change 3333import java .util .Locale ;
3434
3535import javax .annotation .Nonnull ;
36+ import javax .annotation .Nullable ;
3637
3738import static org .schabi .newpipe .extractor .utils .JsonUtils .EMPTY_STRING ;
3839import static org .schabi .newpipe .extractor .utils .Utils .isNullOrEmpty ;
@@ -262,6 +263,7 @@ public StreamType getStreamType() {
262263 return StreamType .AUDIO_STREAM ;
263264 }
264265
266+ @ Nullable
265267 @ Override
266268 public StreamInfoItemsCollector getRelatedStreams () throws IOException , ExtractionException {
267269 final StreamInfoItemsCollector collector = new StreamInfoItemsCollector (getServiceId ());
Original file line number Diff line number Diff line change @@ -183,9 +183,9 @@ public static String getFeedUrlFrom(final String channelIdOrUser) {
183183 }
184184
185185 public static Calendar parseDateFrom (String textualUploadDate ) throws ParsingException {
186- Date date ;
186+ final Date date ;
187187 try {
188- SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" );
188+ final SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" );
189189 sdf .setTimeZone (TimeZone .getTimeZone ("GMT" ));
190190 date = sdf .parse (textualUploadDate );
191191 } catch (ParseException e ) {
Original file line number Diff line number Diff line change @@ -576,11 +576,14 @@ private StreamInfoItemExtractor getNextStream() throws ExtractionException {
576576 }
577577 }
578578
579+ @ Nullable
579580 @ Override
580581 public StreamInfoItemsCollector getRelatedStreams () throws ExtractionException {
581582 assertPageFetched ();
582583
583- if (getAgeLimit () != NO_AGE_LIMIT ) return null ;
584+ if (getAgeLimit () != NO_AGE_LIMIT ) {
585+ return null ;
586+ }
584587
585588 try {
586589 final StreamInfoItemsCollector collector = new StreamInfoItemsCollector (getServiceId ());
Original file line number Diff line number Diff line change @@ -321,6 +321,7 @@ public StreamExtractor(StreamingService service, LinkHandler linkHandler) {
321321 * @throws IOException
322322 * @throws ExtractionException
323323 */
324+ @ Nullable
324325 public abstract StreamInfoItemsCollector getRelatedStreams () throws IOException , ExtractionException ;
325326
326327 /**
Original file line number Diff line number Diff line change @@ -249,6 +249,7 @@ public void testVideoStreams() throws Exception {
249249 assertFalse (stream .getResolution ().isEmpty ());
250250
251251 final int formatId = stream .getFormatId ();
252+ // see MediaFormat: video stream formats range from 0 to 0x100
252253 assertTrue ("format id does not fit a video stream: " + formatId ,
253254 0 <= formatId && formatId < 0x100 );
254255 }
@@ -270,6 +271,7 @@ public void testAudioStreams() throws Exception {
270271 assertIsSecureUrl (stream .getUrl ());
271272
272273 final int formatId = stream .getFormatId ();
274+ // see MediaFormat: video stream formats range from 0x100 to 0x1000
273275 assertTrue ("format id does not fit an audio stream: " + formatId ,
274276 0x100 <= formatId && formatId < 0x1000 );
275277 }
@@ -291,6 +293,7 @@ public void testSubtitles() throws Exception {
291293 assertIsSecureUrl (stream .getUrl ());
292294
293295 final int formatId = stream .getFormatId ();
296+ // see MediaFormat: video stream formats range from 0x1000 to 0x10000
294297 assertTrue ("format id does not fit a subtitles stream: " + formatId ,
295298 0x1000 <= formatId && formatId < 0x10000 );
296299 }
You can’t perform that action at this time.
0 commit comments