Giter Club home page Giter Club logo

Comments (2)

DPH avatar DPH commented on August 25, 2024

I had the same problem. It started after the change 'Add minor support for getting track info when playing radio' 14 days ago. I discovered it occurs when no music is playing on a zone:
d = dom.findtext('.//TrackMetaData') returns nothing.
This causes the metadata = XML.fromstring(d.encode('utf-8')) to fail.

I have added a check for this in my code, but need to learn how to post it as a change.
In the meantime this is my replacement code for get_current_track_info(self) - only the addition of an extra if:

def get_current_track_info(self):
    """ Get information about the currently playing track.

    Returns:
    A dictionary containing the following information about the currently
    playing track: playlist_position, duration, title, artist, album, and
    a link to the album art.

    If we're unable to return data for a field, we'll return an empty
    string. This can happen for all kinds of reasons so be sure to check
    values. For example, a track may not have complete metadata and be
    missing an album name. In this case track['album'] will be an empty string.

    """
    response = self.__send_command(TRANSPORT_ENDPOINT, GET_CUR_TRACK_ACTION, GET_CUR_TRACK_BODY)

    print response


    dom = XML.fromstring(response)

    track = {}

    track['playlist_position'] = dom.findtext('.//Track')
    track['duration'] = dom.findtext('.//TrackDuration')
    track['uri'] = dom.findtext('.//TrackURI')
    track['time_played'] = dom.findtext('.//RelTime')    ####DPH Add

    d = dom.findtext('.//TrackMetaData')


    #DPH==================
    if track['duration'] is not 'NOT_IMPLEMENTED':               #then nothing playing
        track['title'] = ''
        track['artist'] = ''
        track['album'] = ''
        track['album_art'] = ''
        #====================================================


    # Duration seems to be '0:00:00' when listening to radio
    elif track['duration'] == '0:00:00':
        metadata = XML.fromstring(d.encode('utf-8'))

        # #Try parse trackinfo
        trackinfo = metadata.findtext('.//{urn:schemas-rinconnetworks-com:metadata-1-0/}streamContent')

        try:
            index = trackinfo.find(' - ')

            if index > -1:
                track['artist'] = trackinfo[:index]
                track['title'] = trackinfo[index+3:]
        except:
            logger.warning('Could not handle track info: "%s"', trackinfo)
            logger.warning(traceback.format_exc())
            track['artist'] = ''
            track['title'] = trackinfo

        track['album'] = ''
        track['album_art'] = ''

    # If the speaker is playing from the line-in source, querying for track
    # metadata will return "NOT_IMPLEMENTED".
    elif d is not '' or d is not 'NOT_IMPLEMENTED':
        # Track metadata is returned in DIDL-Lite format
        metadata = XML.fromstring(d.encode('utf-8'))

        track['title'] = metadata.findtext('.//{http://purl.org/dc/elements/1.1/}title')
        track['artist'] = metadata.findtext('.//{http://purl.org/dc/elements/1.1/}creator')
        track['album'] = metadata.findtext('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}album')

        album_art = metadata.findtext('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}albumArtURI')

        if album_art is not None:
            track['album_art'] = 'http://' + self.speaker_ip + ':1400' + metadata.findtext('.//{urn:schemas-upnp-org:metadata-1-0/upnp/}albumArtURI')
        else:
            track['album_art'] = ''
    else:
        track['title'] = ''
        track['artist'] = ''
        track['album'] = ''
        track['album_art'] = ''

    return track

Regards DPH

from soco.

rahims avatar rahims commented on August 25, 2024

Thanks for reporting. Just pushed a fix.

from soco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.