From cbed5026b6b6c651e56a052b2649ba8d131b8d1e Mon Sep 17 00:00:00 2001 From: ItIsJoeyG <60891047+Joey451-OG@users.noreply.github.com> Date: Tue, 7 Mar 2023 20:00:01 -0600 Subject: [PATCH] 1.2.0 release. Cleaned up the logic system in YT Download.py and now if you do not specify a directory, your file will be saved to 'C:/Users/%userprofile%/Documents/Yt Download' --- YT Download.py | 60 ++++++++++++++++--------------- __pycache__/main.cpython-311.pyc | Bin 2159 -> 2152 bytes main.py | 17 ++++----- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/YT Download.py b/YT Download.py index 2f4b933..e965327 100644 --- a/YT Download.py +++ b/YT Download.py @@ -1,56 +1,58 @@ import PySimpleGUI as sg -import main as dowloader +import main as downloader +import os sg.theme('DarkAmber') # Color Scheme +user_dir = os.environ['USERPROFILE'] + '\Documents\YT Download' + # GUI layout layout = [ [sg.Text("Thank you for using YT Download!")], [sg.Text("YouTube URL:"), sg.InputText(key='URL')], [sg.Checkbox('Download as an audio file (mp3)?', default=False, key='isAudio')], - [sg.Text('File path. Leave blank to save download to program location.')], + [sg.Text('File path. Leave blank to save download to:')], + [sg.Text(f'{user_dir}')], [sg.Input(key='DIR'), sg.FolderBrowse()], [sg.Button('Download'), sg.Cancel()] ] -# Returns 'program directory' if dir is empy, otherwise returns dir -def format_dir(dir): - if dir == '': - return 'program directory.' - else: - return dir +# Main logic function. Calls the appropriate functions in main.py and handles input errors. +def GUI_checks(event, audio_val, url_val, dir_val): + title = downloader.return_title(url_val) -def incorrect_url_check(title): - if title == 'ERROR': - sg.popup('INVALID YOUTUBE URL', icon='logo.ico', title='YT Download') - return False + if dir_val == '': + dir_val = user_dir + + if audio_val: + file_type = '.mp3' else: - return title + file_type = '.mp4' + + if event == 'Download': + if url_val == '': + sg.popup('Please make sure to provide a URL', icon='logo.ico', title='YT Download') + else: + if title == 'ERROR': + sg.popup('INVALID YOUTUBE URL', icon='logo.ico', title='YT Download') + title = False -# Main logic loop. Calls the apropriate functions in main.py + if title != False and url_val != '': + downloader.logic(url_val, audio_val, dir_val) + sg.popup(f'Downloaded {title} as a {file_type} file to {dir_val}', icon='logo.ico', title='YT Download') + + + +# Main setup loop. Calls GUI_checks() window = sg.Window('YT Download', layout, icon='logo.ico') while True: event, values = window.read() # Check the active event and the value dictionary. print(event, values) # Print event and values for debuging in the command line. - if event == sg.WIN_CLOSED or event == 'Cancel': # Break the loop if the window is closed or the 'Cancel' button is pressed break - if event == 'Download' and values['isAudio'] and values['URL'] != "": # When the 'Download' button is pressed, check to see if the 'isAudio' check box is checked and see if the url feild is not blank. - dir = format_dir(values['DIR']) # Then, call format_dir() and fetch the video title. Finially, download the audio and display the popup when done. - title = incorrect_url_check(dowloader.return_title(values['URL'])) - if title != False: - dowloader.logic(values['URL'], True, dir) - sg.popup(f'Downloaded {title} as a .mp3 file to {dir}', icon='logo.ico', title='YT Download') - elif event == 'Download' and not values['isAudio'] and values['URL'] != "": # When the 'Download' button is pressed, check to see if the 'isAudio' check box is not checked and see if the url feild is not blank. - dir = format_dir(values['DIR']) # Then, call format_dir() and fetch the video title. Finially, download the video and display the popup when done. - title = incorrect_url_check(dowloader.return_title(values['URL'])) - if title != False: - dowloader.logic(values['URL'], False, dir) - sg.popup(f'Downloaded {title} as a .mp4 file to {dir}', icon='logo.ico', title='YT Download') - elif event == 'Download' and values['URL'] == '': - sg.popup('Please make sure to provide a URL', icon='logo.ico', title='YT Download') + GUI_checks(event, values['isAudio'], values['URL'], values['DIR']) window.close() # Kill the program \ No newline at end of file diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc index 9beba3b38e687d85225fd9aaaff9b1368b61efd8..9a945639668cdbf990cda131942d1b5caf90fc52 100644 GIT binary patch delta 610 zcmY+9OKTHR6oAj2XWDTzNN9Zob7|Bxn|7fHmEw!BIFN>t#zjLmY3`_Fr@3Vw4hF$4 z>fSO7MHF3#B5oA%e@vi@G9b8YR}SdPRnJ5l=z;T{_qpf(%J1d%kGeh%DE^+x*tUL} zw6-e?Pfsvyi?kGWYztZ{(~&uLd>N|w{j9etBx5T)@Pk#$s3mgX+m6@2-n`vdH0w8O zbjh(go<-LzYlHd^Y>$R^kMWT54Xa1*ahI+%slmgZ!#j-noQB+8n;B0OEUkC^{> z!aTa8ig1_*U_$g*E)y|&BhQ`^Kj5Cvqum4;;NPWsv@aViF%j=JYKdwtcLHYfL^RBX zm-SLg-3hdb?C|?`*Daxc9@T3jHX&7jmg5U^gVNly#pl(5RNO619f_mY%KPalY@W@g zP7bGjXvLS!cb5iQWk;*TQpKg1u2;!I#MR=hvlzH%GE8R3UUahspJ3QGJm+t2ex0+x zv97rnu|!b4w}@0EgzQGKS}4R&{t5D?94mJQVD5k!gBkr%uiPkTq?E!@&@pm3g%KtQ QnNDGZoJ6D)5W@ow0HyJitN;K2 delta 562 zcmaDM@Lqs-IWI340}xoBU`aVUkyny2W}>>AwLl7Y3u6>pieL&akY-QeYhj4uNZ}7= z&=h(JQmx5!i!(C6w4^jC)y3x)YiUVlPH`2Ri>p(p`^Nh%OcL@gRxtrZ`B|ySCB-q7 zB`G=KMTrFksYR2km=zd>H_v9?z?gE2r8qmYAek9t9u%+wX%PSO8Xz&9p@ylJxrRA~ zF`Ee_U&NRv1>`YR0of%W0VqgewgIx>GGMh3sTAhP(^-`nStjph)t6;i1~hp!+%`sr z6b7JoSpAA5fQlzGvANW<++q$5^0~$C8Jt*}l9_*t*~K&H7IR8wQ85cpi2@K5i2)h6 zSab5zGn0!Hfox?UF3tuL4Ga&scpID_uyb{!HPtrM-r(SQpsaR5)ApjWZ7=VH%!?cf zH_-SG*!ey%FteK6<&d1KyFz%y#8BO+Nm*!Ujvivj|-82~?F3e$ .postprocessor| for a list of settings. 'key': 'FFmpegExtractAudio', - 'preferredcodec': 'mp3', + 'preferredcodec': 'mp3' }] } + # Handels downlaoding and retriving information def YoutubeDownloader(settings, url, isDownload=False): @@ -32,15 +33,11 @@ def YoutubeDownloader(settings, url, isDownload=False): # Main logic. Sets directory when specified and calls YoutubeDownloader() -def logic(URL, ISaudio, DIR='skip'): - - dir = DIR - - if dir == 'skip': # No directory was specified. - pass - else: # Format both the video and audio options with the specified directory. - audio_options['outtmpl'] = dir + '/%(title)s.%(ext)s' - video_options['outtmpl'] = dir + '/%(title)s.%(ext)s' +def logic(URL, ISaudio, DIR): + + + audio_options['outtmpl'] = DIR + '/%(title)s.%(ext)s' + video_options['outtmpl'] = DIR + '/%(title)s.%(ext)s' if ISaudio: # Download as audio or video YoutubeDownloader(audio_options, URL, True)