1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 11:02:35 +01: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 @Nullable
private Stream getAudioSource(@NonNull final StreamInfo info) { 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()) { if (!audioStreams.isEmpty()) {
final int index = ListHelper.getDefaultAudioFormat(context, audioStreams); final int index = ListHelper.getDefaultAudioFormat(context, audioStreams);
return getStreamForIndex(index, audioStreams); return getStreamForIndex(index, audioStreams);
} else { } else {
final List<VideoStream> videoStreams = getPlayableStreams(info.getVideoStreams()); final List<VideoStream> videoStreams = getPlayableStreams(
info.getVideoStreams(), info.getServiceId());
if (!videoStreams.isEmpty()) { if (!videoStreams.isEmpty()) {
final int index = ListHelper.getDefaultResolutionIndex(context, videoStreams); final int index = ListHelper.getDefaultResolutionIndex(context, videoStreams);
return getStreamForIndex(index, videoStreams); return getStreamForIndex(index, videoStreams);

View File

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

View File

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