-
Notifications
You must be signed in to change notification settings - Fork 182
/
helper.py
72 lines (59 loc) · 2.38 KB
/
helper.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
import base64
import jiosaavn
from pyDes import *
def format_song(data, lyrics):
try:
data['media_url'] = decrypt_url(data['encrypted_media_url'])
if data['320kbps'] != "true":
data['media_url'] = data['media_url'].replace(
"_320.mp4", "_160.mp4")
data['media_preview_url'] = data['media_url'].replace(
"_320.mp4", "_96_p.mp4").replace("_160.mp4", "_96_p.mp4").replace("//aac.", "//preview.")
except KeyError or TypeError:
url = data['media_preview_url']
url = url.replace("preview", "aac")
if data['320kbps'] == "true":
url = url.replace("_96_p.mp4", "_320.mp4")
else:
url = url.replace("_96_p.mp4", "_160.mp4")
data['media_url'] = url
data['song'] = format(data['song'])
data['music'] = format(data['music'])
data['singers'] = format(data['singers'])
data['starring'] = format(data['starring'])
data['album'] = format(data['album'])
data["primary_artists"] = format(data["primary_artists"])
data['image'] = data['image'].replace("150x150", "500x500")
if lyrics:
if data['has_lyrics'] == 'true':
data['lyrics'] = jiosaavn.get_lyrics(data['id'])
else:
data['lyrics'] = None
try:
data['copyright_text'] = data['copyright_text'].replace("©", "©")
except KeyError:
pass
return data
def format_album(data, lyrics):
data['image'] = data['image'].replace("150x150", "500x500")
data['name'] = format(data['name'])
data['primary_artists'] = format(data['primary_artists'])
data['title'] = format(data['title'])
for song in data['songs']:
song = format_song(song, lyrics)
return data
def format_playlist(data, lyrics):
data['firstname'] = format(data['firstname'])
data['listname'] = format(data['listname'])
for song in data['songs']:
song = format_song(song, lyrics)
return data
def format(string):
return string.encode().decode().replace(""", "'").replace("&", "&").replace("'", "'")
def decrypt_url(url):
des_cipher = des(b"38346591", ECB, b"\0\0\0\0\0\0\0\0",
pad=None, padmode=PAD_PKCS5)
enc_url = base64.b64decode(url.strip())
dec_url = des_cipher.decrypt(enc_url, padmode=PAD_PKCS5).decode('utf-8')
dec_url = dec_url.replace("_96.mp4", "_320.mp4")
return dec_url