Created
December 12, 2021 15:47
-
-
Save eslof/a080c51581731074f4df7b76ca158d91 to your computer and use it in GitHub Desktop.
Renames SRT files to match MP4 names in folder in sorted order (e.g. by episode) to be auto-detected by media players.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
from pathlib import Path | |
print_app = partial(print, "SRT Fix:") | |
files = [f for f in Path().iterdir() if f.is_file()] | |
mp4 = sorted([f for f in files if f.suffix.lower().endswith(".mp4")]) | |
srt = sorted([f for f in files if f.suffix.lower().endswith(".srt")]) | |
assert len(mp4) == len(srt), f"Count miss! MP4s: {len(mp4)}, SRTs: {len(srt)}." | |
print_app( | |
f"Looking at {len(mp4)} MP4 files with matching subs starting with" | |
f"\n(MP4) {mp4[0]}" | |
f"\n(SRT) {srt[0]}" | |
f"\nIf this looks correct press Enter." | |
) | |
input() | |
for mp4_f, srt_f in zip(mp4, srt): | |
target_name = mp4_f.with_suffix(srt_f.suffix) | |
if srt_f == target_name: | |
continue | |
srt_f.rename(target_name) | |
print_app("Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment