def api_getsonginfo(self, value): basedir = cherry.config['media.basedir'] #TODO yet another dirty hack. removing the /serve thing is a mess. path = unquote(value) if path.startswith('/serve/'): path = path[7:] elif path.startswith('serve/'): path = path[6:] abspath = os.path.join(basedir, path) return json.dumps(metainfo.getSongInfo(abspath).dict())
def api_getsonginfo(self, value): basedir = cherry.config['media.basedir'] #TODO yet another dirty hack. removing the /serve thing is a mess. path = unquote(value) if path.startswith('/serve/'): path = path[7:] elif path.startswith('serve/'): path = path[6:] abspath = os.path.join(basedir, path) return json.dumps(metainfo.getSongInfo(abspath).dict())
def _add_meta_tags(trackid, fullpath): info = metainfo.getSongInfo(fullpath) if info.artist != '-': media.addTag( info.artist, 'artist', 'Artists', 0, 1, None, trackid) if info.title != '-': media.addTag( info.title, 'title', 'Titles', 0, 1, None, trackid) if info.album != '-': media.addTag( info.album, 'album', 'Albums', 0, 1, info.track, trackid)
def api_getsonginfo(self, path): basedir = cherry.config['media.basedir'] abspath = os.path.join(basedir, path) return json.dumps(metainfo.getSongInfo(abspath).dict())
def api_getsonginfo(self, path): basedir = cherry.config['media.basedir'] abspath = os.path.join(basedir, path) return json.dumps(metainfo.getSongInfo(abspath).dict())
def api_fetchalbumart(self, directory): _save_and_release_session() default_folder_image = "../res/img/folder.png" log.i('Fetching album art for: %s' % directory) filepath = os.path.join(cherry.config['media.basedir'], directory) if os.path.isfile(filepath): # if the given path is a file, try to get the image from ID3 tag = TinyTag.get(filepath, image=True) image_data = tag.get_image() if image_data: log.d('Image found in tag.') header = {'Content-Type': 'image/jpg', 'Content-Length': len(image_data)} cherrypy.response.headers.update(header) return image_data else: # if the file does not contain an image, display the image of the # parent directory directory = os.path.dirname(directory) #try getting a cached album art image b64imgpath = albumArtFilePath(directory) img_data = self.albumartcache_load(b64imgpath) if img_data: cherrypy.response.headers["Content-Length"] = len(img_data) return img_data #try getting album art inside local folder fetcher = albumartfetcher.AlbumArtFetcher() localpath = os.path.join(cherry.config['media.basedir'], directory) header, data, resized = fetcher.fetchLocal(localpath) if header: if resized: #cache resized image for next time self.albumartcache_save(b64imgpath, data) cherrypy.response.headers.update(header) return data elif cherry.config['media.fetch_album_art']: # maximum of files to try to fetch metadata for albumart keywords METADATA_ALBUMART_MAX_FILES = 10 #fetch album art from online source try: foldername = os.path.basename(directory) keywords = foldername # remove any odd characters from the folder name keywords = re.sub('[^A-Za-z\s]', ' ', keywords) # try getting metadata from files in the folder for a more # accurate match files = os.listdir(localpath) for i, filename in enumerate(files): if i >= METADATA_ALBUMART_MAX_FILES: break path = os.path.join(localpath, filename) metadata = metainfo.getSongInfo(path) if metadata.artist and metadata.album: keywords = '{} - {}'.format(metadata.artist, metadata.album) break log.i(_("Fetching album art for keywords {keywords!r}").format(keywords=keywords)) header, data = fetcher.fetch(keywords) if header: cherrypy.response.headers.update(header) self.albumartcache_save(b64imgpath, data) return data else: # albumart fetcher failed, so we serve a standard image raise cherrypy.HTTPRedirect(default_folder_image, 302) except: # albumart fetcher threw exception, so we serve a standard image raise cherrypy.HTTPRedirect(default_folder_image, 302) else: # no local album art found, online fetching deactivated, show default raise cherrypy.HTTPRedirect(default_folder_image, 302)
def api_getsonginfo(self, value): basedir = cherry.config['media.basedir'] #TODO yet another dirty hack. removing the /serve thing is a mess. abspath = os.path.join(basedir, unquote(value)[7:]) return json.dumps(metainfo.getSongInfo(abspath).dict())
def api_getsonginfo(self, value): basedir = cherry.config['media.basedir'] #TODO yet another dirty hack. removing the /serve thing is a mess. abspath = os.path.join(basedir, unquote(value)[7:]) return json.dumps(metainfo.getSongInfo(abspath).dict())