This project is a Python script that records internet radio shows and downloads them for later listening. The recording schedule and stream URLs are managed via a configuration file, and the script uses environment variables for flexible deployment.
- Python 3
- ffmpeg
- Virtual environment (recommended)
- Schedule recordings for specific days and times.
- Record multiple shows concurrently.
- Automatic file naming and organization.
- Configuration file for easy management of show details.
- Environment variables for flexible deployment.
- Test the schedule to verify stream availability.
-
Clone the repository:
git clone https://github.com/codybrom/radiojoe.git cd radiojoe
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install the required Python libraries:
pip install schedule pytz requests
-
Create a
config.json
file in the root directory with your show details and information for the ID3 tags. Duration is measured in seconds (3600 = 1 hour){ "shows": [ { "name": "KEXP", "url": "https://17793.live.streamtheworld.com/KUOWFM_HIGH_MP3.mp3", "day": "Thursday", "time": "10:00 PM", "timezone": "America/Los_Angeles", "duration": 3600, "artist": "KUOW Spotlight", "album": "KUOW Spotlight", "genre": "Radio" }, // Add other shows here ] }
-
Create a
run_recorder.sh
script to set environment variables and run the Python script:#!/bin/bash # Set environment variables export RADIOJOE_BASE_DIR="/path/to/your/project" export RADIOJOE_LOG_FILE="$RADIOJOE_BASE_DIR/recorder.log" export RADIOJOE_OUTPUT_DIR="$RADIOJOE_BASE_DIR/recordings" export RADIOJOE_CONFIG_FILE="$RADIOJOE_BASE_DIR/config.json" # Set the working directory cd "$RADIOJOE_BASE_DIR" # Activate virtual environment source /path/to/your/project/venv/bin/activate # Run the Python script python3 "$RADIOJOE_BASE_DIR/recorder.py"
Make sure to update the paths in this script to match your system.
Make the run script executable and run it:
chmod +x run_recorder.sh
./run_recorder.sh
The show_schedule.py
script allows you to test the upcoming schedule and verify the availability of the streams. To run the schedule test:
-
Make sure you're in the project directory and your virtual environment is activated.
-
Run the following command:
python3 show_schedule.py
This will display the upcoming recordings for the next 7 days, organized by date. For each show, it will test the stream URL and display the status:
- ✅: The stream is accessible and appears to be an audio stream.
- ❓: The stream is accessible but may not be an audio stream.
- ❌: The stream is not accessible or there was an error.
- ⏳: The connection timed out.
This test helps ensure that your configured streams are working correctly before the scheduled recording time.
To ensure the script runs at system startup:
-
Open the crontab editor:
crontab -e
-
Add the following entry:
@reboot /path/to/your/project/run_recorder.sh >> /path/to/your/project/recorder.log 2>&1
Replace
/path/to/your/project
with the actual path to your project directory.
recorder.py
: The main Python script that handles scheduling and recording.show_schedule.py
: Script to test and display the upcoming schedule.config.json
: Configuration file for show details.run_recorder.sh
: Bash script to set environment variables and run the Python script.recordings/
: Directory where recorded shows are saved (created automatically).recorder.log
: Log file for the script's operations.
You can customize the following environment variables in run_recorder.sh
:
RADIOJOE_BASE_DIR
: The base directory of the project.RADIOJOE_LOG_FILE
: Path to the log file.RADIOJOE_OUTPUT_DIR
: Directory where recordings are saved.RADIOJOE_CONFIG_FILE
: Path to the configuration file.
- If the script isn't running as expected, check the
recorder.log
file for error messages. - Ensure that ffmpeg is installed and accessible in your system's PATH.
- Verify that the URLs in your
config.json
are correct and accessible. - Use the
show_schedule.py
script to test the availability of your configured streams.
Feel free to fork this project and submit pull requests with any improvements or bug fixes.