-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
91 lines (73 loc) · 2.27 KB
/
web.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import json
from flask import Flask, Response, request
import audio
CLOSEDPROFILE_TRACKS = [
{
"title":"Ваш профиль закрыт",
"artist":"VK2Pls",
"url":"http://octonezd.pw/ClosedProfile.mp3",
"duration":29
}
]
DOWNLOAD_TEMPLATE = """
<tr>
<td>%(number)s</td>
<td>%(artist)s</td>
<td>%(title)s</td>
<td><a href="%(url)s" download="%(artist)s - %(title)s.mp3" filename="%(artist)s - %(title)s.mp3">Скачать</a></td>
<td><a href="%(url)s" class="dropbox-saver"></a></td>
</tr>\n
"""
app = Flask(__name__, static_url_path='')
with open('index.html') as f:
INDEX = f.read()
with open('session.txt') as f:
VKSESSION = f.read()
with open("save.html") as f:
SAVEFILES = f.read()
@app.route("/")
def hello():
return INDEX
def get_music(user):
try:
tracks = audio.audio_get(user)
except (audio.VKError, audio.ClosedProfile):
tracks = CLOSEDPROFILE_TRACKS
return tracks
@app.route("/<user>.pls")
def pls(user):
tracks = get_music(user)
return audio.create_pls(tracks)
@app.route("/<user>.m3u8")
def m3u8(user):
tracks = get_music(user)
return audio.create_m3u(tracks)
@app.route("/json/<user>")
def jsdump(user):
try:
tracks = audio.audio_get(user)
except (audio.VKError, audio.ClosedProfile):
return Response(json.dumps('{"error": 1, "error_description": {"en": "Audio is closed in user\'s profile", "ru": "Музыка закрыта в настройках профиля пользователя"}}'),
mimetype="application/json"), 423
else:
return Response(json.dumps(tracks),
mimetype="application/json")
@app.route("/save/<user>")
def drpbox(user):
tracks = audio.audio_get(user)
if len(tracks) > 100:
tracks_saveall = tracks[:99]
else:
tracks_saveall = tracks
droptracks = []
for track in tracks_saveall:
droptracks.append({
"url":track["url"],
"filename":("%s - %s.mp3" % (track["artist"], track["title"])).replace("/", "").replace("\\","")
})
table = ""
for track in tracks:
table += DOWNLOAD_TEMPLATE % track
return SAVEFILES % (table, json.dumps(droptracks))
if __name__ == "__main__":
app.run(port=8081)