Beispiel #1
0
    def play(self, track_dict):

        self.logger.info('play(): %r' % track_dict)

        if self.user['lastfm']:


            track = Track(**track_dict)

            if self.current_track:
                self.logger.info(
                    'play(): scrobbling previous track: %r',
                    self.current_track
                )
                # noinspection PyUnresolvedReferences
                resp = yield self.lastfm.track.scrobble(
                    track=self.current_track.title,
                    artist=self.current_track.artist,
                    album=self.current_track.album,
                    timestamp=self.current_track._timestamp,
                )
                self.logger.debug('play(): scrobble response: %r', resp)

            self.logger.info('play(): updating "Now Playing"')
            resp = yield self.lastfm.track.update_now_playing(
                track=track.title,
                artist=track.artist,
                album=track.album,
            )
            self.logger.debug('play(): update_now_playing response: %r', resp)
            track._timestamp = int(time.time())
            self.current_track = track
Beispiel #2
0
def sync_track(account_id, path, do_delete):

    logger.info('updating path=%r; do_delete=%r', path, do_delete)

    try:
        user = User.objects.get(dropbox__id=account_id)
    except User.DoesNotExist:
        logger.warning('dropbox account not found: %s; bailing out',
                       account_id)
        return

    client = Client.for_account(user.dropbox)

    try:
        id3 = get_id3(client, path, title=os.path.basename(path))
    except Exception:
        logger.exception('could not get tags')
        return

    logger.debug('id3 dict=%r', id3)

    if not id3:
        return

    try:
        track = Track.objects.get(user=user.pk, dropbox__path=path)
    except Track.DoesNotExist:
        if do_delete:
            logger.warning('track %s already deleted', path)
            return
        track = Track()
        action = 'add'
    else:
        if do_delete:
            logger.info('deleting track %s @ %s', track.id, path)
            track.delete()
            user.emit('sync', 'track:remove', str(track.id))
            return
        else:
            action = 'update'

    track.update_fields(user=user,
                        source='dropbox',
                        dropbox=DropboxTrack(path=path),
                        **id3)
    track.save()
    user.emit('sync', 'track:' + action, track.to_json())
    logger.info('track %s @ %s saved', track.id, path)
Beispiel #3
0
def sync_track(account_id, path, do_delete):

    logger.info('updating path=%r; do_delete=%r', path, do_delete)

    try:
        user = User.objects.get(dropbox__id=account_id)
    except User.DoesNotExist:
        logger.warning('dropbox account not found: %s; bailing out', account_id)
        return

    client = Client.for_account(user.dropbox)

    try:
        id3 = get_id3(client, path, title=os.path.basename(path))
    except Exception:
        logger.exception('could not get tags')
        return

    logger.debug('id3 dict=%r', id3)

    if not id3:
        return

    try:
        track = Track.objects.get(user=user.pk, dropbox__path=path)
    except Track.DoesNotExist:
        if do_delete:
            logger.warning('track %s already deleted', path)
            return
        track = Track()
        action = 'add'
    else:
        if do_delete:
            logger.info('deleting track %s @ %s', track.id, path)
            track.delete()
            user.emit('sync', 'track:remove', str(track.id))
            return
        else:
            action = 'update'

    track.update_fields(
        user=user,
        source='dropbox',
        dropbox=DropboxTrack(path=path),
        **id3
    )
    track.save()
    user.emit('sync', 'track:' + action, track.to_json())
    logger.info('track %s @ %s saved', track.id, path)
Beispiel #4
0
def add_video_by_url(user_id, url):

    log = get_task_logger(__name__)
    log.info('start user_id=%s url=%s', user_id, url)

    user = User.objects.get(id=user_id)
    video_id = client.get_video_id(url)

    log.debug('video_id=%s', video_id)

    video = client.get_video(video_id)['data']

    log.debug('video=%s', video)

    try:
        track = Track.objects.get(user=user, youtube__id=video_id)
    except Track.DoesNotExist:
        track = Track()

    log.debug('existing track=%s', track)

    track.update_fields(
        **{
            'user': user,
            'title': video['title'],
            'artist': None,
            'album': None,
            'source': 'youtube',
            'youtube': YoutubeTrack(**video)
        })

    log.debug('saving track=%s', track)

    track.save()

    log.info('done track.id=%s', track.id)

    user.emit('sync', 'track:add', track.to_json())
Beispiel #5
0
def add_video_by_url(user_id, url):

    log = get_task_logger(__name__)
    log.info('start user_id=%s url=%s', user_id, url)

    user = User.objects.get(id=user_id)
    video_id = client.get_video_id(url)

    log.debug('video_id=%s', video_id)

    video = client.get_video(video_id)['data']

    log.debug('video=%s', video)

    try:
        track = Track.objects.get(user=user, youtube__id=video_id)
    except Track.DoesNotExist:
        track = Track()

    log.debug('existing track=%s', track)

    track.update_fields(**{
        'user': user,
        'title': video['title'],
        'artist': None,
        'album': None,
        'source': 'youtube',
        'youtube': YoutubeTrack(**video)
    })

    log.debug('saving track=%s', track)

    track.save()

    log.info('done track.id=%s', track.id)

    user.emit('sync', 'track:add', track.to_json())