Package: podcast-downloader
Podcast DownloaderThe Python module for downloading files from given RSS feeds.
It is not using database of any sort. It require configuration file.The script is analyzing the directory where it put the previously downloaded files.
It is compering the last added file with the rss feed, finding the missing ones, and downloading them.As name suggested, the script is designed for podcasts. The files searched by default aremp3.SetupInstallation from PyPIpipinstallpodcast_downloaderRunning the scriptThe scriptrequire configuration filein order to work.
After installation, the script can be called as any Python module:python-mpodcast_downloaderIn actionUsing theexample above, the result will be:[2020-06-16 19:54:35] Loading configuration (from file: "~/.podcast_downloader_config.json")
[2020-06-16 19:54:35] Checking "The Skeptic Guide"
[2020-06-16 19:54:35] Last downloaded file "skepticast2020-06-13.mp3"
[2020-06-16 19:54:39] The Skeptic Guide: Nothing new
[2020-06-16 19:54:39] ------------------------------
[2020-06-16 19:54:39] FinishedConfigurationThe configuration fileThe configuration file is placed in home directory.The name:.podcast_downloader_config.json. The file is format inJSON. The expected encoding isutf-8.An example of configuration file{"if_directory_empty":"download_from_4_days","podcasts":[{"name":"Python for dummies","rss_link":"http://python-for-dummies/atom.rss","path":"~/podcasts/PythonForDummies"},{"name":"The Skeptic Guide","rss_link":"https://feed.theskepticsguide.org/feed/rss.aspx","path":"~/podcasts/SGTTU"}]}The settings hierarchyThe script will replace default values by read from configuration file.
Those will be cover by all values given by command line.command line parameters > configuration file > default valuesThe main optionsPropertyTypeRequiredDefaultNotedownloads_limitnumbernoinfinityif_directory_emptystringnodownload_lastSeeIn case of empty directorypodcast_extensionskey-valueno{".mp3": "audio/mpeg"}The file filterpodcastssubsectionyes[]SeePodcasts sub categoryhttp_headerskey-valueno{"User-Agent": "podcast-downloader"}SeeHTTP request headersPodcasts sub categoryPodcastsis the part of configuration file where you provide the array of objects with fallowing content:PropertyTypeRequiredDefaultNotenamestringyes-The name of channel (use in logger)rss_linkstringyes-The URL of RSS feedpathstringyes-The path to directory, where podcast are stored, will be downloadedfile_name_templatestringno%file_name%.%file_extension%The template for the downloaded files, seeFile name templatedisablebooleannofalseThis podcast will be ignoredpodcast_extensionskey-valueno{".mp3": "audio/mpeg"}The file filterif_directory_emptystringnodownload_lastSeeIn case of empty directoryrequire_datebooleannofalseDeprecatedIs date of podcast should be added into name of file - use thefile_name_template:[%publish_date%] %file_name%.%file_extension%"http_headerskey-valueno{"User-Agent": "podcast-downloader"}HTTP request headersSome servers may don't like how the urllib is presenting itself to them (the HTTP User-Agent header). This may lead into problem likes:urllib.error.HTTPError: HTTP Error 403: Forbidden. It may be require to present the script client as something else.There is an option to specify HTTP headers when downloading files.
You can provide them using thehttp_headersvalue in the configuration file.
The option value should be a dictionary where each header is presented as a key-value pair, with the key being the header title and the value being the header value.Default value:{"User-Agent": "podcast-downloader"}. Providing any value forhttp_headerswill override the default value.Podcasthttp_headerswill be merged with the globalhttp_headers. In case of a conflict (same key name), the vale from podcast sub-configuration will override the global one.Example:{"http_headers":{"User-Agent":"podcast-downloader"},"podcasts":[{"name":"Unu Podcast","rss_link":"http://www.unupodcast.org/feed.rss","path":"~/podcasts/unu_podcast","https_headers":{"User-Agent":"User-Agent: Mozilla/5.0",}}]}Script argumentsThe script accept following command line arguments:Short versionLong nameParameterDefaultNote--downloads_limitnumberinfinityThe maximum number of downloaded mp3 files--if_directory_emptystringdownload_lastThe general approach on empty directoryAdding date to file nameIf RSS channel doesn't have single and constant name convention, it may causing the script to working incorrectly. The solution is force files to have common and meaningful prefix. The script is able to adding the date on beginning of downloaded file name.UseFile name templateand option%publish_date%.File name templateUse to change the name of downloaded file after its downloading.Default value (the%file_name%.%file_extension%) will simple save up the file as it was uploaded by original creator. The file name and its extension is taken from the link to podcast file.Template values:NameNotes%file_name%The file name taken from link, without extension%file_extension%The extension for the file, taken from link%publish_date%The publish date of the RSS entry, in formatYEARMMDD%title%The title of the RSS entryExamples:[%publish_date%] %file_name%.%file_extension%[%publish_date%] %title%.%file_extension%File types filterPodcasts are mostly stored as*.mp3files. By default Podcast Downloader will look just for them.If your podcast support other types of media files, you can precised your own podcast file filter, by providing extension for the file (like.mp3), and type of link in RSS feed itself (formp3it isaudio/mpeg).If you don't know the type of the file, you can check the RSS file. Seek forenclosuretags, should looks like this:<enclosureurl="https://an.apple.supporter.page/podcast/episode23.m4a"length="14527149"type="audio/x-m4a"/>Notes: the dot on the file extension is require.Example"podcast_extensions":{".mp3":"audio/mpeg",".m4a":"audio/x-m4a"}In case of empty directoryIf a directory for podcast is empty, the script needs to recognize what to do. Due to lack of database, you can:download all episodes from feeddownload only the last episodedownload last n episodesdownload all new episode from last n daysdownload all new episode since day after, the last episode should appearDownload all from feedThe script will download all episodes from the feed.Set bydownload_all_from_feed.Only lastThe script will download only the last episode from the feed.
It is a good approach when you wish to start listening the podcast.
It is also default approach of the script.Set bydownload_last.Download last n episodesThe script will download exactly given number of episodes from the feed.Set bydownload_last_n_episodes. Thenmust be replaced by number of episodes, which you wanted to have downloaded. For example:download_last_5_episodesmeans that five last episodes will be downloaded.Download all from n daysThe script will download all episodes which appear in lastndays. I can be use when you are downloading on regular schedule.
Thennumber is given within the setup value:download_from_n_days. For example:download_from_3_daysmeans download all episodes from last 3 days.Download all episode since last exceptedThe script will download all episodes which appear after the day of release of last episode.Thennumber is the day of the normal episode.
You can provide here week days as word (size of the letters is ignored)Full week dayShorten nameMondayMonTuesdayTuesWednesdayWedsThursdayThursFridayFriSaturdaySatSundaySunYou can provide the number, it will means the day of the month. The script accepts only number from 1 to 28.Set bydownload_from_.Examples:Example valueMeaningdownload_from_mondayNew episodes appear in Monday. The script will download all episodes since last Tuesday (including it)download_from_FriNew episodes appear in Friday. The script will download all episodes since last Saturday (including it)download_from_12New episodes appear each 12th of month. The script will download all episodes since 13 month beforeThe analyze of the RSS feedThe script is look through all theitemsnodes in RSS file. Theitemnode can contain theenclosurenode. Those nodes are used to passing the files. According to the convention the singleitemshould contain only oneenclosure, but script (asthe library usedunder it) can handle the multiple files attached into podcastitem.