How to use the guessit.guess_file_info function in guessit

To help you get started, we’ve selected a few guessit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Diaoul / subliminal / subliminal / services / podnapisiweb.py View on Github external
params['sY'] = year
        r = self.session.get(self.server_url + '/ppodnapisi/search', params=params)
        if r.status_code != 200:
            logger.error(u'Request %s returned status code %d' % (r.url, r.status_code))
            return []
        subtitles = []
        soup = BeautifulSoup(r.content, self.required_features)
        for sub in soup('subtitle'):
            if 'n' in sub.flags:
                logger.debug(u'Skipping hearing impaired')
                continue
            language = self.get_language(int(sub.languageId.text))
            confidence = float(sub.rating.text) / 5.0
            sub_keywords = set()
            for release in sub.release.text.split():
                sub_keywords |= get_keywords(guessit.guess_file_info(release + '.srt', 'autodetect'))
            sub_path = get_subtitle_path(filepath, language, self.multi)
            subtitle = ResultSubtitle(sub_path, language, self.__class__.__name__.lower(),
                                      sub.url.text, confidence=confidence, keywords=sub_keywords)
            subtitles.append(subtitle)
        return subtitles
github nzbget / VideoSort / lib / guessit / __main__.py View on Github external
def guess_file(filename, info='filename', options=None, **kwargs):
    options = options or {}
    filename = u(filename)

    if not options.get('yaml') and not options.get('show_property'):
        print('For:', filename)
    guess = guess_file_info(filename, info, options, **kwargs)

    if not options.get('unidentified'):
        try:
            del guess['unidentified']
        except KeyError:
            pass

    if options.get('show_property'):
        print (guess.get(options.get('show_property'), ''))
        return

    if options.get('yaml'):
        import yaml
        for k, v in guess.items():
            if isinstance(v, list) and len(v) == 1:
                guess[k] = v[0]
github CouchPotato / CouchPotatoServer / libs / subliminal / core.py View on Github external
def matching_confidence(video, subtitle):
    """Compute the probability (confidence) that the subtitle matches the video

    :param video: video to match
    :type video: :class:`~subliminal.videos.Video`
    :param subtitle: subtitle to match
    :type subtitle: :class:`~subliminal.subtitles.Subtitle`
    :return: the matching probability
    :rtype: float

    """
    guess = guessit.guess_file_info(subtitle.release, 'autodetect')
    video_keywords = get_keywords(video.guess)
    subtitle_keywords = get_keywords(guess) | subtitle.keywords
    logger.debug(u'Video keywords %r - Subtitle keywords %r' % (video_keywords, subtitle_keywords))
    replacement = {'keywords': len(video_keywords & subtitle_keywords)}
    if isinstance(video, Episode):
        replacement.update({'series': 0, 'season': 0, 'episode': 0})
        matching_format = '{series:b}{season:b}{episode:b}{keywords:03b}'
        best = matching_format.format(series=1, season=1, episode=1, keywords=len(video_keywords))
        if guess['type'] in ['episode', 'episodesubtitle']:
            if 'series' in guess and guess['series'].lower() == video.series.lower():
                replacement['series'] = 1
            if 'season' in guess and guess['season'] == video.season:
                replacement['season'] = 1
            if 'episodeNumber' in guess and guess['episodeNumber'] == video.episode:
                replacement['episode'] = 1
    elif isinstance(video, Movie):
github pymedusa / Medusa / lib / subliminal / videos.py View on Github external
def from_path(cls, path):
        """Create a :class:`Video` subclass guessing all informations from the given path

        :param string path: path
        :return: video object
        :rtype: :class:`Episode` or :class:`Movie` or :class:`UnknownVideo`

        """
        guess = guessit.guess_file_info(path, 'autodetect')
        result = None
        if guess['type'] == 'episode' and 'series' in guess and 'season' in guess and 'episodeNumber' in guess:
            title = None
            if 'title' in guess:
                title = guess['title']
            result = Episode(path, guess['series'], guess['season'], guess['episodeNumber'], title, guess)
        if guess['type'] == 'movie' and 'title' in guess:
            year = None
            if 'year' in guess:
                year = guess['year']
            result = Movie(path, guess['title'], year, guess)
        if not result:
            result = UnknownVideo(path, guess)
        if not isinstance(result, cls):
            raise ValueError('Video is not of requested type')
        return result
github albertz / RandomFtpGrabber / FileInfo.py View on Github external
def get_info(url):
    return guessit.guess_file_info(filename=url)
github omerbenamram / py-expander / src / pyexpander / categorize.py View on Github external
def get_path_video(filename):
    guess = guessit.guess_file_info(filename)

    if guess[u'type'] == u'episode':
        series = guess.get(u'series', u'').title()
        season = guess.get(u'season', u'')

        return config.TV_PATH.format(series=series, season=season)
    elif guess[u'type'] == u'movie':
        title = guess.get(u'title', u'').title()
        year = guess.get(u'year', u'')

        return config.MOVIE_PATH.format(title=title, year=year)
    else:
        return None
github wackou / smewt / smewt / views.py View on Github external
if not os.path.exists(incoming):
                msg = 'Incoming folder doesn\'t exist: %s' % incoming
                log.warning(msg)
                return msg

            # find the root folder for moving episodes
            for c in config.collections:
                if c.name == 'Series':
                    try:
                        series_folder = json.loads(c.folders)[0][0]
                    except IndexError:
                        return 'OK'

            result = []
            for f in utils.dirwalk(incoming):
                info = guessit.guess_file_info(f, 'autodetect')
                if info['type'].startswith('episode'):
                    path = utils.path(series_folder, info['series'],
                                      'Season %d' % info['season'], os.path.basename(f),
                                      createdir=True)

                    # FIXME: add as task in the task manager
                    log.info('Moving %s to %s...', os.path.basename(f), path)
                    shutil.copy(f, path)
                    os.remove(f)
                    result.append('Moved %s' % os.path.basename(f))

            return '\n'.join(result) or 'OK'



        elif action == 'regenerate_thumbnails':
github Diaoul / subliminal / subliminal / core.py View on Github external
def matching_confidence(video, subtitle):
    """Compute the probability (confidence) that the subtitle matches the video

    :param video: video to match
    :type video: :class:`~subliminal.videos.Video`
    :param subtitle: subtitle to match
    :type subtitle: :class:`~subliminal.subtitles.Subtitle`
    :return: the matching probability
    :rtype: float

    """
    guess = guessit.guess_file_info(subtitle.release, 'autodetect')
    video_keywords = get_keywords(video.guess)
    subtitle_keywords = get_keywords(guess) | subtitle.keywords
    logger.debug(u'Video keywords %r - Subtitle keywords %r' % (video_keywords, subtitle_keywords))
    replacement = {'keywords': len(video_keywords & subtitle_keywords)}
    if isinstance(video, Episode):
        replacement.update({'series': 0, 'season': 0, 'episode': 0})
        matching_format = '{series:b}{season:b}{episode:b}{keywords:03b}'
        best = matching_format.format(series=1, season=1, episode=1, keywords=len(video_keywords))
        if guess['type'] in ['episode', 'episodesubtitle']:
            if 'series' in guess and guess['series'].lower() == video.series.lower():
                replacement['series'] = 1
            if 'season' in guess and guess['season'] == video.season:
                replacement['season'] = 1
            if 'episodeNumber' in guess and guess['episodeNumber'] == video.episode:
                replacement['episode'] = 1
    elif isinstance(video, Movie):
github Diaoul / subliminal / subliminal / plugins / BierDopje.py View on Github external
page.close()

        # get the subs for the show id we have
        for language in languages:
            subs_url = '%sGetAllSubsFor/%s/%s/%s/%s' % (self.server_url, show_id, season, episode, language)
            self.logger.debug(u'Getting subtitles at %s' % subs_url)
            page = urllib2.urlopen(subs_url)
            dom = minidom.parse(page)
            page.close()
            for sub in dom.getElementsByTagName('result'):
                sub_release = sub.getElementsByTagName('filename')[0].firstChild.data
                if sub_release.endswith('.srt'):
                    sub_release = sub_release[:-4]
                sub_release = sub_release + '.avi'  # put a random extension for guessit not to fail guessing that file
                # guess information from subtitle
                sub_guess = guessit.guess_file_info(sub_release, 'episode')
                sub_release_group = set()
                if 'releaseGroup' in sub_guess:
                    sub_release_group.add(sub_guess['releaseGroup'].lower())
                else:
                    if 'title' in sub_guess:
                        sub_release_group.add(sub_guess['title'].lower())
                    if 'screenSize' in sub_guess:
                        sub_release_group.add(sub_guess['screenSize'].lower())
                sub_link = sub.getElementsByTagName('downloadlink')[0].firstChild.data
                result = Subtitle(filepath, self.getSubtitlePath(filepath, language), self.__class__.__name__, language, sub_link, sub_release, sub_release_group)
                sublinks.append(result)
        sublinks.sort(self._cmpReleaseGroup)
        return sublinks