-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylist_core.py
executable file
·75 lines (56 loc) · 2.48 KB
/
playlist_core.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
from download_preference import download_with_subtitle, download_without_subtitle
from string_formatter import name_fixer
from clint.textui import colored
from typing import Union, Any
from pytube import Playlist
import download_engine
import ux_engine
def playlist_data_parse(playlist_link) -> None:
playlist_obj = Playlist(playlist_link)
all_video_urls: list = list(playlist_obj.video_urls)
playlist_data: dict[str, Union[str, list, Any]] = {
"title": playlist_obj.title,
"channel_name": playlist_obj.owner,
"urls": all_video_urls,
"total_videos": len(all_video_urls),
"raw_obj": playlist_obj
}
initiate = ux_engine.PlaylistUXEngine(playlist_data)
playlist_downloader_func_step_1(initiate, playlist_data)
def playlist_downloader_func_step_1(initiate, playlist_data) -> None:
initiate.show_task_data()
selection_data: dict = initiate.selection_choice("playlist")
if selection_data.get("download"):
playlist_data.update(title=name_fixer(
playlist_data.get("title")))
if selection_data.get("subtitle"):
yt_dlp_config = download_with_subtitle()
else:
yt_dlp_config = download_without_subtitle()
if selection_data.get("download"):
playlist_downloader_func_step_2(playlist_data, yt_dlp_config)
def playlist_downloader_func_step_2(playlist_data, yt_dlp_config) -> None:
check_progress: int = 0
for url in playlist_data.get("urls"):
initiate_download = download_engine.PlaylistDownloadEngine(
playlist_data.get("title"), url, yt_dlp_config, playlist_data.get("total_videos"), check_progress)
signal_from_initiate_download = initiate_download.downloader()
if signal_from_initiate_download.get("forcefully_stopped"):
break
else:
check_progress += 1
if check_progress == playlist_data.get("total_videos"):
download_msg(playlist_data.get("title"),
signal_from_initiate_download)
def download_msg(playlist_name: str, signal: dict):
print(colored.cyan("Download of "), end="")
print(colored.yellow(f"{playlist_name} "), end="")
if not signal.get("download_failed"):
print(colored.cyan("is Completed.\n"))
else:
print(colored.cyan(
"is completed "), end="")
print(colored.red(
"with some errors."))
print(colored.blue(
"Error log is saved in the file -> \"failed_download.log\"\n"))