Class YoutubeStreamExtractor
- java.lang.Object
-
- org.schabi.newpipe.extractor.Extractor
-
- org.schabi.newpipe.extractor.stream.StreamExtractor
-
- org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor
-
public class YoutubeStreamExtractor extends StreamExtractor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.schabi.newpipe.extractor.stream.StreamExtractor
StreamExtractor.Privacy
-
-
Field Summary
-
Fields inherited from class org.schabi.newpipe.extractor.stream.StreamExtractor
NO_AGE_LIMIT, UNKNOWN_SUBSCRIBER_COUNT
-
-
Constructor Summary
Constructors Constructor Description YoutubeStreamExtractor(StreamingService service, LinkHandler linkHandler)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAgeLimit()Get the age limit.java.util.List<AudioStream>getAudioStreams()This should return a list of availableAudioStreams.java.lang.StringgetCategory()The name of the category of the stream.java.lang.StringgetDashMpdUrl()Get the dash mpd url.DescriptiongetDescription()This is the stream description.java.lang.StringgetErrorMessage()Should analyse the webpage's document and extracts any error message there might be.java.util.List<Frameset>getFrames()Should return a list of Frameset object that contains preview of stream framesjava.lang.StringgetHlsUrl()I am not sure if this is in use, and how this is used.java.util.LocalegetLanguageInfo()The locale language of the stream.longgetLength()This should return the length of a video in seconds.java.lang.StringgetLicence()The name of the licence of the stream.longgetLikeCount()The amount of likes a video/audio stream got.java.util.List<MetaInfo>getMetaInfo()Meta information about the stream.java.lang.StringgetName()Get the nameStreamExtractor.PrivacygetPrivacy()The privacy of the stream (Eg.MultiInfoItemsCollectorgetRelatedItems()Should return a list of streams related to the current handled.java.util.List<StreamSegment>getStreamSegments()The list of stream segments by timestamps for the stream.StreamTypegetStreamType()Get theStreamType.java.util.List<SubtitlesStream>getSubtitles(MediaFormat format)This will return a list of availableSubtitlesStreams given by a specific type.java.util.List<SubtitlesStream>getSubtitlesDefault()This will return a list of availableSubtitlesStreams.java.util.List<java.lang.String>getTags()The list of tags of the stream.java.lang.StringgetTextualUploadDate()The original textual date provided by the service.java.util.List<Image>getThumbnails()This will return the thumbnails of the stream.longgetTimeStamp()Attempts to parse (and return) the offset to start playing the video from.DateWrappergetUploadDate()A more generalInstantinstance set to the date provided by the service.
Implementations usually will just parse the date returned from theStreamExtractor.getTextualUploadDate().java.util.List<Image>getUploaderAvatars()The image files/profile pictures/avatars of the creator/uploader of the stream.java.lang.StringgetUploaderName()The name of the creator/uploader of the stream.longgetUploaderSubscriberCount()The subscriber count of the uploader.java.lang.StringgetUploaderUrl()The Url to the page of the creator/uploader of the stream.java.util.List<VideoStream>getVideoOnlyStreams()This should return a list of availableVideoStreams.java.util.List<VideoStream>getVideoStreams()This should return a list of availableVideoStreams.longgetViewCount()The count of how many people have watched the video/listened to the audio stream.booleanisUploaderVerified()Whether the uploader has been verified by the service's provider.voidonFetchPage(Downloader downloader)Fetch the current page.static voidsetFetchIosClient(boolean fetchIosClient)Set whether to fetch the iOS player responses.static voidsetPoTokenProvider(PoTokenProvider poTokenProvider)Set thePoTokenProviderinstance to be used for fetchingpoTokens.-
Methods inherited from class org.schabi.newpipe.extractor.stream.StreamExtractor
getContentAvailability, getDislikeCount, getHost, getRelatedStreams, getSubChannelAvatars, getSubChannelName, getSubChannelUrl, getSupportInfo, getTimestampSeconds, isShortFormContent
-
Methods inherited from class org.schabi.newpipe.extractor.Extractor
assertPageFetched, fetchPage, forceContentCountry, forceLocalization, getBaseUrl, getDownloader, getExtractorContentCountry, getExtractorLocalization, getId, getLinkHandler, getOriginalUrl, getService, getServiceId, getTimeAgoParser, getUrl, isPageFetched
-
-
-
-
Constructor Detail
-
YoutubeStreamExtractor
public YoutubeStreamExtractor(StreamingService service, LinkHandler linkHandler)
-
-
Method Detail
-
getName
@Nonnull public java.lang.String getName() throws ParsingExceptionDescription copied from class:ExtractorGet the name- Specified by:
getNamein classExtractor- Returns:
- the name
- Throws:
ParsingException- if the name cannot be extracted
-
getTextualUploadDate
@Nullable public java.lang.String getTextualUploadDate()
Description copied from class:StreamExtractorThe original textual date provided by the service. Should be used as a fallback ifStreamExtractor.getUploadDate()isn't provided by the service, or it fails for some reason.If the stream is a live stream,
nullshould be returned.- Overrides:
getTextualUploadDatein classStreamExtractor- Returns:
- The original textual date provided by the service, or
null. - See Also:
StreamExtractor.getUploadDate()
-
getUploadDate
public DateWrapper getUploadDate() throws ParsingException
Description copied from class:StreamExtractorA more generalInstantinstance set to the date provided by the service.
Implementations usually will just parse the date returned from theStreamExtractor.getTextualUploadDate().If the stream is a live stream,
nullshould be returned.- Overrides:
getUploadDatein classStreamExtractor- Returns:
- The date this item was uploaded, or
null. - Throws:
ParsingException- if there is an error in the extraction or the extracted date couldn't be parsed.- See Also:
StreamExtractor.getTextualUploadDate()
-
getThumbnails
@Nonnull public java.util.List<Image> getThumbnails() throws ParsingException
Description copied from class:StreamExtractorThis will return the thumbnails of the stream.- Specified by:
getThumbnailsin classStreamExtractor- Returns:
- the thumbnails of the stream
- Throws:
ParsingException
-
getDescription
@Nonnull public Description getDescription() throws ParsingException
Description copied from class:StreamExtractorThis is the stream description.- Overrides:
getDescriptionin classStreamExtractor- Returns:
- The description of the stream/video or
Description.EMPTY_DESCRIPTIONif the description is empty. - Throws:
ParsingException
-
getAgeLimit
public int getAgeLimit() throws ParsingExceptionDescription copied from class:StreamExtractorGet the age limit.- Overrides:
getAgeLimitin classStreamExtractor- Returns:
- The age which limits the content or 0 if there is no limit
- Throws:
ParsingException- if an error occurs while parsing
-
getLength
public long getLength() throws ParsingExceptionDescription copied from class:StreamExtractorThis should return the length of a video in seconds.- Overrides:
getLengthin classStreamExtractor- Returns:
- The length of the stream in seconds or 0 when it has no length (e.g. a livestream).
- Throws:
ParsingException
-
getTimeStamp
public long getTimeStamp() throws ParsingExceptionAttempts to parse (and return) the offset to start playing the video from.- Overrides:
getTimeStampin classStreamExtractor- Returns:
- the offset (in seconds), or 0 if no timestamp is found.
- Throws:
ParsingException
-
getViewCount
public long getViewCount() throws ParsingExceptionDescription copied from class:StreamExtractorThe 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- Overrides:
getViewCountin classStreamExtractor- Returns:
- amount of views or -1 if not available.
- Throws:
ParsingException
-
getLikeCount
public long getLikeCount() throws ParsingExceptionDescription copied from class:StreamExtractorThe amount of likes a video/audio stream got. If the current stream has no likes or its not available simply return -1- Overrides:
getLikeCountin classStreamExtractor- Returns:
- the amount of likes the stream got or -1 if not available.
- Throws:
ParsingException
-
getUploaderUrl
@Nonnull public java.lang.String getUploaderUrl() throws ParsingExceptionDescription copied from class:StreamExtractorThe 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 theChannelExtractor, so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects this url.- Specified by:
getUploaderUrlin classStreamExtractor- Returns:
- the url to the page of the creator/uploader of the stream or an empty string
- Throws:
ParsingException
-
getUploaderName
@Nonnull public java.lang.String getUploaderName() throws ParsingExceptionDescription copied from class:StreamExtractorThe name of the creator/uploader of the stream. If the name is not available you can simply return an empty string.- Specified by:
getUploaderNamein classStreamExtractor- Returns:
- the name of the creator/uploader of the stream or an empty tring
- Throws:
ParsingException
-
isUploaderVerified
public boolean isUploaderVerified() throws ParsingExceptionDescription copied from class:StreamExtractorWhether the uploader has been verified by the service's provider. If there is no verification implemented, returnfalse.- Overrides:
isUploaderVerifiedin classStreamExtractor- Returns:
- whether the uploader has been verified by the service's provider
- Throws:
ParsingException
-
getUploaderAvatars
@Nonnull public java.util.List<Image> getUploaderAvatars() throws ParsingException
Description copied from class:StreamExtractorThe image files/profile pictures/avatars of the creator/uploader of the stream.If they are not available in the stream on specific cases, you must return an empty list for these ones, like it is made by default.
- Overrides:
getUploaderAvatarsin classStreamExtractor- Returns:
- the avatars of the sub-channel of the stream or an empty list (default)
- Throws:
ParsingException
-
getUploaderSubscriberCount
public long getUploaderSubscriberCount() throws ParsingExceptionDescription copied from class:StreamExtractorThe subscriber count of the uploader. If the subscriber count is not implemented, or is unavailable, return-1.- Overrides:
getUploaderSubscriberCountin classStreamExtractor- Returns:
- the subscriber count of the uploader or -1L if not available
- Throws:
ParsingException
-
getDashMpdUrl
@Nonnull public java.lang.String getDashMpdUrl() throws ParsingExceptionDescription copied from class:StreamExtractorGet the dash mpd url. If you don't know what a dash MPD is you can read about it here.- Overrides:
getDashMpdUrlin classStreamExtractor- Returns:
- the url as a string or an empty string or an empty string if not available
- Throws:
ParsingException- if an error occurs while reading
-
getHlsUrl
@Nonnull public java.lang.String getHlsUrl() throws ParsingExceptionDescription copied from class:StreamExtractorI 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.- Overrides:
getHlsUrlin classStreamExtractor- Returns:
- The Url to the hls stream or an empty string if not available.
- Throws:
ParsingException
-
getAudioStreams
public java.util.List<AudioStream> getAudioStreams() throws ExtractionException
Description copied from class:StreamExtractorThis should return a list of availableAudioStreams. 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.- Specified by:
getAudioStreamsin classStreamExtractor- Returns:
- a list of audio only streams in the format of AudioStream
- Throws:
ExtractionException
-
getVideoStreams
public java.util.List<VideoStream> getVideoStreams() throws ExtractionException
Description copied from class:StreamExtractorThis should return a list of availableVideoStreams. 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.- Specified by:
getVideoStreamsin classStreamExtractor- Returns:
- a list of combined video and streams in the format of AudioStream
- Throws:
ExtractionException
-
getVideoOnlyStreams
public java.util.List<VideoStream> getVideoOnlyStreams() throws ExtractionException
Description copied from class:StreamExtractorThis should return a list of availableVideoStreams. 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.- Specified by:
getVideoOnlyStreamsin classStreamExtractor- Returns:
- a list of video and streams in the format of AudioStream
- Throws:
ExtractionException
-
getSubtitlesDefault
@Nonnull public java.util.List<SubtitlesStream> getSubtitlesDefault() throws ParsingException
Description copied from class:StreamExtractorThis will return a list of availableSubtitlesStreams. If no subtitles are available an empty list can be returned.- Overrides:
getSubtitlesDefaultin classStreamExtractor- Returns:
- a list of available subtitles or an empty list
- Throws:
ParsingException
-
getSubtitles
@Nonnull public java.util.List<SubtitlesStream> getSubtitles(MediaFormat format) throws ParsingException
Description copied from class:StreamExtractorThis will return a list of availableSubtitlesStreams given by a specific type. If no subtitles in that specific format are available an empty list can be returned.- Overrides:
getSubtitlesin classStreamExtractor- Parameters:
format- the media format by which the subtitles should be filtered- Returns:
- a list of available subtitles or an empty list
- Throws:
ParsingException
-
getStreamType
public StreamType getStreamType()
Description copied from class:StreamExtractorGet theStreamType.- Specified by:
getStreamTypein classStreamExtractor- Returns:
- the type of the stream
-
getRelatedItems
@Nullable public MultiInfoItemsCollector getRelatedItems() throws ExtractionException
Description copied from class:StreamExtractorShould 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. The first related stream might be what was previously known as a next stream. If related streams aren't available simply returnnull.- Overrides:
getRelatedItemsin classStreamExtractor- Returns:
- a list of InfoItems showing the related videos/streams
- Throws:
ExtractionException
-
getErrorMessage
public java.lang.String getErrorMessage()
Should analyse the webpage's document and extracts any error message there might be.- Overrides:
getErrorMessagein classStreamExtractor- Returns:
- Error message;
nullif there is no error message.
-
onFetchPage
public void onFetchPage(@Nonnull Downloader downloader) throws java.io.IOException, ExtractionExceptionDescription copied from class:ExtractorFetch the current page.- Specified by:
onFetchPagein classExtractor- Parameters:
downloader- the downloader to use- Throws:
java.io.IOException- if the page can not be loadedExtractionException- if the pages content is not understood
-
getFrames
@Nonnull public java.util.List<Frameset> getFrames() throws ExtractionException
Should return a list of Frameset object that contains preview of stream frames Should return a list of Frameset object that contains preview of stream framesWarning: When using this method be aware that the YouTube API very rarely returns framesets, that are slightly too small e.g. framesPerPageX = 5, frameWidth = 160, but the url contains a storyboard that is only 795 pixels wide (5*160 > 795). You will need to handle this "manually" to avoid errors.
- Overrides:
getFramesin classStreamExtractor- Returns:
- list of preview frames or empty list if frames preview is not supported or not found for specified stream
- Throws:
ExtractionException- See Also:
- TeamNewPipe/NewPipe#11596
-
getPrivacy
@Nonnull public StreamExtractor.Privacy getPrivacy()
Description copied from class:StreamExtractorThe privacy of the stream (Eg. Public, Private, Unlisted…).- Overrides:
getPrivacyin classStreamExtractor- Returns:
- the privacy of the stream.
-
getCategory
@Nonnull public java.lang.String getCategory()
Description copied from class:StreamExtractorThe name of the category of the stream. If the category is not available you can simply return an empty string.- Overrides:
getCategoryin classStreamExtractor- Returns:
- the category of the stream or an empty string.
-
getLicence
@Nonnull public java.lang.String getLicence() throws ParsingExceptionDescription copied from class:StreamExtractorThe name of the licence of the stream. If the licence is not available you can simply return an empty string.- Overrides:
getLicencein classStreamExtractor- Returns:
- the licence of the stream or an empty String.
- Throws:
ParsingException
-
getLanguageInfo
public java.util.Locale getLanguageInfo()
Description copied from class:StreamExtractorThe locale language of the stream. If the language is not available you can simply return null. If the language is provided by a language code, you can return new Locale(language_code);- Overrides:
getLanguageInfoin classStreamExtractor- Returns:
- the locale language of the stream or
null.
-
getTags
@Nonnull public java.util.List<java.lang.String> getTags()
Description copied from class:StreamExtractorThe list of tags of the stream. If the tag list is not available you can simply return an empty list.- Overrides:
getTagsin classStreamExtractor- Returns:
- the list of tags of the stream or Collections.emptyList().
-
getStreamSegments
@Nonnull public java.util.List<StreamSegment> getStreamSegments() throws ParsingException
Description copied from class:StreamExtractorThe list of stream segments by timestamps for the stream. If the segment list is not available you can simply return an empty list.- Overrides:
getStreamSegmentsin classStreamExtractor- Returns:
- The list of segments of the stream or an empty list.
- Throws:
ParsingException
-
getMetaInfo
@Nonnull public java.util.List<MetaInfo> getMetaInfo() throws ParsingException
Description copied from class:StreamExtractorMeta information about the stream.This can be information about the stream creator (e.g. if the creator is a public broadcaster) or further information on the topic (e.g. hints that the video might contain conspiracy theories or contains information about a current health situation like the Covid-19 pandemic).
The meta information often contains links to external sources like Wikipedia or the WHO.- Overrides:
getMetaInfoin classStreamExtractor- Returns:
- The meta info of the stream or an empty list if not provided.
- Throws:
ParsingException
-
setPoTokenProvider
public static void setPoTokenProvider(@Nullable PoTokenProvider poTokenProvider)Set thePoTokenProviderinstance to be used for fetchingpoTokens.This method allows setting an implementation of
PoTokenProviderwhich will be used to obtain poTokens required for YouTube player requests and streaming URLs. These tokens are used by YouTube to verify the integrity of the user's device or browser and are required for playback with several clients.Without a
PoTokenProvider, the extractor makes its best effort to fetch as many streams as possible, but withoutpoTokens, some formats may be not available or fetching may be slower due to additional requests done to get streams.Note that any provider change will be only applied on the next
Extractor.fetchPage()request.- Parameters:
poTokenProvider- thePoTokenProviderinstance to set, which can be null to remove a provider already passed- See Also:
PoTokenProvider
-
setFetchIosClient
public static void setFetchIosClient(boolean fetchIosClient)
Set whether to fetch the iOS player responses.This method allows fetching the iOS player response, which can be useful in scenarios where streams from the iOS player response are needed, especially HLS manifests.
Note that at the time of writing, YouTube is rolling out a
poTokenrequirement on this client, formats from HLS manifests do not seem to be affected.- Parameters:
fetchIosClient- whether to fetch the iOS client
-
-