コード例 #1
0
ファイル: web.py プロジェクト: daveisadork/Blofeld
 def get_cover(self, songid=None, size='original', download=False):
     logger.debug("%s (%s)\tget_cover(songid=%s, size=%s, download=%s)\tHeaders: %s" % (utils.find_originating_host(cherrypy.request.headers), cherrypy.request.login, songid, size, download, cherrypy.request.headers))
     try:
         song = self.library.db[songid]
     except:
         raise cherrypy.HTTPError(404)
     try:
         size = int(size)
     except:
         size = 'original'
     cover = find_cover(song)
     if cover is None:
         raise cherrypy.HTTPError(404,'Not Found')
     if download:
         return serve_file(cover,
                     mimetypes.guess_type(cover)[0], "attachment", os.path.basename(cover))
     if size != 'original':
         artwork = resize_cover(song, cover, size)
     else:
         artwork = cover
     cherrypy.response.headers['Content-Type'] = mimetypes.guess_type(cover)[0]
     return serve_file(artwork,
                     mimetypes.guess_type(artwork)[0], "inline", os.path.basename(artwork))
コード例 #2
0
ファイル: download.py プロジェクト: daveisadork/Blofeld
def create_archive(songs):
    try:
        files = []
        for song in songs:
            location = song["location"].encode("utf8")
            print type(location)
            zip_path = song["location"].replace(cfg["MUSIC_PATH"], "").encode("utf8")
            files.append((location, zip_path))
            zip_cover_path = os.path.join(os.path.dirname(zip_path), "Cover.jpg")
            cover = (find_cover(song), zip_cover_path)
            if cover not in files:
                files.append(cover)
        path = os.path.join(cfg["CACHE_DIR"], "%s.zip") % hashlib.sha1(str(files)).hexdigest()
        logger.debug("Creating archive at %s" % path)
        logger.debug(files)
        archive = zipfile.ZipFile(path, "w", zipfile.ZIP_STORED)
        for item in files:
            logger.debug('Added "%s" to "%s"' % item)
            archive.write(*item)
        archive.close()
        return path
    except Exception as e:
        logger.exception(e)