Skip to content

Instantly share code, notes, and snippets.

@ahmetanbar
Created February 15, 2020 21:59
Show Gist options
  • Save ahmetanbar/bcdb3db2f2d18b9e8b3d7b848d4bb641 to your computer and use it in GitHub Desktop.
Save ahmetanbar/bcdb3db2f2d18b9e8b3d7b848d4bb641 to your computer and use it in GitHub Desktop.
Clear "-en" string from name of subtitle file to provide autodetection subtitle file by video player for udemy course
from os import listdir, rename
from os.path import isfile, join, isdir
class Subtitle:
def __init__(self,path,lang):
self.path = path
self.lang = lang
def find_files_edit_name(self, onlyfiles, path):
for file in onlyfiles:
if "-" + lang + ".srt" == file[-7:]:
print(file)
rename(path + "/" + file, path + "/" + file[:-7] + ".srt")
def find_directories(self):
onlydirs = [f for f in listdir(self.path) if isdir(join(path, f))]
for dir in onlydirs:
path_and_folder = self.path + "/" + dir
onlyfiles = [f for f in listdir(path_and_folder) if isfile(join(path_and_folder, f))]
self.find_files_edit_name(onlyfiles, path_and_folder)
def edit_names(self):
self.find_directories()
path = "path/unitycoursename"
lang = "language short code" # en, de, tr
course = Subtitle(path,lang)
course.edit_names()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment