2020-05-08 13:32:23 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Import the required libraries
|
2020-05-08 13:32:23 +00:00
|
|
|
from os import listdir, system
|
|
|
|
|
from os.path import isfile, join
|
|
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Set the in and out folders
|
2021-04-14 19:58:22 +00:00
|
|
|
InFolder="FilesIn"
|
|
|
|
|
OutFolder="FilesOut"
|
2020-06-24 01:05:43 +00:00
|
|
|
|
2021-04-14 19:58:22 +00:00
|
|
|
# Chose actions for subs, video, audio, and images
|
2020-06-24 01:05:43 +00:00
|
|
|
SubtitleAction = "copy"
|
|
|
|
|
AudioAction = "libvorbis"
|
2021-04-14 19:58:22 +00:00
|
|
|
VideoAction = "h264_nvenc"
|
|
|
|
|
ImageAction = "jpeg"
|
2020-05-08 13:32:23 +00:00
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Make a list with all the files in the appropriate folder
|
|
|
|
|
onlyfiles = [f for f in listdir(InFolder) if isfile(join(InFolder, f))]
|
2020-05-08 13:32:23 +00:00
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Check file type and do the appropriate action
|
2020-05-08 13:32:23 +00:00
|
|
|
for f in onlyfiles:
|
2020-06-24 01:05:43 +00:00
|
|
|
InFilePath = "./" + InFolder + "/" + f
|
2021-04-14 19:58:22 +00:00
|
|
|
if f[-4:] == ".mkv" or f[-4:] == ".mp4" or f[-4:] == ".m4a":
|
|
|
|
|
print(f + " is a " + f[-3:] + " file, transcoding...")
|
|
|
|
|
OutFilePath = "./" + OutFolder + "/" + f[:-4] + ".mkv"
|
2020-06-24 01:05:43 +00:00
|
|
|
# Transcode
|
2021-04-14 19:58:22 +00:00
|
|
|
system("ffmpeg -loglevel 0 -i '" + InFilePath + "' -c:s " + SubtitleAction + " -c:a " + AudioAction + " -c:v " + VideoAction + " '" + OutFilePath + "' && rm '" + InFilePath + "'")
|
|
|
|
|
|
|
|
|
|
if f[-5:] == ".webp":
|
|
|
|
|
print(f + " is a " + f[-4:] + " file, converting...")
|
|
|
|
|
OutFilePath = "./" + OutFolder + "/" + f[:-4] + ImageAction
|
|
|
|
|
# Convert
|
|
|
|
|
system("convert '" + InFilePath + "' '" + OutFilePath + "' && rm '" + InFilePath + "'")
|
2020-05-08 14:10:07 +00:00
|
|
|
|
|
|
|
|
# Print status message
|
|
|
|
|
print("That was all the files.")
|
2020-05-08 13:32:23 +00:00
|
|
|
|
2020-05-08 14:10:07 +00:00
|
|
|
# Thank the user
|
|
|
|
|
print("Thank you for using my tool!")
|