Skip to content

Commit

Permalink
Added bitrate selector and program now saves location bitrate and for…
Browse files Browse the repository at this point in the history
…mat you download in
  • Loading branch information
rickyrorton committed Jun 19, 2022
1 parent 8968389 commit 378fbcd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
14 changes: 7 additions & 7 deletions downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def m4atagger(mp4,m4a,song,path):
except Exception as e:
print(e)

def mp3convtagger(mp4,mp3,song,path):
def mp3convtagger(mp4,mp3,song,path,bitrate):
try:
iconname=ospath.join(path,remove_sus_characters(song['artists'][0]['name']+'-'+song['name'])+'.jpg')
request.urlretrieve(song['album']['images'][0]['url'],iconname)
convert=AudioSegment.from_file(mp4)
convert.export(mp3,format='mp3')
convert.export(mp3,format='mp3',bitrate=bitrate)
tags=ID3(mp3)
tags.add(TIT2(encoding=3, text=[song['name']]))
tags.add(TALB(encoding=3, text=[song['album']['name']]))
Expand Down Expand Up @@ -130,7 +130,7 @@ def flacconvtagger(webm,flac,song,path):
except Exception as e:
print(e)

def start(dlbut,scrltxt,progress,link:str,path:str,threadno:int,filetype:str):
def start(dlbut,scrltxt,progress,link:str,path:str,threadno:int,filetype:str,bitrate:str):
global threads
global leader
scrltxt.config(state='normal')
Expand All @@ -150,7 +150,7 @@ def start(dlbut,scrltxt,progress,link:str,path:str,threadno:int,filetype:str):
dlbut['state']='disabled'
progress['maximum']=1
for i in range(1):
t=Thread(target=download_song,args=(link,scrltxt,path,filetype,dlbut,progress),daemon=False)
t=Thread(target=download_song,args=(link,scrltxt,path,filetype,dlbut,progress,bitrate),daemon=False)
t.start()
threads.append(t)

Expand All @@ -166,7 +166,7 @@ def start(dlbut,scrltxt,progress,link:str,path:str,threadno:int,filetype:str):
add_text(scrltxt,'Downloading playlist \"{}\" with {} songs\n'.format(name,len(tracks)))
lead=True
for i in range(threadno):
t=Thread(target=download_playlist,args=(tracks[i::threadno],scrltxt,path,filetype,lead,dlbut,progress,False),daemon=False)
t=Thread(target=download_playlist,args=(tracks[i::threadno],scrltxt,path,filetype,lead,dlbut,progress,bitrate,False),daemon=False)
t.start()
if not lead:
threads.append(t)
Expand All @@ -185,7 +185,7 @@ def start(dlbut,scrltxt,progress,link:str,path:str,threadno:int,filetype:str):
add_text(scrltxt,'Downloading album \"{}\" with {} songs\n'.format(name,len(tracks)))
lead=True
for i in range(threadno):
t=Thread(target=download_playlist,args=(tracks[i::threadno],scrltxt,path,filetype,lead,dlbut,progress,True),daemon=False)
t=Thread(target=download_playlist,args=(tracks[i::threadno],scrltxt,path,filetype,lead,dlbut,progress,bitrate,True),daemon=False)
t.start()
if not lead:
threads.append(t)
Expand Down Expand Up @@ -314,7 +314,7 @@ def download_playlist(tracks,scrltxt,path,filetype,leader,button,progress,album:
print('ISRC-',song['name'],i['title'])
break
vid=YouTube(vid_url)
except:
except Exception as e:
results = YoutubeSearch(song['artists'][0]['name']+' '+song['name'], max_results=10).to_dict()
spsonglen = int(song['duration_ms']/1000)
vid=accusearch(results=results,songlen=spsonglen)
Expand Down
53 changes: 44 additions & 9 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from os import path as ospath
import downloader
from webbrowser import open_new_tab
from pickle import load,dump

#defining a window
global window
Expand All @@ -29,11 +30,14 @@
download_location=Label(window,text='Download location:',font = ("Arial Bold",10),bg = '#3d3d3d', fg = 'white',justify=LEFT)
download_location.place(relx=0.5,rely=0.84,anchor=CENTER)

thread_number=Label(window,text='How many threads to use?\n(More threads=more cpu usage)',font = ("Arial Bold",10),bg = '#3d3d3d', fg = 'white')
thread_number.place(relx=0.2,rely=0.77,anchor=CENTER)
thread_number=Label(window,text='Thread count:',font = ("Arial Bold",10),bg = '#3d3d3d', fg = 'white')
thread_number.place(relx=0.12,rely=0.78,anchor=CENTER)

filetype=Label(window,text='Filetype:',font = ("Arial Bold",10),bg = '#3d3d3d', fg = 'white')
filetype.place(relx=0.73,rely=0.77,anchor=CENTER)
filetype.place(relx=0.46,rely=0.78,anchor=CENTER)

bitrate=Label(window,text='Bitrate:',font = ("Arial Bold",10),bg = '#3d3d3d', fg = 'white')
bitrate.place(relx=0.73,rely=0.78,anchor=CENTER)

global progress
progress=Progressbar(window,orient = HORIZONTAL,mode = 'determinate',length=100)
Expand All @@ -56,14 +60,21 @@
global filetype_default
filetypes=['.m4a','.mp3','.wav','.flac']
filetype_default=StringVar()
filetype_default.set('.m4a')
filetype_default.set('.m4a')
filetype_dropdown=OptionMenu(window,filetype_default,*filetypes)
filetype_dropdown.place(relx=0.8,rely=0.75)
filetype_dropdown.place(relx=0.52,rely=0.755)

global bitrate_default
bitrates=['96k','128k','192k','320k']
bitrate_default=StringVar()
bitrate_default.set('192k')
bitrate_dropdown=OptionMenu(window,bitrate_default,*bitrates)
bitrate_dropdown.place(relx=0.78,rely=0.755)

global thread_num_set
thread_num_set=Scale(window,from_=1,to=20,tickinterval=19,orient=HORIZONTAL,highlightbackground='#3d3d3d',background='#3d3d3d',fg='white')
thread_num_set.set(4)
thread_num_set.place(relx=0.4,rely=0.73)
thread_num_set.place(relx=0.2,rely=0.73)

entry_cont = LabelFrame(window, font=("Arial Bold", 15), background='#1DB954', foreground='white', borderwidth=5, labelanchor="n")
entry_cont.place(relx=0.62,rely=0.12,width=394,height=24,anchor=CENTER)
Expand All @@ -87,7 +98,15 @@ def server_invite():

#setting default download location
global location
location=ospath.join(application_path,'Downloads').replace('\\','/')
if ospath.exists(ospath.join(application_path,'spdconfig.dat')):
f=open(ospath.join(application_path,'spdconfig.dat'),'rb')
dict=load(f)
location=dict['location']
filetype_default.set(dict['filetype'])
bitrate_default.set(dict['bitrate'])
thread_num_set.set(dict['threads'])
else:
location=ospath.join(application_path,'Downloads').replace('\\','/')
download_location.config(text='Download location:'+str(location))

#function for importing pictures into the gui
Expand Down Expand Up @@ -118,10 +137,25 @@ def directrory():
global location
location=askdirectory()
if location:
dict={'location':location,'bitrate':bitrate_default.get(),'filetype':filetype_default.get(),'threads':thread_num_set.get()}
f=open(ospath.join(application_path,'spdconfig.dat'),'wb')
dump(dict,f)
f.close()
download_location.config(text='Download location:'+str(location))
else:
pass

def saveconf(*args):
global localtion
dict={'location':location,'bitrate':bitrate_default.get(),'filetype':filetype_default.get(),'threads':thread_num_set.get()}

f=open(ospath.join(application_path,'spdconfig.dat'),'wb')
dump(dict,f)
f.close()

filetype_default.trace('w',saveconf)
bitrate_default.trace('w',saveconf)
thread_num_set.config(command=saveconf)
def start_downloader():
global location
global output_box
Expand All @@ -131,7 +165,8 @@ def start_downloader():
link=playlist_link.get()
playlist_link.delete(0,len(link))
threads=thread_num_set.get()
filetype=filetype_default.get()
downloader.start(dlbut=download_button,link=link,path=location,threadno=threads,filetype=filetype,scrltxt=output_box,progress=progress)
filetype=filetype_default.get()
bitrate=bitrate_default.get()
downloader.start(dlbut=download_button,link=link,path=location,threadno=threads,filetype=filetype,scrltxt=output_box,progress=progress,bitrate=bitrate)

window.mainloop()

0 comments on commit 378fbcd

Please sign in to comment.