コード例 #1
0
ファイル: sonos.py プロジェクト: robwebset/script.sonos
    def mergeTrackInfoAndEvent(self, track, eventDetails, previousTrack=None):
        # Check if the new and previous tracks are the same, if they are then we can
        # check to see if there are lyrics that should be copied over to stop us getting
        # them again
        track = Lyrics.copyLyricsIfSameTrack(track, previousTrack)

        # If there is no event data, then just return the track unchanged
        if eventDetails is None:
            # Check to see if the track has changed, if it has not, then we can
            # safely use the previous event we stored
            if (previousTrack is not None) and (track['uri'] == previousTrack['uri']) and (previousTrack['lastEventDetails'] is not None):
                log("Sonos: Using previous Event details for merge")
                track['lastEventDetails'] = previousTrack['lastEventDetails']
                eventDetails = previousTrack['lastEventDetails']
            else:
                log("Sonos: Event details not set for merge")
                track['lastEventDetails'] = None
                return track
        else:
            log("Sonos: Event details set for merge")
            track['lastEventDetails'] = eventDetails

        # We do not want to throw an exception if we fail to process an event
        # It has been seen to happen in some strange cases, so we just catch and
        # log the error
        try:
            # Now process each part of the event message
            if eventDetails.enqueued_transport_uri_meta_data not in [None, '']:
                enqueued_transport = eventDetails.enqueued_transport_uri_meta_data
                log("enqueued_transport_uri_meta_data = %s" % enqueued_transport)

                # Check if this is radio stream, in which case use that as the title
                # Station Name
                if hasattr(enqueued_transport, 'title') and (enqueued_transport.title not in [None, '']):
                    if not enqueued_transport.title.startswith('ZPSTR_'):
                        # Only set the title if not already set, or it is an Audio Broadcast
                        if (track['title'] is None) or (track['title'] == "") or isinstance(enqueued_transport, DidlAudioBroadcast):
                            track['title'] = enqueued_transport.title

            # Process the current track info
            if eventDetails.current_track_meta_data not in [None, '']:
                current_track = eventDetails.current_track_meta_data
                log("current_track_meta_data = %s" % current_track)

                # Check if this is radio stream, in which case use that as the album title
                if hasattr(current_track, 'radio_show') and (current_track.radio_show not in [None, '']):
                    if not current_track.radio_show.startswith('ZPSTR_'):
                        if (track['album'] is None) or (track['album'] == ""):
                            track['album'] = current_track.radio_show
                            # This may be something like: Drivetime,p239255 so need to remove the last section
                            trimmed = track['album'].rpartition(',p')[0]
                            if (trimmed is not None) and (trimmed != ""):
                                track['album'] = trimmed
                # If not a radio stream then use the album tag
                elif hasattr(current_track, 'album') and (current_track.album not in [None, '']):
                    if (track['album'] is None) or (track['album'] == ""):
                        track['album'] = current_track.album

                # Name of track. Can be ZPSTR_CONNECTING/_BUFFERING during transition,
                # or None if not a radio station
                if hasattr(current_track, 'stream_content') and (current_track.stream_content not in [None, '']):
                    if not current_track.stream_content.startswith('ZPSTR_'):
                        if (track['artist'] is None) or (track['artist'] == ""):
                            track['artist'] = current_track.stream_content
                # otherwise we have the creator to use as the artist
                elif hasattr(current_track, 'creator') and (current_track.creator not in [None, '']):
                    if (track['artist'] is None) or (track['artist'] == ""):
                        track['artist'] = current_track.creator

                # If it was a radio stream, the title will already have been set using the enqueued_transport
                if hasattr(current_track, 'title') and (current_track.title not in [None, '']):
                    if not current_track.title.startswith('ZPSTR_'):
                        if (track['title'] is None) or (track['title'] == ""):
                            track['title'] = current_track.title

                # If the track has no album art, use the event one (if it exists)
                if (track['album_art'] is None) or (track['album_art'] == ""):
                    if hasattr(current_track, 'album_art_uri') and (current_track.album_art_uri not in [None, '']):
                        track['album_art'] = current_track.album_art_uri
                        # Make sure the Album art is fully qualified
                        if not track['album_art'].startswith(('http:', 'https:')):
                            track['album_art'] = 'http://' + self.ip_address + ':1400' + track['album_art']

            # Process Next Track Information
            if eventDetails.next_track_meta_data not in [None, '']:
                next_track = eventDetails.next_track_meta_data
                log("next_track_meta_data = %s" % next_track)
                if hasattr(next_track, 'creator') and (next_track.creator not in [None, '']):
                    if not hasattr(track, 'next_artist') or (track['next_artist'] is None) or (track['next_artist'] == ""):
                        track['next_artist'] = next_track.creator
                if hasattr(next_track, 'album') and (next_track.album not in [None, '']):
                    if not hasattr(track, 'next_album') or (track['next_album'] is None) or (track['next_album'] == ""):
                            track['next_album'] = next_track.album
                if hasattr(next_track, 'title') and (next_track.title not in [None, '']):
                    if not hasattr(track, 'next_title') or (track['next_title'] is None) or (track['next_title'] == ""):
                        track['next_title'] = next_track.title
                if hasattr(next_track, 'album_art_uri') and (next_track.album_art_uri not in [None, '']):
                    if not hasattr(track, 'next_art_uri') or (track['next_art_uri'] is None) or (track['next_art_uri'] == ""):
                        track['next_art_uri'] = next_track.album_art_uri
        except:
            log("Sonos: Failed to update using event details: %s" % traceback.format_exc(), xbmc.LOGERROR)
            # Should really display on the screen that some of the display information
            # might not be complete of upto date, only show the error once
            if Sonos.SHOWN_ERROR is not True:
                Sonos.SHOWN_ERROR = True
                xbmc.executebuiltin('Notification(%s, %s, 3000, %s)' % (ADDON.getLocalizedString(32001).encode('utf-8'), ADDON.getLocalizedString(32063).encode('utf-8'), ICON))

        return track
コード例 #2
0
ファイル: sonos.py プロジェクト: noba3/KoTos
    def mergeTrackInfoAndEvent(self, track, eventDetails, previousTrack=None):
        # Check if the new and previous tracks are the same, if they are then we can
        # check to see if there are lyrics that should be copied over to stop us getting
        # them again
        track = Lyrics.copyLyricsIfSameTrack(track, previousTrack)

        # If there is no event data, then just return the track unchanged
        if eventDetails is None:
            # Check to see if the track has changed, if it has not, then we can
            # safely use the previous event we stored
            if (previousTrack is not None) and (
                    track['uri'] == previousTrack['uri']) and (
                        previousTrack['lastEventDetails'] is not None):
                log("Sonos: Using previous Event details for merge")
                track['lastEventDetails'] = previousTrack['lastEventDetails']
                eventDetails = previousTrack['lastEventDetails']
            else:
                log("Sonos: Event details not set for merge")
                track['lastEventDetails'] = None
                return track
        else:
            log("Sonos: Event details set for merge")
            track['lastEventDetails'] = eventDetails

        # We do not want to throw an exception if we fail to process an event
        # It has been seen to happen in some strange cases, so we just catch and
        # log the error
        try:
            # Now process each part of the event message
            if eventDetails.enqueued_transport_uri_meta_data not in [None, '']:
                enqueued_transport = eventDetails.enqueued_transport_uri_meta_data
                log("enqueued_transport_uri_meta_data = %s" %
                    enqueued_transport)

                # Check if this is radio stream, in which case use that as the title
                # Station Name
                if hasattr(enqueued_transport,
                           'title') and (enqueued_transport.title
                                         not in [None, '']):
                    if not enqueued_transport.title.startswith('ZPSTR_'):
                        if (track['title'] is None) or (track['title'] == ""):
                            track['title'] = enqueued_transport.title

            # Process the current track info
            if eventDetails.current_track_meta_data not in [None, '']:
                current_track = eventDetails.current_track_meta_data
                log("current_track_meta_data = %s" % current_track)

                # Check if this is radio stream, in which case use that as the album title
                if hasattr(current_track,
                           'radio_show') and (current_track.radio_show
                                              not in [None, '']):
                    if not current_track.radio_show.startswith('ZPSTR_'):
                        if (track['album'] is None) or (track['album'] == ""):
                            track['album'] = current_track.radio_show
                            # This may be something like: Drivetime,p239255 so need to remove the last section
                            trimmed = track['album'].rpartition(',p')[0]
                            if (trimmed is not None) and (trimmed != ""):
                                track['album'] = trimmed
                # If not a radio stream then use the album tag
                elif hasattr(current_track, 'album') and (current_track.album
                                                          not in [None, '']):
                    if (track['album'] is None) or (track['album'] == ""):
                        track['album'] = current_track.album

                # Name of track. Can be ZPSTR_CONNECTING/_BUFFERING during transition,
                # or None if not a radio station
                if hasattr(current_track,
                           'stream_content') and (current_track.stream_content
                                                  not in [None, '']):
                    if not current_track.stream_content.startswith('ZPSTR_'):
                        if (track['artist'] is None) or (track['artist']
                                                         == ""):
                            track['artist'] = current_track.stream_content
                # otherwise we have the creator to use as the artist
                elif hasattr(current_track,
                             'creator') and (current_track.creator
                                             not in [None, '']):
                    if (track['artist'] is None) or (track['artist'] == ""):
                        track['artist'] = current_track.creator

                # If it was a radio stream, the title will already have been set using the enqueued_transport
                if hasattr(current_track, 'title') and (current_track.title
                                                        not in [None, '']):
                    if not current_track.title.startswith('ZPSTR_'):
                        if (track['title'] is None) or (track['title'] == ""):
                            track['title'] = current_track.title

                # If the track has no album art, use the event one (if it exists)
                if (track['album_art'] is None) or (track['album_art'] == ""):
                    if hasattr(current_track, 'album_art_uri') and (
                            current_track.album_art_uri not in [None, '']):
                        track['album_art'] = current_track.album_art_uri
                        # Make sure the Album art is fully qualified
                        if not track['album_art'].startswith(
                            ('http:', 'https:')):
                            track[
                                'album_art'] = 'http://' + self.ip_address + ':1400' + track[
                                    'album_art']

            # Process Next Track Information
            if eventDetails.next_track_meta_data not in [None, '']:
                next_track = eventDetails.next_track_meta_data
                log("next_track_meta_data = %s" % next_track)
                if hasattr(next_track, 'creator') and (next_track.creator
                                                       not in [None, '']):
                    if not hasattr(track, 'next_artist') or (
                            track['next_artist'] is
                            None) or (track['next_artist'] == ""):
                        track['next_artist'] = next_track.creator
                if hasattr(next_track, 'album') and (next_track.album
                                                     not in [None, '']):
                    if not hasattr(track, 'next_album') or (
                            track['next_album'] is
                            None) or (track['next_album'] == ""):
                        track['next_album'] = next_track.album
                if hasattr(next_track, 'title') and (next_track.title
                                                     not in [None, '']):
                    if not hasattr(track, 'next_title') or (
                            track['next_title'] is
                            None) or (track['next_title'] == ""):
                        track['next_title'] = next_track.title
                if hasattr(next_track,
                           'album_art_uri') and (next_track.album_art_uri
                                                 not in [None, '']):
                    if not hasattr(track, 'next_art_uri') or (
                            track['next_art_uri'] is
                            None) or (track['next_art_uri'] == ""):
                        track['next_art_uri'] = next_track.album_art_uri
        except:
            log(
                "Sonos: Failed to update using event details: %s" %
                traceback.format_exc(), xbmc.LOGERROR)
            # Should really display on the screen that some of the display information
            # might not be complete of upto date, only show the error once
            if Sonos.SHOWN_ERROR is not True:
                Sonos.SHOWN_ERROR = True
                xbmc.executebuiltin(
                    'Notification(%s, %s, 3000, %s)' %
                    (__addon__.getLocalizedString(32001).encode('utf-8'),
                     __addon__.getLocalizedString(32063).encode('utf-8'),
                     __icon__))

        return track