package org.schabi.newpipe.extractor.utils; import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.InfoItemsCollector; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamInfo; import java.util.Collections; import java.util.List; public class ExtractorHelper { private ExtractorHelper() {} public static InfoItemsPage getItemsPageOrLogError(Info info, ListExtractor extractor) { try { InfoItemsPage page = extractor.getInitialPage(); info.addAllErrors(page.getErrors()); return page; } catch (Exception e) { info.addError(e); return InfoItemsPage.emptyPage(); } } public static List getRelatedVideosOrLogError(StreamInfo info, StreamExtractor extractor) { try { InfoItemsCollector collector = extractor.getRelatedVideos(); info.addAllErrors(collector.getErrors()); //noinspection unchecked return (List) collector.getItems(); } catch (Exception e) { info.addError(e); return Collections.emptyList(); } } }