rhythmbox_playlists_writer.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:migrate-itunes-to-rhythmbox 作者: phauer 项目源码 文件源码
def write(playlists: List[Playlist], target_path: Path, target_library_root: str, source_library_root: str, exclude_playlist_folders: bool = True) -> None:
    persistent_id_to_playlist_dict = create_persistent_id_to_playlist_dict(playlists)
    filtered_playlist = filter_playlists_if_necessary(playlists, exclude_playlist_folders)
    root = etree.Element("rhythmdb-playlists")
    for playlist in filtered_playlist:
        name = create_playlist_name(playlist, persistent_id_to_playlist_dict)
        attributes = {'name': name, 'show-browser': 'true', 'browser-position': "231",
                      'search-type': "search-match", 'type': "static"}
        playlist_element = etree.SubElement(root, "playlist", attributes)
        for song in playlist.tracks:
            if song.location_escaped is not None:
                transformed_location = transform_to_rhythmbox_path(song.location_escaped, target_library_root, source_library_root)
                location_element = etree.SubElement(playlist_element, "location")
                location_element.text = transformed_location
            else:
                print("   Can't convert the track [{} - {}] in playlist '{}' because there is no file location defined. It's probably a remote file."
                      .format(song.artist, song.name, playlist.name))
    common.write_to_file(root, target_path, add_standalone_to_xml_declaration=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号