Exemplo n.º 1
0
def process_track_info(resp):
    '''{u'track': {u'album': {u'@attr': {u'position': u'10'},
                           u'artist': u'deadmau5',
                           u'image': [{u'#text': u'http://userserve-ak.last.fm/serve/64s/39945013.jpg',
                                       u'size': u'small'},
                                      {u'#text': u'http://userserve-ak.last.fm/serve/126/39945013.jpg',
                                       u'size': u'medium'},
                                      {u'#text': u'http://userserve-ak.last.fm/serve/174s/39945013.jpg',
                                       u'size': u'large'},
                                      {u'#text': u'http://userserve-ak.last.fm/serve/300x300/39945013.jpg',
                                       u'size': u'extralarge'}],
                           u'mbid': u'4b1b7059-a511-4257-8fae-380eb36d36cd',
                           u'title': u'For Lack Of A Better Name',
                           u'url': u'http://www.last.fm/music/deadmau5/For+Lack+Of+A+Better+Name'},
                u'artist': {u'mbid': u'',
                            u'name': u'deadmau5',
                            u'url': u'http://www.last.fm/music/deadmau5'},
                u'duration': u'307000',
                u'id': u'332264316',
                u'listeners': u'68667',
                u'mbid': u'',
                u'name': u'Strobe',
                u'playcount': u'458109',
                u'streamable': {u'#text': u'0', u'fulltrack': u'0'},
                u'toptags': {u'tag': [{u'name': u'progressive house',
                                       u'url': u'http://www.last.fm/tag/progressive%20house'},
                                      {u'name': u'house',
                                       u'url': u'http://www.last.fm/tag/house'},
                                      {u'name': u'electronic',
                                       u'url': u'http://www.last.fm/tag/electronic'},
                                      {u'name': u'epic',
                                       u'url': u'http://www.last.fm/tag/epic'},
                                      {u'name': u'beautiful',
                                       u'url': u'http://www.last.fm/tag/beautiful'}]},
                u'url': u'http://www.last.fm/music/deadmau5/_/Strobe'}}'''
    track_dict = resp.get('track')
    try:
        track = Track.objects.get(name=track_dict.get('name'), artist__name=track_dict.get('artist').get('name'))
    except ObjectDoesNotExist:
        track = Track(name=track_dict.get('name'))
        
    track.album = None
    track.lfmid = track_dict.get('id')
    track.duration = int(track_dict.get('duration'))
    
    #image = Image(url=track_dict.get('album')[0].get('#text'))
    #image.save()
    #track.image = image
    
    track.name = track_dict.get('name')
    #TODO: track.tags
    #track.tag_count = 0
    track.url = track_dict.get('url')
    track.mbid = track_dict.get('mbid')
    track.listeners = track_dict.get('listeners')
    track.global_playcount = int(track_dict.get('playcount'))
    
    artist = get_or_create_artist(track_dict.get('artist').get('name'))

    track.artist = artist
    
    track.save()
Exemplo n.º 2
0
def process_track_info(resp):
    '''{u'track': {u'album': {u'@attr': {u'position': u'10'},
                           u'artist': u'deadmau5',
                           u'image': [{u'#text': u'http://userserve-ak.last.fm/serve/64s/39945013.jpg',
                                       u'size': u'small'},
                                      {u'#text': u'http://userserve-ak.last.fm/serve/126/39945013.jpg',
                                       u'size': u'medium'},
                                      {u'#text': u'http://userserve-ak.last.fm/serve/174s/39945013.jpg',
                                       u'size': u'large'},
                                      {u'#text': u'http://userserve-ak.last.fm/serve/300x300/39945013.jpg',
                                       u'size': u'extralarge'}],
                           u'mbid': u'4b1b7059-a511-4257-8fae-380eb36d36cd',
                           u'title': u'For Lack Of A Better Name',
                           u'url': u'http://www.last.fm/music/deadmau5/For+Lack+Of+A+Better+Name'},
                u'artist': {u'mbid': u'',
                            u'name': u'deadmau5',
                            u'url': u'http://www.last.fm/music/deadmau5'},
                u'duration': u'307000',
                u'id': u'332264316',
                u'listeners': u'68667',
                u'mbid': u'',
                u'name': u'Strobe',
                u'playcount': u'458109',
                u'streamable': {u'#text': u'0', u'fulltrack': u'0'},
                u'toptags': {u'tag': [{u'name': u'progressive house',
                                       u'url': u'http://www.last.fm/tag/progressive%20house'},
                                      {u'name': u'house',
                                       u'url': u'http://www.last.fm/tag/house'},
                                      {u'name': u'electronic',
                                       u'url': u'http://www.last.fm/tag/electronic'},
                                      {u'name': u'epic',
                                       u'url': u'http://www.last.fm/tag/epic'},
                                      {u'name': u'beautiful',
                                       u'url': u'http://www.last.fm/tag/beautiful'}]},
                u'url': u'http://www.last.fm/music/deadmau5/_/Strobe'}}'''
    track_dict = resp.get('track')
    try:
        track = Track.objects.get(
            name=track_dict.get('name'),
            artist__name=track_dict.get('artist').get('name'))
    except ObjectDoesNotExist:
        track = Track(name=track_dict.get('name'))

    track.album = None
    track.lfmid = track_dict.get('id')
    track.duration = int(track_dict.get('duration'))

    #image = Image(url=track_dict.get('album')[0].get('#text'))
    #image.save()
    #track.image = image

    track.name = track_dict.get('name')
    #TODO: track.tags
    #track.tag_count = 0
    track.url = track_dict.get('url')
    track.mbid = track_dict.get('mbid')
    track.listeners = track_dict.get('listeners')
    track.global_playcount = int(track_dict.get('playcount'))

    artist = get_or_create_artist(track_dict.get('artist').get('name'))

    track.artist = artist

    track.save()
Exemplo n.º 3
0
        except:
            print 'DOUBLE ERROR RAINBOW'
    try:
        t = Track.objects.get(name=track.get('name'))
        
        image = None
        if track.get('image') and len(track.get('image')[0].get('#text')):
            image = Image(url=track.get('image')[0].get('#text'))
            image.save()
    
        if image is not None:
            t.image = image
            
    except ObjectDoesNotExist:
        t = Track(name=track.get('name'))
        t.url = track.get('url')
        t.mbid = track.get('mbid')
        t.duration = track.get('duration') and int(track.get('duration')) or 0
        t.artist = get_or_create_artist(track.get('artist').get('name'))
        
        job_data = {'track_name':track.get('name'),
                    'artist_name':track.get('artist').get('name')}
        CLIENT.call('lfm.get_track_info', json.dumps(job_data))
            
        if not week:
            t.tag_count = int(track.get('tagcount'))

        t.save()
        
    #TODO: add a MoreThanOneObjectReturned except clause here
Exemplo n.º 4
0
        except:
            print 'DOUBLE ERROR RAINBOW'
    try:
        t = Track.objects.get(name=track.get('name'))

        image = None
        if track.get('image') and len(track.get('image')[0].get('#text')):
            image = Image(url=track.get('image')[0].get('#text'))
            image.save()

        if image is not None:
            t.image = image

    except ObjectDoesNotExist:
        t = Track(name=track.get('name'))
        t.url = track.get('url')
        t.mbid = track.get('mbid')
        t.duration = track.get('duration') and int(track.get('duration')) or 0
        t.artist = get_or_create_artist(track.get('artist').get('name'))

        job_data = {
            'track_name': track.get('name'),
            'artist_name': track.get('artist').get('name')
        }
        CLIENT.call('lfm.get_track_info', json.dumps(job_data))

        if not week:
            t.tag_count = int(track.get('tagcount'))

        t.save()