Browse Source

Added support for regex-based TV show name overrides.

master
treyzania 6 years ago
parent
commit
7e7ba12494
1 changed files with 32 additions and 11 deletions
  1. 32
    11
      booty.py

+ 32
- 11
booty.py View File

@@ -23,18 +23,18 @@ meta_exts = [
'.bmp'
]

def filebot_rename(src, dest, action, name=None, format=None):
def filebot_rename(src, destdir, action, name=None, format=None):
if not os.path.isdir(dest):
os.makedirs(dest)
args = ['filebot',
'-rename', src,
'-non-strict',
'--output', dest,
'--output', destdir,
'--action', action,
'--conflict', 'index']
if name is not None:
args.append('--filter')
args.append('name == \"' + name + '\"')
args.append('n == \"' + name + '\"')
if format is not None:
args.append('--format')
args.append(format)
@@ -54,6 +54,28 @@ cfg = None
with open(cfgpath) as data:
cfg = json.load(data)

# Load custom title names for TV shows.
title_overrides = []
for t in cfg['overrides']:
title_overrides.append({
'name': t['name'],
'pat': re.compile(t['pattern'])
})

raw_tv_regex = re.compile('.*\\.S[0-9][0-9](E[0-9][0-9])?\\..*')
def gen_title_action(fpath, action):
mname = None
bn = os.path.basename(fpath)

# Check to see if it's a TV show and if we can provide a specific title for it.
if raw_tv_regex.match(bn) is not None:
for to in title_overrides:
if to['pat'].match(bn) is not None:
mname = to['name']
print('found title ' + to['name'] + ' for ' + fpath)

return { 'src': fpath, 'action': action, 'medianame': mname }

# Now go over all of the input files and figure out what to do with them.
sources = []
rarregex = re.compile('\\.r[0-9][0-9]')
@@ -63,30 +85,29 @@ for f in os.listdir(os.getcwd()):

name, ext = os.path.splitext(f)
if ext in video_exts:
sources.append({ 'src': f, 'action': 'hardlink' })
sources.append(gen_title_action(f, 'hardlink'))
elif ext == '.rar':

# RARs are a little more complicated to handle.
exd = os.path.expanduser(os.path.join(cfg['extractdir'], os.path.basename(f)))
contents = unrar(f, dest=exd)
for ff in os.listdir(contents):
_, ext2 = os.path.splitext(ff)
if ext2 in video_exts:
sources.append({ 'src': os.path.join(contents, ff), 'action': 'move' })
sources.append(gen_title_action(os.path.join(contents, ff), 'move'))
else:
pass

elif ext in meta_exts or rarregex.match(ext) is not None:
pass
else:
print('warning: ignoring file because of extension: ' + f)

#raw_tv_episode_regex = re.compile('\\.S[0-9][0-9]E[0-9][0-9]\\.')
#raw_tv_season_regex = re.compile('\\.S[0-9]\\.')
#tv_name_regex = re.compile('.* -')
#movie_regex = re.compile('.* \\([0-9][0-9][0-9][0-9]\\)')

# Create the output directory if it doesn't exist yet.
outdir = cfg['outdir']
if not os.path.isdir(outdir):
os.makedirs(outdir, mode=0o755)
print('created destination directory ' + outdir)

for e in sources:
filebot_rename(e['src'], outdir, e['action'], format='{plex}')
filebot_rename(e['src'], outdir, e['action'], name=e['medianame'], format='{plex}')

Loading…
Cancel
Save