def load_user_config(self): if not os.path.isfile(USER_PATH_CONFIG): return try: with open(USER_PATH_CONFIG, 'r') as config: user_codecs = {} for line in config: try: if line.strip() == '' or line[:1] == '#': continue (codec_name, paths) = [x.strip() for x in line.split('=', 1)] paths = [x.strip() for x in paths.split(',')] except ValueError: self.log.debug('Error parsing line: {}'.format(line)) continue user_codecs[codec_name] = paths for codec_name in reversed(sorted(user_codecs.keys())): paths = user_codecs[codec_name] if codec_name == 'itunes': codec = match_codec('m4a') else: codec = match_codec(codec_name) if not codec: continue for path in reversed(paths): prefix = MusicTreePrefix(path, self.db.codec_configuration.extensions('aac')) if codec_name == 'itunes': self.add_prefix(prefix, prepend=False) else: self.add_prefix(prefix, prepend=True) except IOError as e: raise PrefixError('Error reading {}: {}'.format( USER_PATH_CONFIG, e, ))
def load_user_config(self): if not os.path.isfile(USER_PATH_CONFIG): return try: with open(USER_PATH_CONFIG, 'r') as config: user_codecs = {} for line in config: try: if line.strip() == '' or line[:1] == '#': continue (codec_name, paths) = [x.strip() for x in line.split('=', 1)] paths = [x.strip() for x in paths.split(',')] except ValueError: self.log.debug('Error parsing line: %s' % line) continue user_codecs[codec_name] = paths for codec_name in reversed(sorted(user_codecs.keys())): paths = user_codecs[codec_name] if codec_name == 'itunes': codec = match_codec('m4a') else: codec = match_codec(codec_name) if not codec: continue for path in reversed(paths): prefix = MusicTreePrefix(path, self.db.codecs.extensions('aac')) if codec_name == 'itunes': self.register_prefix(prefix, prepend=False) else: self.register_prefix(prefix, prepend=True) except IOError, (ecode, emsg): raise PrefixError('Error reading %s: %s' % (USER_PATH_CONFIG, emsg))
def load(self): super(Album, self).load() self.metadata_files = [] for name in os.listdir(self.path): if match_codec(name) is not None: self.files.append((self.path, name)) else: metadata = match_metadata(name) if metadata is not None: self.metadata_files.append(MetaDataFile(os.path.join(self.path, name), metadata)) self.files.sort()
def load(self): IterableTrackFolder.load(self) self.metadata_files = [] for f in os.listdir(self.path): if match_codec(f) is not None: self.files.append((self.path, f)) else: metadata = match_metadata(f) if metadata is not None: self.metadata_files.append(MetaDataFile(os.path.join(self.path, f), metadata)) self.files.sort()
def filter_tracks(self, regexp=None, re_path=True, re_file=True, as_tracks=False): if not len(self.files): self.load() tracks = [track for track in self.files if match_codec(track[1])] if regexp is not None: if not re_file and not re_path: raise TreeError('No matches if both re_file and re_path are False') if isinstance(regexp, basestring): regexp = re.compile(regexp) tracks = [track for track in tracks if re_path and regexp.match(track[0]) or re_file and regexp.match(track[1])] if as_tracks: return [Track(os.path.join(t[0], t[1])) for t in tracks] else: return tracks
def get_codec(self, codec): return match_codec(codec)