Skip to content

Commit

Permalink
Add jiosaavn support
Browse files Browse the repository at this point in the history
Only /song urls at the moment
  • Loading branch information
cyberboysumanjay authored and TheHardGamer committed May 28, 2021
1 parent 0ea9769 commit 0e6e8bf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
40 changes: 23 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pyglet
import ast
import webbrowser
import saavn

pyglet.font.add_file('googlesans.ttf')

Expand Down Expand Up @@ -393,17 +394,22 @@ def yt():

def yt_dl():
finallink = yt()
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': '%(title)s.%(ext)s',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
youtube_dl.YoutubeDL(ydl_opts).download([finallink])
messagebox.showinfo(title="Youtube to MP3", message="Download Complete!")
if "jiosaavn" not in finallink:
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': '%(title)s.%(ext)s',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
youtube_dl.YoutubeDL(ydl_opts).download([finallink])
messagebox.showinfo(title="Youtube to MP3", message="Download Complete!")
else:
flink = finallink.strip("\n")
saavn.jiosaavndl(flink)
messagebox.showinfo(title="Jiosaavn to MP3", message="Download Complete!")

def vid_dl():
finallink = yt()
Expand Down Expand Up @@ -446,15 +452,15 @@ def stop_stream():
ytframe = Frame(main)
ytframe.grid(row=6, column=0, pady=5)
ytframe.configure(bg="#04030F")
ytdl_button = Button(ytframe, text="Download the video", font=("Google Sans",9), command=vid_dl, bg="#0FFF95")
ytdl_button = Button(ytframe, text="Download the video", font=("Google Sans",9), command=vid_dl, bg="#0FFF95", fg="black")
ytdl_button.grid(row=1, column=0, padx=2)
ytdl_button = Button(ytframe, text="Download video as MP3", font=("Google Sans",9), command=yt_dl, bg="#0FFF95")
ytdl_button = Button(ytframe, text="Download as MP3", font=("Google Sans",9), command=yt_dl, bg="#0FFF95", fg="black")
ytdl_button.grid(row=1, column=1, padx=2)
ytdl_button = Button(ytframe, text="Stream The above YT link", font=("Google Sans",9), command=stream, bg="#0FFF95")
ytdl_button = Button(ytframe, text="Stream The above YT link", font=("Google Sans",9), command=stream, bg="#0FFF95", fg="black")
ytdl_button.grid(row=1, column=2, padx=2)
ytdl_button = Button(ytframe, text="Pause/Resume the stream", font=("Google Sans",9), command=pause_stream, bg="#0FFF95")
ytdl_button = Button(ytframe, text="Pause/Resume the stream", font=("Google Sans",9), command=pause_stream, bg="#0FFF95", fg="black")
ytdl_button.grid(row=1, column=3, padx=2)
ytdl_button = Button(ytframe, text="Stop the stream", font=("Google Sans",9), command=stop_stream, bg="#0FFF95")
ytdl_button = Button(ytframe, text="Stop the stream", font=("Google Sans",9), command=stop_stream, bg="#0FFF95", fg="black")
ytdl_button.grid(row=1, column=4, padx=2)

def show_eq():
Expand Down Expand Up @@ -487,7 +493,7 @@ def update_values(self):
t = threading.Thread(target=k)
t.start()

showeq_button = Button(main, text="Show visualizer", font=("Google Sans",9), command=show_eq, bg="#0FFF95")
showeq_button = Button(main, text="Show visualizer", font=("Google Sans",9), command=show_eq, bg="#0FFF95", fg="black")
showeq_button.grid(row=7, column=0)

# Set app icon
Expand Down
32 changes: 32 additions & 0 deletions saavn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import requests
import json
from pyDes import *
import base64
from pydub import AudioSegment
import os

url = "https://www.jiosaavn.com/api.php?__call=song.getDetails&cc=in&_marker=0%3F_marker%3D0&_format=json&pids="

def format(string):
return string.encode().decode('unicode-escape').replace(""","'").replace("&", "&").replace("'", "'")

def jiosaavndl(inpurl):
if(inpurl > ''):
res = requests.get(inpurl, data=[('bitrate', '320')])
pid = res.text.split('"song":{"type":"')[1].split('","image":')[0].split('"id":"')[-1]
finalurl = url + pid
encid = requests.get(finalurl).text.encode().decode('unicode-escape')
encid = json.loads(encid)
jsondata = encid[pid]
jsondata['media_url'] = jsondata['encrypted_media_url']
jsondata['song'] = format(jsondata['song'])
des_cipher = des(b"38346591", ECB, b"\0\0\0\0\0\0\0\0",pad=None, padmode=PAD_PKCS5)
enc_url = base64.b64decode(jsondata['encrypted_media_url'].strip())
dec_url = des_cipher.decrypt(enc_url, padmode=PAD_PKCS5).decode('utf-8')
dec_url = dec_url.replace("_96.mp4", "_320.mp4")
filename = jsondata['song'] + ".m4a"
song = requests.get(dec_url, allow_redirects=True, timeout=5)
open(filename, 'wb').write(song.content)
finalname = os.path.splitext(filename)[0]
AudioSegment.from_file(filename).export(finalname + ".mp3", format="mp3", bitrate="320k")
return

0 comments on commit 0e6e8bf

Please sign in to comment.