Skip to content

Commit

Permalink
update api, now using encryptedMediaUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Liupold committed Apr 15, 2023
1 parent 125b40f commit 2951f89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions fmdpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""fmdpy."""
from . import conf

VERSION = "0.6.2"
VERSION = "0.6.3"
install_requires = ['click', 'music-tag>=0.4.3', 'requests', 'pillow',
'lyricsgenius', 'dataclasses', 'spotipy', 'tqdm', 'pydub']
'lyricsgenius', 'dataclasses', 'spotipy', 'tqdm', 'pydub',
'pycryptodome']

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' +
Expand Down
20 changes: 13 additions & 7 deletions fmdpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
import requests
from fmdpy import headers, ART
from fmdpy.song import Song
from Crypto.Cipher import DES
import base64 as bs64

def get_song_urls(song_obj):
"""Fetch song download url."""
req = requests.get(headers=headers,
url="https://www.jiosaavn.com/api.php?__call=song.getDetails&cc=in" \
+ f"&_marker=0%3F_marker%3D0&_format=json&pids={song_obj.songid}")
raw_json = req.json()[song_obj.songid]
if 'media_preview_url' in raw_json.keys():
song_obj.url = raw_json['media_preview_url'].\
replace('https://preview.saavncdn.com/', 'https://aac.saavncdn.com/').\
replace('_96_p.mp4', '_320.mp4')
url="https://www.jiosaavn.com/api.php?__call=song.getDetails" \
+ f"&ctx=web6dot0&_marker=0&_format=json&pids={song_obj.songid}")

raw_json = req.json()['songs'][0]
if 'encrypted_media_url' in raw_json.keys():
key = '38346591'.encode('utf-8')
dciper = DES.new(key, DES.MODE_ECB)
decrypted = dciper.decrypt(bs64.b64decode(raw_json['encrypted_media_url']))
song_obj.url = decrypted.replace(b'\x05', b'').decode().replace('_96', '_320')
song_obj.thumb_url = raw_json['image'].replace(
'-150x150.jpg', '-500x500.jpg')
print(raw_json)
print(song_obj)

def parse_search_query(query_json):
song_list = []
Expand Down

0 comments on commit 2951f89

Please sign in to comment.