Created
February 15, 2020 21:59
-
-
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
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 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