-
Notifications
You must be signed in to change notification settings - Fork 2
/
ytm.py
54 lines (39 loc) · 1.52 KB
/
ytm.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
43
44
45
46
47
48
49
50
51
52
53
54
from flask.helpers import send_from_directory
from ytmusicapi import YTMusic
import flask
import json
ytmusic = YTMusic("headers_auth.json")
app = flask.Flask(__name__)
@app.route("/api/library/playlists")
def libraryPlaylists():
playlists = ytmusic.get_library_playlists()
playlists[0]["count"] = "Some"
for p in playlists:
p["id"] = p["playlistId"]
del p["playlistId"]
try:
p["thumbnail"] = p["thumbnails"][1]["url"]
except IndexError:
# Handle empty thumbnails
p["thumbnail"] = "https://lh3.googleusercontent.com/wr28amLh-pMk4vmrYv_Orhly8DTtdvZJFuLwmXG5RNvZJjGlFe_WMnKp4pWlZI1gL7ihQn-xZuzZ0A6VZZbv2Z-iTEH3dpjn=s576"
del p["thumbnails"]
return json.dumps(playlists, indent=2)
@app.route("/api/playlist/<id>")
def playlist(id):
limit = flask.request.args.get("limit", 9999999999, type=int)
start = flask.request.args.get("start", 0, type=int)
playlist = ytmusic.get_playlist(id, limit=limit)
playlist["thumbnail"] = playlist["thumbnails"][1]["url"]
del playlist["thumbnails"]
playlist["tracks"] = playlist["tracks"][start:]
return json.dumps(playlist, indent=2)
@app.route("/assets/<path>")
def assets(path):
return send_from_directory("assets", path)
@app.errorhandler(404)
def catchAllIndex(path):
# Hooking 404 means that we can load on vue paths
# that don't exist on the server
return send_from_directory("assets", "index.html")
if __name__ == "__main__":
app.run(host='0.0.0.0', port=9000)