Skip to content

Instantly share code, notes, and snippets.

@looneym
Created November 29, 2016 00:05
Show Gist options
  • Save looneym/e03b9e37c9a83a6fe23c19937d5744ac to your computer and use it in GitHub Desktop.
Save looneym/e03b9e37c9a83a6fe23c19937d5744ac to your computer and use it in GitHub Desktop.
Shitty script to rename files for plex
from imdb import IMDb
from os import listdir
import os
from os.path import isfile, join
ia = IMDb()
def get_name(f):
result = ia.search_movie(f, results=1)
try:
title = result[0].get('title')
year = result[0].get('year')
return str("%s (%d)" % (title, year))
except:
# TODO: actually handle errors...
title = "FUCCCCCCK"
year = 2016
return str("%s (%d)" % (title, year))
def rename_file(f, full_name):
print "reaming %s ||||| to ||||| %s" % (f, full_name)
mypath = "/Volumes/Micheal's Backup Drive/AAA~~MICHEAL'S LAPTOP/Movies"
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
for f in files:
extension = os.path.splitext(f)[1]
name = get_name(f)
full_name = name + extension
rename_file(f, full_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment