make NewPipe compatible with latest Extractor refactorings

This commit is contained in:
Christian Schabesberger 2018-02-24 22:57:25 +01:00
parent 72a9940863
commit a42da09d6c
10 changed files with 46 additions and 45 deletions

View file

@ -55,7 +55,7 @@ dependencies {
exclude module: 'support-annotations' exclude module: 'support-annotations'
} }
implementation 'com.github.TeamNewPipe:NewPipeExtractor:7716b1437815' implementation 'com.github.TeamNewPipe:NewPipeExtractor:86db415b181'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19' testImplementation 'org.mockito:mockito-core:1.10.19'

View file

@ -19,7 +19,8 @@ import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer; import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListFragment<I, ListExtractor.NextItemsResult> { public abstract class BaseListInfoFragment<I extends ListInfo>
extends BaseListFragment<I, ListExtractor.InfoItemPage> {
@State @State
protected int serviceId = Constants.NO_SERVICE_ID; protected int serviceId = Constants.NO_SERVICE_ID;
@ -29,7 +30,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
protected String url; protected String url;
protected I currentInfo; protected I currentInfo;
protected String currentNextItemsUrl; protected String currentNextPageUrl;
protected Disposable currentWorker; protected Disposable currentWorker;
@Override @Override
@ -73,7 +74,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
public void writeTo(Queue<Object> objectsToSave) { public void writeTo(Queue<Object> objectsToSave) {
super.writeTo(objectsToSave); super.writeTo(objectsToSave);
objectsToSave.add(currentInfo); objectsToSave.add(currentInfo);
objectsToSave.add(currentNextItemsUrl); objectsToSave.add(currentNextPageUrl);
} }
@Override @Override
@ -81,7 +82,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
public void readFrom(@NonNull Queue<Object> savedObjects) throws Exception { public void readFrom(@NonNull Queue<Object> savedObjects) throws Exception {
super.readFrom(savedObjects); super.readFrom(savedObjects);
currentInfo = (I) savedObjects.poll(); currentInfo = (I) savedObjects.poll();
currentNextItemsUrl = (String) savedObjects.poll(); currentNextPageUrl = (String) savedObjects.poll();
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -116,7 +117,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
.subscribe((@NonNull I result) -> { .subscribe((@NonNull I result) -> {
isLoading.set(false); isLoading.set(false);
currentInfo = result; currentInfo = result;
currentNextItemsUrl = result.next_streams_url; currentNextPageUrl = result.next_streams_url;
handleResult(result); handleResult(result);
}, (@NonNull Throwable throwable) -> onError(throwable)); }, (@NonNull Throwable throwable) -> onError(throwable));
} }
@ -125,7 +126,7 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
* Implement the logic to load more items<br/> * Implement the logic to load more items<br/>
* You can use the default implementations from {@link org.schabi.newpipe.util.ExtractorHelper} * You can use the default implementations from {@link org.schabi.newpipe.util.ExtractorHelper}
*/ */
protected abstract Single<ListExtractor.NextItemsResult> loadMoreItemsLogic(); protected abstract Single<ListExtractor.InfoItemPage> loadMoreItemsLogic();
protected void loadMoreItems() { protected void loadMoreItems() {
isLoading.set(true); isLoading.set(true);
@ -134,9 +135,9 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
currentWorker = loadMoreItemsLogic() currentWorker = loadMoreItemsLogic()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe((@io.reactivex.annotations.NonNull ListExtractor.NextItemsResult nextItemsResult) -> { .subscribe((@io.reactivex.annotations.NonNull ListExtractor.InfoItemPage InfoItemPage) -> {
isLoading.set(false); isLoading.set(false);
handleNextItems(nextItemsResult); handleNextItems(InfoItemPage);
}, (@io.reactivex.annotations.NonNull Throwable throwable) -> { }, (@io.reactivex.annotations.NonNull Throwable throwable) -> {
isLoading.set(false); isLoading.set(false);
onError(throwable); onError(throwable);
@ -144,17 +145,17 @@ public abstract class BaseListInfoFragment<I extends ListInfo> extends BaseListF
} }
@Override @Override
public void handleNextItems(ListExtractor.NextItemsResult result) { public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result); super.handleNextItems(result);
currentNextItemsUrl = result.nextItemsUrl; currentNextPageUrl = result.nextPageUrl;
infoListAdapter.addInfoItemList(result.nextItemsList); infoListAdapter.addInfoItemList(result.infoItemList);
showListFooter(hasMoreItems()); showListFooter(hasMoreItems());
} }
@Override @Override
protected boolean hasMoreItems() { protected boolean hasMoreItems() {
return !TextUtils.isEmpty(currentNextItemsUrl); return !TextUtils.isEmpty(currentNextPageUrl);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////

View file

@ -388,8 +388,8 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
@Override @Override
protected Single<ListExtractor.NextItemsResult> loadMoreItemsLogic() { protected Single<ListExtractor.InfoItemPage> loadMoreItemsLogic() {
return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextItemsUrl); return ExtractorHelper.getMoreChannelItems(serviceId, url, currentNextPageUrl);
} }
@Override @Override
@ -464,14 +464,14 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
return new ChannelPlayQueue( return new ChannelPlayQueue(
currentInfo.getServiceId(), currentInfo.getServiceId(),
currentInfo.getUrl(), currentInfo.getUrl(),
currentInfo.getNextStreamsUrl(), currentInfo.getNextPageUrl(),
infoListAdapter.getItemsList(), infoListAdapter.getItemsList(),
index index
); );
} }
@Override @Override
public void handleNextItems(ListExtractor.NextItemsResult result) { public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result); super.handleNextItems(result);
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {

View file

@ -141,12 +141,12 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
} }
@Override @Override
public Single<ListExtractor.NextItemsResult> loadMoreItemsLogic() { public Single<ListExtractor.InfoItemPage> loadMoreItemsLogic() {
String contentCountry = PreferenceManager String contentCountry = PreferenceManager
.getDefaultSharedPreferences(activity) .getDefaultSharedPreferences(activity)
.getString(getString(R.string.content_country_key), .getString(getString(R.string.content_country_key),
getString(R.string.default_country_value)); getString(R.string.default_country_value));
return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextItemsUrl, contentCountry); return ExtractorHelper.getMoreKioskItems(serviceId, url, currentNextPageUrl, contentCountry);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -174,7 +174,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
} }
@Override @Override
public void handleNextItems(ListExtractor.NextItemsResult result) { public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result); super.handleNextItems(result);
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {

View file

@ -206,8 +206,8 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
@Override @Override
protected Single<ListExtractor.NextItemsResult> loadMoreItemsLogic() { protected Single<ListExtractor.InfoItemPage> loadMoreItemsLogic() {
return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextItemsUrl); return ExtractorHelper.getMorePlaylistItems(serviceId, url, currentNextPageUrl);
} }
@Override @Override
@ -300,14 +300,14 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
return new PlaylistPlayQueue( return new PlaylistPlayQueue(
currentInfo.getServiceId(), currentInfo.getServiceId(),
currentInfo.getUrl(), currentInfo.getUrl(),
currentInfo.getNextStreamsUrl(), currentInfo.getNextPageUrl(),
infoListAdapter.getItemsList(), infoListAdapter.getItemsList(),
index index
); );
} }
@Override @Override
public void handleNextItems(ListExtractor.NextItemsResult result) { public void handleNextItems(ListExtractor.InfoItemPage result) {
super.handleNextItems(result); super.handleNextItems(result);
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {

View file

@ -71,7 +71,7 @@ import io.reactivex.subjects.PublishSubject;
import static org.schabi.newpipe.util.AnimationUtils.animateView; import static org.schabi.newpipe.util.AnimationUtils.animateView;
public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor.NextItemsResult> implements BackPressable { public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor.InfoItemPage> implements BackPressable {
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Search // Search
@ -725,9 +725,9 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, searchQuery, currentNextPage, contentCountry, filter) searchDisposable = ExtractorHelper.getMoreSearchItems(serviceId, searchQuery, currentNextPage, contentCountry, filter)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ListExtractor.NextItemsResult>() { .subscribe(new Consumer<ListExtractor.InfoItemPage>() {
@Override @Override
public void accept(@NonNull ListExtractor.NextItemsResult result) throws Exception { public void accept(@NonNull ListExtractor.InfoItemPage result) throws Exception {
isLoading.set(false); isLoading.set(false);
handleNextItems(result); handleNextItems(result);
} }
@ -841,9 +841,9 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
} }
@Override @Override
public void handleNextItems(ListExtractor.NextItemsResult result) { public void handleNextItems(ListExtractor.InfoItemPage result) {
showListFooter(false); showListFooter(false);
currentPage = Integer.parseInt(result.getNextItemsUrl()); currentPage = Integer.parseInt(result.getNextPageUrl());
infoListAdapter.addInfoItemList(result.getNextItemsList()); infoListAdapter.addInfoItemList(result.getNextItemsList());
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {

View file

@ -83,8 +83,8 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
}; };
} }
SingleObserver<ListExtractor.NextItemsResult> getNextItemsObserver() { SingleObserver<ListExtractor.InfoItemPage> getNextPageObserver() {
return new SingleObserver<ListExtractor.NextItemsResult>() { return new SingleObserver<ListExtractor.InfoItemPage>() {
@Override @Override
public void onSubscribe(@NonNull Disposable d) { public void onSubscribe(@NonNull Disposable d) {
if (isComplete || isInitial || (fetchReactor != null && !fetchReactor.isDisposed())) { if (isComplete || isInitial || (fetchReactor != null && !fetchReactor.isDisposed())) {
@ -95,11 +95,11 @@ abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> ext
} }
@Override @Override
public void onSuccess(@NonNull ListExtractor.NextItemsResult result) { public void onSuccess(@NonNull ListExtractor.InfoItemPage result) {
if (!result.hasMoreStreams()) isComplete = true; if (!result.hasNextPage()) isComplete = true;
nextUrl = result.nextItemsUrl; nextUrl = result.nextPageUrl;
append(extractListItems(result.nextItemsList)); append(extractListItems(result.infoItemList));
fetchReactor.dispose(); fetchReactor.dispose();
fetchReactor = null; fetchReactor = null;

View file

@ -16,7 +16,7 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue<ChannelInfo, C
} }
public ChannelPlayQueue(final ChannelInfo info) { public ChannelPlayQueue(final ChannelInfo info) {
this(info.getServiceId(), info.getUrl(), info.getNextStreamsUrl(), info.getRelatedStreams(), 0); this(info.getServiceId(), info.getUrl(), info.getNextPageUrl(), info.getRelatedStreams(), 0);
} }
public ChannelPlayQueue(final int serviceId, public ChannelPlayQueue(final int serviceId,
@ -43,7 +43,7 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue<ChannelInfo, C
ExtractorHelper.getMoreChannelItems(this.serviceId, this.baseUrl, this.nextUrl) ExtractorHelper.getMoreChannelItems(this.serviceId, this.baseUrl, this.nextUrl)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(getNextItemsObserver()); .subscribe(getNextPageObserver());
} }
} }
} }

View file

@ -16,7 +16,7 @@ public final class PlaylistPlayQueue extends AbstractInfoPlayQueue<PlaylistInfo,
} }
public PlaylistPlayQueue(final PlaylistInfo info) { public PlaylistPlayQueue(final PlaylistInfo info) {
this(info.getServiceId(), info.getUrl(), info.getNextStreamsUrl(), info.getRelatedStreams(), 0); this(info.getServiceId(), info.getUrl(), info.getNextPageUrl(), info.getRelatedStreams(), 0);
} }
public PlaylistPlayQueue(final int serviceId, public PlaylistPlayQueue(final int serviceId,
@ -43,7 +43,7 @@ public final class PlaylistPlayQueue extends AbstractInfoPlayQueue<PlaylistInfo,
ExtractorHelper.getMorePlaylistItems(this.serviceId, this.baseUrl, this.nextUrl) ExtractorHelper.getMorePlaylistItems(this.serviceId, this.baseUrl, this.nextUrl)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(getNextItemsObserver()); .subscribe(getNextPageObserver());
} }
} }
} }

View file

@ -29,7 +29,7 @@ import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult; import org.schabi.newpipe.extractor.ListExtractor.InfoItemPage;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
@ -78,7 +78,7 @@ public final class ExtractorHelper {
); );
} }
public static Single<NextItemsResult> getMoreSearchItems(final int serviceId, public static Single<InfoItemPage> getMoreSearchItems(final int serviceId,
final String query, final String query,
final int nextPageNumber, final int nextPageNumber,
final String searchLanguage, final String searchLanguage,
@ -86,7 +86,7 @@ public final class ExtractorHelper {
checkServiceId(serviceId); checkServiceId(serviceId);
return searchFor(serviceId, query, nextPageNumber, searchLanguage, filter) return searchFor(serviceId, query, nextPageNumber, searchLanguage, filter)
.map((@NonNull SearchResult searchResult) -> .map((@NonNull SearchResult searchResult) ->
new NextItemsResult(searchResult.resultList, new InfoItemPage(searchResult.resultList,
nextPageNumber + "", nextPageNumber + "",
searchResult.errors)); searchResult.errors));
} }
@ -117,7 +117,7 @@ public final class ExtractorHelper {
ChannelInfo.getInfo(NewPipe.getService(serviceId), url))); ChannelInfo.getInfo(NewPipe.getService(serviceId), url)));
} }
public static Single<NextItemsResult> getMoreChannelItems(final int serviceId, public static Single<InfoItemPage> getMoreChannelItems(final int serviceId,
final String url, final String url,
final String nextStreamsUrl) { final String nextStreamsUrl) {
checkServiceId(serviceId); checkServiceId(serviceId);
@ -133,7 +133,7 @@ public final class ExtractorHelper {
PlaylistInfo.getInfo(NewPipe.getService(serviceId), url))); PlaylistInfo.getInfo(NewPipe.getService(serviceId), url)));
} }
public static Single<NextItemsResult> getMorePlaylistItems(final int serviceId, public static Single<InfoItemPage> getMorePlaylistItems(final int serviceId,
final String url, final String url,
final String nextStreamsUrl) { final String nextStreamsUrl) {
checkServiceId(serviceId); checkServiceId(serviceId);
@ -149,7 +149,7 @@ public final class ExtractorHelper {
KioskInfo.getInfo(NewPipe.getService(serviceId), url, contentCountry))); KioskInfo.getInfo(NewPipe.getService(serviceId), url, contentCountry)));
} }
public static Single<NextItemsResult> getMoreKioskItems(final int serviceId, public static Single<InfoItemPage> getMoreKioskItems(final int serviceId,
final String url, final String url,
final String nextStreamsUrl, final String nextStreamsUrl,
final String contentCountry) { final String contentCountry) {