From 7a30f4a7d2598549e9fcd5a8d75a04461c420609 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Sat, 30 May 2020 17:51:23 +0200 Subject: [PATCH 1/2] Remove calls to getNextStream() --- app/build.gradle | 2 +- .../fragments/detail/VideoDetailFragment.java | 4 -- .../list/videos/RelatedVideosFragment.java | 37 ++++++------------- .../newpipe/player/helper/PlayerHelper.java | 31 ++++++++-------- .../newpipe/util/RelatedStreamInfo.java | 16 -------- 5 files changed, 29 insertions(+), 61 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b77e6c986..94c7a2ce5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -163,7 +163,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:a70cb0283ffc3bba2709815673a5a7940aab0a3a' + implementation 'com.github.wb9688:NewPipeExtractor:70136e6a099d610d1fe6340549aa0542f7f26f1e' implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" implementation "org.jsoup:jsoup:1.13.1" diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index fff689930..b2f1709c2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -365,10 +365,6 @@ public class VideoDetailFragment extends BaseStateFragment public void onSaveInstanceState(final Bundle outState) { super.onSaveInstanceState(outState); - // Check if the next video label and video is visible, - // if it is, include the two elements in the next check - int nextCount = currentInfo != null && currentInfo.getNextVideo() != null ? 2 : 0; - if (!isLoading.get() && currentInfo != null && isVisible()) { outState.putSerializable(INFO_KEY, currentInfo); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java index 5d48afd15..d66433fa8 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java @@ -9,7 +9,6 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.CompoundButton; import android.widget.Switch; import androidx.annotation.NonNull; @@ -40,9 +39,7 @@ public class RelatedVideosFragment extends BaseListInfoFragment PreferenceManager.getDefaultSharedPreferences(getContext()).edit() - .putBoolean(getString(R.string.auto_queue_key), b).apply(); - } - }); + .putBoolean(getString(R.string.auto_queue_key), b).apply()); return headerRootLayout; } else { return null; @@ -105,7 +92,7 @@ public class RelatedVideosFragment extends BaseListInfoFragment loadMoreItemsLogic() { - return Single.fromCallable(() -> ListExtractor.InfoItemsPage.emptyPage()); + return Single.fromCallable(ListExtractor.InfoItemsPage::emptyPage); } /*////////////////////////////////////////////////////////////////////////// @@ -216,8 +203,8 @@ public class RelatedVideosFragment extends BaseListInfoFragment - * This method detects and prevents cycle by naively checking if a - * candidate next video's url already exists in the existing items. + * This method detects and prevents cycles by naively checking + * if a candidate next video's url already exists in the existing items. *

*

- * To select the next video, {@link StreamInfo#getNextVideo()} is first - * checked. If it is nonnull and is not part of the existing items, then - * it will be used as the next video. Otherwise, an random item with - * non-repeating url will be selected from the {@link StreamInfo#getRelatedStreams()}. + * The first item in {@link StreamInfo#getRelatedStreams()} is checked first. + * If it is non-null and is not part of the existing items, it will be used as the next stream. + * Otherwise, a random item with non-repeating url will be selected + * from the {@link StreamInfo#getRelatedStreams()}. *

* * @param info currently playing stream @@ -152,27 +152,28 @@ public final class PlayerHelper { @Nullable public static PlayQueue autoQueueOf(@NonNull final StreamInfo info, @NonNull final List existingItems) { - Set urls = new HashSet<>(existingItems.size()); + final Set urls = new HashSet<>(existingItems.size()); for (final PlayQueueItem item : existingItems) { urls.add(item.getUrl()); } - final StreamInfoItem nextVideo = info.getNextVideo(); - if (nextVideo != null && !urls.contains(nextVideo.getUrl())) { - return getAutoQueuedSinglePlayQueue(nextVideo); - } - final List relatedItems = info.getRelatedStreams(); if (relatedItems == null) { return null; } - List autoQueueItems = new ArrayList<>(); + if (relatedItems.get(0) != null && relatedItems.get(0) instanceof StreamInfoItem + && !urls.contains(relatedItems.get(0).getUrl())) { + return getAutoQueuedSinglePlayQueue((StreamInfoItem) relatedItems.get(0)); + } + + final List autoQueueItems = new ArrayList<>(); for (final InfoItem item : info.getRelatedStreams()) { if (item instanceof StreamInfoItem && !urls.contains(item.getUrl())) { autoQueueItems.add((StreamInfoItem) item); } } + Collections.shuffle(autoQueueItems); return autoQueueItems.isEmpty() ? null : getAutoQueuedSinglePlayQueue(autoQueueItems.get(0)); diff --git a/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java b/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java index ce642da5e..fcd392d67 100644 --- a/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java +++ b/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java @@ -4,16 +4,12 @@ import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.stream.StreamInfo; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class RelatedStreamInfo extends ListInfo { - - private StreamInfoItem nextStream; - public RelatedStreamInfo(final int serviceId, final ListLinkHandler listUrlIdHandler, final String name) { super(serviceId, listUrlIdHandler, name); @@ -25,20 +21,8 @@ public class RelatedStreamInfo extends ListInfo { RelatedStreamInfo relatedStreamInfo = new RelatedStreamInfo( info.getServiceId(), handler, info.getName()); List streams = new ArrayList<>(); - if (info.getNextVideo() != null) { - streams.add(info.getNextVideo()); - } streams.addAll(info.getRelatedStreams()); relatedStreamInfo.setRelatedItems(streams); - relatedStreamInfo.setNextStream(info.getNextVideo()); return relatedStreamInfo; } - - public StreamInfoItem getNextStream() { - return nextStream; - } - - public void setNextStream(final StreamInfoItem nextStream) { - this.nextStream = nextStream; - } } From 4274827dbe4a814f2aa4cb2ffc8c4168f5a322a3 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Wed, 15 Jul 2020 18:52:36 +0200 Subject: [PATCH 2/2] Use relatedItems instead of info.getRelatedStreams() --- app/build.gradle | 2 +- .../newpipe/fragments/list/videos/RelatedVideosFragment.java | 2 +- .../java/org/schabi/newpipe/player/helper/PlayerHelper.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 94c7a2ce5..229871f59 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -163,7 +163,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.wb9688:NewPipeExtractor:70136e6a099d610d1fe6340549aa0542f7f26f1e' + implementation 'com.github.wb9688:NewPipeExtractor:fc3a63fec56c110d7f434ef4377b3eeb2b8bbefe' implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" implementation "org.jsoup:jsoup:1.13.1" diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java index d66433fa8..cf2101111 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java @@ -83,7 +83,7 @@ public class RelatedVideosFragment extends BaseListInfoFragment PreferenceManager.getDefaultSharedPreferences(getContext()).edit() - .putBoolean(getString(R.string.auto_queue_key), b).apply()); + .putBoolean(getString(R.string.auto_queue_key), b).apply()); return headerRootLayout; } else { return null; diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index da0e7403a..e63e56bf9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -168,7 +168,7 @@ public final class PlayerHelper { } final List autoQueueItems = new ArrayList<>(); - for (final InfoItem item : info.getRelatedStreams()) { + for (final InfoItem item : relatedItems) { if (item instanceof StreamInfoItem && !urls.contains(item.getUrl())) { autoQueueItems.add((StreamInfoItem) item); }