From 62d36126ea30f7465651c5e9b7d1064e9dd251a9 Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Wed, 1 Sep 2021 00:55:56 +0100 Subject: [PATCH 01/10] Load full stream info when enqueuing a stream This commit calls getStreamInfo causing a full network fetch of stream info (I believe only if required) when adding a stream item to the queue. This should prevent UI issues of missing metadata when queueing videos that have been fast-loaded and are missing metadata. Fixes #7035 --- .../newpipe/util/StreamDialogEntry.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index ec51cc370..dc5852416 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.util; import android.content.Context; import android.net.Uri; +import android.util.Log; import android.widget.Toast; import androidx.fragment.app.Fragment; @@ -20,6 +21,7 @@ import java.util.Collections; import java.util.List; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; +import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.schedulers.Schedulers; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; @@ -60,11 +62,15 @@ public enum StreamDialogEntry { * Info: Add this entry within showStreamDialog. */ enqueue(R.string.enqueue_stream, (fragment, item) -> { - NavigationHelper.enqueueOnPlayer(fragment.getContext(), new SinglePlayQueue(item)); + fetchItemInfoIfSparse(item, + fullItem -> NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem) + ); }), enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> { - NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), new SinglePlayQueue(item)); + fetchItemInfoIfSparse(item, + fullItem -> NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem) + ); }), start_here_on_background(R.string.start_here_on_background, (fragment, item) -> @@ -203,4 +209,31 @@ public enum StreamDialogEntry { fragment.requireActivity().getSupportFragmentManager(), item.getServiceId(), uploaderUrl, item.getUploaderName()); } + + ///////////////////////////////////////////// + // helper functions // + ///////////////////////////////////////////// + + private interface InfoCallback { + void onInfo(SinglePlayQueue item); + } + + private static void fetchItemInfoIfSparse(final StreamInfoItem item, + final InfoCallback callback) { + if (item.getDuration() < 0) { + // Sparse item: fetched by fast fetch + final Disposable currentWorker = ExtractorHelper.getStreamInfo( + item.getServiceId(), + item.getUrl(), + false + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { + callback.onInfo(new SinglePlayQueue(result)); + }, throwable -> Log.e("StreamDialogEntry", throwable.toString())); + } else { + callback.onInfo(new SinglePlayQueue(item)); + } + } } From bc2f0f9f3ee9c2adcbf75cf576bdf47e833de41f Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Thu, 28 Oct 2021 01:11:53 +0100 Subject: [PATCH 02/10] Update stream state in database after loading --- .../schabi/newpipe/local/feed/FeedFragment.kt | 5 +++++ .../newpipe/util/StreamDialogEntry.java | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index b3619276d..1b00d20ea 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -159,6 +159,11 @@ class FeedFragment : BaseStateFragment() { } } + // TODO: Move + fun redrawContent() { + groupAdapter.notifyItemRangeChanged(0, Int.MAX_VALUE) + } + fun setupListViewMode() { // does everything needed to setup the layouts for grid or list modes groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountStreams(context) else 1 diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index dc5852416..321c744b7 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -62,13 +62,13 @@ public enum StreamDialogEntry { * Info: Add this entry within showStreamDialog. */ enqueue(R.string.enqueue_stream, (fragment, item) -> { - fetchItemInfoIfSparse(item, + fetchItemInfoIfSparse(fragment, item, fullItem -> NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem) ); }), enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> { - fetchItemInfoIfSparse(item, + fetchItemInfoIfSparse(fragment, item, fullItem -> NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem) ); }), @@ -218,8 +218,9 @@ public enum StreamDialogEntry { void onInfo(SinglePlayQueue item); } - private static void fetchItemInfoIfSparse(final StreamInfoItem item, - final InfoCallback callback) { + private static void fetchItemInfoIfSparse(final Fragment fragment, + final StreamInfoItem item, + final InfoCallback callback) { if (item.getDuration() < 0) { // Sparse item: fetched by fast fetch final Disposable currentWorker = ExtractorHelper.getStreamInfo( @@ -227,9 +228,19 @@ public enum StreamDialogEntry { item.getUrl(), false ) + .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { + final HistoryRecordManager recordManager = + new HistoryRecordManager(fragment.getContext()); + recordManager.saveStreamState(result, 0) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnError(throwable -> Log.e("StreamDialogEntry", + throwable.toString())) + .subscribe(); + callback.onInfo(new SinglePlayQueue(result)); }, throwable -> Log.e("StreamDialogEntry", throwable.toString())); } else { From 91611fcae43d8cbec91344f7231ef48ddb84be55 Mon Sep 17 00:00:00 2001 From: Tom <25043847+Douile@users.noreply.github.com> Date: Tue, 23 Nov 2021 15:22:11 +0000 Subject: [PATCH 03/10] Don't fetch uneeded stream info for live streams Co-authored-by: Stypox --- .../main/java/org/schabi/newpipe/util/StreamDialogEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 321c744b7..1667ed649 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -221,7 +221,7 @@ public enum StreamDialogEntry { private static void fetchItemInfoIfSparse(final Fragment fragment, final StreamInfoItem item, final InfoCallback callback) { - if (item.getDuration() < 0) { + if ((item.getStreamType() == StreamType.LIVE_STREAM || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) && item.getDuration() < 0) { // Sparse item: fetched by fast fetch final Disposable currentWorker = ExtractorHelper.getStreamInfo( item.getServiceId(), From 6472e9b6b67f3bb431bf11b547bdb9b70355d0d4 Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Fri, 3 Dec 2021 21:29:34 +0000 Subject: [PATCH 04/10] Remove unused code --- .../main/java/org/schabi/newpipe/local/feed/FeedFragment.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 1b00d20ea..b3619276d 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -159,11 +159,6 @@ class FeedFragment : BaseStateFragment() { } } - // TODO: Move - fun redrawContent() { - groupAdapter.notifyItemRangeChanged(0, Int.MAX_VALUE) - } - fun setupListViewMode() { // does everything needed to setup the layouts for grid or list modes groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountStreams(context) else 1 From 3d1a3606c977d5351e5cffd1d23d8110d02a455f Mon Sep 17 00:00:00 2001 From: Tom <25043847+Douile@users.noreply.github.com> Date: Fri, 3 Dec 2021 21:30:26 +0000 Subject: [PATCH 05/10] Remove unused variable Co-authored-by: Stypox --- .../main/java/org/schabi/newpipe/util/StreamDialogEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 1667ed649..60201d5a8 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -223,7 +223,7 @@ public enum StreamDialogEntry { final InfoCallback callback) { if ((item.getStreamType() == StreamType.LIVE_STREAM || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) && item.getDuration() < 0) { // Sparse item: fetched by fast fetch - final Disposable currentWorker = ExtractorHelper.getStreamInfo( + ExtractorHelper.getStreamInfo( item.getServiceId(), item.getUrl(), false From ec7de2a6dc075e7293dbcf95f2975fdafc1e2015 Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Fri, 3 Dec 2021 21:53:36 +0000 Subject: [PATCH 06/10] Fix StreamType check, missing import, and styling errors --- .../java/org/schabi/newpipe/util/StreamDialogEntry.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 60201d5a8..82701723b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -10,6 +10,7 @@ import androidx.fragment.app.Fragment; import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.dialog.PlaylistCreationDialog; import org.schabi.newpipe.local.history.HistoryRecordManager; @@ -21,7 +22,6 @@ import java.util.Collections; import java.util.List; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; -import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.schedulers.Schedulers; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; @@ -221,7 +221,9 @@ public enum StreamDialogEntry { private static void fetchItemInfoIfSparse(final Fragment fragment, final StreamInfoItem item, final InfoCallback callback) { - if ((item.getStreamType() == StreamType.LIVE_STREAM || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) && item.getDuration() < 0) { + if (!(item.getStreamType() == StreamType.LIVE_STREAM + || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) + && item.getDuration() < 0) { // Sparse item: fetched by fast fetch ExtractorHelper.getStreamInfo( item.getServiceId(), From 7cd3603bbb285db7730a2153c66b3a5ac1c49af1 Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Fri, 3 Dec 2021 22:38:03 +0000 Subject: [PATCH 07/10] Fetch sparse items when playing in background or popup --- .../newpipe/util/StreamDialogEntry.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 82701723b..ac05e3460 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -73,13 +73,20 @@ public enum StreamDialogEntry { ); }), - start_here_on_background(R.string.start_here_on_background, (fragment, item) -> - NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), - new SinglePlayQueue(item), true)), + start_here_on_background(R.string.start_here_on_background, (fragment, item) -> { + fetchItemInfoIfSparse(fragment, item, + fullItem -> { + NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), + fullItem, true); + }); + }), - start_here_on_popup(R.string.start_here_on_popup, (fragment, item) -> - NavigationHelper.playOnPopupPlayer(fragment.getContext(), - new SinglePlayQueue(item), true)), + start_here_on_popup(R.string.start_here_on_popup, (fragment, item) -> { + fetchItemInfoIfSparse(fragment, item, fullItem -> { + NavigationHelper.playOnPopupPlayer(fragment.getContext(), + fullItem, true); + }); + }), set_as_playlist_thumbnail(R.string.set_as_playlist_thumbnail, (fragment, item) -> { }), // has to be set manually From baee915db5beb1fa53170339416b3b344f5a0777 Mon Sep 17 00:00:00 2001 From: Tom <25043847+Douile@users.noreply.github.com> Date: Sun, 12 Dec 2021 12:51:01 +0000 Subject: [PATCH 08/10] Remove unecessary line Co-authored-by: Stypox --- app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index ac05e3460..8096ff21b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -237,7 +237,6 @@ public enum StreamDialogEntry { item.getUrl(), false ) - .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { From 3ff00ff50e6590a8a3b774cb5589eebf4549fee3 Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Sun, 12 Dec 2021 13:01:40 +0000 Subject: [PATCH 09/10] Fix lambda code formatting Co-authored-by: Stypox --- .../newpipe/util/StreamDialogEntry.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 8096ff21b..a0539e9a8 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -62,30 +62,23 @@ public enum StreamDialogEntry { * Info: Add this entry within showStreamDialog. */ enqueue(R.string.enqueue_stream, (fragment, item) -> { - fetchItemInfoIfSparse(fragment, item, - fullItem -> NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem) - ); + fetchItemInfoIfSparse(fragment, item, fullItem -> + NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem)); }), enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> { - fetchItemInfoIfSparse(fragment, item, - fullItem -> NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem) - ); + fetchItemInfoIfSparse(fragment, item, fullItem -> + NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem)); }), start_here_on_background(R.string.start_here_on_background, (fragment, item) -> { - fetchItemInfoIfSparse(fragment, item, - fullItem -> { - NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), - fullItem, true); - }); + fetchItemInfoIfSparse(fragment, item, fullItem -> + NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), fullItem, true)); }), start_here_on_popup(R.string.start_here_on_popup, (fragment, item) -> { - fetchItemInfoIfSparse(fragment, item, fullItem -> { - NavigationHelper.playOnPopupPlayer(fragment.getContext(), - fullItem, true); - }); + fetchItemInfoIfSparse(fragment, item, fullItem -> + NavigationHelper.playOnPopupPlayer(fragment.getContext(), fullItem, true)); }), set_as_playlist_thumbnail(R.string.set_as_playlist_thumbnail, (fragment, item) -> { From 064242d9626121e9c498ec19a7e4755efcc4c76b Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Mon, 3 Jan 2022 17:51:31 +0000 Subject: [PATCH 10/10] Remove unecessary interface InfoCallback Co-authored-by: Stypox Replace the unecessary callback interface InfoCallback in favour of the standard type Consumer --- .../org/schabi/newpipe/util/StreamDialogEntry.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index a0539e9a8..d87a011b4 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -20,6 +20,7 @@ import org.schabi.newpipe.util.external_communication.ShareUtils; import java.util.Collections; import java.util.List; +import java.util.function.Consumer; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.schedulers.Schedulers; @@ -214,13 +215,9 @@ public enum StreamDialogEntry { // helper functions // ///////////////////////////////////////////// - private interface InfoCallback { - void onInfo(SinglePlayQueue item); - } - private static void fetchItemInfoIfSparse(final Fragment fragment, final StreamInfoItem item, - final InfoCallback callback) { + final Consumer callback) { if (!(item.getStreamType() == StreamType.LIVE_STREAM || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) && item.getDuration() < 0) { @@ -242,10 +239,10 @@ public enum StreamDialogEntry { throwable.toString())) .subscribe(); - callback.onInfo(new SinglePlayQueue(result)); + callback.accept(new SinglePlayQueue(result)); }, throwable -> Log.e("StreamDialogEntry", throwable.toString())); } else { - callback.onInfo(new SinglePlayQueue(item)); + callback.accept(new SinglePlayQueue(item)); } } }