def __parse_line(self, line, fd, path): if line.startswith('#EXTINF:'): line = line.strip()[8:] artist = title = location = None if ',' in line: line = line.split(',', 1)[1] if ' - ' in line: artist, title = line.split(' - ', 1) else: title = line for line in fd: location = self.get_asb_path(line.strip()) if os.path.exists(location): break elif location.startswith('#EXT'): self.__parse_line(line, fd, path) return else: logger.warning('File not found %r in playlist %r', location, path) location = None song = Song(location, title) if artist is not None: song.artist = artist self.add_song(song) elif line.startswith('#EXTM3U'): return else: if os.path.exists(line): self.add_file(line) else: logger.warning('File not found %r in playlist %r', line, path)
def songs_to_plfile(self): for song in self: if not song.location: continue loc = song.location # replacing old root with new root in the playlist file if self.old_root is not None and self.new_root is not None: if loc.startswith(self.old_root): loc = os.path.join(self.new_root, loc[len(self.old_root):].lstrip('/')) else: loc = os.path.join(self.new_root, loc.lstrip('/')) loc = to_fat_compat(loc) target_song = Song(loc) target_song.title = song.title target_song.artist = song.artist target_song.length = song.length yield target_song