Thank you for your donation!


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


Alternative renderers and metadata
#8
[Please don't hijack threads. You have already started a thread for your project. My purpose in creating this thread was to have a place to focus on the topic of getting metadata  from alternative renderers without hijacking your thread in turn. That's why I created it here in the "Community>Uncatagorized" section and not, e.g., in the "moOde audio player>Support" section..]

I suggest you read all of https://appcodelabs.com/show-artist-song...spberry-pi (skipping the part about the display itself since you have your own code for that) and try exercising the Python module presented in the "writing the code" section (again, without the part about the display).

Apart from the need to redefine the render() function to fit your display code, that code would seem to do pretty much what you just outlined. I did this myself the other day to see how the metadata varied as I tried different combinations of connecting/disconnecting Airplay sources, selecting tracks, starting and stopping playback. The cut-down code I used follows.

There are some interesting anomalies as tracks change because the metadata dribbles in.

Regards,
Kent

Code:
#!/usr/bin/env python3
# @TheOldPresbyope
# this code was copied from
# https://appcodelabs.com/show-artist-song-metadata-using-airplay-on-raspberry-pi
# and modified to print to console as if it were a three-line display

# NOTE - doesn't clear previous value of specific key when no new value is received

import sys
import re

# a device isn't needed but let's define a dummy just
# to keep the same render() syntax as in the original code
device = "null"

artist = ""
track = ""
album = ""

def extract(line):
   m = re.match('^(Title|Artist|Album Name): \"(.*?)\"\.$', line)
   if m:
       return m.group(1), m.group(2)
   else:
       return None, None

def update(key, val):
   global artist, album, track
   if key == "Artist":
       artist = val
   elif key == "Album Name":
       album = val
   elif key == "Title":
        track = val

def render(device):
   # print to console instead of writing output to a device
   # use an ASCII escape sequence to imitate a three-line display
   print("\u001b[2J")
   print("Artist: " + artist)
   print("Album Name: " + album)
   print("Title: " + track)

# Create devices
   # deleted all the device code

# Welcome message
   # No, let's not

# Main loop
try:
   while True:
       line = sys.stdin.readline()
       key, val = extract(line)
       if key and val:
           update(key, val)
           render(device)

except KeyboardInterrupt:
   sys.stdout.flush()
   pass
Reply


Messages In This Thread
RE: Alternative renderers and metadata - by TheOldPresbyope - 06-02-2020, 07:08 PM

Forum Jump: