Skip to content

Commit

Permalink
Remove AV1 streams from stream list
Browse files Browse the repository at this point in the history
This commit extends the method which filters streams provided from the extractor to only return playable streams.
  • Loading branch information
TobiGr committed Feb 4, 2023
1 parent 1db1a00 commit 47d8cf4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ dependencies {
// name and the commit hash with the commit hash of the (pushed) commit you want to test
// This works thanks to JitPack: https://jitpack.io/
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:999fb7f812f8f39712dda88cf5ff4db3ee877fdc'
implementation 'com.github.FireMasterK :NewPipeExtractor:9ba960d57126c0b6aef7208852a67f13f7e88d40'
implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0'

/** Checkstyle **/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.schabi.newpipe.player.resolver;

import static org.schabi.newpipe.util.ListHelper.getNonTorrentStreams;
import static org.schabi.newpipe.util.ListHelper.getPlayableStreams;

import android.content.Context;
import android.util.Log;
Expand Down Expand Up @@ -68,12 +68,12 @@ public MediaSource resolve(@NonNull final StreamInfo info) {
*/
@Nullable
private Stream getAudioSource(@NonNull final StreamInfo info) {
final List<AudioStream> audioStreams = getNonTorrentStreams(info.getAudioStreams());
final List<AudioStream> audioStreams = getPlayableStreams(info.getAudioStreams());
if (!audioStreams.isEmpty()) {
final int index = ListHelper.getDefaultAudioFormat(context, audioStreams);
return getStreamForIndex(index, audioStreams);
} else {
final List<VideoStream> videoStreams = getNonTorrentStreams(info.getVideoStreams());
final List<VideoStream> videoStreams = getPlayableStreams(info.getVideoStreams());
if (!videoStreams.isEmpty()) {
final int index = ListHelper.getDefaultResolutionIndex(context, videoStreams);
return getStreamForIndex(index, videoStreams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import static com.google.android.exoplayer2.C.TIME_UNSET;
import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams;
import static org.schabi.newpipe.util.ListHelper.getNonTorrentStreams;
import static org.schabi.newpipe.util.ListHelper.getPlayableStreams;

public class VideoPlaybackResolver implements PlaybackResolver {
private static final String TAG = VideoPlaybackResolver.class.getSimpleName();
Expand Down Expand Up @@ -72,8 +72,8 @@ public MediaSource resolve(@NonNull final StreamInfo info) {

// Create video stream source
final List<VideoStream> videoStreamsList = ListHelper.getSortedStreamVideosList(context,
getNonTorrentStreams(info.getVideoStreams()),
getNonTorrentStreams(info.getVideoOnlyStreams()), false, true);
getPlayableStreams(info.getVideoStreams()),
getPlayableStreams(info.getVideoOnlyStreams()), false, true);
final int index;
if (videoStreamsList.isEmpty()) {
index = -1;
Expand All @@ -100,7 +100,7 @@ public MediaSource resolve(@NonNull final StreamInfo info) {
}

// Create optional audio stream source
final List<AudioStream> audioStreams = getNonTorrentStreams(info.getAudioStreams());
final List<AudioStream> audioStreams = getPlayableStreams(info.getAudioStreams());
final AudioStream audio = audioStreams.isEmpty() ? null : audioStreams.get(
ListHelper.getDefaultAudioFormat(context, audioStreams));

Expand Down
27 changes: 18 additions & 9 deletions app/src/main/java/org/schabi/newpipe/util/ListHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public final class ListHelper {
// Use a Set for better performance
private static final Set<String> HIGH_RESOLUTION_LIST = Set.of("1440p", "2160p");

// AV1 Itag IDs from 394 - 401. AV1 is not yet supported by NewPipe
private static final List<Integer> UNSUPPORTED_ITAG_IDS =
List.of(394, 395, 396, 397, 398, 399, 400, 401);

private ListHelper() { }

/**
Expand Down Expand Up @@ -121,7 +125,7 @@ public static int getDefaultAudioFormat(final Context context,
*/
@NonNull
public static <S extends Stream> List<S> getStreamsOfSpecifiedDelivery(
final List<S> streamList,
@Nullable final List<S> streamList,
final DeliveryMethod deliveryMethod) {
return getFilteredStreamList(streamList,
stream -> stream.getDeliveryMethod() == deliveryMethod);
Expand All @@ -136,23 +140,28 @@ public static <S extends Stream> List<S> getStreamsOfSpecifiedDelivery(
*/
@NonNull
public static <S extends Stream> List<S> getUrlAndNonTorrentStreams(
final List<S> streamList) {
@Nullable final List<S> streamList) {
return getFilteredStreamList(streamList,
stream -> stream.isUrl() && stream.getDeliveryMethod() != DeliveryMethod.TORRENT);
}

/**
* Return a {@link Stream} list which only contains non-torrent streams.
* Return a {@link Stream} list which only contains streams which can be played by the player.
* <br>
* Some formats are not supported. For more info, see {@link #UNSUPPORTED_ITAG_IDS}.
* Torrent streams are also removed.
*
* @param streamList the original stream list
* @param <S> the item type's class that extends {@link Stream}
* @return a stream list which only contains non-torrent streams
* @return a stream list which only contains streams that can be played the player
*/
@NonNull
public static <S extends Stream> List<S> getNonTorrentStreams(
final List<S> streamList) {
public static <S extends Stream> List<S> getPlayableStreams(
@Nullable final List<S> streamList) {
return getFilteredStreamList(streamList,
stream -> stream.getDeliveryMethod() != DeliveryMethod.TORRENT);
stream -> stream.getDeliveryMethod() != DeliveryMethod.TORRENT
&& (stream.getItagItem() == null
|| !UNSUPPORTED_ITAG_IDS.contains(stream.getItagItem().id)));
}

/**
Expand Down Expand Up @@ -199,7 +208,7 @@ public static List<VideoStream> getSortedStreamVideosList(
* @return a new stream list filtered using the given predicate
*/
private static <S extends Stream> List<S> getFilteredStreamList(
final List<S> streamList,
@Nullable final List<S> streamList,
final Predicate<S> streamListPredicate) {
if (streamList == null) {
return Collections.emptyList();
Expand All @@ -210,7 +219,7 @@ private static <S extends Stream> List<S> getFilteredStreamList(
.collect(Collectors.toList());
}

private static String computeDefaultResolution(final Context context, final int key,
private static String computeDefaultResolution(@NonNull final Context context, final int key,
final int value) {
final SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(context);
Expand Down

0 comments on commit 47d8cf4

Please sign in to comment.