Skip to content

Commit d102957

Browse files
committed
Updating Project
1 parent f01ffb7 commit d102957

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

Project 14 - Media Searcher and Downloader/Application.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
import asyncio
55

66

7-
async def media_search():
8-
media_search()
7+
# async def media_search():
8+
# media_search()
99

10-
async def Download_Media():
11-
downloadMedia()
10+
# async def Download_Media():
11+
# downloadMedia()
1212

1313
async def main():
14-
app_header()
14+
# app_header()
15+
downloadMedia()
1516
# await media_search()
16-
await downloadMedia()
17-
17+
# await downloadMedia()
18+
1819
if __name__ == '__main__':
1920
asyncio.run(main())

Project 14 - Media Searcher and Downloader/__modules__/youtube_Media_Downloader.py

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import yt_dlp
22
import os
33
import argparse
4+
from win10toast import ToastNotifier
45

56
def get_default_dir():
67
return os.path.join(os.path.expanduser('~'), "Downloads")
@@ -10,35 +11,19 @@ def download_media(url, save_to=None, resolution=None):
1011
save_to = get_default_dir()
1112

1213
if not os.path.exists(save_to):
13-
os.mkdir(save_to)
14+
os.mkdir(save_to, exist_ok=True)
1415

1516
ydl_opts = {
1617
'outtmpl': os.path.join(save_to, '%(title)s.%(ext)s'), # Output path and filename template
18+
'format': 'bestvideo[height<=?{0}]+bestaudio/best[height<=?{0}]'.format(resolution or '1080')
1719
}
1820

1921
try:
2022
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
2123
info_dict = ydl.extract_info(url, download=True)
22-
formats = info_dict.get('formats', [])
23-
24-
selected_format = None
25-
26-
for format_item in formats:
27-
if 'height' in format_item:
28-
if resolution and f'{resolution}p' in format_item.get('format_note', '').lower():
29-
selected_format = format_item
30-
break
31-
elif not resolution:
32-
selected_format = format_item
33-
34-
if selected_format:
35-
print(f"Selected Resolution: {selected_format['format_note']}")
36-
ydl_opts['format'] = selected_format['format_id']
37-
ydl.download([url])
38-
downloaded_file_path = os.path.join(save_to, f"{info_dict.get('title')}.mp4")
39-
print(f"Download completed successfully. File saved to: {downloaded_file_path}")
40-
else:
41-
print("No suitable format found for the requested resolution.")
24+
downloaded_file_path = os.path.join(save_to, f"{info_dict.get('title')}.mp4")
25+
ToastNotifier().show_toast('Downloading Completed Successfully', f'File saved to : {downloaded_file_path}')
26+
print(f"Download completed successfully. File saved to: {downloaded_file_path}")
4227

4328
print('\n------------------------------Video Info------------------------------\n')
4429
print(f"Title: {info_dict.get('title')}")

0 commit comments

Comments
 (0)