Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ytconverter/downloaders/multi_mp4.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ def run():
)
)

ask_subs = input(
apply_style("\nDownload subtitles for all videos? (y/n): ", "/cyan/bold")
).strip().lower()
sub_options = {}
cookie_path = ""
if ask_subs == "y":
print(apply_style("Note: YouTube may block subtitle extraction with HTTP 429. If that happens provide a cookies file.", "/yellow"))
cookie_path = input(apply_style("Enter path to cookies file for yt-dlp (optional, press Enter to skip): ", "/green")).strip()
lang = input(
apply_style("Enter subtitle language code (e.g. en) or leave blank for all: ", "/green")
).strip()
pref_auto = input(
apply_style("Also download automatic subtitles if manual not available? (y/n) [y]: ", "/green")
).strip().lower()
if pref_auto == "":
pref_auto = "y"
sub_options["writesubtitles"] = True
sub_options["writeautomaticsub"] = pref_auto == "y"
if lang:
sub_options["subtitleslangs"] = lang
sub_options["convertsubtitles"] = "srt"
if cookie_path:
sub_options["cookiefile"] = cookie_path

destination = Path(get_download_path("mp4"))
k = 1
for url in down_list:
Expand All @@ -85,10 +109,18 @@ def run():
vid_title = sanitize(info["title"])[:60]
print(apply_style(f"\nStarting Video {k} Download...\n", "/cyan/bold"))
time1 = int(time.time())

ydl_opts = {
"format": format_map[choice],
"outtmpl": str(destination / f"{vid_title}.%(ext)s"),
"quiet": True,
"no_warnings": True,
}
if sub_options:
for k_opt, v_opt in sub_options.items():
if v_opt is not None:
ydl_opts[k_opt] = v_opt

try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
Expand Down
32 changes: 28 additions & 4 deletions ytconverter/downloaders/single_mp4.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def run():

title = sanitize(info.get("title", "Unknown title"))

# Display formats with size
for idx, fmt in enumerate(formats, 1):
res = (
fmt.get("resolution", "Audio Only")
Expand Down Expand Up @@ -142,9 +141,6 @@ def run():
"outtmpl": str(video_out)
}




print("\033[36;1mStarting Video Download...\033[0m\n")
t0 = int(time.time())
try:
Expand Down Expand Up @@ -186,5 +182,33 @@ def run():
if Path("audio_temp").exists():
shutil.rmtree("audio_temp", ignore_errors=True)

try:
ask_subs = input("\n\033[36;1mDownload subtitles for this video? (y/n): \033[0m").strip().lower()
if ask_subs == "y":
print("\033[33;1mNote: YouTube may block subtitle extraction with HTTP 429. If that happens provide a cookies file.\033[0m")
cookie_path = input("\033[36;1mEnter path to cookies file (optional, press Enter to skip): \033[0m").strip()
lang = input("\033[36;1mEnter subtitle language code (e.g. en) or leave blank for all: \033[0m").strip()
pref_auto = input("\033[36;1mAlso download automatic subtitles if manual not available? (y/n) [y]: \033[0m").strip().lower()
if pref_auto == "":
pref_auto = "y"
cmd = ["yt-dlp", "--skip-download", "--write-sub"]
if pref_auto == "y":
cmd += ["--write-auto-sub"]
if lang:
cmd += ["--sub-lang", lang]
cmd += ["--convert-subs", "srt"]
if cookie_path:
cmd += ["--cookies", cookie_path]
cmd += ["-o", str(dest / f"{safe_title}.%(ext)s")]
cmd += [url]
print("\033[36;1mDownloading subtitles...\033[0m")
try:
sp.run(cmd, check=True)
print("\033[32;1mSubtitles downloaded (converted to .srt where possible).\033[0m")
except Exception as e:
print(f"\033[31;1mSubtitle download error: {e}\033[0m")
except Exception:
pass

if __name__=="__main__":
run()