diff --git a/README.md b/README.md index 69d897e6..b13f04ff 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # NewPipe Extractor -[![Build Status](https://travis-ci.org/TeamNewPipe/NewPipeExtractor.svg?branch=master)](https://travis-ci.org/TeamNewPipe/NewPipeExtractor) [![JIT Pack Badge](https://jitpack.io/v/TeamNewPipe/NewPipeExtractor.svg)](https://jitpack.io/#TeamNewPipe/NewPipeExtractor) [Documentation](https://teamnewpipe.github.io/NewPipeExtractor/javadoc/) +[![Build Status](https://travis-ci.org/TeamNewPipe/NewPipeExtractor.svg?branch=master)](https://travis-ci.org/TeamNewPipe/NewPipeExtractor) [![JIT Pack Badge](https://jitpack.io/v/TeamNewPipe/NewPipeExtractor.svg)](https://jitpack.io/#TeamNewPipe/NewPipeExtractor) [Documentation](https://teamnewpipe.github.io/documentation/) NewPipe Extractor is a library for extracting things from streaming sites. It is a core component of [NewPipe](https://github.com/TeamNewPipe/NewPipe), but could be used independently. diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java index e39e6977..21ead42c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java @@ -36,7 +36,14 @@ public enum MediaFormat { M4A (0x3, "m4a", "m4a", "audio/mp4"), WEBMA (0x4, "WebM", "webm", "audio/webm"), MP3 (0x5, "MP3", "mp3", "audio/mpeg"), - OPUS (0x6, "opus", "opus", "audio/opus"); + OPUS (0x6, "opus", "opus", "audio/opus"), + // subtitles formats + VTT (0x7, "WebVTT", "vtt", "text/vtt"), + TTML (0x8, "Timed Text Markup Language", "ttml", "application/ttml+xml"), + TRANSCRIPT1 (0x9, "TranScript v1", "srv1", "text/xml"), + TRANSCRIPT2 (0xA, "TranScript v2", "srv2", "text/xml"), + TRANSCRIPT3 (0xB, "TranScript v3", "srv3", "text/xml"), + SRT (0xC, "SubRip file format", "srt", "text/srt"); public final int id; public final String name; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java index 846355ed..36690438 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ServiceList.java @@ -8,6 +8,24 @@ import java.util.List; import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableList; +/* + * Copyright (C) Christian Schabesberger 2018 + * ServiceList.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + /** * A list of supported services. */ @@ -19,6 +37,10 @@ public final class ServiceList { public static final YoutubeService YouTube; public static final SoundcloudService SoundCloud; + /** + * When creating a new service, put this service in the end of this list, + * and give it the next free id. + */ private static final List SERVICES = unmodifiableList( asList( YouTube = new YoutubeService(0), diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index 0921e67a..702c4f36 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -20,11 +20,38 @@ import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.utils.Localization; +/* + * Copyright (C) Christian Schabesberger 2018 + * StreamingService.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + public abstract class StreamingService { + + /** + * This class holds meta information about the service implementation. + */ public static class ServiceInfo { private final String name; private final List mediaCapabilities; + /** + * Creates a new instance of a ServiceInfo + * @param name the name of the service + * @param mediaCapabilities the type of media this service can handle + */ public ServiceInfo(String name, List mediaCapabilities) { this.name = name; this.mediaCapabilities = Collections.unmodifiableList(mediaCapabilities); @@ -43,6 +70,10 @@ public abstract class StreamingService { } } + /** + * LinkType will be used to determine which type of URL you are handling, and therefore which part + * of NewPipe should handle a certain URL. + */ public enum LinkType { NONE, STREAM, @@ -53,6 +84,16 @@ public abstract class StreamingService { private final int serviceId; private final ServiceInfo serviceInfo; + /** + * Creates a new Streaming service. + * If you Implement one do not set id within your implementation of this extractor, instead + * set the id when you put the extractor into + * ServiceList. + * All other parameters can be set directly from the overriding constructor. + * @param id the number of the service to identify him within the NewPipe frontend + * @param name the name of the service + * @param capabilities the type of media this service can handle + */ public StreamingService(int id, String name, List capabilities) { this.serviceId = id; this.serviceInfo = new ServiceInfo(name, capabilities); @@ -74,9 +115,31 @@ public abstract class StreamingService { //////////////////////////////////////////// // Url Id handler //////////////////////////////////////////// + + /** + * Must return a new instance of an implementation of LinkHandlerFactory for streams. + * @return an instance of a LinkHandlerFactory for streams + */ public abstract LinkHandlerFactory getStreamLHFactory(); + + /** + * Must return a new instance of an implementation of ListLinkHandlerFactory for channels. + * If support for channels is not given null must be returned. + * @return an instance of a ListLinkHandlerFactory for channels or null + */ public abstract ListLinkHandlerFactory getChannelLHFactory(); + + /** + * Must return a new instance of an implementation of ListLinkHandlerFactory for playlists. + * If support for playlists is not given null must be returned. + * @return an instance of a ListLinkHandlerFactory for playlists or null + */ public abstract ListLinkHandlerFactory getPlaylistLHFactory(); + + /** + * Must return an instance of an implementation of SearchQueryHandlerFactory. + * @return an instance of a SearchQueryHandlerFactory + */ public abstract SearchQueryHandlerFactory getSearchQHFactory(); public abstract ListLinkHandlerFactory getCommentsLHFactory(); @@ -84,15 +147,62 @@ public abstract class StreamingService { //////////////////////////////////////////// // Extractor //////////////////////////////////////////// + + /** + * Must create a new instance of a SearchExtractor implementation. + * @param queryHandler specifies the keyword lock for, and the filters which should be applied. + * @param localization specifies the language/country for the extractor. + * @return a new SearchExtractor instance + */ public abstract SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler, Localization localization); + + /** + * Must create a new instance of a SuggestionExtractor implementation. + * @param localization specifies the language/country for the extractor. + * @return a new SuggestionExtractor instance + */ public abstract SuggestionExtractor getSuggestionExtractor(Localization localization); + + /** + * Outdated or obsolete. null can be returned. + * @return just null + */ public abstract SubscriptionExtractor getSubscriptionExtractor(); + + /** + * Must create a new instance of a KioskList implementation. + * @return a new KioskList instance + * @throws ExtractionException + */ public abstract KioskList getKioskList() throws ExtractionException; + /** + * Must create a new instance of a ChannelExtractor implementation. + * @param linkHandler is pointing to the channel which should be handled by this new instance. + * @param localization specifies the language used for the request. + * @return a new ChannelExtractor + * @throws ExtractionException + */ public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler, Localization localization) throws ExtractionException; + + /** + * Must crete a new instance of a PlaylistExtractor implementation. + * @param linkHandler is pointing to the playlist which should be handled by this new instance. + * @param localization specifies the language used for the request. + * @return a new PlaylistExtractor + * @throws ExtractionException + */ public abstract PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler, Localization localization) throws ExtractionException; + + /** + * Must create a new instance of a StreamExtractor implementation. + * @param linkHandler is pointing to the stream which should be handled by this new instance. + * @param localization specifies the language used for the request. + * @return a new StreamExtractor + * @throws ExtractionException + */ public abstract StreamExtractor getStreamExtractor(LinkHandler linkHandler, Localization localization) throws ExtractionException; public abstract CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler, @@ -192,6 +302,11 @@ public abstract class StreamingService { /** * figure out where the link is pointing to (a channel, video, playlist, etc.) + /** + * Figures out where the link is pointing to (a channel, a video, a playlist, etc.) + * @param url the url on which it should be decided of which link type it is + * @return the link type of url + * @throws ParsingException */ public final LinkType getLinkTypeByUrl(String url) throws ParsingException { LinkHandlerFactory sH = getStreamLHFactory(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Subtitles.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Subtitles.java deleted file mode 100644 index affd854e..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Subtitles.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.schabi.newpipe.extractor; - -import org.schabi.newpipe.extractor.stream.SubtitlesFormat; - -import java.io.Serializable; -import java.util.Locale; - -public class Subtitles implements Serializable { - private final SubtitlesFormat format; - private final Locale locale; - private final String URL; - private final boolean autoGenerated; - - public Subtitles(SubtitlesFormat format, Locale locale, String URL, boolean autoGenerated) { - this.format = format; - this.locale = locale; - this.URL = URL; - this.autoGenerated = autoGenerated; - } - - public SubtitlesFormat getFileType() { return format; } - - public Locale getLocale() { - return locale; - } - - public String getURL() { - return URL; - } - - public boolean isAutoGenerated() { - return autoGenerated; - } -} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java index f19f46c3..005722e3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java @@ -172,13 +172,13 @@ public class SoundcloudStreamExtractor extends StreamExtractor { @Override @Nonnull - public List getSubtitlesDefault() throws IOException, ExtractionException { + public List getSubtitlesDefault() throws IOException, ExtractionException { return Collections.emptyList(); } @Override @Nonnull - public List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException { + public List getSubtitles(MediaFormat format) throws IOException, ExtractionException { return Collections.emptyList(); } @@ -188,12 +188,12 @@ public class SoundcloudStreamExtractor extends StreamExtractor { } @Override - public StreamInfoItem getNextVideo() throws IOException, ExtractionException { + public StreamInfoItem getNextStream() throws IOException, ExtractionException { return null; } @Override - public StreamInfoItemsCollector getRelatedVideos() throws IOException, ExtractionException { + public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId()) + "/related" diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java index ddac5499..709e5f57 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java @@ -53,7 +53,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { final String site; - final String url = getUrl() + "?gl="+ getLocalization().getCountry(); + final String url = getUrl(); //String url = builder.build().toString(); //if we've been passed a valid language code, append it to the URL site = downloader.download(url, getLocalization()); @@ -61,6 +61,11 @@ public class YoutubeSearchExtractor extends SearchExtractor { doc = Jsoup.parse(site, url); } + @Override + public String getUrl() throws ParsingException { + return super.getUrl() + "&gl="+ getLocalization().getCountry(); + } + @Override public String getSearchSuggestion() { final Element el = doc.select("div[class*=\"spell-correction\"]").first(); @@ -79,7 +84,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { @Override public String getNextPageUrl() throws ExtractionException { - return getUrl() + "&page=" + 2 + "&gl=" + getLocalization().getCountry(); + return getUrl() + "&page=" + 2; } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 66898557..e5208d5a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -7,6 +7,7 @@ import com.grack.nanojson.JsonParserException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import org.mozilla.javascript.Context; import org.mozilla.javascript.Function; import org.mozilla.javascript.ScriptableObject; @@ -460,15 +461,15 @@ public class YoutubeStreamExtractor extends StreamExtractor { @Override @Nonnull - public List getSubtitlesDefault() throws IOException, ExtractionException { - return getSubtitles(SubtitlesFormat.TTML); + public List getSubtitlesDefault() throws IOException, ExtractionException { + return getSubtitles(MediaFormat.TTML); } @Override @Nonnull - public List getSubtitles(final SubtitlesFormat format) throws IOException, ExtractionException { + public List getSubtitles(final MediaFormat format) throws IOException, ExtractionException { assertPageFetched(); - List subtitles = new ArrayList<>(); + List subtitles = new ArrayList<>(); for (final SubtitlesInfo subtitlesInfo : subtitlesInfos) { subtitles.add(subtitlesInfo.getSubtitle(format)); } @@ -490,13 +491,17 @@ public class YoutubeStreamExtractor extends StreamExtractor { } @Override - public StreamInfoItem getNextVideo() throws IOException, ExtractionException { + public StreamInfoItem getNextStream() throws IOException, ExtractionException { assertPageFetched(); try { StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); - collector.commit(extractVideoPreviewInfo(doc.select("div[class=\"watch-sidebar-section\"]") - .first().select("li").first())); + Elements watch = doc.select("div[class=\"watch-sidebar-section\"]"); + if (watch.size() < 1) { + return null;// prevent the snackbar notification "report error" on age-restricted videos + } + + collector.commit(extractVideoPreviewInfo(watch.first().select("li").first())); return collector.getItems().get(0); } catch (Exception e) { throw new ParsingException("Could not get next video", e); @@ -504,7 +509,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } @Override - public StreamInfoItemsCollector getRelatedVideos() throws IOException, ExtractionException { + public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { assertPageFetched(); try { StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); @@ -815,21 +820,16 @@ public class YoutubeStreamExtractor extends StreamExtractor { final String languageCode; final boolean isGenerated; - final Locale locale; - public SubtitlesInfo(final String baseUrl, final String languageCode, final boolean isGenerated) { this.cleanUrl = baseUrl .replaceAll("&fmt=[^&]*", "") // Remove preexisting format if exists .replaceAll("&tlang=[^&]*", ""); // Remove translation language this.languageCode = languageCode; this.isGenerated = isGenerated; - - final String[] splits = languageCode.split("-"); - this.locale = splits.length == 2 ? new Locale(splits[0], splits[1]) : new Locale(languageCode); } - public Subtitles getSubtitle(final SubtitlesFormat format) { - return new Subtitles(format, locale, cleanUrl + "&fmt=" + format.getExtension(), isGenerated); + public SubtitlesStream getSubtitle(final MediaFormat format) { + return new SubtitlesStream(format, languageCode, cleanUrl + "&fmt=" + format.getSuffix(), isGenerated); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index 6071b2dc..3b9f0653 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -1,7 +1,7 @@ package org.schabi.newpipe.extractor.stream; /* - * Created by Christian Schabesberger on 10.08.15. + * Created by Christian Schabesberger on 10.08.18. * * Copyright (C) Christian Schabesberger 2016 * StreamExtractor.java is part of NewPipe. @@ -21,8 +21,8 @@ package org.schabi.newpipe.extractor.stream; */ import org.schabi.newpipe.extractor.Extractor; +import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.Subtitles; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; @@ -34,7 +34,7 @@ import java.io.IOException; import java.util.List; /** - * Scrapes information from a video streaming service (eg, YouTube). + * Scrapes information from a video/audio streaming service (eg, YouTube). */ public abstract class StreamExtractor extends Extractor { @@ -44,22 +44,235 @@ public abstract class StreamExtractor extends Extractor { super(service, linkHandler, localization); } + /** + * The day on which the stream got uploaded/created. The return information should be in the format + * dd.mm.yyyy, however it NewPipe will not crash if its not. + * @return The day on which the stream got uploaded. + * @throws ParsingException + */ @Nonnull public abstract String getUploadDate() throws ParsingException; + + /** + * This will return the url to the thumbnail of the stream. Try to return the medium resolution here. + * @return The url of the thumbnail. + * @throws ParsingException + */ @Nonnull public abstract String getThumbnailUrl() throws ParsingException; + + /** + * This is the stream description. On YouTube this is the video description. You can return simple HTML here. + * @return The description of the stream/video. + * @throws ParsingException + */ @Nonnull public abstract String getDescription() throws ParsingException; /** - * Get the age limit + * Get the age limit. * @return The age which limits the content or {@value NO_AGE_LIMIT} if there is no limit * @throws ParsingException if an error occurs while parsing */ public abstract int getAgeLimit() throws ParsingException; + /** + * This should return the length of a video in seconds. + * @return The length of the stream in seconds. + * @throws ParsingException + */ public abstract long getLength() throws ParsingException; + + /** + * If the url you are currently handling contains a time stamp/seek, you can return the + * position it represents here. + * If the url has no time stamp simply return zero. + * @return the timestamp in seconds + * @throws ParsingException + */ public abstract long getTimeStamp() throws ParsingException; + + /** + * The count of how many people have watched the video/listened to the audio stream. + * If the current stream has no view count or its not available simply return -1 + * @return amount of views. + * @throws ParsingException + */ + public abstract long getViewCount() throws ParsingException; + + /** + * The Amount of likes a video/audio stream got. + * If the current stream has no likes or its not available simply return -1 + * @return the amount of likes the stream got + * @throws ParsingException + */ + public abstract long getLikeCount() throws ParsingException; + + /** + * The Amount of dislikes a video/audio stream got. + * If the current stream has no dislikes or its not available simply return -1 + * @return the amount of likes the stream got + * @throws ParsingException + */ + public abstract long getDislikeCount() throws ParsingException; + + /** + * The Url to the page of the creator/uploader of the stream. This must not be a homepage, + * but the page offered by the service the extractor handles. This url will be handled by the + * ChannelExtractor, + * so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects + * this url. + * @return the url to the page of the creator/uploader of the stream or an empty String + * @throws ParsingException + */ + @Nonnull + public abstract String getUploaderUrl() throws ParsingException; + + /** + * The name of the creator/uploader of the stream. + * If the name is not available you can simply return an empty string. + * @return the name of the creator/uploader of the stream or an empty String + * @throws ParsingException + */ + @Nonnull + public abstract String getUploaderName() throws ParsingException; + + /** + * The url to the image file/profile picture/avatar of the creator/uploader of the stream. + * If the url is not available you can return an empty String. + * @return The url of the image file of the uploader or an empty String + * @throws ParsingException + */ + @Nonnull + public abstract String getUploaderAvatarUrl() throws ParsingException; + + /** + * Get the dash mpd url. If you don't know what a dash MPD is you can read about it + * here. + * @return the url as a string or an empty string + * @throws ParsingException if an error occurs while reading + */ + @Nonnull public abstract String getDashMpdUrl() throws ParsingException; + + /** + * I am not sure if this is in use, and how this is used. However the frontend is missing support + * for HLS streams. Prove me if I am wrong. Please open an + * issue, + * or fix this description if you know whats up with this. + * @return The Url to the hls stream. + * @throws ParsingException + */ + @Nonnull public abstract String getHlsUrl() throws ParsingException; + + /** + * This should return a list of available + * AudioStreams + * You can also return null or an empty list, however be aware that if you don't return anything + * in getVideoStreams(), getVideoOnlyStreams() and getDashMpdUrl() either the Collector will handle this as + * a failed extraction procedure. + * @return a list of audio only streams in the format of AudioStream + * @throws IOException + * @throws ExtractionException + */ + public abstract List getAudioStreams() throws IOException, ExtractionException; + + /** + * This should return a list of available + * VideoStreams + * Be aware this is the list of video streams which do contain an audio stream. + * You can also return null or an empty list, however be aware that if you don't return anything + * in getAudioStreams(), getVideoOnlyStreams() and getDashMpdUrl() either the Collector will handle this as + * a failed extraction procedure. + * @return a list of combined video and streams in the format of AudioStream + * @throws IOException + * @throws ExtractionException + */ + public abstract List getVideoStreams() throws IOException, ExtractionException; + + /** + * This should return a list of available + * VideoStreams. + * Be aware this is the list of video streams which do NOT contain an audio stream. + * You can also return null or an empty list, however be aware that if you don't return anything + * in getAudioStreams(), getVideoStreams() and getDashMpdUrl() either the Collector will handle this as + * a failed extraction procedure. + * @return a list of video and streams in the format of AudioStream + * @throws IOException + * @throws ExtractionException + */ + public abstract List getVideoOnlyStreams() throws IOException, ExtractionException; + + /** + * This will return a list of available + * Subtitless. + * If no subtitles are available an empty list can returned. + * @return a list of available subtitles or an empty list + * @throws IOException + * @throws ExtractionException + */ + @Nonnull + public abstract List getSubtitlesDefault() throws IOException, ExtractionException; + + /** + * This will return a list of available + * Subtitless. + * given by a specific type. + * If no subtitles in that specific format are available an empty list can returned. + * @param format the media format by which the subtitles should be filtered + * @return a list of available subtitles or an empty list + * @throws IOException + * @throws ExtractionException + */ + @Nonnull + public abstract List getSubtitles(MediaFormat format) throws IOException, ExtractionException; + + /** + * Get the StreamType. + * @return the type of the stream + * @throws ParsingException + */ + public abstract StreamType getStreamType() throws ParsingException; + + /** + * should return the url of the next stream. NewPipe will automatically play + * the next stream if the user wants that. + * If the next stream is is not available simply return null + * @return the InfoItem of the next stream + * @throws IOException + * @throws ExtractionException + */ + public abstract StreamInfoItem getNextStream() throws IOException, ExtractionException; + + /** + * Should return a list of streams related to the current handled. Many services show suggested + * streams. If you don't like suggested streams you should implement them anyway since they can + * be disabled by the user later in the frontend. + * This list MUST NOT contain the next available video as this should be return through getNextStream() + * If is is not available simply return null + * @return a list of InfoItems showing the related videos/streams + * @throws IOException + * @throws ExtractionException + */ + public abstract StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException; + + /** + * Should analyse the webpage's document and extracts any error message there might be. (e.g. GEMA block) + * + * @return Error message; null if there is no error message. + */ + public abstract String getErrorMessage(); + + ////////////////////////////////////////////////////////////////// + /// Helper + ////////////////////////////////////////////////////////////////// + + /** + * Override this function if the format of time stamp in the url is not the same format as that form youtube. + * Honestly I don't even know the time stamp fromat of youtube. + * @param regexPattern + * @return the sime stamp/seek for the video in seconds + * @throws ParsingException + */ protected long getTimestampSeconds(String regexPattern) throws ParsingException { String timeStamp; try { @@ -103,43 +316,6 @@ public abstract class StreamExtractor extends Extractor { } } else { return 0; - }}; - - public abstract long getViewCount() throws ParsingException; - public abstract long getLikeCount() throws ParsingException; - public abstract long getDislikeCount() throws ParsingException; - - @Nonnull - public abstract String getUploaderUrl() throws ParsingException; - @Nonnull - public abstract String getUploaderName() throws ParsingException; - @Nonnull - public abstract String getUploaderAvatarUrl() throws ParsingException; - - /** - * Get the dash mpd url - * @return the url as a string or an empty string - * @throws ParsingException if an error occurs while reading - */ - @Nonnull public abstract String getDashMpdUrl() throws ParsingException; - @Nonnull public abstract String getHlsUrl() throws ParsingException; - public abstract List getAudioStreams() throws IOException, ExtractionException; - public abstract List getVideoStreams() throws IOException, ExtractionException; - public abstract List getVideoOnlyStreams() throws IOException, ExtractionException; - - @Nonnull - public abstract List getSubtitlesDefault() throws IOException, ExtractionException; - @Nonnull - public abstract List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException; - - public abstract StreamType getStreamType() throws ParsingException; - public abstract StreamInfoItem getNextVideo() throws IOException, ExtractionException; - public abstract StreamInfoItemsCollector getRelatedVideos() throws IOException, ExtractionException; - - /** - * Analyses the webpage's document and extracts any error message there might be. - * - * @return Error message; null if there is no error message. - */ - public abstract String getErrorMessage(); + } + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index 7b2792fc..a52d376d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -8,13 +8,10 @@ import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.Subtitles; -import org.schabi.newpipe.extractor.comments.CommentsInfo; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.utils.DashMpdParser; import org.schabi.newpipe.extractor.utils.ExtractorHelper; -import org.schabi.newpipe.extractor.utils.Localization; /* * Created by Christian Schabesberger on 26.08.15. @@ -163,6 +160,9 @@ public class StreamInfo extends Info { streamInfo.getVideoOnlyStreams().addAll(result.getVideoOnlyStreams()); streamInfo.getAudioStreams().addAll(result.getAudioStreams()); streamInfo.getVideoStreams().addAll(result.getVideoStreams()); + streamInfo.segmentedVideoOnlyStreams = result.getSegmentedVideoOnlyStreams(); + streamInfo.segmentedAudioStreams = result.getSegmentedAudioStreams(); + streamInfo.segmentedVideoStreams = result.getSegmentedVideoStreams(); } catch (Exception e) { // Sometimes we receive 403 (forbidden) error when trying to download the // manifest (similar to what happens with youtube-dl), @@ -254,7 +254,7 @@ public class StreamInfo extends Info { streamInfo.addError(e); } try { - streamInfo.setNextVideo(extractor.getNextVideo()); + streamInfo.setNextVideo(extractor.getNextStream()); } catch (Exception e) { streamInfo.addError(e); } @@ -289,12 +289,17 @@ public class StreamInfo extends Info { private List videoOnlyStreams; private String dashMpdUrl; + private List segmentedVideoStreams; + private List segmentedAudioStreams; + private List segmentedVideoOnlyStreams; + + private String hlsUrl; private StreamInfoItem nextVideo; private List relatedStreams; private long startPosition = 0; - private List subtitles; + private List subtitles; /** * Get the stream type @@ -449,6 +454,30 @@ public class StreamInfo extends Info { this.dashMpdUrl = dashMpdUrl; } + public List getSegmentedVideoStreams() { + return segmentedVideoStreams; + } + + public void setSegmentedVideoStreams(List segmentedVideoStreams) { + this.segmentedVideoStreams = segmentedVideoStreams; + } + + public List getSegmentedAudioStreams() { + return segmentedAudioStreams; + } + + public void setSegmentedAudioStreams(List segmentedAudioStreams) { + this.segmentedAudioStreams = segmentedAudioStreams; + } + + public List getSegmentedVideoOnlyStreams() { + return segmentedVideoOnlyStreams; + } + + public void setSegmentedVideoOnlyStreams(List segmentedVideoOnlyStreams) { + this.segmentedVideoOnlyStreams = segmentedVideoOnlyStreams; + } + public String getHlsUrl() { return hlsUrl; } @@ -481,11 +510,11 @@ public class StreamInfo extends Info { this.startPosition = startPosition; } - public List getSubtitles() { + public List getSubtitles() { return subtitles; } - public void setSubtitles(List subtitles) { + public void setSubtitles(List subtitles) { this.subtitles = subtitles; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesFormat.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesFormat.java deleted file mode 100644 index 3a16f105..00000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesFormat.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.schabi.newpipe.extractor.stream; - -public enum SubtitlesFormat { - // YouTube subtitles formats - // TRANSCRIPT(3) is default YT format based on TTML, - // but unlike VTT or TTML, it is NOT W3 standard - // TRANSCRIPT subtitles are NOT supported by ExoPlayer, only VTT and TTML - VTT (0x0, "vtt"), - TTML (0x1, "ttml"), - TRANSCRIPT1 (0x2, "srv1"), - TRANSCRIPT2 (0x3, "srv2"), - TRANSCRIPT3 (0x4, "srv3"); - - private final int id; - private final String extension; - - SubtitlesFormat(int id, String extension) { - this.id = id; - this.extension = extension; - } - - public String getExtension() { - return extension; - } -} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesStream.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesStream.java new file mode 100644 index 00000000..d0e09ac1 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesStream.java @@ -0,0 +1,73 @@ +package org.schabi.newpipe.extractor.stream; + +import org.schabi.newpipe.extractor.MediaFormat; + +import java.io.Serializable; +import java.util.Locale; + +public class SubtitlesStream extends Stream implements Serializable { + private final MediaFormat format; + private final Locale locale; + private final String url; + private final boolean autoGenerated; + private final String code; + + public SubtitlesStream(MediaFormat format, String languageCode, String url, boolean autoGenerated) { + super(url, format); + + /* + * Locale.forLanguageTag only for API >= 21 + * Locale.Builder only for API >= 21 + * Country codes doesn't work well without + */ + final String[] splits = languageCode.split("-"); + switch (splits.length) { + default: + this.locale = new Locale(splits[0]); + break; + case 3: + this.locale = new Locale(splits[0], splits[1], splits[2]);// complex variants doesn't work! + break; + case 2: + this.locale = new Locale(splits[0], splits[1]); + break; + } + this.code = languageCode; + this.format = format; + this.url = url; + this.autoGenerated = autoGenerated; + } + + public String getExtension() { + return format.suffix; + } + + public String getURL() { + return url; + } + + public boolean isAutoGenerated() { + return autoGenerated; + } + + @Override + public boolean equalStats(Stream cmp) { + return super.equalStats(cmp)&& + cmp instanceof SubtitlesStream && + code.equals(((SubtitlesStream) cmp).code) && + autoGenerated == ((SubtitlesStream) cmp).autoGenerated; + } + + public String getDisplayLanguageName() { + return locale.getDisplayName(locale); + } + + public String getLanguageTag() { + return code; + } + + public Locale getLocale() { + return locale; + } + +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java index 6c656d77..8a994cbd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java @@ -59,10 +59,23 @@ public class DashMpdParser { private final List audioStreams; private final List videoOnlyStreams; - public ParserResult(List videoStreams, List audioStreams, List videoOnlyStreams) { + private final List segmentedVideoStreams; + private final List segmentedAudioStreams; + private final List segmentedVideoOnlyStreams; + + + public ParserResult(List videoStreams, + List audioStreams, + List videoOnlyStreams, + List segmentedVideoStreams, + List segmentedAudioStreams, + List segmentedVideoOnlyStreams) { this.videoStreams = videoStreams; this.audioStreams = audioStreams; this.videoOnlyStreams = videoOnlyStreams; + this.segmentedVideoStreams = segmentedVideoStreams; + this.segmentedAudioStreams = segmentedAudioStreams; + this.segmentedVideoOnlyStreams = segmentedVideoOnlyStreams; } public List getVideoStreams() { @@ -76,10 +89,22 @@ public class DashMpdParser { public List getVideoOnlyStreams() { return videoOnlyStreams; } + + public List getSegmentedVideoStreams() { + return segmentedVideoStreams; + } + + public List getSegmentedAudioStreams() { + return segmentedAudioStreams; + } + + public List getSegmentedVideoOnlyStreams() { + return segmentedVideoOnlyStreams; + } } /** - * Will try to download (using {@link StreamInfo#dashMpdUrl}) and parse the dash manifest, + * Will try to download (using {@link StreamInfo#getDashMpdUrl()}) and parse the dash manifest, * then it will search for any stream that the ItagItem has (by the id). *

* It has video, video only and audio streams and will only add to the list if it don't @@ -90,7 +115,8 @@ public class DashMpdParser { * * @param streamInfo where the parsed streams will be added */ - public static ParserResult getStreams(final StreamInfo streamInfo) throws DashMpdParsingException, ReCaptchaException { + public static ParserResult getStreams(final StreamInfo streamInfo) + throws DashMpdParsingException, ReCaptchaException { String dashDoc; Downloader downloader = NewPipe.getDownloader(); try { @@ -113,6 +139,10 @@ public class DashMpdParser { final List audioStreams = new ArrayList<>(); final List videoOnlyStreams = new ArrayList<>(); + final List segmentedVideoStreams = new ArrayList<>(); + final List segmentedAudioStreams = new ArrayList<>(); + final List segmentedVideoOnlyStreams = new ArrayList<>(); + for (int i = 0; i < representationList.getLength(); i++) { final Element representation = (Element) representationList.item(i); try { @@ -126,34 +156,61 @@ public class DashMpdParser { // instead we need to add the "media=" value from the tags inside the // tag in order to get a full working url. However each of these is just pointing to a part of the // video, so we can not return a URL with a working stream here. - // We decided not to ignore such streams for the moment. - if (itag != null && segmentationList == null) { + // Instead of putting those streams into the list of regular stream urls wie put them in a + // for example "segmentedVideoStreams" list. + if (itag != null) { final MediaFormat mediaFormat = MediaFormat.getFromMimeType(mimeType); if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) { - final AudioStream audioStream = new AudioStream(url, mediaFormat, itag.avgBitrate); - - if (!Stream.containSimilarStream(audioStream, streamInfo.getAudioStreams())) { - audioStreams.add(audioStream); + if(segmentationList == null) { + final AudioStream audioStream = new AudioStream(url, mediaFormat, itag.avgBitrate); + if (!Stream.containSimilarStream(audioStream, streamInfo.getAudioStreams())) { + audioStreams.add(audioStream); + } + } else { + segmentedAudioStreams.add( + new AudioStream(id, mediaFormat, itag.avgBitrate)); } } else { boolean isVideoOnly = itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY); - final VideoStream videoStream = new VideoStream(url, mediaFormat, itag.resolutionString, isVideoOnly); - if (isVideoOnly) { - if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoOnlyStreams())) { - streamInfo.getVideoOnlyStreams().add(videoStream); - videoOnlyStreams.add(videoStream); + if(segmentationList == null) { + final VideoStream videoStream = new VideoStream(url, + mediaFormat, + itag.resolutionString, + isVideoOnly); + + if (isVideoOnly) { + if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoOnlyStreams())) { + videoOnlyStreams.add(videoStream); + } + } else if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoStreams())) { + videoStreams.add(videoStream); + } + } else { + final VideoStream videoStream = new VideoStream(id, + mediaFormat, + itag.resolutionString, + isVideoOnly); + + if(isVideoOnly) { + segmentedVideoOnlyStreams.add(videoStream); + } else { + segmentedVideoStreams.add(videoStream); } - } else if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoStreams())) { - videoStreams.add(videoStream); } } } } catch (Exception ignored) { } } - return new ParserResult(videoStreams, audioStreams, videoOnlyStreams); + return new ParserResult( + videoStreams, + audioStreams, + videoOnlyStreams, + segmentedVideoStreams, + segmentedAudioStreams, + segmentedVideoOnlyStreams); } catch (Exception e) { throw new DashMpdParsingException("Could not parse Dash mpd", e); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java index a25e9051..0072fcb3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java @@ -30,7 +30,7 @@ public class ExtractorHelper { public static List getRelatedVideosOrLogError(StreamInfo info, StreamExtractor extractor) { try { - InfoItemsCollector collector = extractor.getRelatedVideos(); + InfoItemsCollector collector = extractor.getRelatedStreams(); info.addAllErrors(collector.getErrors()); //noinspection unchecked diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java index b6c5b3a2..3970efde 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java @@ -101,7 +101,7 @@ public class SoundcloudStreamExtractorDefaultTest { @Test public void testGetRelatedVideos() throws ExtractionException, IOException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); + StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); assertFalse(relatedVideos.getItems().isEmpty()); assertTrue(relatedVideos.getErrors().isEmpty()); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 1cb6388a..9cfd6c00 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -219,7 +219,7 @@ public class YoutubePlaylistExtractorTest { @Test public void testUploaderName() throws Exception { - assertEquals("Tomas Nilsson", extractor.getUploaderName()); + assertEquals("Tomas Nilsson TOMPA571", extractor.getUploaderName()); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorAgeRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorAgeRestrictedTest.java index ec8b495f..dbf8d6d6 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorAgeRestrictedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorAgeRestrictedTest.java @@ -4,13 +4,13 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.SubtitlesFormat; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.utils.Localization; @@ -131,6 +131,6 @@ public class YoutubeStreamExtractorAgeRestrictedTest { @Test public void testGetSubtitlesList() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty()); + assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java index a5ac490e..a300d622 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorControversialTest.java @@ -4,13 +4,13 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.SubtitlesFormat; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.utils.Localization; @@ -124,6 +124,6 @@ public class YoutubeStreamExtractorControversialTest { @Test public void testGetSubtitlesList() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(!extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty()); + assertTrue(!extractor.getSubtitles(MediaFormat.TTML).isEmpty()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDASHTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDASHTest.java index 0d4013e9..ceba6092 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDASHTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDASHTest.java @@ -47,15 +47,21 @@ public class YoutubeStreamExtractorDASHTest { @Test public void testGetDashMpd() { - System.out.println(info.getDashMpdUrl()); assertTrue(info.getDashMpdUrl(), info.getDashMpdUrl() != null && !info.getDashMpdUrl().isEmpty()); } @Test - public void testDashMpdParser() { + public void testRegularStreams() { assertEquals(0, info.getAudioStreams().size()); assertEquals(0, info.getVideoOnlyStreams().size()); assertEquals(4, info.getVideoStreams().size()); } + + @Test + public void testSegmentedStreams() { + assertEquals(2, info.getSegmentedAudioStreams().size()); + assertEquals(3, info.getSegmentedVideoOnlyStreams().size()); + assertEquals(0, info.getSegmentedVideoStreams().size()); + } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java index 2c026f36..27b54c54 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java @@ -3,12 +3,12 @@ package org.schabi.newpipe.extractor.services.youtube; import org.junit.BeforeClass; import org.junit.Test; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.stream.*; -import org.schabi.newpipe.extractor.utils.DashMpdParser; import org.schabi.newpipe.extractor.utils.Localization; import org.schabi.newpipe.extractor.utils.Utils; @@ -17,7 +17,6 @@ import java.io.IOException; import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.youtube.YoutubeTrendingExtractorTest.extractor; /* * Created by Christian Schabesberger on 30.12.15. @@ -151,7 +150,7 @@ public class YoutubeStreamExtractorDefaultTest { @Test public void testGetRelatedVideos() throws ExtractionException, IOException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); + StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); Utils.printErrors(relatedVideos.getErrors()); assertFalse(relatedVideos.getItems().isEmpty()); assertTrue(relatedVideos.getErrors().isEmpty()); @@ -166,7 +165,7 @@ public class YoutubeStreamExtractorDefaultTest { @Test public void testGetSubtitlesList() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty()); + assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java index af314e63..92349c85 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java @@ -28,7 +28,7 @@ public class YoutubeSearchCountTest { public void testViewCount() { ChannelInfoItem ci = (ChannelInfoItem) itemsPage.getItems().get(0); assertTrue("Count does not fit: " + Long.toString(ci.getSubscriberCount()), - 65043316 < ci.getSubscriberCount() && ci.getSubscriberCount() < 68043316); + 69043316 < ci.getSubscriberCount() && ci.getSubscriberCount() < 73043316); } } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java index 937cee5e..14b94b51 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java @@ -45,12 +45,12 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto } assertFalse("First and second page are equal", equals); - assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=3&gl=GB", secondPage.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=3", secondPage.getNextPageUrl()); } @Test public void testGetSecondPageUrl() throws Exception { - assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=2&gl=GB", extractor.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=2", extractor.getNextPageUrl()); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java index 3df6434e..3e7d3311 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java @@ -49,18 +49,22 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas itemsPage = extractor.getInitialPage(); } + @Test + public void testGetUrl() throws Exception { + assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB", extractor.getUrl()); + } @Test public void testGetSecondPageUrl() throws Exception { - assertEquals("https://www.youtube.com/results?q=pewdiepie&page=2&gl=GB", extractor.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=2", extractor.getNextPageUrl()); } @Test public void testResultList_FirstElement() { InfoItem firstInfoItem = itemsPage.getItems().get(1); - // THe channel should be the first item + // The channel should be the first item assertTrue(firstInfoItem instanceof ChannelInfoItem); assertEquals("name", "PewDiePie", firstInfoItem.getName()); assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.getUrl()); @@ -96,7 +100,7 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas } assertFalse("First and second page are equal", equals); - assertEquals("https://www.youtube.com/results?q=pewdiepie&page=3&gl=GB", secondPage.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=3", secondPage.getNextPageUrl()); } @Test