1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 00:20:32 +00:00

Apply new itag filter only to YouTube streams

This commit is contained in:
TobiGr 2023-04-17 13:10:29 +02:00
parent f8c3ec4be7
commit e18a6b09f8
3 changed files with 16 additions and 8 deletions

View File

@ -68,12 +68,14 @@ public class AudioPlaybackResolver implements PlaybackResolver {
*/
@Nullable
private Stream getAudioSource(@NonNull final StreamInfo info) {
final List<AudioStream> audioStreams = getPlayableStreams(info.getAudioStreams());
final List<AudioStream> audioStreams = getPlayableStreams(
info.getAudioStreams(), info.getServiceId());
if (!audioStreams.isEmpty()) {
final int index = ListHelper.getDefaultAudioFormat(context, audioStreams);
return getStreamForIndex(index, audioStreams);
} else {
final List<VideoStream> videoStreams = getPlayableStreams(info.getVideoStreams());
final List<VideoStream> videoStreams = getPlayableStreams(
info.getVideoStreams(), info.getServiceId());
if (!videoStreams.isEmpty()) {
final int index = ListHelper.getDefaultResolutionIndex(context, videoStreams);
return getStreamForIndex(index, videoStreams);

View File

@ -72,8 +72,8 @@ public class VideoPlaybackResolver implements PlaybackResolver {
// Create video stream source
final List<VideoStream> videoStreamsList = ListHelper.getSortedStreamVideosList(context,
getPlayableStreams(info.getVideoStreams()),
getPlayableStreams(info.getVideoOnlyStreams()), false, true);
getPlayableStreams(info.getVideoStreams(), info.getServiceId()),
getPlayableStreams(info.getVideoOnlyStreams(), info.getServiceId()), false, true);
final int index;
if (videoStreamsList.isEmpty()) {
index = -1;
@ -100,7 +100,8 @@ public class VideoPlaybackResolver implements PlaybackResolver {
}
// Create optional audio stream source
final List<AudioStream> audioStreams = getPlayableStreams(info.getAudioStreams());
final List<AudioStream> audioStreams = getPlayableStreams(
info.getAudioStreams(), info.getServiceId());
final AudioStream audio = audioStreams.isEmpty() ? null : audioStreams.get(
ListHelper.getDefaultAudioFormat(context, audioStreams));

View File

@ -1,5 +1,7 @@
package org.schabi.newpipe.util;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
@ -162,16 +164,19 @@ public final class ListHelper {
* Some formats are not supported. For more info, see {@link #SUPPORTED_ITAG_IDS}.
* Torrent streams are also removed, because they cannot be retrieved.
*
* @param streamList the original stream list
* @param <S> the item type's class that extends {@link Stream}
* @param streamList the original stream list
* @param serviceId
* @return a stream list which only contains streams that can be played the player
*/
@NonNull
public static <S extends Stream> List<S> getPlayableStreams(
@Nullable final List<S> streamList) {
@Nullable final List<S> streamList, final int serviceId) {
final int youtubeServiceId = YouTube.getServiceId();
return getFilteredStreamList(streamList,
stream -> stream.getDeliveryMethod() != DeliveryMethod.TORRENT
&& (stream.getItagItem() == null
&& (serviceId != youtubeServiceId
|| stream.getItagItem() == null
|| SUPPORTED_ITAG_IDS.contains(stream.getItagItem().id)));
}