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

'.bmp' '.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): if not os.path.isdir(dest):
os.makedirs(dest) os.makedirs(dest)
args = ['filebot', args = ['filebot',
'-rename', src, '-rename', src,
'-non-strict', '-non-strict',
'--output', dest,
'--output', destdir,
'--action', action, '--action', action,
'--conflict', 'index'] '--conflict', 'index']
if name is not None: if name is not None:
args.append('--filter') args.append('--filter')
args.append('name == \"' + name + '\"')
args.append('n == \"' + name + '\"')
if format is not None: if format is not None:
args.append('--format') args.append('--format')
args.append(format) args.append(format)
with open(cfgpath) as data: with open(cfgpath) as data:
cfg = json.load(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. # Now go over all of the input files and figure out what to do with them.
sources = [] sources = []
rarregex = re.compile('\\.r[0-9][0-9]') rarregex = re.compile('\\.r[0-9][0-9]')


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

# RARs are a little more complicated to handle.
exd = os.path.expanduser(os.path.join(cfg['extractdir'], os.path.basename(f))) exd = os.path.expanduser(os.path.join(cfg['extractdir'], os.path.basename(f)))
contents = unrar(f, dest=exd) contents = unrar(f, dest=exd)
for ff in os.listdir(contents): for ff in os.listdir(contents):
_, ext2 = os.path.splitext(ff) _, ext2 = os.path.splitext(ff)
if ext2 in video_exts: 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: else:
pass pass

elif ext in meta_exts or rarregex.match(ext) is not None: elif ext in meta_exts or rarregex.match(ext) is not None:
pass pass
else: else:
print('warning: ignoring file because of extension: ' + f) 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'] outdir = cfg['outdir']
if not os.path.isdir(outdir): if not os.path.isdir(outdir):
os.makedirs(outdir, mode=0o755) os.makedirs(outdir, mode=0o755)
print('created destination directory ' + outdir) print('created destination directory ' + outdir)


for e in sources: 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