-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1148 from Stypox/mediaccc-channel-tab-handler
[MediaCCC] Allow obtaining channel tab link handler
- Loading branch information
Showing
6 changed files
with
167 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...g/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCChannelTabExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.schabi.newpipe.extractor.services.media_ccc.extractors; | ||
|
||
import com.grack.nanojson.JsonObject; | ||
|
||
import org.schabi.newpipe.extractor.InfoItem; | ||
import org.schabi.newpipe.extractor.ListExtractor; | ||
import org.schabi.newpipe.extractor.MultiInfoItemsCollector; | ||
import org.schabi.newpipe.extractor.Page; | ||
import org.schabi.newpipe.extractor.StreamingService; | ||
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor; | ||
import org.schabi.newpipe.extractor.downloader.Downloader; | ||
import org.schabi.newpipe.extractor.exceptions.ExtractionException; | ||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; | ||
import org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems.MediaCCCStreamInfoItemExtractor; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* MediaCCC does not really have channel tabs, but rather a list of videos for each conference, | ||
* so this class just acts as a videos channel tab extractor. | ||
*/ | ||
public class MediaCCCChannelTabExtractor extends ChannelTabExtractor { | ||
@Nullable | ||
private JsonObject conferenceData; | ||
|
||
/** | ||
* @param conferenceData will be not-null if conference data has already been fetched by | ||
* {@link MediaCCCConferenceExtractor}. Otherwise, if this parameter is | ||
* {@code null}, conference data will be fetched anew. | ||
*/ | ||
public MediaCCCChannelTabExtractor(final StreamingService service, | ||
final ListLinkHandler linkHandler, | ||
@Nullable final JsonObject conferenceData) { | ||
super(service, linkHandler); | ||
this.conferenceData = conferenceData; | ||
} | ||
|
||
@Override | ||
public void onFetchPage(@Nonnull final Downloader downloader) | ||
throws ExtractionException, IOException { | ||
if (conferenceData == null) { | ||
// only fetch conference data if we don't have it already | ||
conferenceData = MediaCCCConferenceExtractor.fetchConferenceData(downloader, getId()); | ||
} | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ListExtractor.InfoItemsPage<InfoItem> getInitialPage() { | ||
final MultiInfoItemsCollector collector = | ||
new MultiInfoItemsCollector(getServiceId()); | ||
Objects.requireNonNull(conferenceData) // will surely be != null after onFetchPage | ||
.getArray("events") | ||
.stream() | ||
.filter(JsonObject.class::isInstance) | ||
.map(JsonObject.class::cast) | ||
.forEach(event -> collector.commit(new MediaCCCStreamInfoItemExtractor(event))); | ||
return new ListExtractor.InfoItemsPage<>(collector, null); | ||
} | ||
|
||
@Override | ||
public ListExtractor.InfoItemsPage<InfoItem> getPage(final Page page) { | ||
return ListExtractor.InfoItemsPage.emptyPage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCChannelTabExtractorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.schabi.newpipe.extractor.services.media_ccc; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.schabi.newpipe.downloader.DownloaderTestImpl; | ||
import org.schabi.newpipe.extractor.NewPipe; | ||
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor; | ||
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; | ||
|
||
/** | ||
* Test that it is possible to create and use a channel tab extractor ({@link | ||
* org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCChannelTabExtractor}) without | ||
* passing through the conference extractor | ||
*/ | ||
public class MediaCCCChannelTabExtractorTest { | ||
public static class CCCamp2023 { | ||
private static ChannelTabExtractor extractor; | ||
|
||
@BeforeAll | ||
public static void setUpClass() throws Exception { | ||
NewPipe.init(DownloaderTestImpl.getInstance()); | ||
extractor = MediaCCC.getChannelTabExtractorFromId("camp2023", ChannelTabs.VIDEOS); | ||
extractor.fetchPage(); | ||
} | ||
|
||
@Test | ||
void testName() { | ||
assertEquals(ChannelTabs.VIDEOS, extractor.getName()); | ||
} | ||
|
||
@Test | ||
void testGetUrl() throws Exception { | ||
assertEquals("https://media.ccc.de/c/camp2023", extractor.getUrl()); | ||
} | ||
|
||
@Test | ||
void testGetOriginalUrl() throws Exception { | ||
assertEquals("https://media.ccc.de/c/camp2023", extractor.getOriginalUrl()); | ||
} | ||
|
||
@Test | ||
void testGetInitalPage() throws Exception { | ||
assertEquals(177, extractor.getInitialPage().getItems().size()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters