def get_image_for_bean(bean, controls): """ Lookup image for the bean :param bean: FModel :param controls: :return: str """ if bean.image and os.path.exists(bean.image): return bean.image if bean.path and not bean.path.startswith("http"): cover = get_image_by_path(bean.path) if cover: return cover cover = set_cover_from_tags(bean) if cover: return cover image = controls.lastfm_service.get_album_image_url(bean.artist, bean.title) if image: try: ext = image.rpartition(".")[2] cache_name = "%s%s.%s" % (COVERS_DIR, crc32(image), ext) if os.path.exists(cache_name): return cache_name urllib.urlretrieve(image, cache_name) return cache_name except: pass return None
def add_update_image_paths(beans): for bean in beans: if bean.path and bean.is_file: set_cover_from_tags(bean) if not bean.image: bean.image = get_image_by_path(bean.path) return beans
def add_upadte_image_paths(beans): for bean in beans: if bean.path: bean.image = get_image_by_path(bean.path) return beans
def parse(self): file = open(self.cue_path, "r") code = self.code_detecter(self.cue_path); logging.debug("File encoding is" + str(code)) title = "" performer = "" index = "00:00:00" full_file = None self.cue_file.image = get_image_by_path(self.cue_path) self.files_count = 0 for line in file: if not self.is_valid and not line.startswith(FILE): continue else: self.is_valid = True try: pass line = unicode(line, code) except: logging.error("File encoding is too strange" + str(code)) pass line = str(line).strip() if not line: continue if line.startswith(TITLE): title = self.get_line_value(line) if self.files_count == 0: self.cue_file.title = title if line.startswith(PERFORMER): performer = self.get_line_value(line) if self.files_count == 0: self.cue_file.performer = performer if line.startswith(FILE): self.files_count += 1 file = self.get_line_value(line) file = os.path.basename(file) if "/" in file: file = file[file.rfind("/")+1:] if "\\" in file: file = file[file.rfind("\\")+1:] dir = os.path.dirname(self.cue_path) full_file = os.path.join(dir, file) logging.debug("CUE source" + full_file) exists = os.path.exists(full_file) """if there no source cue file""" if not exists: """try to find other source""" ext = file_utils.get_file_extension(full_file) nor = full_file[:-len(ext)] logging.info("Normalized path" + nor) find_source = False for support_ext in FC().audio_formats: try_name = nor + support_ext if os.path.exists(try_name): full_file = try_name logging.debug("Found source for cue file name" + try_name) find_source = True break; if not find_source: self.is_valid = False self.files_count -= 1 logging.warn("Can't find source for " + line + " Check source file name") continue if self.files_count == 0: self.cue_file.file = full_file if line.startswith(INDEX): index = self.get_line_value(line) if line.startswith("INDEX 01"): cue_track = CueTrack(title, performer, index, full_file) self.cue_file.append_track(cue_track) logging.debug("CUE file parsed " + str(self.cue_file.file)) return self.normalize()
def parse(self): if self.embedded_cue: data = self.embedded_cue else: file = open(self.cue_path, "r") data = file.read() code = self.code_detecter(correct_encoding(data)) data = data.replace('\r\n', '\n').split('\n') title = "" performer = "" index = "00:00:00" full_file = None self.cue_file.image = get_image_by_path(self.cue_path) self.files_count = 0 for line in data: if not self.is_valid and not line.startswith(FILE): continue else: self.is_valid = True try: line = unicode(line, code) except: logging.error("There is some problems while converting in unicode") line = str(line).strip() if not line: continue if line.startswith(TITLE): title = self.get_line_value(line) if self.files_count == 0: self.cue_file.title = title if line.startswith(PERFORMER): performer = self.get_line_value(line) if self.files_count == 0: self.cue_file.performer = performer if line.startswith(FILE): self.files_count += 1 file = self.get_line_value(line) file = os.path.basename(file) if "/" in file: file = file[file.rfind("/")+1:] if "\\" in file: file = file[file.rfind("\\")+1:] dir = os.path.dirname(self.cue_path) full_file = os.path.join(dir, file) logging.debug("CUE source" + full_file) exists = os.path.exists(full_file) """if there no source cue file""" if not exists: """try to find other source""" ext = file_utils.get_file_extension(full_file) nor = full_file[:-len(ext)] logging.info("Normalized path" + nor) find_source = False for support_ext in FC().audio_formats: try_name = nor + support_ext if os.path.exists(try_name): full_file = try_name logging.debug("Found source for cue file name" + try_name) find_source = True break if not find_source: self.is_valid = False self.files_count -= 1 logging.warn("Can't find source for " + line + " Check source file name") continue if self.files_count == 0: self.cue_file.file = full_file if line.startswith(INDEX): index = self.get_line_value(line) if line.startswith("INDEX 01"): cue_track = CueTrack(title, performer, index, full_file) self.cue_file.append_track(cue_track) logging.debug("CUE file parsed " + str(self.cue_file.file)) return self.normalize()