Skip to content

Instantly share code, notes, and snippets.

@ZenulAbidin
Last active April 12, 2020 23:48
Show Gist options
  • Save ZenulAbidin/3734af6060f54dd1643e7472ee53d4f7 to your computer and use it in GitHub Desktop.
Save ZenulAbidin/3734af6060f54dd1643e7472ee53d4f7 to your computer and use it in GitHub Desktop.
Converts JWplayer filenames to a episode order + title filename, removing funny numbers. Tested on videos ripped from itpro.tv using jdownloader.
import json
import os
import glob
import ntpath
mp4path_dir = "/directory/path" # No trailing slash please
actual_json = json.load(open('path to json file'))
os.chdir(mp4path_dir)
for fileID in glob.iglob(mp4path_dir + '/*.mp4'):
fileIDfilename = ntpath.basename(fileID)
fileIDnoExt = ntpath.splitext(fileIDfilename)[0]
results = [ep for ep in actual_json['episodes'] if ep["jwPlayer"] == fileIDnoExt.replace("-15605065", "")]
if len(results) == 0:
continue
else:
episode = results[0]
try:
os.rename(fileIDnoExt + ".mp4", str(episode["order"]) + " - " + episode["title"] + ".mp4")
except FileNotFoundError:
os.rename(fileIDnoExt + "-15605065.mp4", str(episode["order"]) + " - " + episode["title"] + ".mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment