radio-to-spotify
is a Go-based tool that scrapes now-playing songs from online radio stations and creates Spotify playlists based on the last hour of songs played by a station. It can run as a daemon to periodically fetch and store the now-playing data.
docker run -v --rm -it ceddicedced/radiotospotify
- Features
- Installation
- Configuration
- Usage
- Running with Docker
- Contributing
- License
- Acknowledgements
- Contact
- Fetch Now-Playing Songs: Scrape current songs playing on various radio stations.
- Store Fetched Songs: Store songs in a file, SQLite, or PostgreSQL database.
- Create Spotify Playlists: Generate Spotify playlists based on stored songs.
- Run as a Daemon: Periodically fetch and store songs.
- Go (version 1.16+)
- SQLite (if using SQLite storage)
- PostgreSQL (if using PostgreSQL storage)
- Spotify Developer Account
git clone https://github.com/ceddicedced/radio-to-spotify.git
cd radio-to-spotify
go build -o radio-to-spotify main.go
Create a stations.json
file to define the radio stations to scrape:
{
[
{
"id": "1live",
"name": "WDR 1LIVE",
"url": "https://www.wdr.de/radio/radiotext/streamtitle_1live.txt",
"type": "plaintext",
"regex": "(?P<artist>.+?) - (?P<title>.+)",
"playlistID": "3yJEj5bAmhc6bFREajJu6t"
},
{
"id": "rs2",
"name": "94.3 rs2",
"url": "https://iris-rs2.loverad.io/flow.json?station=7",
"type": "json",
"artistKey": ["result", "entry", 0, "song", "entry", 0, "artist", "entry", 0, "name"],
"titleKey": ["result", "entry", 0, "song", "entry", 0, "title"],
"playlistID" :"4v8AVb5aOixKbR2NjDZuLq"
},
{
"id": "radio1",
"name": "Radio Eins",
"url": "https://www.radioeins.de/include/rad/nowonair/now_on_air.html",
"type": "html",
"artistTag": "p.artist",
"titleTag": "p.songtitle",
"playlistID": "2S41FhYMM5TDT3bL8XYWEK"
}
]
}
id
: Unique identifier for the station.name
: Name of the station.url
: URL to scrape the now-playing songs.type
: Type of response (html or json or plaintext).artistTag
: HTML tag for the artist name (html type).titleTag
: HTML tag for the song title (html type).artistKey
: JSON key for the artist name (json type).regex
: Regular expression to extract the artist and title (plaintext type).titleKey
: JSON key for the song title (json type).playlistID
: Spotify playlist ID to add the songs.
Set up your environment variables for Spotify integration:
SPOTIFY_ID
: Your Spotify Client IDSPOTIFY_SECRET
: Your Spotify Client SecretSPOTIFY_REDIRECT_URL
: Your Spotify Redirect URL
You can store these in a .env
file:
SPOTIFY_ID=your_spotify_client_id
SPOTIFY_SECRET=your_spotify_client_secret
SPOTIFY_REDIRECT_URL=your_spotify_redirect_url
Fetch the now-playing songs for all stations defined in the stations.json
file:
./radio-to-spotify fetch --config=stations.json --loglevel=debug --storage=file --storage-path=data/db.json
Fetch and store now-playing songs for a specific station (dry run):
./radio-to-spotify store --config=stations.json --station=radiofritz --loglevel=info --dry-run --storage=file --storage-path=data/db.json
Create a Spotify playlist for the last hour of songs for a specific station:
./radio-to-spotify playlist --config=stations.json --station=radiofritz --loglevel=error --storage=file --storage-path=data/db.json --playlist-range=lasthour
Run the tool as a daemon to periodically fetch and store now-playing songs:
./radio-to-spotify daemon --config=stations.json --loglevel=debug --storage=file --storage-path=data/db.json --interval=1m --playlist-range=lasthour
You can use the provided Docker image ceddicedced/radiotospotify
to run the application:
docker pull ceddicedced/radiotospotify
docker run -v $(pwd)/data:/app/data -e SPOTIFY_ID -e SPOTIFY_SECRET -e SPOTIFY_REDIRECT_URL ceddicedced/radiotospotify daemon --config=stations.json --loglevel=debug --storage=file --storage-path=data/db.json --interval=1m --playlist-range=lasthour
To build and run your own Docker image:
docker build -t radio-to-spotify .
docker run -v $(pwd)/data:/app/data -e SPOTIFY_ID -e SPOTIFY_SECRET -e SPOTIFY_REDIRECT_URL radio-to-spotify daemon --config=stations.json --loglevel=debug --storage=file --storage-path=data/db.json --interval=1m --playlist-range=lasthour
Contributions are welcome! Please open an issue or submit a pull request for any changes.
This project is licensed under the MIT License. See the LICENSE file for details.
Created by Ceddicedced - feel free to contact me!