Esempio n. 1
0
def get_media_info(file_path: str):
    logger.debug(f"Raw filepath {file_path!r}")
    file_path = cleanup_encoding(file_path)
    parsed = urlsplit(file_path)
    file_is_url = False
    guessit_path = file_path
    if is_url(parsed):
        file_is_url = True
        # remove the query and fragment from the url, keeping only important parts
        scheme, netloc, path, _, _ = parsed
        path = unquote(path)  # quoting should only be applied to the path
        file_path = urlunsplit((scheme, netloc, path, "", ""))
        logger.debug(f"Converted to url {file_path!r}")
        # only use the actual path for guessit, skipping other parts
        guessit_path = path
        logger.debug(f"Guessit url {guessit_path!r}")

    if not whitelist_file(file_path, file_is_url):
        logger.info("File path not in whitelist.")
        return None
    if exclude_file(file_path):
        logger.info("Ignoring file.")
        return None
    guess = use_regex and custom_regex(file_path) or use_guessit(guessit_path)
    logger.debug(f"Guess: {guess}")
    return cleanup_guess(guess)
Esempio n. 2
0
    def handle(self):
        from trakt_scrobbler.file_info import whitelist_file

        path = self.argument("path")
        whitelist_path = whitelist_file(path, is_url(path), return_path=True)
        if whitelist_path is True:
            self.info("Whitelist is empty, so given path is trivially whitelisted.")
        elif whitelist_path:
            self.info(f"The path is whitelisted through {fmt(whitelist_path)}")
        else:
            self.line_error("The path is not in whitelist!")
Esempio n. 3
0
    def update_status(self):
        if not self.WATCHED_PROPS.issubset(self.vars):
            logger.warning("Incomplete media status info")
            return
        fpath = self.vars['path']
        if not is_url(fpath) and not Path(fpath).is_absolute():
            fpath = str(Path(self.vars['working-directory']) / fpath)

        # Update last known position if player is stopped
        pos = self.vars['time-pos']
        if self.vars['state'] == 0 and self.status['state'] == 2:
            pos += round(time.time() - self.status['time'], 3)
        pos = min(pos, self.vars['duration'])

        self.status = {
            'state': self.vars['state'],
            'filepath': fpath,
            'position': pos,
            'duration': self.vars['duration'],
            'time': time.time()
        }
        self.handle_status_update()
Esempio n. 4
0
 def _parse_single(self, path: str):
     if is_url(path):
         return self._parse_url(path)
     else:
         return self._parse_local(path)