-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
373 additions
and
30 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
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
17 changes: 17 additions & 0 deletions
17
extractor/src/main/java/org/schabi/newpipe/extractor/feed/FeedExtractor.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,17 @@ | ||
package org.schabi.newpipe.extractor.feed; | ||
|
||
import org.schabi.newpipe.extractor.ListExtractor; | ||
import org.schabi.newpipe.extractor.StreamingService; | ||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; | ||
import org.schabi.newpipe.extractor.stream.StreamInfoItem; | ||
|
||
/** | ||
* This class helps to extract items from lightweight feeds that the services may provide. | ||
* <p> | ||
* YouTube is an example of a service that has this alternative available. | ||
*/ | ||
public abstract class FeedExtractor extends ListExtractor<StreamInfoItem> { | ||
public FeedExtractor(StreamingService service, ListLinkHandler listLinkHandler) { | ||
super(service, listLinkHandler); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
extractor/src/main/java/org/schabi/newpipe/extractor/feed/FeedInfo.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,52 @@ | ||
package org.schabi.newpipe.extractor.feed; | ||
|
||
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; | ||
import org.schabi.newpipe.extractor.ListInfo; | ||
import org.schabi.newpipe.extractor.NewPipe; | ||
import org.schabi.newpipe.extractor.StreamingService; | ||
import org.schabi.newpipe.extractor.exceptions.ExtractionException; | ||
import org.schabi.newpipe.extractor.stream.StreamInfoItem; | ||
import org.schabi.newpipe.extractor.utils.ExtractorHelper; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class FeedInfo extends ListInfo<StreamInfoItem> { | ||
|
||
public FeedInfo(int serviceId, String id, String url, String originalUrl, String name, List<String> contentFilter, String sortFilter) { | ||
super(serviceId, id, url, originalUrl, name, contentFilter, sortFilter); | ||
} | ||
|
||
public static FeedInfo getInfo(String url) throws IOException, ExtractionException { | ||
return getInfo(NewPipe.getServiceByUrl(url), url); | ||
} | ||
|
||
public static FeedInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException { | ||
final FeedExtractor extractor = service.getFeedExtractor(url); | ||
|
||
if (extractor == null) { | ||
throw new IllegalArgumentException("Service \"" + service.getServiceInfo().getName() + "\" doesn't support FeedExtractor."); | ||
} | ||
|
||
extractor.fetchPage(); | ||
return getInfo(extractor); | ||
} | ||
|
||
public static FeedInfo getInfo(FeedExtractor extractor) throws IOException, ExtractionException { | ||
extractor.fetchPage(); | ||
|
||
final int serviceId = extractor.getServiceId(); | ||
final String id = extractor.getId(); | ||
final String url = extractor.getUrl(); | ||
final String originalUrl = extractor.getOriginalUrl(); | ||
final String name = extractor.getName(); | ||
|
||
final FeedInfo info = new FeedInfo(serviceId, id, url, originalUrl, name, null, null); | ||
|
||
final InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor); | ||
info.setRelatedItems(itemsPage.getItems()); | ||
info.setNextPageUrl(itemsPage.getNextPageUrl()); | ||
|
||
return info; | ||
} | ||
} |
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
82 changes: 82 additions & 0 deletions
82
...n/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeFeedExtractor.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,82 @@ | ||
package org.schabi.newpipe.extractor.services.youtube.extractors; | ||
|
||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
import org.schabi.newpipe.extractor.ListExtractor; | ||
import org.schabi.newpipe.extractor.StreamingService; | ||
import org.schabi.newpipe.extractor.downloader.Downloader; | ||
import org.schabi.newpipe.extractor.downloader.Response; | ||
import org.schabi.newpipe.extractor.exceptions.ExtractionException; | ||
import org.schabi.newpipe.extractor.feed.FeedExtractor; | ||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; | ||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper; | ||
import org.schabi.newpipe.extractor.stream.StreamInfoItem; | ||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
|
||
public class YoutubeFeedExtractor extends FeedExtractor { | ||
public YoutubeFeedExtractor(StreamingService service, ListLinkHandler linkHandler) { | ||
super(service, linkHandler); | ||
} | ||
|
||
private Document document; | ||
|
||
@Override | ||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { | ||
final String channelIdOrUser = getLinkHandler().getId(); | ||
final String feedUrl = YoutubeParsingHelper.getFeedUrlFrom(channelIdOrUser); | ||
|
||
final Response response = downloader.get(feedUrl); | ||
document = Jsoup.parse(response.responseBody()); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ListExtractor.InfoItemsPage<StreamInfoItem> getInitialPage() { | ||
final Elements entries = document.select("feed > entry"); | ||
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); | ||
|
||
for (Element entryElement : entries) { | ||
collector.commit(new YoutubeFeedInfoItemExtractor(entryElement)); | ||
} | ||
|
||
return new InfoItemsPage<>(collector, null); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getId() { | ||
return document.getElementsByTag("yt:channelId").first().text(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getUrl() { | ||
return document.select("feed > author > uri").first().text(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getName() { | ||
return document.select("feed > author > name").first().text(); | ||
} | ||
|
||
@Override | ||
public String getNextPageUrl() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean hasNextPage() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.