-
Notifications
You must be signed in to change notification settings - Fork 12
/
yt_clipper.py
executable file
·141 lines (104 loc) · 3.88 KB
/
yt_clipper.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
import certifi
from clipper import (
argparser,
clip_maker,
clipper_types,
util,
ytc_logger,
ytc_settings,
)
from clipper.clipper_types import ClipperState
from clipper.ffmpeg_version import getFfmpegVersion
from clipper.version import __version__
from clipper.ytc_logger import logger
from clipper.ytdl import ytdl_bin_get_version
UNKNOWN_PROPERTY = "unknown"
def main() -> None:
cs = clipper_types.ClipperState()
args, unknown, argsFromArgFiles, argFiles, argsFromArgFilesMap = argparser.getArgs()
cs.settings.update({"color_space": None, **args})
ytc_settings.loadSettings(cs.settings)
setupDepPaths(cs)
if cs.settings["printVersions"]:
print(argparser.getDepVersionsString(cs.clipper_paths))
sys.exit(0)
setupOutputPaths(cs)
ytc_logger.setUpLogger(cs)
logger.debug(f"yt-dlp path set: {cs.clipper_paths.ytdlPath}")
logger.report(f"yt_clipper version: {__version__}")
logger.report(
f"yt-dlp version: {ytdl_bin_get_version(cs.clipper_paths)}",
)
logger.report(f"{getFfmpegVersion(cs.clipper_paths.ffmpegPath)}", extra={"highlighter": None})
logger.info("-" * 80)
logger.debug(f"The following arguments were read from the command line {sys.argv[1:]}:")
if argsFromArgFiles:
logger.notice(f"The following default arguments were read from {argFiles}:")
logger.notice(argsFromArgFilesMap)
logger.info("-" * 80)
elif argFiles:
logger.notice(f"No uncommented arguments were found in {argFiles}")
logger.info("-" * 80)
if unknown:
logger.notice(
f"The following unknown arguments were provided and were ignored:",
)
logger.notice(unknown)
logger.info("-" * 80)
enableMinterpEnhancements(cs)
ytc_settings.getInputVideo(cs)
ytc_settings.getGlobalSettings(cs)
logger.info("-" * 80)
if not cs.settings["preview"]:
clip_maker.makeClips(cs)
else:
clip_maker.previewClips(cs)
ytc_logger.printReport(cs)
if cs.settings["notifyOnCompletion"]:
util.notifyOnComplete(cs.settings["titleSuffix"])
def setupDepPaths(cs: ClipperState) -> None:
settings = cs.settings
cp = cs.clipper_paths
if getattr(sys, "frozen", False):
cp.ffmpegPath = "./bin/ffmpeg"
cp.ffprobePath = "./bin/ffprobe"
cp.ffplayPath = "./bin/ffplay"
cp.ytdlPath = "./bin/yt-dlp"
if sys.platform == "win32":
cp.ffmpegPath += ".exe"
cp.ffprobePath += ".exe"
cp.ffplayPath += ".exe"
cp.ytdlPath += ".exe"
if sys.platform == "darwin":
cp.ytdlPath += "_macos"
certifi_cacert_path = certifi.where()
os.environ["SSL_CERT_FILE"] = certifi_cacert_path
os.environ["REQUESTS_CA_BUNDLE"] = certifi_cacert_path
if settings["ytdlLocation"]:
cp.ytdlPath = settings["ytdlLocation"]
def setupOutputPaths(cs: ClipperState) -> None:
settings = cs.settings
cp = cs.clipper_paths
cp.clipsPath += f'/{settings["titleSuffix"]}'
os.makedirs(f"{cp.clipsPath}/temp", exist_ok=True)
settings["downloadVideoPath"] = f'{cp.clipsPath}/{settings["downloadVideoNameStem"]}'
def enableMinterpEnhancements(cm: ClipperState) -> None:
settings = cm.settings
cp = cm.clipper_paths
if settings["enableMinterpEnhancements"] and sys.platform == "win32":
cp.ffmpegPath = "./bin/ffmpeg_ytc.exe"
if not Path(cp.ffmpegPath).is_file():
logger.critical(
f"{cp.ffmpegPath} required for minterp enhancements not found.",
)
sys.exit(1)
else:
logger.success(f"Found {cp.ffmpegPath}. Minterp enhancements enabled.")
else:
settings["enableMinterpEnhancements"] = False
if __name__ == "__main__":
main()