Esempio n. 1
0
def art(artist, album, song=None):
    """ Send the artwork for the given album """
    import hashlib
    
    c = sqlcollection.SQLCollection()
    a = c.get(artist, album)
    artpath = ''
    try:
        album = a[0].get('albums')[0]
        artpath = album.get('artworkurl')
    except:
        abort(404)

    size = int(request.args.get('s', 64))
    
    
    tmpdir = appdir('tmp/art/')
    tmpref = hashlib.md5(album.full_url()).hexdigest() + '_' + str(size)
    tmpref += '.jpg'
    if not os.path.exists(tmpdir):
        os.mkdir(tmpdir)
        
    if os.path.exists(tmpdir + tmpref): 
        return send_file_partial(tmpdir + tmpref)
        
    if not artpath:
        tmpref = 'unknown_' + str(size) + '.jpg'
        artpath = appdir('/static/assets/unknowncover.jpg')
    import Image

    im = Image.open(artpath)
    sizetuple = size, size
    im.thumbnail(sizetuple, Image.ANTIALIAS)
    im.save(tmpdir + tmpref, 'JPEG', quality=100)
    return send_file_partial(tmpdir + tmpref)
Esempio n. 2
0
def playlist_get(name=None):
    if name is not None:
        try:
            if not valid_playlist_name(name):
                raise Exception
            return send_file_partial(appdir('persistent/playlists/' + name + '.json'))
        except:
            abort(404)
    else:
        #index
        files = os.listdir(appdir('persistent/playlists/'))
        playlists = []
        for f in files: 
            if f.startswith('.'): continue
            if f.endswith('.json'):
                playlists.append(f[:-5])
        return json.dumps(playlists)
Esempio n. 3
0
def play(artist, album, song):
    """ Send the specified song """
    print 'Play!'
    c = sqlcollection.SQLCollection()
    a = c.get(artist, album, song)
    try:
        album = a[0].get('albums')[0]
        song = album.get('songs')[0]
    except IndexError:
        abort(404)
    try:
        transcode(song)
        return send_file_partial(song.get('filepath'))
    except Exception as e:
        raise
        print str(e)
        abort(500)