Moode Forum
[SOLVED] How to import radio stations - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: Community (https://moodeaudio.org/forum/forumdisplay.php?fid=18)
+--- Forum: General Discussion (https://moodeaudio.org/forum/forumdisplay.php?fid=21)
+--- Thread: [SOLVED] How to import radio stations (/showthread.php?tid=5623)



How to import radio stations - haeckse - 06-11-2023

Hey all,

A while ago I've created a React web client for streaming internet radio: RadioMii

The client pulls the info about the streams from radio-browser.info

Favorites created in RadioMii can be exported with XSPF or M3U format.

As it seems, Moode does not provide an option yet to import radio stations via M3U files. When I copy a M3U file to /var/lib/mpd/playlists, its radio stations don't appear in the UI, presumably because of missing entries in the db and missing cover images.

Looking into Moode's default radio playlist, the #EXTIMG tag shows that the station images seem to be stored locally, so the images are presumably referenced in the db entries then:

Code:
#EXTGENRE:Various
#EXTIMG:local
http://subfm.radioca.st/Sub.FM
http://kdhx-ice.streamguys1.com:80/live

I wonder if there is a way on console level to do a M3U bulk import with fetching station images dynamically and write them to Moode's database. I could adjust the RadioMii M3U export so that it contains the link to an image in #EXTIMG and also some other data like the stations genre, homepage, language, country, bitrate etc. as extended info key-value pairs.

Cheers
Andrea


RE: Import radio stations - TheOldPresbyope - 06-11-2023

(06-11-2023, 09:13 AM)haeckse Wrote: Hey all,

A while ago I've created a React web client for streaming internet radio: RadioMii

The client pulls the info about the streams from radio-browser.info

Favorites created in RadioMii can be exported with XSPF or M3U format.

As it seems, Moode does not provide an option yet to import radio stations via M3U files. When I copy a M3U file to /var/lib/mpd/playlists, its radio stations don't appear in the UI, presumably because of missing entries in the db and missing cover images.

Looking into Moode's default radio playlist, the #EXTIMG tag shows that the station images seem to be stored locally, so the images are presumably referenced in the db entries then:

Code:
#EXTGENRE:Various
#EXTIMG:local
http://subfm.radioca.st/Sub.FM
http://kdhx-ice.streamguys1.com:80/live

I wonder if there is a way on console level to do a M3U bulk import with fetching station images dynamically and write them to Moode's database. I could adjust the RadioMii M3U export so that it contains the link to an image in #EXTIMG and also some other data like the stations genre, homepage, language, country, bitrate etc. as extended info key-value pairs.

Cheers
Andrea

Hi, Andrea.

moOde stores data about radio stations in three places:
  • individual .pls files in /var/lib/mpd/music/RADIO
  • logo images (and thumbnails) in /var/local/www/imagesw/radio-logos
  • entries to link the above together along with various metadata in the cfg_radio table of moOde's database /var/local/www/db/moode-sqlite3.db
There's Tim's PHP code you can examine to see how this data gets used in moOde; there's Bitlab's nice utility /var/www/util/station_manager.py and there's even old code of mine lingering about in my github repo (which I wouldn't bother with now that station_manager.py exists).

I'm thinking a quick-n-dirty solution to the problem you pose is to write some code to convert your .m3u files and image files into a form which fits what station_manager.py already does. But it's up to you how you want to slice-and-dice the problem.

Regards,
Kent

PS - .m3u files are used in moOde only to store playlists.


RE: Import radio stations - Tim Curtis - 06-11-2023

ETA: To add to what Kent mentioned.

M3U files are only used for playlists and are stored in /var/lib/mpd/playlists. You could use system Backup to export just the Playlists, modify the backup zip to contain your playlists, re-zip the file and then do a Restore.

If you want to do bulk import of radio stations into the Radio feature then read below.

1. SQL table cfg_radio in /var/local/www/db/moode-sqlite3.db

This table contains metadata for each station and is referenced by the station URL which is what MPD loads into the Queue from a station .pls file.

Code:
moodeutl -q "select * from cfg_radio"

2. Station .pls files in /var/lib/mpd/music/RADIO/

These files are what MPD indexes into its database and what MPD reads to load a station URL into the Queue. These files are generated from the cfg_radio table during the image build process using the station_manager.py utility

Code:
pi@moode:~ $ cat /var/lib/mpd/music/RADIO/FluxFM.pls 
[playlist]
File1=https://fluxmusic.api.radiosphere.io/channels/FluxFM/stream.aac?quality=4
Title1=FluxFM
Length1=-1
NumberOfEntries=1
Version=2

3. Station cover logos in /var/local/www/imagesw/radio-logos/ and radio-logos/thumbs/

Code:
radio-logos/stationName.jpg             Full sized logo displayed in Playback view
radio-logos/thumbs/statioName.jpg       Thumbnail (200px) displayed in Radio view
radio-logos/thumbs/stationName_sm.jpg   Small thumbnail (80px) displayed in the Queue and Playbar

4. Station manager utility
https://github.com/moode-player/moode/blob/develop/www/util/station_manager.py

Code:
pi@moode:~ $ /var/www/util/station_manager.py -h
usage: station_manager.py [-h] [--version] (--import | --export | --clear | --compare | --diff DIFF | --regeneratepls) [--scope {all,moode,other}]
                         [--type {favorite,regular,hidden,nothidden}] [--how {clear,merge}] [--db DB] [--logopath LOGOPATH]
                         [backupfile]

Manages import and export of moOde radiostations.

positional arguments:
 backupfile            Filename of the station backup. Required by the import, export and compare.

optional arguments:
 -h, --help            show this help message and exit
 --version             show program's version number and exit
 --import              Import radio stations from backup.
 --export              Export radio stations to backup.
 --clear               Clear radio stations. This will delete the contents of the SQL table, logo images and pls files of the selected stations within the specified scope.
 --compare             Show difference between SQL table and station backup.
 --diff DIFF           Create a diff backup with the difference between the old (=backup) and new (=db) to this files.
 --regeneratepls       Regenerate the radio .pls files from db.
 --scope {all,moode,other}
                       Indicate to which stations the specified action applies. (default: other)
 --type {favorite,regular,hidden,nothidden}
                       Indicate the type of station to export.
 --how {clear,merge}   On import, clear stations before action or merge and add. (default: merge)
 --db DB               File name of the SQL database. (default: /var/local/www/db/moode-sqlite3.db
 --logopath LOGOPATH   Location of the radio logos. (default: /var/local/www/imagesw/radio-logo

Root privileges required for import or clear.
pi@moode:~ $

The station manager utility can be used to bulk import stations into the Radio feature by the following process:

- Export the already bundled stations
- Unzip the export file
- Modify radio-logos/ and station_data.json to only include the stations to be imported
- Re-zip 
- Import the zip which will add the stations to cfg_radio starting at id=500, add the radio logos and create the .pls files.
sudo /var/www/util/station_manager.py --scope other --import ./tim.zip

Code:
pi@moode:~ $ /var/www/util/station_manager.py --scope all --export ./tim.zip
SQL database location is '/var/local/www/db/moode-sqlite3.db'
Station logos location is '/var/local/www/imagesw/radio-logos'
Export station data
Export station logos

pi@moode:~ $ ls
devutl.sh  piano.sh  tim.zip

pi@moode:~ $ unzip -q tim.zip

pi@moode:~ $ ls
devutl.sh  piano.sh  radio-logos  station_data.json  tim.zip



RE: Import radio stations - haeckse - 06-11-2023

Hello @TheOldPresbyope,
hello @Tim Curtis,

Thank you guys for all the information about what is expected where in the directory structure, that helps a lot.

Now I know how to proceed and with the neat station manager utility the import will work just fine.

Cheers,
Andrea