From dd57e246b87359297deb338d9896605e00201908 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Wed, 15 Apr 2020 15:31:53 +0200 Subject: [PATCH 1/2] Use getNextPage() instead of getNextPageUrl() --- app/build.gradle | 2 +- .../fragments/list/BaseListInfoFragment.java | 13 ++++---- .../list/channel/ChannelFragment.java | 4 +-- .../list/comments/CommentsFragment.java | 2 +- .../list/kiosk/DefaultKioskFragment.java | 2 +- .../fragments/list/kiosk/KioskFragment.java | 2 +- .../list/playlist/PlaylistFragment.java | 4 +-- .../fragments/list/search/SearchFragment.java | 24 +++++++-------- .../playqueue/AbstractInfoPlayQueue.java | 13 ++++---- .../player/playqueue/ChannelPlayQueue.java | 9 +++--- .../player/playqueue/PlaylistPlayQueue.java | 9 +++--- .../schabi/newpipe/util/ExtractorHelper.java | 30 +++++++++---------- 12 files changed, 57 insertions(+), 57 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0c2c20357..e6c768cd3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -163,7 +163,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.TeamNewPipe:NewPipeExtractor:54d9e5a2f89d6d739dadb6c744efeaf981c85bef' + implementation 'com.github.wb9688:NewPipeExtractor:4890b2906f805ccfccc83be13d954ed2cb8fc4e5' 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/BaseListInfoFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java index aed7c4795..82b1d18ed 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java @@ -9,6 +9,7 @@ import androidx.annotation.NonNull; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListInfo; +import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.views.NewPipeRecyclerView; @@ -30,7 +31,7 @@ public abstract class BaseListInfoFragment protected String url; protected I currentInfo; - protected String currentNextPageUrl; + protected Page currentNextPage; protected Disposable currentWorker; @Override @@ -78,7 +79,7 @@ public abstract class BaseListInfoFragment public void writeTo(final Queue objectsToSave) { super.writeTo(objectsToSave); objectsToSave.add(currentInfo); - objectsToSave.add(currentNextPageUrl); + objectsToSave.add(currentNextPage); } @Override @@ -86,7 +87,7 @@ public abstract class BaseListInfoFragment public void readFrom(@NonNull final Queue savedObjects) throws Exception { super.readFrom(savedObjects); currentInfo = (I) savedObjects.poll(); - currentNextPageUrl = (String) savedObjects.poll(); + currentNextPage = (Page) savedObjects.poll(); } /*////////////////////////////////////////////////////////////////////////// @@ -130,7 +131,7 @@ public abstract class BaseListInfoFragment .subscribe((@NonNull I result) -> { isLoading.set(false); currentInfo = result; - currentNextPageUrl = result.getNextPageUrl(); + currentNextPage = result.getNextPage(); handleResult(result); }, (@NonNull Throwable throwable) -> onError(throwable)); } @@ -182,7 +183,7 @@ public abstract class BaseListInfoFragment @Override public void handleNextItems(final ListExtractor.InfoItemsPage result) { super.handleNextItems(result); - currentNextPageUrl = result.getNextPageUrl(); + currentNextPage = result.getNextPage(); infoListAdapter.addInfoItemList(result.getItems()); showListFooter(hasMoreItems()); @@ -190,7 +191,7 @@ public abstract class BaseListInfoFragment @Override protected boolean hasMoreItems() { - return !TextUtils.isEmpty(currentNextPageUrl); + return Page.isValid(currentNextPage); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index b88d375ff..330aa7b42 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -403,7 +403,7 @@ public class ChannelFragment extends BaseListInfoFragment @Override protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl); + return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPage); } @Override @@ -555,7 +555,7 @@ public class ChannelFragment extends BaseListInfoFragment } } return new ChannelPlayQueue(currentInfo.getServiceId(), currentInfo.getUrl(), - currentInfo.getNextPageUrl(), streamItems, index); + currentInfo.getNextPage(), streamItems, index); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java index d23293c8a..c8e18f610 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java @@ -71,7 +71,7 @@ public class CommentsFragment extends BaseListInfoFragment { @Override protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMoreCommentItems(serviceId, currentInfo, currentNextPageUrl); + return ExtractorHelper.getMoreCommentItems(serviceId, currentInfo, currentNextPage); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/DefaultKioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/DefaultKioskFragment.java index 0702553ad..4b758a9c0 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/DefaultKioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/DefaultKioskFragment.java @@ -44,7 +44,7 @@ public class DefaultKioskFragment extends KioskFragment { name = kioskTranslatedName; currentInfo = null; - currentNextPageUrl = null; + currentNextPage = null; } catch (ExtractionException e) { onUnrecoverableError(e, UserAction.REQUESTED_KIOSK, "none", "Loading default kiosk from selected service", 0); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index 21a7944ee..a9dc59951 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -150,7 +150,7 @@ public class KioskFragment extends BaseListInfoFragment { @Override public Single loadMoreItemsLogic() { - return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPageUrl); + return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPage); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 93df98c97..e2ec9c1f3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -229,7 +229,7 @@ public class PlaylistFragment extends BaseListInfoFragment { @Override protected Single loadMoreItemsLogic() { - return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl); + return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPage); } @Override @@ -349,7 +349,7 @@ public class PlaylistFragment extends BaseListInfoFragment { return new PlaylistPlayQueue( currentInfo.getServiceId(), currentInfo.getUrl(), - currentInfo.getNextPageUrl(), + currentInfo.getNextPage(), infoItems, index ); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 9bfead4f0..55f286b9d 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -37,6 +37,7 @@ import org.schabi.newpipe.database.history.model.SearchHistoryEntry; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.search.SearchExtractor; @@ -123,8 +124,7 @@ public class SearchFragment extends BaseListFragment menuItemToFilterName; private StreamingService service; - private String currentPageUrl; - private String nextPageUrl; + private Page nextPage; private String contentCountry; private boolean isSuggestionsEnabled = true; @@ -354,15 +354,13 @@ public class SearchFragment extends BaseListFragment objectsToSave) { super.writeTo(objectsToSave); - objectsToSave.add(currentPageUrl); - objectsToSave.add(nextPageUrl); + objectsToSave.add(nextPage); } @Override public void readFrom(@NonNull final Queue savedObjects) throws Exception { super.readFrom(savedObjects); - currentPageUrl = (String) savedObjects.poll(); - nextPageUrl = (String) savedObjects.poll(); + nextPage = (Page) savedObjects.poll(); } @Override @@ -845,7 +843,7 @@ public class SearchFragment extends BaseListFragment isLoading.set(false)) @@ -962,8 +960,7 @@ public class SearchFragment extends BaseListFragment ext final int serviceId; final String baseUrl; - String nextUrl; + Page nextPage; private transient Disposable fetchReactor; @@ -29,16 +30,16 @@ abstract class AbstractInfoPlayQueue ext this(item.getServiceId(), item.getUrl(), null, Collections.emptyList(), 0); } - AbstractInfoPlayQueue(final int serviceId, final String url, final String nextPageUrl, + AbstractInfoPlayQueue(final int serviceId, final String url, final Page nextPage, final List streams, final int index) { super(index, extractListItems(streams)); this.baseUrl = url; - this.nextUrl = nextPageUrl; + this.nextPage = nextPage; this.serviceId = serviceId; this.isInitial = streams.isEmpty(); - this.isComplete = !isInitial && (nextPageUrl == null || nextPageUrl.isEmpty()); + this.isComplete = !isInitial && !Page.isValid(nextPage); } protected abstract String getTag(); @@ -66,7 +67,7 @@ abstract class AbstractInfoPlayQueue ext if (!result.hasNextPage()) { isComplete = true; } - nextUrl = result.getNextPageUrl(); + nextPage = result.getNextPage(); append(extractListItems(result.getRelatedItems())); @@ -100,7 +101,7 @@ abstract class AbstractInfoPlayQueue ext if (!result.hasNextPage()) { isComplete = true; } - nextUrl = result.getNextPageUrl(); + nextPage = result.getNextPage(); append(extractListItems(result.getItems())); diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/ChannelPlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/ChannelPlayQueue.java index 5a2e34d31..9e0d2b694 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/ChannelPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/ChannelPlayQueue.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.player.playqueue; +import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; @@ -17,15 +18,15 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue streams, final int index) { - super(serviceId, url, nextPageUrl, streams, index); + super(serviceId, url, nextPage, streams, index); } @Override @@ -41,7 +42,7 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue streams, final int index) { - super(serviceId, url, nextPageUrl, streams, index); + super(serviceId, url, nextPage, streams, index); } @Override @@ -40,7 +41,7 @@ public final class PlaylistPlayQueue extends AbstractInfoPlayQueue contentFilter, final String sortFilter, - final String pageUrl) { + final Page page) { checkServiceId(serviceId); return Single.fromCallable(() -> SearchInfo.getMoreItems(NewPipe.getService(serviceId), NewPipe.getService(serviceId) .getSearchQHFactory() - .fromQuery(searchString, contentFilter, sortFilter), - pageUrl)); + .fromQuery(searchString, contentFilter, sortFilter), page)); } @@ -125,10 +125,10 @@ public final class ExtractorHelper { } public static Single getMoreChannelItems(final int serviceId, final String url, - final String nextStreamsUrl) { + final Page nextPage) { checkServiceId(serviceId); return Single.fromCallable(() -> - ChannelInfo.getMoreItems(NewPipe.getService(serviceId), url, nextStreamsUrl)); + ChannelInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage)); } public static Single> getFeedInfoFallbackToChannelInfo( @@ -157,10 +157,10 @@ public final class ExtractorHelper { public static Single getMoreCommentItems(final int serviceId, final CommentsInfo info, - final String nextPageUrl) { + final Page nextPage) { checkServiceId(serviceId); return Single.fromCallable(() -> - CommentsInfo.getMoreItems(NewPipe.getService(serviceId), info, nextPageUrl)); + CommentsInfo.getMoreItems(NewPipe.getService(serviceId), info, nextPage)); } public static Single getPlaylistInfo(final int serviceId, final String url, @@ -172,10 +172,10 @@ public final class ExtractorHelper { } public static Single getMorePlaylistItems(final int serviceId, final String url, - final String nextStreamsUrl) { + final Page nextPage) { checkServiceId(serviceId); return Single.fromCallable(() -> - PlaylistInfo.getMoreItems(NewPipe.getService(serviceId), url, nextStreamsUrl)); + PlaylistInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage)); } public static Single getKioskInfo(final int serviceId, final String url, @@ -184,12 +184,10 @@ public final class ExtractorHelper { Single.fromCallable(() -> KioskInfo.getInfo(NewPipe.getService(serviceId), url))); } - public static Single getMoreKioskItems(final int serviceId, - final String url, - final String nextStreamsUrl) { + public static Single getMoreKioskItems(final int serviceId, final String url, + final Page nextPage) { return Single.fromCallable(() -> - KioskInfo.getMoreItems(NewPipe.getService(serviceId), - url, nextStreamsUrl)); + KioskInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage)); } /*////////////////////////////////////////////////////////////////////////// @@ -240,8 +238,8 @@ public final class ExtractorHelper { * @param infoType the {@link InfoItem.InfoType} of the item * @return a {@link Single} that loads the item */ - public static Maybe loadFromCache(final int serviceId, final String url, - final InfoItem.InfoType infoType) { + private static Maybe loadFromCache(final int serviceId, final String url, + final InfoItem.InfoType infoType) { checkServiceId(serviceId); return Maybe.defer(() -> { //noinspection unchecked From e183fc6118826716def8e09d65721acf11fe89ac Mon Sep 17 00:00:00 2001 From: wb9688 Date: Tue, 7 Jul 2020 21:04:08 +0200 Subject: [PATCH 2/2] Bump NPE version --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index e6c768cd3..7fe72f1f1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -163,7 +163,7 @@ dependencies { exclude module: 'support-annotations' } - implementation 'com.github.wb9688:NewPipeExtractor:4890b2906f805ccfccc83be13d954ed2cb8fc4e5' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:a70cb0283ffc3bba2709815673a5a7940aab0a3a' implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" implementation "org.jsoup:jsoup:1.13.1"