Skip to content

Commit 58732c0

Browse files
IndexError Fix#1
1 parent 68a6dbc commit 58732c0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

jiosaavn.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ def get_song(id,lyrics):
2828

2929
def get_song_id(url):
3030
res = requests.get(url, data=[('bitrate', '320')])
31-
return res.text.split('"song":{"type":"')[1].split('","image":')[0].split('"id":"')[-1]
31+
try:
32+
return res.text.split('"song":{"type":"')[1].split('","image":')[0].split('"id":"')[-1]
33+
except IndexError:
34+
return(res.text.split('"pid":"'))[1].split('","')[0]
3235

3336
def get_album(album_id,lyrics):
3437
songs_json = []
@@ -44,7 +47,10 @@ def get_album(album_id,lyrics):
4447

4548
def get_album_id(input_url):
4649
res = requests.get(input_url)
47-
return res.text.split('"album_id":"')[1].split('"')[0]
50+
try:
51+
return res.text.split('"album_id":"')[1].split('"')[0]
52+
except IndexError:
53+
return res.text.split('"page_id","')[1].split('","')[0]
4854

4955
def get_playlist(listId,lyrics):
5056
try:
@@ -60,7 +66,11 @@ def get_playlist(listId,lyrics):
6066

6167
def get_playlist_id(input_url):
6268
res = requests.get(input_url).text
63-
return res.split('"type":"playlist","id":"')[1].split('"')[0]
69+
try:
70+
return res.split('"type":"playlist","id":"')[1].split('"')[0]
71+
except IndexError:
72+
return res.split('"page_id","')[1].split('","')[0]
73+
6474

6575
def get_lyrics(id):
6676
url = endpoints.lyrics_base_url+id

0 commit comments

Comments
 (0)