diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index 3cb6847de..0d8845fa4 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -38,6 +38,7 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSuggestio import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor; import org.schabi.newpipe.extractor.services.youtube.extractors.kiosk.YoutubeLiveExtractor; import org.schabi.newpipe.extractor.services.youtube.extractors.kiosk.YoutubeTrendingGamingVideosExtractor; +import org.schabi.newpipe.extractor.services.youtube.extractors.kiosk.YoutubeTrendingMoviesAndShowsTrailersExtractor; import org.schabi.newpipe.extractor.services.youtube.extractors.kiosk.YoutubeTrendingPodcastsEpisodesExtractor; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelTabLinkHandlerFactory; @@ -48,6 +49,7 @@ import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQu import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingGamingVideosLinkHandlerFactory; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingPodcastsEpisodesLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; @@ -167,6 +169,8 @@ public class YoutubeService extends StreamingService { YoutubeTrendingPodcastsEpisodesLinkHandlerFactory.INSTANCE; final ListLinkHandlerFactory trendingGamingVideosLHF = YoutubeTrendingGamingVideosLinkHandlerFactory.INSTANCE; + final ListLinkHandlerFactory trendingMoviesAndShowsLHF = + YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory.INSTANCE; try { list.addKioskEntry( @@ -193,6 +197,15 @@ public class YoutubeService extends StreamingService { trendingGamingVideosLHF, YoutubeTrendingGamingVideosLinkHandlerFactory.KIOSK_ID ); + list.addKioskEntry( + (streamingService, url, id) -> + new YoutubeTrendingMoviesAndShowsTrailersExtractor( + YoutubeService.this, + trendingMoviesAndShowsLHF.fromUrl(url), + id), + trendingMoviesAndShowsLHF, + YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory.KIOSK_ID + ); list.addKioskEntry( (streamingService, url, id) -> new YoutubeTrendingExtractor( YoutubeService.this, diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/kiosk/YoutubeTrendingMoviesAndShowsTrailersExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/kiosk/YoutubeTrendingMoviesAndShowsTrailersExtractor.java new file mode 100644 index 000000000..d04999e7e --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/kiosk/YoutubeTrendingMoviesAndShowsTrailersExtractor.java @@ -0,0 +1,24 @@ +package org.schabi.newpipe.extractor.services.youtube.extractors.kiosk; + +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; + +import javax.annotation.Nonnull; + +public class YoutubeTrendingMoviesAndShowsTrailersExtractor + extends YoutubeChartsBaseKioskExtractor { + + public YoutubeTrendingMoviesAndShowsTrailersExtractor(final StreamingService streamingService, + final ListLinkHandler linkHandler, + final String kioskId) { + super(streamingService, linkHandler, kioskId, "TRENDING_MOVIES"); + } + + @Nonnull + @Override + public String getName() throws ParsingException { + // This is the official YouTube Charts name, even if shows' trailers are returned too + return "Trending Movie Trailers"; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory.java new file mode 100644 index 000000000..76884d876 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory.java @@ -0,0 +1,51 @@ +package org.schabi.newpipe.extractor.services.youtube.linkHandler; + +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; +import org.schabi.newpipe.extractor.utils.Utils; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Locale; + +public final class YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory + extends ListLinkHandlerFactory { + + public static final String KIOSK_ID = "trending_movies_and_shows"; + + public static final YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory INSTANCE = + new YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory(); + + private static final String PATH = "/charts/TrendingTrailers"; + + private YoutubeTrendingMoviesAndShowsTrailersLinkHandlerFactory() { + } + + @Override + public String getUrl(final String id, + final List contentFilter, + final String sortFilter) + throws ParsingException, UnsupportedOperationException { + return "https://charts.youtube.com" + PATH; + } + + @Override + public String getId(final String url) throws ParsingException, UnsupportedOperationException { + return KIOSK_ID; + } + + @Override + public boolean onAcceptUrl(final String url) throws ParsingException { + final URL urlObj; + try { + urlObj = Utils.stringToURL(url); + } catch (final MalformedURLException e) { + return false; + } + + return Utils.isHTTP(urlObj) + && "charts.youtube.com".equals(urlObj.getHost().toLowerCase(Locale.ROOT)) + && PATH.equals(urlObj.getPath()); + } +}