smol_scriptz/rename.py

24 lines
616 B
Python
Raw Normal View History

from os import makedirs, rename, walk
from os.path import exists, join
matched = open("matched.txt", "r")
videos = []
vid_path = 'vids/'
done_path = 'done/'
if not exists(done_path):
makedirs(done_path)
for (dirpath, dirnames, filenames) in walk(vid_path):
videos.extend(filenames)
for line in matched:
idx = [int(s) for s in line.split("-") if s.isdigit()]
for video in videos:
if str(idx[0]) in video:
try:
rename(join(vid_path + video), join(done_path + line.strip('\n') + ".mp4"))
except ValueError:
print("err")
print("done!")