Adding webradios by writing files .pls .m3u into a directory

General discussion about RuneAudio. Do not post any support or feature requests here.

Re: Adding webradios by writing files .pls .m3u into a direc

Postby xan » 16 Oct 2015, 22:35

A bit late but maybe someone is still interested... Here is not a python script but a small bash-script that scans the Webradio directory and adds the the radio stations to redis.

Code: Select all
#! /bin/bash

for FILE in /mnt/MPD/Webradio/*.pls;
   NAME=$(echo $FILE | grep -Po "(?<=/)[^/]+(?=\.)");
   echo "station: $NAME";
   URL=$(grep -Po "(?<=File1=).*$" "$FILE");
   echo "url: $URL";
   redis-cli hset "webradios" "${NAME}" "${URL}";
mpc update webradio;

You can copy that into a file called "updateWebradios" in the /bin directory (/bin/updateWebradios) chmod it to 755 and then you can call it by just typing "updateWebradios" into the command line.

Or you can just copy that as one line into the command line and hit enter
Code: Select all
for FILE in /mnt/MPD/Webradio/*.pls; do NAME=$(echo $FILE | grep -Po "(?<=/)[^/]+(?=\.)"); echo "station: $NAME"; URL=$(grep -Po "(?<=File1=).*$" "$FILE"); echo "url: $URL"; redis-cli hset "webradios" "${NAME}" "${URL}"; done; mpc update webradio;

After you have run the script you still have to go to "RESOURCES" and click "update MPD library" to get the stations visible. I am working on that...
Posts: 1
Joined: 10 Nov 2014, 23:12

Re: Adding webradios by writing files .pls .m3u into a direc

Postby surfninja » 19 Oct 2015, 20:06

this is great xan. I was going to write a perl version for the forum but didn't know the redis set syntax. Now I do.

thanks for posting.
rAudio 1, Raspberry Pi 2B
rAudio 1, Raspberry Pi 4B
rAudio 1, Raspberry Pi Zero W
Posts: 92
Joined: 13 Mar 2015, 22:06
Location: Twin Cities

Re: Adding webradios by writing files .pls .m3u into a direc

Postby Sprigo » 02 Nov 2015, 22:28

Well done xan! This saves me so much time as I was having to add them manually each time. :D
Posts: 14
Joined: 22 Sep 2015, 15:33

Re: Adding webradios by writing files .pls .m3u into a direc

Postby c-moll » 25 Mar 2016, 11:00

I've added my webradio folder according to the above instructions. But now the stations are listed in a random order. How can I sort the list?

Raspberry Pi 3B - HifiBerry Amp+ - Raspberry Pi 7" Touchscreen
User avatar
Posts: 10
Joined: 01 Oct 2014, 13:30
Location: Germany

Re: Adding webradios by writing files .pls .m3u into a direc

Postby gargonia » 16 Oct 2019, 21:11

Even later than xan, but here's a Python script that will bulk add web radio stations. It can either do it from .pls files in /mnt/MPD/Webradio or from a .csv file:

Code: Select all
#!/usr/bin/env python2

import glob
import os
import string
import subprocess
import sys
import time

def read_file(file_name):
   file_handle = open(file_name,'r')
   file_lines = map(string.strip,file_handle.readlines())
   return file_lines

def create_pls_files(stations):
   for station in stations:
      station_pls_file = open('/mnt/MPD/Webradio/%s.pls' % station,'w')
Title1=%s""" % (station,stations[station]))

def get_pls_stations():
   station_files = glob.glob('/mnt/MPD/Webradio/*.pls')
   station_data = {}
   for station_file in station_files:
      station = read_file(station_file)
      station_name = station[3].split('=')[-1]
      station_url = station[2].split('=')[-1]
      station_data[station_name] = station_url
   return station_data

def get_csv_stations():
   station_file = raw_input('Please enter the path to the webradio station file: ')
   if not os.path.isfile(station_file):
      print('Unable to find the file... please check the path and run again.')
      station_data = read_file(station_file)
      stations = dict(station.split(',') for station in station_data)
      return stations

def update_rune(stations):
   for station in sorted(stations.keys()):['redis-cli','hset','webradios',station,stations[station]])

def main():
   update_type = raw_input('Update from PLS files or CSV (P/c)? ')
   stations = {}
   if update_type.lower() == 'c':
      stations = get_csv_stations()
      stations = get_pls_stations()

if __name__ == '__main__':

Hope this helps someone else encountering this problem.
Posts: 1
Joined: 16 Oct 2019, 15:56

support RuneAudio Donate with PayPal


Return to General discussion

Who is online

Users browsing this forum: Google [Bot] and 1 guest