def test_reorder_title(self): self.assertEqual(reorder_title("Simpsons, The"), "The Simpsons") self.assertEqual(reorder_title("Simpsons,The"), "The Simpsons") self.assertEqual( reorder_title("Simpsons,Les", articles=('the', 'le', 'la', 'les')), "Les Simpsons") self.assertEqual( reorder_title("Simpsons, Les", articles=('the', 'le', 'la', 'les')), "Les Simpsons")
def test_reorder_title(self): assert reorder_title("Simpsons, The") == "The Simpsons" assert reorder_title("Simpsons,The") == "The Simpsons" assert reorder_title("Simpsons,Les", articles=('the', 'le', 'la', 'les')) == "Les Simpsons" assert reorder_title("Simpsons, Les", articles=('the', 'le', 'la', 'les')) == "Les Simpsons"
def process(mtree): # 1- try to promote language to subtitle language where it makes sense for node in mtree.nodes(): if "language" not in node.guess: continue def promote_subtitle(): # pylint: disable=W0631 node.guess.set("subtitleLanguage", node.guess["language"], confidence=node.guess.confidence("language")) del node.guess["language"] # - if we matched a language in a file with a sub extension and that # the group is the last group of the filename, it is probably the # language of the subtitle # (eg: 'xxx.english.srt') if mtree.node_at((-1,)).value.lower() in subtitle_exts and node == mtree.leaves()[-2]: promote_subtitle() # - if a language is in an explicit group just preceded by "st", # it is a subtitle language (eg: '...st[fr-eng]...') try: idx = node.node_idx previous = mtree.node_at((idx[0], idx[1] - 1)).leaves()[-1] if previous.value.lower()[-2:] == "st": promote_subtitle() except IndexError: pass # 2- ", the" at the end of a series title should be prepended to it for node in mtree.nodes(): if "series" not in node.guess: continue node.guess["series"] = reorder_title(node.guess["series"])
def process(self, mtree): """perform some post-processing steps """ # 1- try to promote language to subtitle language where it makes sense for node in mtree.nodes(): if "language" not in node.guess: continue # - if we matched a language in a file with a sub extension and that # the group is the last group of the filename, it is probably the # language of the subtitle # (eg: 'xxx.english.srt') if mtree.node_at((-1,)).value.lower() in subtitle_exts and node == mtree.leaves()[-2]: self.promote_subtitle(node) # - if we find in the same explicit group # a subtitle prefix before the language, # or a subtitle suffix after the language, # then upgrade the language explicit_group = mtree.node_at(node.node_idx[:2]) group_str = explicit_group.value.lower() for sub_prefix in subtitle_prefixes: if sub_prefix in find_words(group_str) and 0 <= group_str.find(sub_prefix) < ( node.span[0] - explicit_group.span[0] ): self.promote_subtitle(node) for sub_suffix in subtitle_suffixes: if sub_suffix in find_words(group_str) and (node.span[0] - explicit_group.span[0]) < group_str.find( sub_suffix ): self.promote_subtitle(node) # - if a language is in an explicit group just preceded by "st", # it is a subtitle language (eg: '...st[fr-eng]...') try: idx = node.node_idx previous = mtree.node_at((idx[0], idx[1] - 1)).leaves()[-1] if previous.value.lower()[-2:] == "st": self.promote_subtitle(node) except IndexError: pass # 2- ", the" at the end of a series title should be prepended to it for node in mtree.nodes(): if "series" not in node.guess: continue node.guess["series"] = reorder_title(node.guess["series"])
def process(mtree): # 1- try to promote language to subtitle language where it makes sense for node in mtree.nodes(): if 'language' not in node.guess: continue def promote_subtitle(): # pylint: disable=W0631 node.guess.set('subtitleLanguage', node.guess['language'], confidence=node.guess.confidence('language')) del node.guess['language'] # - if we matched a language in a file with a sub extension and that # the group is the last group of the filename, it is probably the # language of the subtitle # (eg: 'xxx.english.srt') if (mtree.node_at((-1, )).value.lower() in subtitle_exts and node == mtree.leaves()[-2]): promote_subtitle() # - if we find the word 'sub' before the language, and in the same explicit # group, then upgrade the language explicit_group = mtree.node_at(node.node_idx[:2]) group_str = explicit_group.value.lower() if ('sub' in find_words(group_str) and 0 <= group_str.find('sub') < (node.span[0] - explicit_group.span[0])): promote_subtitle() # - if a language is in an explicit group just preceded by "st", # it is a subtitle language (eg: '...st[fr-eng]...') try: idx = node.node_idx previous = mtree.node_at((idx[0], idx[1] - 1)).leaves()[-1] if previous.value.lower()[-2:] == 'st': promote_subtitle() except IndexError: pass # 2- ", the" at the end of a series title should be prepended to it for node in mtree.nodes(): if 'series' not in node.guess: continue node.guess['series'] = reorder_title(node.guess['series'])
def process(mtree): # 1- try to promote language to subtitle language where it makes sense for node in mtree.nodes(): if 'language' not in node.guess: continue def promote_subtitle(): # pylint: disable=W0631 node.guess.set('subtitleLanguage', node.guess['language'], confidence=node.guess.confidence('language')) del node.guess['language'] # - if we matched a language in a file with a sub extension and that # the group is the last group of the filename, it is probably the # language of the subtitle # (eg: 'xxx.english.srt') if (mtree.node_at((-1,)).value.lower() in subtitle_exts and node == mtree.leaves()[-2]): promote_subtitle() # - if we find the word 'sub' before the language, and in the same explicit # group, then upgrade the language explicit_group = mtree.node_at(node.node_idx[:2]) group_str = explicit_group.value.lower() if ('sub' in find_words(group_str) and 0 <= group_str.find('sub') < (node.span[0] - explicit_group.span[0])): promote_subtitle() # - if a language is in an explicit group just preceded by "st", # it is a subtitle language (eg: '...st[fr-eng]...') try: idx = node.node_idx previous = mtree.node_at((idx[0], idx[1] - 1)).leaves()[-1] if previous.value.lower()[-2:] == 'st': promote_subtitle() except IndexError: pass # 2- ", the" at the end of a series title should be prepended to it for node in mtree.nodes(): if 'series' not in node.guess: continue node.guess['series'] = reorder_title(node.guess['series'])
def tvu_view(request): # do not block if we don't have the full list of shows yet, show what we have shows = dict(tvu.get_show_mapping(only_cached=True)) try: series = request.params['series'] sid = shows[series] feeds = tvu.get_seasons_for_showid(sid, title=reorder_title(series)) except KeyError: feeds = [] subscribedFeeds = [ f['url'] for f in SMEWTD_INSTANCE.feedWatcher.feedList ] return { 'title': 'TVU.ORG.RU', 'shows': shows.keys(), 'feeds': feeds, 'series': request.params.get('series', None), 'path': request.current_route_path(), 'subscribedFeeds': subscribedFeeds }
def post_process(self, mtree, options=None): for node in mtree.nodes(): if 'series' not in node.guess: continue node.guess['series'] = reorder_title(node.guess['series'])
def test_reorder_title(self): self.assertEqual(reorder_title("Simpsons, The"), "The Simpsons") self.assertEqual(reorder_title("Simpsons,The"), "The Simpsons") self.assertEqual(reorder_title("Simpsons,Les", articles=('the', 'le', 'la', 'les')), "Les Simpsons") self.assertEqual(reorder_title("Simpsons, Les", articles=('the', 'le', 'la', 'les')), "Les Simpsons")