def getTitles(match, name): ''' The title will be the part before the match Clean it up and title() it ''.title() isn't very good under python so this contains a lot of little hacks to make it better and for more control ''' if match: name = name[:match.start()] # Replace .US. with (US) if cfg.tv_sort_countries() == 1: for rep in COUNTRY_REP: # (us) > (US) name = replace_word(name, rep.lower(), rep) # (Us) > (US) name = replace_word(name, titler(rep), rep) # .US. > (US) dotted_country = '.%s.' % (rep.strip('()')) name = replace_word(name, dotted_country, rep) # Remove .US. and (US) elif cfg.tv_sort_countries() == 2: for rep in COUNTRY_REP: # Remove (US) name = replace_word(name, rep, '') dotted_country = '.%s.' % (rep.strip('()')) # Remove .US. name = replace_word(name, dotted_country, '.') title = name.replace('.', ' ').replace('_', ' ') title = title.strip().strip('(').strip('_').strip('-').strip().strip('_') title = titler(title) # title the show name so it is in a consistant letter case #title applied uppercase to 's Python bug? title = title.replace("'S", "'s") # Replace titled country names, (Us) with (US) and so on if cfg.tv_sort_countries() == 1: for rep in COUNTRY_REP: title = title.replace(titler(rep), rep) # Remove country names, ie (Us) elif cfg.tv_sort_countries() == 2: for rep in COUNTRY_REP: title = title.replace(titler(rep), '').strip() # Make sure some words such as 'and' or 'of' stay lowercased. for x in LOWERCASE: xtitled = titler(x) title = replace_word(title, xtitled, x) # Make sure some words such as 'III' or 'IV' stay uppercased. for x in UPPERCASE: xtitled = titler(x) title = replace_word(title, xtitled, x) # The title with spaces replaced by dots dots = title.replace(" - ", "-").replace(' ','.').replace('_','.') dots = dots.replace('(', '.').replace(')','.').replace('..','.').rstrip('.') # The title with spaces replaced by underscores underscores = title.replace(' ','_').replace('.','_').replace('__','_').rstrip('_') return title, dots, underscores
def get_titles(nzo, match, name, titleing=False): """ The title will be the part before the match Clean it up and title() it ''.title() isn't very good under python so this contains a lot of little hacks to make it better and for more control """ if nzo: title = nzo.nzo_info.get('propername') else: title = '' if not title: if match: name = name[:match.start()] # Replace .US. with (US) if cfg.tv_sort_countries() == 1: for rep in COUNTRY_REP: # (us) > (US) name = replace_word(name, rep.lower(), rep) # (Us) > (US) name = replace_word(name, rep.title(), rep) # .US. > (US) dotted_country = '.%s.' % (rep.strip('()')) name = replace_word(name, dotted_country, rep) # Remove .US. and (US) elif cfg.tv_sort_countries() == 2: for rep in COUNTRY_REP: # Remove (US) name = replace_word(name, rep, '') dotted_country = '.%s.' % (rep.strip('()')) # Remove .US. name = replace_word(name, dotted_country, '.') title = name.replace('.', ' ').replace('_', ' ') title = title.strip().strip('(').strip('_').strip('-').strip().strip( '_') if titleing: title = title.title( ) # title the show name so it is in a consistent letter case # title applied uppercase to 's Python bug? title = title.replace("'S", "'s") # Replace titled country names, (Us) with (US) and so on if cfg.tv_sort_countries() == 1: for rep in COUNTRY_REP: title = title.replace(rep.title(), rep) # Remove country names, ie (Us) elif cfg.tv_sort_countries() == 2: for rep in COUNTRY_REP: title = title.replace(rep.title(), '').strip() # Make sure some words such as 'and' or 'of' stay lowercased. for x in LOWERCASE: xtitled = x.title() title = replace_word(title, xtitled, x) # Make sure some words such as 'III' or 'IV' stay uppercased. for x in UPPERCASE: xtitled = x.title() title = replace_word(title, xtitled, x) # Make sure the first letter of the title is always uppercase if title: title = title[0].title() + title[1:] # The title with spaces replaced by dots dots = title.replace(" - ", "-").replace(' ', '.').replace('_', '.') dots = dots.replace('(', '.').replace(')', '.').replace('..', '.').rstrip('.') # The title with spaces replaced by underscores underscores = title.replace(' ', '_').replace('.', '_').replace('__', '_').rstrip('_') return title, dots, underscores