Skip to content

Commit 738257f

Browse files
committed
Updating 14th Project
1 parent f3a0129 commit 738257f

File tree

4 files changed

+43
-42
lines changed

4 files changed

+43
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from __modules__.header_module import app_header
2+
from __modules__.youtube_search_Module import media_search
3+
import asyncio
24

3-
app_header()
45

5-
def main():
6-
return
6+
async def main():
7+
app_header()
8+
await media_search()
9+
710
if __name__ == '__main__':
8-
main()
11+
asyncio.run(main())

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

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pytube import Search
2+
from pytube import YouTube
3+
import asyncio
4+
5+
async def search_query(user_query, r_limit):
6+
q = Search(user_query)
7+
results = []
8+
9+
while len(results) < r_limit:
10+
next_results = q.results
11+
if not next_results:
12+
break
13+
results.extend(next_results)
14+
15+
search_term = user_query
16+
video_info = [{'title': video.title, 'video_id': video.video_id, 'thumbnail': video.thumbnail_url} for video in results]
17+
18+
return search_term, video_info[:r_limit]
19+
20+
async def media_search():
21+
try:
22+
user_input = input("Search here : ")
23+
result_limit = int(input("Set Result Limit : "))
24+
query_results = await search_query(user_input, result_limit)
25+
26+
search_term, video_info = query_results
27+
print()
28+
print('-------------------------------------- Result ---------------------------------------')
29+
print(f'Search Term : {search_term}')
30+
print()
31+
32+
for num, video_info in enumerate(video_info, start=1):
33+
print(f'{num} | Title ==> {video_info['title']} <==\n | URL : https://www.youtube.com/watch?v={video_info['video_id']}\n | Thumbnail : {video_info['thumbnail']}\n-------------------------------------------------------------------------------\n')
34+
except Exception as e:
35+
print(f"Error occurred : {e}")
36+

0 commit comments

Comments
 (0)