Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
Expand All @@ -53,6 +55,7 @@
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
import org.schabi.newpipe.util.text.TextLinkifier;

import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -194,7 +197,17 @@ public static Single<KioskInfo> getKioskInfo(final int serviceId,
final String url,
final boolean forceLoad) {
return checkCache(forceLoad, serviceId, url, InfoCache.Type.KIOSK,
Single.fromCallable(() -> KioskInfo.getInfo(NewPipe.getService(serviceId), url)));
Single.fromCallable(() -> {
try {
return KioskInfo.getInfo(NewPipe.getService(serviceId), url);
} catch (final Exception e) {
if (e.getMessage() != null
&& e.getMessage().contains("Could not get channel name")) {
return getKioskInfoFallback(serviceId, url);
}
throw e;
}
}));
}

public static Single<InfoItemsPage<StreamInfoItem>> getMoreKioskItems(final int serviceId,
Expand All @@ -204,6 +217,33 @@ public static Single<InfoItemsPage<StreamInfoItem>> getMoreKioskItems(final int
KioskInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this have fallback code as well? Might fail when scrolling down otherwise


private static KioskInfo getKioskInfoFallback(final int serviceId, final String url)
throws Exception {
final StreamingService service = NewPipe.getService(serviceId);
final KioskExtractor extractor = service.getKioskList().getExtractorByUrl(url, null);
extractor.fetchPage();

String name;
try {
name = extractor.getName();
} catch (final Exception ignored) {
name = extractor.getId();
}

final Constructor<KioskInfo> constructor = KioskInfo.class
.getDeclaredConstructor(int.class, ListLinkHandler.class, String.class);
constructor.setAccessible(true);
final KioskInfo info = constructor.newInstance(extractor.getServiceId(),
extractor.getLinkHandler(), name);
Comment on lines +233 to +237
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We control the library, I’d avoid the reflection


final org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage<StreamInfoItem> itemsPage =
org.schabi.newpipe.extractor.utils.ExtractorHelper
.getItemsPageOrLogError(info, extractor);
info.setRelatedItems(itemsPage.getItems());
info.setNextPage(itemsPage.getNextPage());
return info;
}

/*//////////////////////////////////////////////////////////////////////////
// Cache
//////////////////////////////////////////////////////////////////////////*/
Expand Down