-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreal_02.py
88 lines (64 loc) · 2.69 KB
/
real_02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import PySimpleGUIQt as psg
import os
import yt_dlp
global values
global real_values
clear = lambda: os.system("clear")
#PySimpleGUIQt.Window("Test", [[]], margins = (100, 50), ).read()
#layout = [[PySimpleGUIQt.Text("Hello from PySimpleGUI")], [sg.Button("OK")]]
layout = [
[psg.Text('Enter your Video/Audio information')],
[psg.Radio(text="Video", group_id="FORMAT", default=True, key="Video_select"), psg.Radio(text="Audio", group_id="FORMAT", default=False, key="Audio_select")],
[psg.Text('URL', size=(15, 1)), psg.InputText(key="URL")],
[psg.Text('File format', size=(15, 1)), psg.InputText(key="FILE_FORMAT")],
[psg.Text("*for audio mp3")],
[psg.Text("*for Video mp4")],
# [sg.Text('Phone', size=(15, 1)), sg.InputText()],
[psg.Text("--press submit 3 times!--")],
[psg.Submit(), psg.Cancel()]
]
window = psg.Window("Test", layout) #size=(200, 200))
def check_event(get_ev):
global values
event, values = window.read()
if event == get_ev:
return True
def download_video_format(url, format):
URLS = [f"{url}"]
ydl_opts = {
'format': f'{format}/bestaudio/best',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download(URLS)
def extract_audio_format(url, audio_format, audio_quality = "bestaudio/best"):
URLS = [f"{url}"]
ydl_opts = {
'format': f"{audio_quality}",
# ℹ️ See help(yt_dlp.postprocessor) for a list of available Postprocessors and their arguments
'postprocessors': [{ # Extract audio using ffmpeg
'key': 'FFmpegExtractAudio',
'preferredcodec': f'{audio_format}',
}]
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
error_code = ydl.download(URLS)
while True:
psg.popup("The 'only audio' function won't work, if ffmpeg is not installed. Downloading Videos should work", title="Infos", non_blocking=True, keep_on_top=True)
global real_values
global values
if check_event("Cancel") or check_event(psg.WIN_CLOSED):
break
if check_event("Submit"):
real_values = values
#download_video_format(values[0], real_values[1])
if real_values["Video_select"]:
psg.popup("--DOWNLOADING-- \n --Please wait!--", title="Downloading", non_blocking=True)
window.disappear()
download_video_format(real_values["URL"], real_values["FILE_FORMAT"])
if real_values["Audio_select"]:
psg.popup("--DOWNLOADING-- \n --Please wait!--", title="Downloading", non_blocking=True)
window.disappear()
extract_audio_format(real_values["URL"], real_values["FILE_FORMAT"])
break
window.close()
print(real_values)