Пример #1
0
Файл: gp.py Проект: vale981/clay
    def from_data(cls, data, source, many=False):
        """
        Construct and return one or many :class:`.Track` instances
        from Google Play Music API response.
        """
        if many:
            return [
                track
                for track in [cls.from_data(one, source) for one in data]
                if track is not None
            ]
        try:
            if source == cls.SOURCE_PLAYLIST and 'track' not in data:
                track = gp.get_track_by_id(UUID(data['trackId']))
            else:
                track = Track(source, data)

            return track
        except Exception as error:  # pylint: disable=bare-except
            logger.error('Failed to parse track data: %s, failing data: %s',
                         repr(error), data)
            # TODO: Fix this.
            # print('Failed to create track from data.')
            # print('Failing payload was:')
            # print(data)
            # raise Exception(
            #     'Failed to create track from data. Original error: {}. Payload: {}'.format(
            #         str(error),
            #         data
            #     )
            # )
            return None

        raise AssertionError()
Пример #2
0
 def _download_track(self, url, error, track):
     if error:
         notification_area.notify('Failed to request media URL: {}'.format(
             str(error)))
         logger.error('Failed to request media URL for track %s: %s',
                      track.original_data, str(error))
         return
     response = urlopen(url)
     path = settings.save_file_to_cache(track.filename, response.read())
     self._play_ready(path, None, track)
Пример #3
0
    def _play_ready(self, url, error, track):
        """
        Called once track's media stream URL request completes.
        If *error* is ``None``, tell libVLC to play media by *url*.
        """
        self._is_loading = False
        if error:
            notification_area.notify('Failed to request media URL: {}'.format(
                str(error)))
            logger.error('Failed to request media URL for track %s: %s',
                         track.original_data, str(error))
            return
        assert track
        media = vlc.Media(url)
        self.media_player.set_media(media)

        self.media_player.play()

        osd_manager.notify(track)
Пример #4
0
def report_error(exc):
    "Print an error message to the debug screen"
    logger.error("{0}: {1}".format(exc.__class__.__name__, exc))