Comments (2)
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.
Thanks for reporting. Just pushed a fix.
from soco.
Related Issues (20)
- [Feature Request] Get event notifications (song change, pause, etc.) HOT 27
- [Feature Request] Get radio logo HOT 4
- [Feature proposal] Unit tests HOT 4
- [BUG] Encode Error with 'get_favorite_radio_stations' HOT 2
- Does not handle Zone bridge HOT 14
- Cannot get get_queue to work (request returns error and therefore get_queue returns empty list) HOT 1
- Bug in get_speakers_ip HOT 6
- Can't set volume to 0 HOT 5
- [Discussion] Form IRC channel for soco HOT 6
- [Random] Some interesting links to look through HOT 10
- [Proposal] Move soco to a group project HOT 11
- Release Procedure HOT 4
- [POLL] What music services do you use. HOT 7
- Source code here does not match published SoCo HOT 4
- Error when using custom streaming service HOT 1
- Access speed to music library HOT 1
- mute and volume functions HOT 2
- Question about Queue HOT 1
- No route to host HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soco.