Radio2Podcast Script
About the Script
Brief Description
I created Radio2Podcast for recording radio broadcasts and converting them into podcasts. You can select a station, set the recording duration, and save files locally, on an FTP server, SFTP or in NextCloud.
The script can be downloaded here: Radio2Podcast 0.052
Changelog
- 2024-12-28 released version 0.052
- The script performs audio conversion only once for each unique parameter configuration (format, bitrate, channels), improving performance and reducing CPU usage.
- Added support for AAC/M4A format (
libfdk_aac
) with the HE-AAC profile.
- 2024-10-20 released version 0.051
- Added SFTP as a new save location alongside local, FTP, and NextCloud.
- Recordings are now saved in .ts format with the original stream quality before converting to the selected format (e.g., mp3 or opus).
- Added support for pauses during recording (e.g., to skip ads) controlled via command-line parameters. More details in the usage section.
- 2024-08-30 released version 0.05
- Renamed the script from RSRS to Radio2Podcast.
- Changed script logic—program and station names can now consist of multiple words. If the program title or station name contains diacritical characters, the script retains them in the RSS but replaces them with Latin equivalents in file paths.
- Added the ability to specify the local save path in config.json. By default, it is
./
(script location), but another directory can be used.
- 2024-07-18 released version 0.04
- Various minor improvements for ease of use, including changes to script parameters and adding a function to monitor the number of locally stored files.
- 2024-05-01 released version 0.3
- Added basic podcast support. The script uploads files to an FTP server in the appropriate folder, then checks the list of audio files in that folder and generates an RSS file each time it runs. The RSS file adheres to standards—though it cannot yet be added to PocketCasts, it works correctly in other podcast apps. The RSS file references a cover image in the folder, which must be named podcast.jpg. File path management has also been improved.
- 2024-04-03 released version 0.02
- Completely rebuilt the script. Users can select the file format (mp3 or opus), bitrate, and channels (stereo or mono) for each destination. This allows saving files locally in .opus 32kbps stereo format, on FTP in mp3 32kbps mono format, and in NextCloud in .opus 16kbps mono format. This feature will also be useful when the script supports podcasts. Added AAC(m4a) to the development plan.
- 2024-03-29 released version 0.01
Development Plan
- Multiple Formats
Ability to save different file types depending on the destination (e.g., .mp3 on FTP and .opus in NextCloud)(done in version 0.02)Support for opus, mp3, and aac/m4a formats(done in version 0.052)
- Podcast Support
If the user chooses to save files on FTP, the script should generate a podcast RSS.(done in version 0.03)The RSS feed should comply with podcast standards.(done in version 0.05)- Rewrite RSS generation code. Replace the pod2gen library with feedgen.
- The script should generate a simple cover image.
- File Save Path
Add the ability to specify a local save path in config.json. Useful if the script runs on a VPS also hosting a web server.(done in version 0.05)Add SFTP support(done in version 0.05)- Add support for Mega.nz.
- Add support for Dropbox.
- Modularity
- Refactor the script into modules/sub-scripts responsible for specific tasks. Currently, everything is centralized in one script, but modularization will make it easier to edit and focus on specific parts (e.g., the RSS generation module).
How to Use the Script
Before First Use
Install:
- Python 3
- pip (Python package manager)
- ffmpeg (with
libfdk_aac
support) - Python modules:
webdavclient3
,pod2gen
,paramiko
Parameters:
- Station Name – name of the radio stream.
- Show Name – used to create folders and file names.
- Recording Duration – specified in minutes.
- Save Location – use the
-s
flag to indicate destinations: local, FTP, SFTP, or NextCloud. You can select one or multiple locations. - Pauses and Segments – use the
-p
flag to insert pauses during recording to skip unwanted segments, such as ads.
Usage in Practice
python3 r2p.py "BBC Radio 1" "Morning Show" 25 -s local nextcloud -p 10,3,15
The script will record the BBC Radio 1 stream for a total of 25 minutes, saving the recording locally and to NextCloud. The recording will start recording for 10 minutes, pause for 3 minutes, and then resume for another 15 minutes. This allows skipping unwanted segments like advertisements by controlling recording and pause intervals.
On Linux, you can use crontab to schedule recordings and set up a recording schedule. Here’s a guide on how to do this.
Generating an RSS Feed
The script automatically generates an RSS feed whenever a file is uploaded to an FTP/SFTP server, turning recorded broadcasts into a podcast. This simplifies distributing recorded radio broadcasts as podcasts, making it easier for listeners to subscribe and automatically receive new episodes.