Thank you for your donation!


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


Make it possible to maintain upmpdcli-radio.conf via Moode’s interface
#5
Ok, so I resolved my logo-filename issue. Logos now display in both Bubble DS and Linn Kazoo, which are the only suitable apps I have.

Below is a Python 3 script (won't work in Python 2.7 without a mod) which reads all the .pls files in the moOde RADIO directory and prints its output to the command line. This output can be redirected to a file which can replace or be concatenated with /etc/upmpdcli-radio.conf.

Put it in pi's home directory on your moOde player; read the limitations in the comments; and assuming you've made it executable invoke it either as

Code:
./gen-upmpdcli-radio.py

to see its output, or as something like

Code:
./gen-upmpdcli-radio.py > upmpdcli-radio.conf

to save the output to a file. If you choose not to make it executable, then invoke as "Python3 gen-upmpdcli-radio.py ...."

This script does not directly overwrite /etc/upmpdcli-radio.conf on purpose but if you are adventuresome, you could do so by invoking it as root and redirecting to that file.

Regards,
Kent

gen-upmpdcli-radio.py
Code:
#!/usr/bin/python3
# utility script to read the .pls files in the moOde r4.4 RADIO directory
# and create counterpart upmpdcli-radio.conf entries, complete with
# artUrl links to the station-logo thumbnails

# prints output to command line; output can be redirected to a file
#    which can replace or be concatenated with /etc/upmpdcli-radio.conf

# Limitations:
#   - the artUrl references a specific moOde player by hostname.
#       - UPnP apps accessing this player must be able to resolve this hostname
#       - If the hostname changes, all artUrl entries must be changed
#   - ignores multiple entries in a .pls file
#   - takes station name from the .pls file name and ignores Title lines in
#     the .pls file, many are too long to be of use; some differ in subtle ways
#   - assumes station logos are in .jpg format which is currently true; could be
#     modified to test for the actual logo file format, e.g., jpg, png, etc.
#   - uses thumbnails rather than full logo art. This may be a limitation
#     to some, a feature to others --- thumbnails look good in a directory listing,
#     not so good in full screen. LOGO_DIR_rel could always be changed.
#

import os, urllib.parse

# maybe overly cautious, but don't assume there
# is no whitespace in .pls entries
def getURLfromPLS(dir, basename):
 with open(dir + basename, "r") as file:
   for line in file:
     if "File1=" in line:
       return (line.replace("File1=", "").strip())
       break
   close(file)

# some useful strings based on moOde r4.x directory structure
# later code assumes there are no unsafe characters in these strings
RADIO_DIR="/var/lib/mpd/music/RADIO/"
LOGO_DIR_rel="images/radio-logos/thumbs/"
LOGO_DIR_abs="/var/www/" + LOGO_DIR_rel

# use current hostname for http protocol source
HOST=os.uname()[1]
URLfrag="http://" + HOST + "/" + LOGO_DIR_rel

# create entries suitable for upmpdcli
ListOfFiles=os.listdir(RADIO_DIR)
ListOfFiles.sort(key=str.lower)
for entry in ListOfFiles:
 if entry.endswith(".pls"):
   radio=entry[:-4]
   url=getURLfromPLS(RADIO_DIR, entry)
   safe_logo_ref=urllib.parse.quote(radio + ".jpg")
   artUrl=(URLfrag + safe_logo_ref)
   print("[radio " + radio + "]")
   print("url = " + url)
   print("artUrl = " + artUrl)
   print()
Reply


Messages In This Thread
RE: Make it possible to maintain upmpdcli-radio.conf via Moode’s interface - by TheOldPresbyope - 12-12-2018, 01:32 PM

Forum Jump: