def process(self, mtree, options=None): """guess the file type now (will be useful later) """ filetype, other = self.guess_filetype(mtree, options) mtree.guess.set('type', filetype, confidence=1.0) log_found_guess(mtree.guess) filetype_info = Guess(other, confidence=1.0) # guess the mimetype of the filename # TODO: handle other mimetypes not found on the default type_maps # mimetypes.types_map['.srt']='text/subtitle' mime, _ = mimetypes.guess_type(mtree.string, strict=False) if mime is not None: filetype_info.update({'mimetype': mime}, confidence=1.0) # Retrieve the last node of category path (extension node) node_ext = list(filter(lambda x: x.category == 'path', mtree.nodes()))[-1] found_guess(node_ext, filetype_info) if mtree.guess.get('type') in [None, 'unknown']: if options.get('name_only'): mtree.guess.set('type', 'movie', confidence=0.6) else: raise TransformerException(__name__, 'Unknown file type')
def process(self, mtree, options=None): if mtree.guess.get('type', '').startswith('episode') and (not mtree.info.get('episodeNumber') or mtree.info.get('season') == 0): for title_leaf in mtree.leaves_containing('title'): guesses = self.guess_special(title_leaf.value, title_leaf, options) for guess in guesses: found_guess(title_leaf, guess, update_guess=False) for unidentified_leaf in mtree.unidentified_leaves(): guesses = self.guess_special(unidentified_leaf.value, unidentified_leaf, options) for guess in guesses: found_guess(unidentified_leaf, guess, update_guess=False) return None
def process(self, mtree, options=None): if mtree.guess.get("type", "").startswith("episode") and ( not mtree.info.get("episodeNumber") or mtree.info.get("season") == 0 ): for leaf in itertools.chain(mtree.leaves_containing("title"), mtree.unidentified_leaves()): guesses = self.guess_details(leaf.value, leaf, options) for guess in guesses: found_guess(leaf, guess, update_guess=False) return None
def process(self, mtree, options=None): if (mtree.guess.get('type', '').startswith('episode') and (not mtree.info.get('episodeNumber') or mtree.info.get('season') == 0)): for leaf in itertools.chain(mtree.leaves_containing('title'), mtree.unidentified_leaves()): guesses = self.guess_details(leaf.value, leaf, options) for guess in guesses: found_guess(leaf, guess, update_guess=False) return None
def process(self, mtree, options=None): GuessFinder(self.guess_country, None, self.log, options).process_nodes(mtree.unidentified_leaves()) for node in mtree.leaves_containing('language'): c = node.clean_value.lower() if c in self.replace_language: node.guess.set('language', None) try: country = Country.fromguessit(c) if self.is_valid_country(country, options): guess = Guess(country=country, confidence=0.9, input=node.value, span=node.span) found_guess(node, guess, logger=log) except babelfish.Error: pass
def process(self, mtree, options=None): if mtree.guess.get('type', '').startswith('episode') and ( not mtree.info.get('episodeNumber') or mtree.info.get('season') == 0): for title_leaf in mtree.leaves_containing('title'): guesses = self.guess_special(title_leaf.value, title_leaf, options) for guess in guesses: found_guess(title_leaf, guess, update_guess=False) for unidentified_leaf in mtree.unidentified_leaves(): guesses = self.guess_special(unidentified_leaf.value, unidentified_leaf, options) for guess in guesses: found_guess(unidentified_leaf, guess, update_guess=False) return None
def process(self, mtree, options=None): """guess the file type now (will be useful later) """ filetype, other = self.guess_filetype(mtree, options) mtree.guess.set("type", filetype, confidence=1.0) log_found_guess(mtree.guess) filetype_info = Guess(other, confidence=1.0) # guess the mimetype of the filename # TODO: handle other mimetypes not found on the default type_maps # mimetypes.types_map['.srt']='text/subtitle' mime, _ = mimetypes.guess_type(mtree.string, strict=False) if mime is not None: filetype_info.update({"mimetype": mime}, confidence=1.0) node_ext = mtree.node_at((-1,)) found_guess(node_ext, filetype_info) if mtree.guess.get("type") in [None, "unknown"]: if options.get("name_only"): mtree.guess.set("type", "movie", confidence=0.6) else: raise TransformerException(__name__, "Unknown file type")