
from pathlib import Path

def ():
    output_dir = Path(output_dir)
    output_playlists = []

    remote_to_local_map = {}

    for local_id, links in link_pattern.items():
        if len(links['items']):
            remote_to_local_map[links['items'][0]] = local_id

    for name, tracks in remote_playlists.items():
        local_tracks = []

        for track in tracks:
            track = track["track"]
            path = "error"
            error = ""
            if track is None:
                error = f"error: track is none"
            elif track["id"] in remote_to_local_map:
                path = local_library[remote_to_local_map[track["id"]]]["path"]
            else:
                error = f"error: not_found - {track["name"]}"

            if error != "":
                local_tracks.append("# " + error)
            else:
                path = (output_dir / ".." ).resolve() / Path(path)
                local_tracks.append(path)

        pl = {
            "name": name,
            "tracks": local_tracks,
        }

        output_playlists.append(pl)


    for pl in output_playlists:
        output_dir.mkdir(parents=True, exist_ok=True)

        playlist_path = Path(output_dir) / f"{pl['name']}.m3u"

        with (playlist_path.open("w", encoding="utf-8") as f):
            for track in pl["tracks"]:
                f.write(str(track))
                f.write("\n")