-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (61 loc) · 2.83 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
57
58
59
60
61
62
63
64
65
66
67
68
from functions import *
import shutil
import os
#############################################################
default_tmp_folder = "tmp"
default_frames_per_second_to_extract = 0.5
default_time_period = [(0, 36000)]
# Get user input
url = input("Enter the YouTube video URL or playlist url: ")
tmp_folder = input(f"Enter the temporary folder path (default: {default_tmp_folder}): ") or default_tmp_folder
frames_per_second_to_extract_input = input(f"Enter the frames per second to extract (default: {default_frames_per_second_to_extract}): ")
if frames_per_second_to_extract_input:
frames_per_second_to_extract = int(frames_per_second_to_extract_input)
else:
frames_per_second_to_extract = default_frames_per_second_to_extract
time_periods = []
time_period_str = input(
f"Enter time periods in seconds format:[(start1,end1),(start2,end2)](default: {default_time_period}): ")
if time_period_str:
try:
time_periods = eval(time_period_str)
except Exception as e:
print("Error parsing time periods:", e)
time_periods = default_time_period
else:
time_periods = default_time_period
debug=False
#debug = input(f"Enable debug mode? (y/n, default: No): ").lower() == "y"
#############################################################
try:
shutil.rmtree(tmp_folder)
print(f"Directory '{tmp_folder}' removed successfully.")
except OSError as e:
print(f"Error: {tmp_folder} : {e.strerror}")
if "playlist" in url.lower():
playlist_videos = extract_playlist_videos(url)
for i, video in enumerate(playlist_videos, 1):
print(f"Processing video {i}/{len(playlist_videos)}")
video_name = download_yt(video, tmp_folder)
extract_frames(os.path.join(tmp_folder, video_name), os.path.join(tmp_folder, "pic"), fps=frames_per_second_to_extract, time_periods=time_periods)
copy_diff_frames(os.path.join(tmp_folder, "pic"))
compile_to_ppt(os.path.join(tmp_folder, "pic", "changed_frames"), f"{video_name}_{i}.ppt")
try:
shutil.rmtree(tmp_folder)
print(f"Directory '{tmp_folder}' removed successfully.")
except OSError as e:
print(f"Error: {tmp_folder} : {e.strerror}")
else:
video_name=download_yt(url, tmp_folder)
print(f"whitelisted time {time_periods}")
extract_frames(os.path.join(tmp_folder,video_name), os.path.join(tmp_folder,"pic"), fps=frames_per_second_to_extract, time_periods=time_periods)
# max_frame = find_largest_frame_number("tmp/pic")
# print(max_frame)
copy_diff_frames(os.path.join(tmp_folder,"pic"))
compile_to_ppt(os.path.join(tmp_folder,"pic/changed_frames"), video_name+".ppt")
if not debug:
try:
shutil.rmtree(tmp_folder)
print(f"Directory '{tmp_folder}' removed successfully.")
except OSError as e:
print(f"Error: {tmp_folder} : {e.strerror}")