coherence.extern.youtubedl.youtubedl (module)¶
-
preferredencoding
()[source]¶ Get preferred encoding.
Returns the best encoding scheme for the system, based on locale.getpreferredencoding() and some further tweaks.
-
exception
DownloadError
[source]¶ Bases:
Exception
Download Error exception.
This exception may be thrown by FileDownloader objects if they are not configured to continue on errors. They will contain the appropriate error message.
-
exception
SameFileError
[source]¶ Bases:
Exception
Same File exception.
This exception will be thrown by FileDownloader objects if they detect multiple files would have to be downloaded to the same file on disk.
-
exception
PostProcessingError
[source]¶ Bases:
Exception
Post Processing exception.
This exception may be raised by PostProcessor’s .run() method to indicate an error in the postprocessing task.
Bases:
Exception
Unavailable Format exception.
This exception will be thrown when a video is requested in a format that is not available for that video.
-
exception
ContentTooShortError
(downloaded, expected)[source]¶ Bases:
Exception
Content Too Short exception.
This exception may be raised by FileDownloader objects when a file they download is too small for what the server announced first, indicating the connection was probably interrupted.
-
downloaded
= None¶
-
expected
= None¶
-
-
class
FileDownloader
(params)[source]¶ Bases:
object
File Downloader class.
File downloader objects are the ones responsible of downloading the actual video file and writing it to disk if the user has requested it, among some other tasks. In most cases there should be one per program. As, given a video URL, the downloader doesn’t know how to extract all the needed information, task that InfoExtractors do, it has to pass the URL to one of them.
For this, file downloader objects have a method that allows InfoExtractors to be registered in a given order. When it is passed a URL, the file downloader handles it to the first InfoExtractor it finds that reports being able to handle it. The InfoExtractor extracts all the information about the video or videos the URL refers to, and asks the FileDownloader to process the video information, possibly downloading the video.
File downloaders accept a lot of parameters. In order not to saturate the object constructor with arguments, it receives a dictionary of options instead. These options are available through the params attribute for the InfoExtractors to use. The FileDownloader also registers itself as the downloader in charge for the InfoExtractors that are added to it, so this is a “mutual registration”.
Available options:
username: Username for authentication purposes. password: Password for authentication purposes. usenetrc: Use netrc for authentication instead. quiet: Do not print messages to stdout. forceurl: Force printing final URL. forcetitle: Force printing title. simulate: Do not download the video files. format: Video format code. outtmpl: Template for output names. ignoreerrors: Do not stop on download errors. ratelimit: Download speed limit, in bytes/sec. nooverwrites: Prevent overwriting files. continuedl: Try to continue downloads if possible.
Create a FileDownloader object with the given options.
-
_ies
= []¶
-
_pps
= []¶
-
_download_retcode
= None¶
-
params
= None¶
-
static
pmkdir
(filename)[source]¶ Create directory components in filename. Similar to Unix “mkdir -p”.
-
static
verify_url
(url)[source]¶ Verify a URL is valid and data could be downloaded. Return real data URL.
-
-
class
InfoExtractor
(downloader=None)[source]¶ Bases:
object
Information Extractor class.
Information extractors are the classes that, given a URL, extract information from the video (or videos) the URL refers to. This information includes the real video URL, the video title and simplified title, author and others. The information is stored in a dictionary which is then passed to the FileDownloader. The FileDownloader processes this information possibly downloading the video to the file system, among other possible outcomes. The dictionaries must include the following fields:
id: Video identifier. url: Final video URL. uploader: Nickname of the video uploader. title: Literal title. stitle: Simplified title. ext: Video filename extension.
Subclasses of this one should re-define the _real_initialize() and _real_extract() methods, as well as the suitable() static method. Probably, they should also be instantiated and added to the main downloader.
Constructor. Receives an optional downloader.
-
_downloader
= None¶
-
_ready
= False¶
-
-
class
YoutubeIE
(downloader=None)[source]¶ Bases:
coherence.extern.youtubedl.youtubedl.InfoExtractor
Information extractor for youtube.com.
Constructor. Receives an optional downloader.
-
_VALID_URL
= '^((?:https://)?(?:\\w+\\.)?youtube\\.com/(?:(?:v/)|(?:(?:watch(?:\\.php)?)?\\?(?:.+&)?v=)))?([0-9A-Za-z_-]+)(?(1).+)?$'¶
-
_LANG_URL
= 'https://uk.youtube.com/?hl=en&persist_hl=1&gl=US&persist_gl=1&opt_out_ackd=1'¶
-
_LOGIN_URL
= 'https://www.youtube.com/signup?next=/&gl=US&hl=en'¶
-
_AGE_URL
= 'https://www.youtube.com/verify_age?next_url=/&gl=US&hl=en'¶
-
_NETRC_MACHINE
= 'youtube'¶
-
_available_formats
= ['22', '35', '18', '5', '17', '13', None]¶
-
_video_extensions
= {'13': '3gp', '17': 'mp4', '18': 'mp4', '22': 'mp4'}¶
-
report_video_info_webpage_download
(video_id)[source]¶ Report attempt to download video info webpage.
Report extracted video URL.
-
-
class
MetacafeIE
(youtube_ie, downloader=None)[source]¶ Bases:
coherence.extern.youtubedl.youtubedl.InfoExtractor
Information Extractor for metacafe.com.
-
_VALID_URL
= '(?:https://)?(?:www\\.)?metacafe\\.com/watch/([^/]+)/([^/]+)/.*'¶
-
_DISCLAIMER
= 'https://www.metacafe.com/family_filter/'¶
-
_FILTER_POST
= 'https://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user'¶
-
_youtube_ie
= None¶
-
-
class
YoutubeSearchIE
(youtube_ie, downloader=None)[source]¶ Bases:
coherence.extern.youtubedl.youtubedl.InfoExtractor
Information Extractor for YouTube search queries.
-
_VALID_QUERY
= 'ytsearch(\\d+|all)?:[\\s\\S]+'¶
-
_TEMPLATE_URL
= 'https://www.youtube.com/results?search_query=%s&page=%s&gl=US&hl=en'¶
-
_VIDEO_INDICATOR
= 'href="/watch\\?v=.+?"'¶
-
_MORE_PAGES_INDICATOR
= '(?m)>\\s*Next\\s*</a>'¶
-
_max_youtube_results
= 1000¶
-
_youtube_ie
= None¶
-
-
class
YoutubePlaylistIE
(youtube_ie, downloader=None)[source]¶ Bases:
coherence.extern.youtubedl.youtubedl.InfoExtractor
Information Extractor for YouTube playlists.
-
_VALID_URL
= '(?:https://)?(?:\\w+\\.)?youtube.com/(?:view_play_list|my_playlists)\\?.*?p=([^&]+).*'¶
-
_TEMPLATE_URL
= 'https://www.youtube.com/view_play_list?p=%s&page=%s&gl=US&hl=en'¶
-
_VIDEO_INDICATOR
= '/watch\\?v=(.+?)&'¶
-
_MORE_PAGES_INDICATOR
= '/view_play_list?p=%s&page=%s'¶
-
_youtube_ie
= None¶
-
-
class
PostProcessor
(downloader=None)[source]¶ Bases:
object
Post Processor class.
PostProcessor objects can be added to downloaders with their add_post_processor() method. When the downloader has finished a successful download, it will take its internal chain of PostProcessors and start calling the run() method on each one of them, first with an initial argument and then with the returned value of the previous PostProcessor.
The chain will be stopped if one of them ever returns None or the end of the chain is reached.
PostProcessor objects follow a “mutual registration” process similar to InfoExtractor objects.
-
_downloader
= None¶
-
run
(information)[source]¶ Run the PostProcessor.
The “information” argument is a dictionary like the ones composed by InfoExtractors. The only difference is that this one has an extra field called “filepath” that points to the downloaded file.
When this method returns None, the postprocessing chain is stopped. However, this method may return an information dictionary that will be passed to the next postprocessing object in the chain. It can be the one it received after changing some fields.
In addition, this method may raise a PostProcessingError exception that will be taken into account by the downloader it was called from.
-