Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Radio Stations and Images sync
#11
(08-10-2019, 01:07 PM)TheOldPresbyope Wrote: @ghoeher

Hi, Georg.

If you can wait a couple more days I should have Python scripts ready for prime time which do the following:
  • in export mode, scan the moOde database for user-defined radio station entries; for each one extract the db info along with the corresponding .pls file, the station logo .jpg file and its thumbnail .jpg file (if the image files exist); save all to a tarball (e.g., a tar file).
  • in import mode, untar the tarball to a temp directory and, for each station, first check if it clashes with a station already present in the moOde database; if not, extract the station entry to the database and the corresponding files to their proper places.
These are just utility scripts (but I suppose they could be combined into one). I'm not tackling any kind of automated player-to-player transfer or any integration with the moOde UI. The user has to run the export script, transfer the tarball, run the import script, all from the command line. Further these scripts are all or none; I'm not tackling any kind of user selection of the stations to export or import.

I starting developing these scripts for my own use but they may be useful to others to:
  • Deal with upgrading to a new major release of moOde
  • Copy stations from one player to another player whether it's running the same release or a different release
  • Share favorites to another user
I'll have to spend some time reading Tim's release notes to see how far back in moOde releases these scripts will work. IIRC, radio logo thumbnails were introduced mid 4.x. Don't recall if the database schema for radio stations or the location of the file directories has changed since 4.0.

Regards,
Kent

Hi Kent,

User added Radio logos were introduced in the 5.0 release and i think thats also when the type column was added to cfg_radio to help differentiate between user added and system pre-defined stations.

To list out the user added stations run the query below. Change 'u; to 's' to list out the system pre-defined stations. User added stations must start at id > 499.

Code:
sqlite3 /var/local/www/db/moode-sqlite3.db "select * from cfg_radio where type='u'"

I think when importing I'd first delete rows where type='u', then do a bulk import from a csv. This might avoid the need to check whether the stations already exist. For example:

Code:
sqlite3 /var/local/www/db/moode-sqlite3.db "DELETE FROM cfg_cfg_radio WHERE type='u'"
sqlite3 /var/local/www/db/moode-sqlite3.db -csv ".import /home/pi/cfg_radio.csv cfg_radio"

The csv file looks like below

Code:
1,http://strm112.1.fm/blues_mobile_mp3,1.FM - Blues Radio,s,local
2,http://eno.emit.com:8000/2bob_live_64.mp3,2BOB Radio 104.7 FM,s,local
3,http://stream.4zzzfm.org.au:789,4ZZZ FM 102.1 - Alternative,s,local
4,http://54.173.171.80:8000/6forty,6forty Radio,s,local
5,http://radio.stereoscenic.com/ama-h,A.M. Ambient,s,local
6,http://live-radio01.mediahubaustralia.com/CTRW/mp3/,ABC Country,s,local
7,http://live-radio01.mediahubaustralia.com/JAZW/mp3/,ABC Jazz,s,local
8,http://stream.absolutradio.de/hot/mp3-128/radioplayer/,Absolut Hot,s,local
9,http://stream.absolutradio.de/hq/mp3-160/radioplayer/,Absolut Radio,s,local
10,http://stream.absolutradio.de/relax/mp3-160/radioplayer/,Absolut Relax,s,local
11,http://radio.stereoscenic.com/asp-h,Ambient Sleeping Pill,s,local
.
.

-Tim
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#12
Hi Tim,

even if you addressed this to Kent in a first way - thanks for the explanation and your great support. Even with those SQL statements only, it would be much easier for me to migrate to a new image.

Regarding the import - deleting "u"-type entries first would make a script easier to implement, but then it's always a kind of "initial" import. But if you - like Kent wrote - want to share your favorites also with someone else, deleting the "u" entries first is not an option. This is nothing essential (at least for me) but would be a nice "addon".

But let's wait for Kent's script - I'm pretty sure it will do it's job perfect.
Reply
#13
@Tim Curtis

Yeah, I sussed out the schema sometime ago (for a while there was a comment in my code which said "I suppose 's' must stand for system). As it stands now, the script exports all entries tagged 'u'. I don't check the ID on export since that seemed redundant knowing your "add station" functionality. On import, your ID=499 divider as well as existing user-defines are observed en passant since my script lets sqlite3 autoincrement the ID just as yours does. I detest CSV so my script exports and imports the database entries as a JSON file. It's a verbose format but did I mention I detest CSV?

My script doesn't clear out the existing user-defined stations because in my imagined scenarios the user may have already added some stations by hand. Seemed rude to squash them  Tongue

Regards,
Kent
Reply
#14
lol, CSV format can definitely be a pain.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#15
See my post in FAQ and Guides

Regards,
Kent
Reply
#16
(08-11-2019, 01:06 PM)Tim Curtis Wrote: lol, CSV format can definitely be a pain.

Tim is there any chance you could alter the permissions in your next release for the folder/var/www/images/radio-logos for the Pi user so that one can manually copy images into that folder, Please. Because at the moment it simply gives permission denied massage.


Attached Files Thumbnail(s)
   
Reply
#17
Thats something I'd leave up to the user. It's not a good practice for me to expand the scope of permissions on a directory unless it solves a generally applicable issue.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#18
(08-21-2019, 07:57 PM)Tim Curtis Wrote: Thats something I'd leave up to the user. It's not a good practice for me to expand the scope of permissions on a directory unless it solves a generally applicable issue.

I tried to change that being the user with no success. Could you direct me how I can accomplish that on my system.


pi@OutdoorSpeakers:/var/www/images $ chmod +rwx radio-logos/
chmod: changing permissions of 'radio-logos/': Operation not permitted


Attached Files Thumbnail(s)
   
Reply
#19
(08-21-2019, 08:13 PM)Im bored Wrote:
(08-21-2019, 07:57 PM)Tim Curtis Wrote: Thats something I'd leave up to the user. It's not a good practice for me to expand the scope of permissions on a directory unless it solves a generally applicable issue.

I tried to change that being the user with no success. Could you direct me how I can accomplish that on my system.


pi@OutdoorSpeakers:/var/www/images $ chmod +rwx radio-logos/
chmod: changing permissions of 'radio-logos/': Operation not permitted

Well you can't change the permissions on a directory owned by root unless you execute the operation as superuser.

But I'm still trying to figure out your report in the other thread. Are you working just with my scripts or also doing handwork on your own? That's likely to cause confusion.

Regards,
Kent
Reply
#20
(08-21-2019, 08:15 PM)TheOldPresbyope Wrote:
(08-21-2019, 08:13 PM)Im bored Wrote:
(08-21-2019, 07:57 PM)Tim Curtis Wrote: Thats something I'd leave up to the user. It's not a good practice for me to expand the scope of permissions on a directory unless it solves a generally applicable issue.

I tried to change that being the user with no success. Could you direct me how I can accomplish that on my system.


pi@OutdoorSpeakers:/var/www/images $ chmod +rwx radio-logos/
chmod: changing permissions of 'radio-logos/': Operation not permitted

Well you can't change the permissions on a directory owned by root unless you execute the operation as superuser.

But I'm still trying to figure out your report in the other thread. Are you working just with my scripts or also doing handwork on your own? That's likely to cause confusion.

Regards,
Kent


I tried your script and since I wasn't having any luck with that I figured a manual way should still be available for me.
Reply


Forum Jump: