def relative_path(self, path): path = path.rstrip(os.sep) if path[:len(self.path)] == self.path: return path_string(path[len(self.path):].lstrip(os.sep)) realpath = os.path.realpath(path) mypath = os.path.realpath(self.path) if realpath[:len(mypath)] == mypath: return path_string(realpath[len(mypath):].lstrip(os.sep)) raise PrefixError('Prefix does not match: {}'.format(path))
def __init__(self, path, metadata=None): if metadata is None: metadata = match_metadata(path) if metadata is None: raise TreeError('Not a metadata file: {0}'.format(path)) self.path = path_string(path) self.extension = os.path.splitext(self.path)[1][1:].lower() if self.extension == '': self.extension = None self.metadata = metadata
def __init__(self, name, config=None, folder=None, unique=True): super(m3uPlaylist, self).__init__(name, unique) if os.path.isfile(name): path = os.path.realpath(name) else: if folder is not None: path = os.path.join(folder, '{0}.m3u'.format(self.name)) else: path = os.path.join('{0}.m3u'.format(self.name)) self.path = path_string(path)
def __init__(self, path, iterable): self.log = SoundforestLogger().default_stream self.__next = None self.__iterable = iterable if path in ['.', '']: path = os.path.realpath(path) self.path = path_string(path) self.prefixes = TreePrefixes() self.invalid_paths = [] self.has_been_iterated = False setattr(self, iterable, [])
def __init__(self, path=None): self.path = path_string(path) if not os.path.isdir(self.path): raise PlaylistError('No such directory: {0}'.format(self.path)) for f in sorted(os.listdir(self.path)): f = os.path.join(self.path, f) if os.path.isdir(f): self.extend(m3uPlaylistDirectory(path=f)) continue if os.path.splitext(f)[1][1:] != 'm3u': continue self.append(m3uPlaylist(f))
def __init__(self, path): self.log = SoundforestLogger().default_stream self.path = path_string(path) self.codec = None self.description = None self.is_metadata = False self.codec = match_codec(path) if self.codec is not None: self.description = self.codec.description.lower() else: m = match_metadata(path) if m: self.is_metadata = True self.description = m.description.lower() elif os.path.isdir(path): self.description = 'unknown directory' else: self.description = 'unknown file format'