Skip to content

Instantly share code, notes, and snippets.

@arionl
Created April 19, 2020 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arionl/4f0e771342e9196df8677bed422372d8 to your computer and use it in GitHub Desktop.
Save arionl/4f0e771342e9196df8677bed422372d8 to your computer and use it in GitHub Desktop.
Rename Disney Shorts
import tvdbsimple as tvdb
import os
from os import listdir
from os.path import isfile, join
from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
mypath = "Disney Animated Shorts"
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
start_letter = 's'
files_to_rename = list(filter(lambda x: not x.startswith(start_letter), files))
for file in files_to_rename:
newname = file[::-1].rstrip().split('.')[1].split('-')[0].rstrip().lower()[::-1]
print(newname)
tvdb.KEYS.API_KEY = ''
mickey = tvdb.Series(78988)
episodes = mickey.Episodes.summary()
seasons = episodes['airedSeasons']
seasons.sort()
for season in seasons:
mickey.Episodes.update_filters(airedSeason=season)
for episode in mickey.Episodes.all():
for file in files_to_rename:
normalized_file = file[::-1].rstrip().split('.')[1].split('-')[0].rstrip().lower()[::-1]
normalized_episode = episode["episodeName"].lower()
#print('s'+f'{episode["airedSeason"]:04}'+'e'+f'{episode["airedEpisodeNumber"]:02}'+' - ' + f'{episode["episodeName"]}')
similar_output = similar(normalized_file,normalized_episode)
if similar_output > 0.75:
print(f'{similar_output:0.2f}'+' "'+f'{normalized_file}'+'" <--> "'+f'{normalized_episode}'+'"')
newfile = 's' + f'{episode["airedSeason"]:04}' + 'e' + f'{episode["airedEpisodeNumber"]:02}' + ' - ' + file[7:]
print(f'{similar_output:0.2f}'+' "' + file + '" --> "' + newfile + '"')
os.rename(mypath + '/' + file, mypath + '/' + newfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment