downloader¶
This module contains the following classes:
DownloadError
, which represents an error occurred while downloading a Web resource.Downloader
, which download files from various Web sources.
Note
This module requires Python module youtube-dl
(pip install youtube-dl
).
-
exception
aeneas.downloader.
DownloadError
[source]¶ Error raised when a given URL is not valid or it cannot be downloaded because of temporary network issues.
-
class
aeneas.downloader.
Downloader
(logger=None, rconf=None)[source]¶ Download files from various Web sources. At the moment, only YouTube videos are officially supported.
Parameters: - rconf (
RuntimeConfiguration
) – a runtime configuration - logger (
Logger
) – the logger object
-
audio_from_youtube
(source_url, download=True, output_file_path=None, download_format=None, largest_audio=True)[source]¶ Download an audio stream from a YouTube video, and save it to file.
If
download
isFalse
, return the list of available audiostreams but do not download.Otherwise, download the audio stream best matching the provided parameters, as follows. If
download_format
is notNone
, download the audio stream with the specified format. Iflargest_audio
isTrue
, download the largest audiostream; otherwise, download the smallest audiostream. Ifpreferred_format
is notNone
, download the audiostream having that format. The latter option works in combination withlargest_audio
.Return the path of the downloaded file.
Parameters: - source_url (string) – the URL of the YouTube video
- download (bool) – if
True
, download the audio stream best matchingpreferred_index
orpreferred_format
andlargest_audio
; ifFalse
, return the list of available audio streams - output_file_path (string) – the path where the downloaded audio should be saved;
if
None
, create a temporary file - download_format (int) – download the audio stream with the given format
- largest_audio (bool) – if
True
, download the largest audio stream available; ifFalse
, download the smallest one.
Return type: string or list of dict
Raises: ImportError: if
youtube-dl
is not installedRaises: OSError: if
output_file_path
cannot be writtenRaises: DownloadError
: ifsource_url
is not a valid YouTube URL or it cannot be downloaded e.g. for temporary network issues
- rconf (