-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathytm-playlist2adoc.py
42 lines (34 loc) · 1.06 KB
/
ytm-playlist2adoc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from ytmusicapi import YTMusic
import json
import sys
tmp = sys.stdin.read()
playlist = json.loads(tmp)
def fmt(s):
return s.replace("|", "")
if playlist:
print(
f"## https://music.youtube.com/playlist?list={playlist['id']}[{playlist['title']}]\n\n"
)
print(f"{playlist['description']}")
if playlist["tracks"]:
print("[.scrollable]")
print('[cols="3,2,2,1"]')
print("|===")
print("|Title|Artist|Album|Duration")
print()
for track in playlist["tracks"]:
if track["thumbnails"]:
img = (
f"image:{track['thumbnails'][0]['url']}[thumbnail,40,40,role=bare]"
)
else:
img = ""
print(f"|{img}{fmt(track['title'])}")
print(f"|{track['artists'][0]['name']}")
if track["album"] and track["album"]["name"]:
print(f"|{track['album']['name']}")
else:
print("|")
print(f"|{track['duration']}")
print("|===")
print()