def copy(self, folder_dst, track_number=None): file_dst = os.path.basename(self.location) folder_dst = to_fat_compat(folder_dst) if track_number is not None: if re.match("^[0-9]+\W*-?\W*", file_dst): file_dst = re.sub("^[0-9]+\W*-?\W*", track_number, file_dst) else: file_dst = track_number + file_dst file_dst = to_fat_compat(os.path.join(folder_dst, file_dst)) if os.path.exists(file_dst): logger.debug('Song %r already here', self) return self.__class__(file_dst, self.encoding) if not os.path.exists(folder_dst): os.makedirs(folder_dst, exist_ok=True) try: logger.warn('Writing %s', file_dst) shutil.copy(self.location, file_dst) except Exception as error: logger.exception(error) return None return self.__class__(file_dst, self.encoding)
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