stable - generate local playlists & add default options
This commit is contained in:
parent
11e3b06824
commit
892568d668
4 changed files with 132 additions and 26 deletions
50
LocalPLaylistGenerator.py
Normal file
50
LocalPLaylistGenerator.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
from pathlib import Path
|
||||
|
||||
def generate_playlists(local_library, library_path, remote_playlists, link_pattern, output_dir):
|
||||
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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue