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:
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 is False, 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 not None, download the audio stream with the specified format. If largest_audio is True, download the largest audiostream; otherwise, download the smallest audiostream. If preferred_format is not None, download the audiostream having that format. The latter option works in combination with largest_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 matching preferred_index or preferred_format and largest_audio; if False, 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; if False, download the smallest one.
Return type:

string or list of dict

Raises:

ImportError: if youtube-dl is not installed

Raises:

OSError: if output_file_path cannot be written

Raises:

DownloadError: if source_url is not a valid YouTube URL or it cannot be downloaded e.g. for temporary network issues