Skip to content

Commit f9cc460

Browse files
committed
Handle missing channel name in kiosk
1 parent 8afb00d commit f9cc460

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
import org.schabi.newpipe.extractor.MetaInfo;
4141
import org.schabi.newpipe.extractor.NewPipe;
4242
import org.schabi.newpipe.extractor.Page;
43+
import org.schabi.newpipe.extractor.StreamingService;
4344
import org.schabi.newpipe.extractor.channel.ChannelInfo;
4445
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo;
4546
import org.schabi.newpipe.extractor.comments.CommentsInfo;
4647
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
48+
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
4749
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
4850
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
4951
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
@@ -53,6 +55,7 @@
5355
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
5456
import org.schabi.newpipe.util.text.TextLinkifier;
5557

58+
import java.lang.reflect.Constructor;
5659
import java.util.Collections;
5760
import java.util.List;
5861

@@ -194,7 +197,17 @@ public static Single<KioskInfo> getKioskInfo(final int serviceId,
194197
final String url,
195198
final boolean forceLoad) {
196199
return checkCache(forceLoad, serviceId, url, InfoCache.Type.KIOSK,
197-
Single.fromCallable(() -> KioskInfo.getInfo(NewPipe.getService(serviceId), url)));
200+
Single.fromCallable(() -> {
201+
try {
202+
return KioskInfo.getInfo(NewPipe.getService(serviceId), url);
203+
} catch (final Exception e) {
204+
if (e.getMessage() != null
205+
&& e.getMessage().contains("Could not get channel name")) {
206+
return getKioskInfoFallback(serviceId, url);
207+
}
208+
throw e;
209+
}
210+
}));
198211
}
199212

200213
public static Single<InfoItemsPage<StreamInfoItem>> getMoreKioskItems(final int serviceId,
@@ -204,6 +217,33 @@ public static Single<InfoItemsPage<StreamInfoItem>> getMoreKioskItems(final int
204217
KioskInfo.getMoreItems(NewPipe.getService(serviceId), url, nextPage));
205218
}
206219

220+
private static KioskInfo getKioskInfoFallback(final int serviceId, final String url)
221+
throws Exception {
222+
final StreamingService service = NewPipe.getService(serviceId);
223+
final KioskExtractor extractor = service.getKioskList().getExtractorByUrl(url, null);
224+
extractor.fetchPage();
225+
226+
String name;
227+
try {
228+
name = extractor.getName();
229+
} catch (final Exception ignored) {
230+
name = extractor.getId();
231+
}
232+
233+
final Constructor<KioskInfo> constructor = KioskInfo.class
234+
.getDeclaredConstructor(int.class, ListLinkHandler.class, String.class);
235+
constructor.setAccessible(true);
236+
final KioskInfo info = constructor.newInstance(extractor.getServiceId(),
237+
extractor.getLinkHandler(), name);
238+
239+
final org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage<StreamInfoItem> itemsPage =
240+
org.schabi.newpipe.extractor.utils.ExtractorHelper
241+
.getItemsPageOrLogError(info, extractor);
242+
info.setRelatedItems(itemsPage.getItems());
243+
info.setNextPage(itemsPage.getNextPage());
244+
return info;
245+
}
246+
207247
/*//////////////////////////////////////////////////////////////////////////
208248
// Cache
209249
//////////////////////////////////////////////////////////////////////////*/

0 commit comments

Comments
 (0)