-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
56 lines (38 loc) · 1.52 KB
/
main.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
from authentication import get_authenticated_service
from urls_handlers import ChannelUrlHandler, UserUrlHandler, PlaylistUrlHandler
from api_requests import ApiV3RequestsHandler
from database_handler import close_connection
try:
service_client = get_authenticated_service()
except Exception as e:
print('\nThe following error occurred while tring to initialize the google client:')
print(e)
close_connection()
exit()
api_requests_handler = ApiV3RequestsHandler(service_client=service_client)
channel_url_handler = ChannelUrlHandler(
api_requests_handler=api_requests_handler)
user_url_handler = UserUrlHandler(api_requests_handler=api_requests_handler)
playlist_url_handler = PlaylistUrlHandler(
api_requests_handler=api_requests_handler)
url_handlers = [channel_url_handler, user_url_handler, playlist_url_handler]
url = raw_input('\nPlease enter a valid youtube channel/account/playlist url:\n')
playlist_id, error = None, False
for i in url_handlers:
try:
playlist_id = i.get_playlist_id(url)
if playlist_id is not None:
print('\nValid url detected\nStart downloading videos info\nPlease wait...')
try:
i.save_videos_info(playlist_id=playlist_id)
except Exception as e:
error = True
print('Error: ', e)
break
except:
continue
if playlist_id is None:
print('Url not valid')
elif not error:
print('The download completed successfully')
close_connection()