Beispiel #1
0
    def _init_from_match(self, match):   
        namedgroups = match.groupdict()

        self.date_based = False
        try:
            self.seasonnumber = int(namedgroups['seasonnumber'])
        except (KeyError, TypeError):
            self.seasonnumber = None

        seriesname = namedgroups.get('seriesname', None)
        if seriesname is None:
            raise ConfigValueError(
                "Regex must contain seriesname. Pattern was:\n" + match.pattern)
        seriesname = cleanRegexedName(seriesname)
        self.seriesname = replaceInputName(seriesname)

        if namedgroups.get('year', None) and not 'month' in namedgroups:
            self.year = int(namedgroups['year'])

        if 'episodenumber1' in namedgroups:
            # Multiple episodes, have episodenumber1 or 2 etc
            epnos = []
            for cur in namedgroups:
                epnomatch = re.match('episodenumber(\d+)', cur)
                if epnomatch:
                    epnos.append(int(match.group(cur)))
            epnos.sort()
            episodenumbers = epnos

        elif 'episodenumberstart' in namedgroups:
            # Multiple episodes, regex specifies start and end number
            start = int(namedgroups['episodenumberstart'])
            end = int(namedgroups['episodenumberend'])
            if start > end:
                # Swap start and end
                start, end = end, start
            episodenumbers = range(start, end + 1)

        elif 'episodenumber' in namedgroups:
            episodenumbers = [int(namedgroups['episodenumber']), ]

        elif 'year' in namedgroups and 'month' in namedgroups and 'day' in namedgroups:
            year = handleYear(namedgroups['year'])

            episodenumbers = [datetime.date(year,
                                            int(namedgroups['month']),
                                            int(namedgroups['day']))]
            self.date_based = True
        else:
            raise ConfigValueError(
                "Regex does not contain episode number group, should"
                "contain episodenumber, episodenumber1-9, or"
                "episodenumberstart and episodenumberend\n\nPattern"
                "was:\n" + match.pattern)
        
        self.set_episodenumbers(episodenumbers)
Beispiel #2
0
    def _init_from_match(self, match):
        groups = match.groupdict()
        groups.pop("rdsep", None)
        groups.pop("rsep", None)

        if 'movietitle' not in groups:
            raise InvalidMatch(
                            "Regex must contain movietitle. Pattern was:\n"
                            + match.re.pattern)
        elif Config['force_name']:
            movietitle = Config['force_name']
        elif groups['movietitle'] is None:
            raise ConfigValueError("Regex match error: movietitle=None in %s"
                                   % match.re.pattern)
        else:
            movietitle = groups.get('movietitle', None)

        movietitle = cleanRegexedName(movietitle)
        movietitle = replaceInputName(movietitle)
        groups['movietitle'] = movietitle

        extra = groups.pop("extra", None)

        if extra:
            # extract part: ie Cd 1, Disc2, dvd one, etcc
            extramatch = re.match(
                "(?i).*"
                "(part|disc|cd|dvd)"
                r"[ \.+\-_]?"
                r"([0-9]+|(?:" + TextToNumber.pattern + r"[ \.+\-_]?)+)"
                ".*",
                extra)
            if extramatch:
                label, number = extramatch.groups()
                try:
                    number = TextToNumber(number.strip().split())
                except KeyError:
                    pass
                groups['part'] = " ".join(("Part", number)).title()

            if groups.get("resolution", None) is None:
                # we try to put resolution guess in
                ripsrc = re.match("(?i).*"
                                  r"(b[rd]rip|bluray|dvd[ \.+\-_]?(rip)?)"
                                  ".*",
                                  extra)
                vcodec = re.match("(?i).*"
                                  "([hx]264|xvid|divx|theora|webm)"
                                  ".*",
                                  extra)
                if ripsrc:
                    ripsrc = ripsrc.groups()[0].lower()
                if vcodec:
                    vcodec = vcodec.groups()[0].lower()

                hd = vcodec in ("h264", "x264")

                if ripsrc == "bluray" and hd:
                    groups['resolution'] = "1080p"

                elif ripsrc in ("brrip", "bdrip") and hd:
                    groups['resolution'] = "720p"

                #info("GUESS-RES: ripsrc={0} vcodec={1}",ripsrc.groups)(, vcodec)

            groups['tags'] = [tag.lower() for tag in
                    re.split(r"[ \.+\-_{}\(\)\[\]]", extra.strip())
                               if len(tag)]

            if groups.get('resolution', None):
                groups['tags'].append(groups['resolution'])

        log.debug("%s\n" % match.string
             + '\n'.join(('{0:>30} :   {1}'.format(k,str(v))
                          for k, v in groups.iteritems() if v))
             + "\n")

        self.extra = groups
        self.movietitle = movietitle
        self.part = groups.get("part", None)
        self.resolution = groups.get("resolution", None)

        try:
            self.releasedate = int(groups.get("releasedate", None))
        except TypeError:
            self.releasedate = None