Last active
November 14, 2021 21:30
-
-
Save kaecy/182f5568b4d47b5b015ea452f6be44bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import sys | |
import shutil | |
# Sub types. | |
SubTypes = ['.srt'] | |
# Video types. | |
VideoTypes = ['.mp4', '.avi', '.mkv'] | |
def endsWith(str, list): | |
for string in list: | |
if str.endswith(string): | |
return True | |
return False | |
def getFiles(path, types): | |
return list(filter(lambda file: endsWith(file, types), os.listdir(path))) | |
if len(sys.argv) == 2: | |
basePath = sys.argv[1] | |
# Get the subtitles | |
subs = getFiles(sys.argv[1] + "/Subs", SubTypes) | |
baseSubsFolder = basePath + "/Subs/" | |
# Get the video filename | |
videoFiles = getFiles(sys.argv[1], VideoTypes) | |
if videoFiles: | |
print("%d video files found." % len(videoFiles)) | |
videoBaseName = videoFiles[0][:videoFiles[0].rfind(".")] | |
for sub in subs: | |
id, lang = sub[:sub.rfind(".")].split("_") | |
lang = lang[:2].lower() | |
subFile = baseSubsFolder + sub | |
newSubName = basePath + "/%s.%s.srt" %(videoBaseName, lang) | |
if os.path.exists(newSubName): | |
newFileSize = os.stat(subFile).st_size | |
oldFileSize = os.stat(newSubName).st_size | |
if newFileSize > oldFileSize: | |
print("Copying new bigger file.") | |
else: | |
print("Skipping %s." % subFile) | |
continue | |
shutil.copyfile(subFile, newSubName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment