def filterBadReleases(name, showLang=u"en"):
    """
    Filters out non-english and just all-around stupid releases by comparing them
    to the resultFilters contents.
    
    name: the release name to check
    
    Returns: True if the release name is OK, False if it's bad.
    """

    additionalFilters = []
    if showLang == u"en":
        additionalFilters.append("dub(bed)?")

    try:
        fp = NameParser()
        parse_result = fp.parse(name)
    except InvalidNameException:
        logger.log(
            u"Unable to parse the filename " + name + " into a valid episode",
            logger.WARNING)
        return False

    # use the extra info and the scene group to filter against
    check_string = ''
    if parse_result.extra_info:
        check_string = parse_result.extra_info
    if parse_result.release_group:
        if check_string:
            check_string = check_string + '-' + parse_result.release_group
        else:
            check_string = parse_result.release_group

    # if there's no info after the season info then assume it's fine
    if not check_string:
        check_string = name

    # if any of the bad strings are in the name then say no
    if sickbeard.IGNORE_WORDS == "":
        ignore_words = "ztreyfgut"
    else:
        ignore_words = sickbeard.IGNORE_WORDS
    for x in resultFilters + ignore_words.split(',') + additionalFilters:
        if x == showLanguages.get(showLang):
            continue
        if re.search('(^|[\W_])' + x + '($|[\W_])', check_string, re.I):
            logger.log(
                u"Invalid scene release: " + name + " contains " + x +
                ", ignoring it", logger.DEBUG)
            return False

    return True
def filterBadReleases(name,showLang=u"en"):
    """
    Filters out non-english and just all-around stupid releases by comparing them
    to the resultFilters contents.
    
    name: the release name to check
    
    Returns: True if the release name is OK, False if it's bad.
    """
    
    additionalFilters = []
    if showLang == u"en":
        additionalFilters.append("dub(bed)?")

    try:
        fp = NameParser()
        parse_result = fp.parse(name)
    except InvalidNameException:
        logger.log(u"Unable to parse the filename "+name+" into a valid episode", logger.WARNING)
        return False

    # use the extra info and the scene group to filter against
    check_string = ''
    if parse_result.extra_info:
        check_string = parse_result.extra_info
    if parse_result.release_group:
        if check_string:
            check_string = check_string + '-' + parse_result.release_group
        else:
            check_string = parse_result.release_group 

    # if there's no info after the season info then assume it's fine
    if not check_string:
        check_string = name

    # if any of the bad strings are in the name then say no
    if sickbeard.IGNORE_WORDS == "":
        ignore_words="ztreyfgut"
    else:
        ignore_words=sickbeard.IGNORE_WORDS
    for x in resultFilters + ignore_words.split(',') + additionalFilters:
        if x == showLanguages.get(showLang):
            continue
        if re.search('(^|[\W_])'+x+'($|[\W_])', check_string, re.I):
            logger.log(u"Invalid scene release: "+name+" contains "+x+", ignoring it", logger.DEBUG)
            return False

    return True
Exemple #3
0
    def __init__(self, force=None, show=None):

        #TODOif not sickbeard.DOWNLOAD_FRENCH:
        #    return
        if sickbeard.showList==None:
            return
        logger.log(u"Beginning the search for french episodes older than "+ str(sickbeard.FRENCH_DELAY) +" days")
       
        frenchlist=[]
        #get list of english episodes that we want to search in french
        myDB = db.DBConnection()
        today = datetime.date.today().toordinal()
        if show:
            frenchsql=myDB.select("SELECT showid, season, episode from tv_episodes where audio_langs='en' and tv_episodes.showid =? and (? - tv_episodes.airdate) > ? order by showid, airdate asc",[show,today,sickbeard.FRENCH_DELAY]) 
            count=myDB.select("SELECT count(*) from tv_episodes where audio_langs='en' and tv_episodes.showid =? and (? - tv_episodes.airdate) > ?",[show,today,sickbeard.FRENCH_DELAY]) 
        else:
            frenchsql=myDB.select("SELECT showid, season, episode from tv_episodes, tv_shows where audio_langs='en' and tv_episodes.showid = tv_shows.tvdb_id and tv_shows.frenchsearch = 1 and (? - tv_episodes.airdate) > ? order by showid, airdate asc",[today,sickbeard.FRENCH_DELAY])
            count=myDB.select("SELECT count(*) from tv_episodes, tv_shows where audio_langs='en' and tv_episodes.showid = tv_shows.tvdb_id and tv_shows.frenchsearch = 1 and (? - tv_episodes.airdate) > ?",[today,sickbeard.FRENCH_DELAY])
        #make the episodes objects
        logger.log(u"Searching for "+str(count[0][0]) +" episodes in french")
        for episode in frenchsql:
            showObj = helpers.findCertainShow(sickbeard.showList, episode[0])
            epObj = showObj.getEpisode(episode[1], episode[2])
            frenchlist.append(epObj)
        
        #for each episode in frenchlist fire a search in french
        delay=[]
        for frepisode in frenchlist:
            if frepisode.show.tvdbid in delay:
                logger.log(u"Previous episode for show "+str(frepisode.show.tvdbid)+" not found in french so skipping this search", logger.DEBUG)
                continue
            result=[]
            for curProvider in providers.sortedProviderList():

                if not curProvider.isActive():
                    continue

                logger.log(u"Searching for french episodes on "+curProvider.name +" for " +frepisode.show.name +" season "+str(frepisode.season)+" episode "+str(frepisode.episode))
                try:
                    curfrench = curProvider.findFrench(frepisode, manualSearch=True)
                except:
                    logger.log(u"Exception", logger.DEBUG)
                    pass
                test=0
                if curfrench:
                    for x in curfrench:
                        if not show_name_helpers.filterBadReleases(x.name):
                            logger.log(u"French "+x.name+" isn't a valid scene release that we want, ignoring it", logger.DEBUG)
                            test+=1
                            continue
                        if sickbeard.IGNORE_WORDS == "":
                            ignore_words="ztreyfgut"
                        else:
                            ignore_words=str(sickbeard.IGNORE_WORDS)
                        for fil in resultFilters + ignore_words.split(','):
                            if fil == showLanguages.get(u"fr"):
                                continue
                            if re.search('(^|[\W_])'+fil+'($|[\W_])', x.url, re.I):
                                logger.log(u"Invalid scene release: "+x.url+" contains "+fil+", ignoring it", logger.DEBUG)
                                test+=1
                    if test==0:
                        result.append(x)
            best=None
            try:
                epi={}
                epi[1]=frepisode
                best = search.pickBestResult(result, episode = epi)
            except:
                pass
            if best:
                best.name=best.name + ' snatchedfr'
                logger.log(u"Found french episode for " +frepisode.show.name +" season "+str(frepisode.season)+" episode "+str(frepisode.episode))
                try:
                    search.snatchEpisode(best, SNATCHED_FRENCH)
                except:
                    logger.log(u"Exception", logger.DEBUG)
                    pass
            else:
                delay.append(frepisode.show.tvdbid)
                logger.log(u"No french episodes found for " +frepisode.show.name +" season "+str(frepisode.season)+" episode "+str(frepisode.episode))
Exemple #4
0
    def _parse_string(self, name):
        if not name:
            return

        matches = []
        bestResult = None

        for (cur_regex_num, cur_regex_name, cur_regex) in self.compiled_regexes:
            match = cur_regex.match(name)

            if not match:
                continue

            result = ParseResult(name)
            result.which_regex = [cur_regex_name]
            result.score = 0 - cur_regex_num

            named_groups = match.groupdict().keys()

            if 'series_name' in named_groups:
                result.series_name = match.group('series_name')
                if result.series_name:
                    result.series_name = self.clean_series_name(result.series_name)
                    result.score += 1

            if 'series_num' in named_groups and match.group('series_num'):
                result.score += 1

            if 'season_num' in named_groups:
                tmp_season = int(match.group('season_num'))
                if cur_regex_name == 'bare' and tmp_season in (19, 20):
                    continue
                result.season_number = tmp_season
                result.score += 1

            if 'ep_num' in named_groups:
                ep_num = self._convert_number(match.group('ep_num'))
                if 'extra_ep_num' in named_groups and match.group('extra_ep_num'):
                    result.episode_numbers = range(ep_num, self._convert_number(match.group('extra_ep_num')) + 1)
                    result.score += 1
                else:
                    result.episode_numbers = [ep_num]
                result.score += 1

            if 'ep_ab_num' in named_groups:
                ep_ab_num = self._convert_number(match.group('ep_ab_num'))
                if 'extra_ab_ep_num' in named_groups and match.group('extra_ab_ep_num'):
                    result.ab_episode_numbers = range(ep_ab_num,
                                                      self._convert_number(match.group('extra_ab_ep_num')) + 1)
                    result.score += 1
                else:
                    result.ab_episode_numbers = [ep_ab_num]
                result.score += 1

            if 'air_date' in named_groups:
                air_date = match.group('air_date')
                try:
                    result.air_date = parser.parse(air_date, fuzzy=True).date()
                    result.score += 1
                except:
                    continue

            if 'extra_info' in named_groups:
                tmp_extra_info = match.group('extra_info')
                
                result.audio_langs = 'en'
                
                if tmp_extra_info:
                    for (cur_lang_regex_name, cur_lang_regex) in self.compiled_language_regexes:
                        lang_match = cur_lang_regex.match(name)
        
                        if not lang_match:
                            continue
                        else:
                            logger.log(u"Found " + showLanguages.get(cur_lang_regex_name) + " episode",logger.DEBUG) 
                            result.audio_langs = cur_lang_regex_name

                # Show.S04.Special or Show.S05.Part.2.Extras is almost certainly not every episode in the season
                if tmp_extra_info and cur_regex_name == 'season_only' and re.search(
                        r'([. _-]|^)(special|extra)s?\w*([. _-]|$)', tmp_extra_info, re.I):
                    continue
                result.extra_info = tmp_extra_info
                result.score += 1

            if 'release_group' in named_groups:
                result.release_group = match.group('release_group')
                result.score += 1

            if 'version' in named_groups:
                # assigns version to anime file if detected using anime regex. Non-anime regex receives -1
                version = match.group('version')
                if version:
                    result.version = version
                else:
                    result.version = 1
            else:
                result.version = -1

            matches.append(result)

        if len(matches):
            # pick best match with highest score based on placement
            bestResult = max(sorted(matches, reverse=True, key=lambda x: x.which_regex), key=lambda x: x.score)

            show = None
            if not self.naming_pattern:
                # try and create a show object for this result
                show = helpers.get_show(bestResult.series_name, self.tryIndexers, self.trySceneExceptions)

            # confirm passed in show object indexer id matches result show object indexer id
            if show:
                if self.showObj and show.indexerid != self.showObj.indexerid:
                    show = None
                bestResult.show = show
            elif not show and self.showObj:
                bestResult.show = self.showObj

            # if this is a naming pattern test or result doesn't have a show object then return best result
            if not bestResult.show or self.naming_pattern:
                return bestResult

            # get quality
            bestResult.quality = common.Quality.nameQuality(name, bestResult.show.is_anime)

            new_episode_numbers = []
            new_season_numbers = []
            new_absolute_numbers = []

            # if we have an air-by-date show then get the real season/episode numbers
            if bestResult.is_air_by_date:
                airdate = bestResult.air_date.toordinal()
                myDB = db.DBConnection()
                sql_result = myDB.select(
                    "SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
                    [bestResult.show.indexerid, bestResult.show.indexer, airdate])

                season_number = None
                episode_numbers = []

                if sql_result:
                    season_number = int(sql_result[0][0])
                    episode_numbers = [int(sql_result[0][1])]
                
                if not season_number or not len(episode_numbers):
                    try:
                        lINDEXER_API_PARMS = sickbeard.indexerApi(bestResult.show.indexer).api_params.copy()

                        if bestResult.show.lang:
                            lINDEXER_API_PARMS['language'] = bestResult.show.lang

                        t = sickbeard.indexerApi(bestResult.show.indexer).indexer(**lINDEXER_API_PARMS)

                        epObj = t[bestResult.show.indexerid].airedOn(bestResult.air_date)[0]

                        season_number = int(epObj["seasonnumber"])
                        episode_numbers = [int(epObj["episodenumber"])]
                    except sickbeard.indexer_episodenotfound:
                        logger.log(u"Unable to find episode with date " + str(bestResult.air_date) + " for show " + bestResult.show.name + ", skipping", logger.WARNING)
                        episode_numbers = []
                    except sickbeard.indexer_error, e:
                        logger.log(u"Unable to contact " + sickbeard.indexerApi(bestResult.show.indexer).name + ": " + ex(e), logger.WARNING)
                        episode_numbers = []

                for epNo in episode_numbers:
                    s = season_number
                    e = epNo

                    if self.convert:
                        (s, e) = scene_numbering.get_indexer_numbering(bestResult.show.indexerid,
                                                                       bestResult.show.indexer,
                                                                       season_number,
                                                                       epNo)
                    new_episode_numbers.append(e)
                    new_season_numbers.append(s)

            elif bestResult.show.is_anime and len(bestResult.ab_episode_numbers):
                scene_season = scene_exceptions.get_scene_exception_by_name(bestResult.series_name)[1]
                for epAbsNo in bestResult.ab_episode_numbers:
                    a = epAbsNo

                    if self.convert:
                        a = scene_numbering.get_indexer_absolute_numbering(bestResult.show.indexerid,
                                                                           bestResult.show.indexer, epAbsNo,
                                                                           True, scene_season)

                    (s, e) = helpers.get_all_episodes_from_absolute_number(bestResult.show, [a])

                    new_absolute_numbers.append(a)
                    new_episode_numbers.extend(e)
                    new_season_numbers.append(s)

            elif bestResult.season_number and len(bestResult.episode_numbers):
                for epNo in bestResult.episode_numbers:
                    s = bestResult.season_number
                    e = epNo

                    if self.convert:
                        (s, e) = scene_numbering.get_indexer_numbering(bestResult.show.indexerid,
                                                                       bestResult.show.indexer,
                                                                       bestResult.season_number,
                                                                       epNo)
                    if bestResult.show.is_anime:
                        a = helpers.get_absolute_number_from_season_and_episode(bestResult.show, s, e)
                        if a:
                            new_absolute_numbers.append(a)

                    new_episode_numbers.append(e)
                    new_season_numbers.append(s)

            # need to do a quick sanity check heregex.  It's possible that we now have episodes
            # from more than one season (by tvdb numbering), and this is just too much
            # for sickbeard, so we'd need to flag it.
            new_season_numbers = list(set(new_season_numbers))  # remove duplicates
            if len(new_season_numbers) > 1:
                raise InvalidNameException("Scene numbering results episodes from "
                                           "seasons %s, (i.e. more than one) and "
                                           "sickrage does not support this.  "
                                           "Sorry." % (str(new_season_numbers)))

            # I guess it's possible that we'd have duplicate episodes too, so lets
            # eliminate them
            new_episode_numbers = list(set(new_episode_numbers))
            new_episode_numbers.sort()

            # maybe even duplicate absolute numbers so why not do them as well
            new_absolute_numbers = list(set(new_absolute_numbers))
            new_absolute_numbers.sort()

            if len(new_absolute_numbers):
                bestResult.ab_episode_numbers = new_absolute_numbers

            if len(new_season_numbers) and len(new_episode_numbers):
                bestResult.episode_numbers = new_episode_numbers
                bestResult.season_number = new_season_numbers[0]

            if self.convert:
                logger.log(
                    u"Converted parsed result " + bestResult.original_name + " into " + str(bestResult).decode('utf-8',
                                                                                                               'xmlcharrefreplace'),
                    logger.DEBUG)
Exemple #5
0
    def _parse_string(self, name):  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
        if not name:
            return

        matches = []
        bestResult = None

        for (cur_regex_num, cur_regex_name, cur_regex) in self.compiled_regexes:
            match = cur_regex.match(name)

            if not match:
                continue

            result = ParseResult(name)
            result.which_regex = [cur_regex_name]
            result.score = 0 - cur_regex_num

            named_groups = match.groupdict().keys()

            if 'series_name' in named_groups:
                result.series_name = match.group('series_name')
                if result.series_name:
                    result.series_name = self.clean_series_name(result.series_name)
                    result.score += 1

            if 'series_num' in named_groups and match.group('series_num'):
                result.score += 1

            if 'season_num' in named_groups:
                tmp_season = int(match.group('season_num'))
                if cur_regex_name == 'bare' and tmp_season in (19, 20):
                    continue
                result.season_number = tmp_season
                result.score += 1

            if 'ep_num' in named_groups:
                ep_num = self._convert_number(match.group('ep_num'))
                if 'extra_ep_num' in named_groups and match.group('extra_ep_num'):
                    result.episode_numbers = range(ep_num, self._convert_number(match.group('extra_ep_num')) + 1)
                    result.score += 1
                else:
                    result.episode_numbers = [ep_num]
                result.score += 1

            if 'ep_ab_num' in named_groups:
                ep_ab_num = self._convert_number(match.group('ep_ab_num'))
                if 'extra_ab_ep_num' in named_groups and match.group('extra_ab_ep_num'):
                    result.ab_episode_numbers = range(ep_ab_num,
                                                      self._convert_number(match.group('extra_ab_ep_num')) + 1)
                    result.score += 1
                else:
                    result.ab_episode_numbers = [ep_ab_num]
                result.score += 1

            if 'air_date' in named_groups:
                air_date = match.group('air_date')
                try:
                    result.air_date = dateutil.parser.parse(air_date, fuzzy_with_tokens=True)[0].date()
                    result.score += 1
                except Exception:
                    continue

            if 'extra_info' in named_groups:
                tmp_extra_info = match.group('extra_info')
                logger.log(tmp_extra_info)
                result.audio_langs = 'eng'

                # Show.S04.Special or Show.S05.Part.2.Extras is almost certainly not every episode in the season
                if tmp_extra_info and cur_regex_name == 'season_only' and re.search(
                        r'([. _-]|^)(special|extra)s?\w*([. _-]|$)', tmp_extra_info, re.I):
                    continue
                if tmp_extra_info :
                    for (cur_lang_regex_name, cur_lang_regex) in self.compiled_language_regexes:
                        lang_match = cur_lang_regex.match(name)

                        if not lang_match:
                            continue
                        else:
                            logger.log(u"Found " + showLanguages.get(cur_lang_regex_name) + " episode",logger.DEBUG)
                            result.audio_langs = cur_lang_regex_name
                result.extra_info = tmp_extra_info
                result.score += 1

            if 'release_group' in named_groups:
                result.release_group = match.group('release_group')
                result.score += 1

            if 'version' in named_groups:
                # assigns version to anime file if detected using anime regex. Non-anime regex receives -1
                version = match.group('version')
                if version:
                    result.version = version
                else:
                    result.version = 1
            else:
                result.version = -1

            matches.append(result)

        if matches:
            # pick best match with highest score based on placement
            bestResult = max(sorted(matches, reverse=True, key=lambda x: x.which_regex), key=lambda x: x.score)

            show = None
            if not self.naming_pattern:
                # try and create a show object for this result
                show = helpers.get_show(bestResult.series_name, self.tryIndexers)

            # confirm passed in show object indexer id matches result show object indexer id
            if show:
                if self.showObj and show.indexerid != self.showObj.indexerid:
                    show = None
                bestResult.show = show
            elif not show and self.showObj:
                bestResult.show = self.showObj

            # if this is a naming pattern test or result doesn't have a show object then return best result
            if not bestResult.show or self.naming_pattern:
                return bestResult

            # get quality
            bestResult.quality = common.Quality.nameQuality(name, bestResult.show.is_anime)

            new_episode_numbers = []
            new_season_numbers = []
            new_absolute_numbers = []

            # if we have an air-by-date show then get the real season/episode numbers
            if bestResult.is_air_by_date:
                airdate = bestResult.air_date.toordinal()
                main_db_con = db.DBConnection()
                sql_result = main_db_con.select(
                    "SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
                    [bestResult.show.indexerid, bestResult.show.indexer, airdate])

                season_number = None
                episode_numbers = []

                if sql_result:
                    season_number = int(sql_result[0][0])
                    episode_numbers = [int(sql_result[0][1])]

                if season_number is None or not episode_numbers:
                    try:
                        lINDEXER_API_PARMS = sickbeard.indexerApi(bestResult.show.indexer).api_params.copy()

                        if bestResult.show.lang:
                            lINDEXER_API_PARMS['language'] = bestResult.show.lang

                        t = sickbeard.indexerApi(bestResult.show.indexer).indexer(**lINDEXER_API_PARMS)

                        epObj = t[bestResult.show.indexerid].airedOn(bestResult.air_date)[0]

                        season_number = int(epObj["seasonnumber"])
                        episode_numbers = [int(epObj["episodenumber"])]
                    except sickbeard.indexer_episodenotfound:
                        logger.log(u"Unable to find episode with date " + str(bestResult.air_date) + " for show " + bestResult.show.name + ", skipping", logger.WARNING)
                        episode_numbers = []
                    except sickbeard.indexer_error as e:
                        logger.log(u"Unable to contact " + sickbeard.indexerApi(bestResult.show.indexer).name + ": " + ex(e), logger.WARNING)
                        episode_numbers = []

                for epNo in episode_numbers:
                    s = season_number
                    e = epNo

                    if bestResult.show.is_scene:
                        (s, e) = scene_numbering.get_indexer_numbering(bestResult.show.indexerid,
                                                                       bestResult.show.indexer,
                                                                       season_number,
                                                                       epNo)
                    new_episode_numbers.append(e)
                    new_season_numbers.append(s)

            elif bestResult.show.is_anime and bestResult.ab_episode_numbers:
                scene_season = scene_exceptions.get_scene_exception_by_name(bestResult.series_name)[1]
                for epAbsNo in bestResult.ab_episode_numbers:
                    a = epAbsNo

                    if bestResult.show.is_scene:
                        a = scene_numbering.get_indexer_absolute_numbering(bestResult.show.indexerid,
                                                                           bestResult.show.indexer, epAbsNo,
                                                                           True, scene_season)

                    (s, e) = helpers.get_all_episodes_from_absolute_number(bestResult.show, [a])

                    new_absolute_numbers.append(a)
                    new_episode_numbers.extend(e)
                    new_season_numbers.append(s)

            elif bestResult.season_number and bestResult.episode_numbers:
                for epNo in bestResult.episode_numbers:
                    s = bestResult.season_number
                    e = epNo

                    if bestResult.show.is_scene:
                        (s, e) = scene_numbering.get_indexer_numbering(bestResult.show.indexerid,
                                                                       bestResult.show.indexer,
                                                                       bestResult.season_number,
                                                                       epNo)
                    if bestResult.show.is_anime:
                        a = helpers.get_absolute_number_from_season_and_episode(bestResult.show, s, e)
                        if a:
                            new_absolute_numbers.append(a)

                    new_episode_numbers.append(e)
                    new_season_numbers.append(s)

            # need to do a quick sanity check heregex.  It's possible that we now have episodes
            # from more than one season (by tvdb numbering), and this is just too much
            # for sickbeard, so we'd need to flag it.
            new_season_numbers = list(set(new_season_numbers))  # remove duplicates
            if len(new_season_numbers) > 1:
                raise InvalidNameException("Scene numbering results episodes from "
                                           "seasons %s, (i.e. more than one) and "
                                           "sickrage does not support this.  "
                                           "Sorry." % (str(new_season_numbers)))

            # I guess it's possible that we'd have duplicate episodes too, so lets
            # eliminate them
            new_episode_numbers = list(set(new_episode_numbers))
            new_episode_numbers.sort()

            # maybe even duplicate absolute numbers so why not do them as well
            new_absolute_numbers = list(set(new_absolute_numbers))
            new_absolute_numbers.sort()

            if new_absolute_numbers:
                bestResult.ab_episode_numbers = new_absolute_numbers

            if new_season_numbers and new_episode_numbers:
                bestResult.episode_numbers = new_episode_numbers
                bestResult.season_number = new_season_numbers[0]

            if bestResult.show.is_scene:
                logger.log(
                    u"Converted parsed result " + bestResult.original_name + " into " + str(bestResult).decode('utf-8',
                                                                                                               'xmlcharrefreplace'),
                    logger.DEBUG)

        # CPU sleep
        time.sleep(0.02)

        return bestResult
Exemple #6
0
    def _parse_string(self, name):

        if not name:
            return None

        for (cur_regex_name, cur_regex) in self.compiled_regexes:
            match = cur_regex.match(name)

            if not match:
                continue

            result = ParseResult(name)
            result.which_regex = [cur_regex_name]

            named_groups = match.groupdict().keys()

            if 'series_name' in named_groups:
                result.series_name = match.group('series_name')
                if result.series_name:
                    result.series_name = self.clean_series_name(
                        result.series_name)

            if 'season_num' in named_groups:
                tmp_season = int(match.group('season_num'))
                if cur_regex_name == 'bare' and tmp_season in (19, 20):
                    continue
                result.season_number = tmp_season

            if 'ep_num' in named_groups:
                ep_num = self._convert_number(match.group('ep_num'))
                if 'extra_ep_num' in named_groups and match.group(
                        'extra_ep_num'):
                    result.episode_numbers = range(
                        ep_num,
                        self._convert_number(match.group('extra_ep_num')) + 1)
                else:
                    result.episode_numbers = [ep_num]

            if 'air_year' in named_groups and 'air_month' in named_groups and 'air_day' in named_groups:
                year = int(match.group('air_year'))
                month = int(match.group('air_month'))
                day = int(match.group('air_day'))

                # make an attempt to detect YYYY-DD-MM formats
                if month > 12:
                    tmp_month = month
                    month = day
                    day = tmp_month

                try:
                    result.air_date = datetime.date(year, month, day)
                except ValueError, e:
                    raise InvalidNameException(e.message)

            if 'extra_info' in named_groups:
                tmp_extra_info = match.group('extra_info')

                result.audio_langs = 'en'

                if tmp_extra_info:
                    for (cur_lang_regex_name,
                         cur_lang_regex) in self.compiled_language_regexes:
                        lang_match = cur_lang_regex.match(name)

                        if not lang_match:
                            continue
                        else:
                            logger.log(
                                u"Found " +
                                showLanguages.get(cur_lang_regex_name) +
                                " episode", logger.DEBUG)
                            result.audio_langs = cur_lang_regex_name

                #if tmp_extra_info and re.search(r'(^|\w|[. _-])*(german)(([. _-])(dubbed))?\w*([. _-]|$)', tmp_extra_info, re.I):
                #   logger.log(u"Found german episode")
                #result.series_language = 'de'

                # Show.S04.Special is almost certainly not every episode in the season
                if tmp_extra_info and cur_regex_name == 'season_only' and re.match(
                        r'([. _-]|^)(special|extra)\w*([. _-]|$)',
                        tmp_extra_info, re.I):
                    continue
                result.extra_info = tmp_extra_info

            if 'release_group' in named_groups:
                result.release_group = match.group('release_group')

            return result
Exemple #7
0
    def _parse_string(self, name):

        if not name:
            return None

        for (cur_regex_name, cur_regex) in self.compiled_regexes:
            match = cur_regex.match(name)

            if not match:
                continue

            result = ParseResult(name)
            result.which_regex = [cur_regex_name]

            named_groups = match.groupdict().keys()

            if "series_name" in named_groups:
                result.series_name = match.group("series_name")
                if result.series_name:
                    result.series_name = self.clean_series_name(result.series_name)

            if "season_num" in named_groups:
                tmp_season = int(match.group("season_num"))
                if cur_regex_name == "bare" and tmp_season in (19, 20):
                    continue
                result.season_number = tmp_season

            if "ep_num" in named_groups:
                ep_num = self._convert_number(match.group("ep_num"))
                if "extra_ep_num" in named_groups and match.group("extra_ep_num"):
                    result.episode_numbers = range(ep_num, self._convert_number(match.group("extra_ep_num")) + 1)
                else:
                    result.episode_numbers = [ep_num]

            if "air_year" in named_groups and "air_month" in named_groups and "air_day" in named_groups:
                year = int(match.group("air_year"))
                month = int(match.group("air_month"))
                day = int(match.group("air_day"))

                # make an attempt to detect YYYY-DD-MM formats
                if month > 12:
                    tmp_month = month
                    month = day
                    day = tmp_month

                try:
                    result.air_date = datetime.date(year, month, day)
                except ValueError, e:
                    raise InvalidNameException(e.message)

            if "extra_info" in named_groups:
                tmp_extra_info = match.group("extra_info")

                result.audio_langs = "en"

                if tmp_extra_info:
                    for (cur_lang_regex_name, cur_lang_regex) in self.compiled_language_regexes:
                        lang_match = cur_lang_regex.match(name)

                        if not lang_match:
                            continue
                        else:
                            logger.log(u"Found " + showLanguages.get(cur_lang_regex_name) + " episode", logger.DEBUG)
                            result.audio_langs = cur_lang_regex_name

                # if tmp_extra_info and re.search(r'(^|\w|[. _-])*(german)(([. _-])(dubbed))?\w*([. _-]|$)', tmp_extra_info, re.I):
                #   logger.log(u"Found german episode")
                # result.series_language = 'de'

                # Show.S04.Special is almost certainly not every episode in the season
                if (
                    tmp_extra_info
                    and cur_regex_name == "season_only"
                    and re.match(r"([. _-]|^)(special|extra)\w*([. _-]|$)", tmp_extra_info, re.I)
                ):
                    continue
                result.extra_info = tmp_extra_info

            if "release_group" in named_groups:
                result.release_group = match.group("release_group")

            return result
Exemple #8
0
    def run(self, force=None, show=None):
        if sickbeard.showList == None:
            return
        logger.log(u"Beginning the search for french episodes older than " +
                   str(sickbeard.FRENCH_DELAY) + " days")
        foundResults = {}
        finalResults = []
        #show = self
        frenchlist = []
        #get list of english episodes that we want to search in french
        myDB = db.DBConnection()
        today = datetime.date.today().toordinal()
        if show:
            frenchsql = myDB.select(
                "SELECT showid, season, episode from tv_episodes where audio_langs='eng' and tv_episodes.showid =? and (? - tv_episodes.airdate) > ? order by showid, airdate asc",
                [show, today, sickbeard.FRENCH_DELAY])
            logger.log(
                "SELECT showid, season, episode from tv_episodes where audio_langs='eng' and tv_episodes.showid ="
                + str(show) + "and (" + str(today) +
                " - tv_episodes.airdate) > " + str(sickbeard.FRENCH_DELAY) +
                "order by showid, airdate asc")
            count = myDB.select(
                "SELECT count(*) from tv_episodes where audio_langs='eng' and tv_episodes.showid =? and (? - tv_episodes.airdate) > ?",
                [show, today, sickbeard.FRENCH_DELAY])
        else:
            frenchsql = myDB.select(
                "SELECT showid, season, episode from tv_episodes, tv_shows where audio_langs='eng' and tv_episodes.showid = tv_shows.indexer_id and tv_shows.frenchsearch = 1 and (? - tv_episodes.airdate) > ? order by showid, airdate asc",
                [today, sickbeard.FRENCH_DELAY])
            count = myDB.select(
                "SELECT count(*) from tv_episodes, tv_shows where audio_langs='eng' and tv_episodes.showid = tv_shows.indexer_id and tv_shows.frenchsearch = 1 and (? - tv_episodes.airdate) > ?",
                [today, sickbeard.FRENCH_DELAY])
        #make the episodes objects

        #logger.log("SELECT showid, season, episode from tv_episodes where audio_langs='eng' and tv_episodes.showid =" + str(show) +"and (" +str(today)+" - tv_episodes.airdate) > "+ str(sickbeard.FRENCH_DELAY) +"order by showid, airdate asc")
        logger.log(
            "SELECT showid, season, episode from tv_episodes, tv_shows where audio_langs='eng' and tv_episodes.showid = tv_shows.indexer_id and tv_shows.frenchsearch = 1 and ("
            + str(today) + " - tv_episodes.airdate) > " +
            str(sickbeard.FRENCH_DELAY) + " order by showid, airdate asc")
        logger.log(u"Searching for " + str(count[0][0]) +
                   " episodes in french")

        #logger.log(frenchsql)

        #logger.log(sickbeard.showList.)

        for episode in frenchsql:

            showObj = Show.find(sickbeard.showList, int(episode[0]))
            if showObj == None:
                logger.log("Show not in show list")

            #showObj = helpers.findCertainShow(sickbeard.showList, episode[0])
            epObj = showObj.getEpisode(episode[1], episode[2])

            #epObj = showObj.getEpisode(int(epInfo[0]), int(epInfo[1]))
            frenchlist.append(epObj)

        #for each episode in frenchlist fire a search in french
        delay = []
        temp = None
        rest = count[0][0]
        for frepisode in frenchlist:
            rest = rest - 1
            if frepisode.show.indexerid in delay:
                logger.log(
                    u"Previous episode for show " + str(frepisode.show.name) +
                    " not found in french so skipping this search",
                    logger.DEBUG)
                continue
            result = []
            for curProvider in providers.sortedProviderList():

                foundResults[curProvider.name] = {}

                if not curProvider.is_active():
                    continue

                logger.log(u"Searching for french episode on " +
                           curProvider.name + " for " + frepisode.show.name +
                           " season " + str(frepisode.season) + " episode " +
                           str(frepisode.episode))
                #try:
                #    logger.log(frepisode)
                #    temp = GenericProvider()
                #    curfrench = temp.findFrench(self, episode=frepisode, manualSearch=True)
                #curfrench =  GenericProvider.findFrench(episode=frepi  sode,manualSearch=True)
                #curProvider.findFrench(frepisode, manualSearch=True)
                #except:
                #    logger.log(u"Exception", logger.DEBUG)
                #    pass

                #for curProvider in providers:
                #    if curProvider.anime_only and not show.is_anime:
                #        logger.log(u"" + str(show.name) + " is not an anime, skipping", logger.DEBUG)
                #        continue

                curfrench = curProvider.find_search_results(
                    frepisode.show, frenchlist, 'sponly', True, True, 'french')

                #curfrench = curProvider.findFrench(frepisode, True)

                #temp = GenericProvider('temp')
                #curfrench = temp.findFrench( episode=frepisode, manualSearch=True)

                if len(curfrench):
                    #make a list of all the results for this provider
                    for curEp in curfrench:
                        if curEp in foundResults:
                            foundResults[
                                curProvider.name][curEp] += curfrench[curEp]
                        else:
                            foundResults[
                                curProvider.name][curEp] = curfrench[curEp]

                if not foundResults[curProvider.name]:
                    continue

                bestSeasonResult = None
                #if SEASON_RESULT in foundResults[curProvider.name]:
                #    bestSeasonResult = search.pickBestResult(foundResults[curProvider.name][SEASON_RESULT], show)
                #_______________________________________________________
                test = 0
                if foundResults[curProvider.name]:
                    for cur_episode in foundResults[curProvider.name]:
                        for x in foundResults[curProvider.name][cur_episode]:
                            tmp = x
                            if not show_name_helpers.filterBadReleases(
                                    x.name):  #x.name):
                                logger.log(
                                    u"French " + x.name +
                                    " isn't a valid scene release that we want, ignoring it",
                                    logger.DEBUG)
                                test += 1
                                continue
                            if sickbeard.IGNORE_WORDS == "":
                                ignore_words = "ztreyfgut"
                            else:
                                ignore_words = str(sickbeard.IGNORE_WORDS)
                            for fil in resultFilters + ignore_words.split(','):
                                if fil == showLanguages.get(u"fre"):
                                    continue
                                if re.search('(^|[\W_])' + fil + '($|[\W_])',
                                             x.url, re.I) or re.search(
                                                 '(^|[\W_])' + fil +
                                                 '($|[\W_])', x.name, re.I):
                                    logger.log(
                                        u"Invalid scene release: " + x.url +
                                        " contains " + fil + ", ignoring it",
                                        logger.DEBUG)
                                    test += 1

                    if test == 0:
                        result.append(x)

            best = None
            try:
                epi = {}
                epi[1] = frepisode
                best = search.pickBestResult(result, showObj)
            except:
                pass
            if best:
                best.name = best.name + ' snatchedfr'
                logger.log(u"Found french episode for " + frepisode.show.name +
                           " season " + str(frepisode.season) + " episode " +
                           str(frepisode.episode))
                try:
                    search.snatchEpisode(best, SNATCHED_FRENCH)
                except:
                    logger.log(u"Exception", logger.DEBUG)
                    pass
            else:
                delay.append(frepisode.show.indexerid)
                logger.log(u"No french episode found for " +
                           frepisode.show.name + " season " +
                           str(frepisode.season) + " episode " +
                           str(frepisode.episode))
            logger.log(str(rest) + u" episodes left")
    def run(self, force=None, show=None):
        if sickbeard.showList == None:
            return
        logger.log(u"Beginning the search for french episodes older than " + str(sickbeard.FRENCH_DELAY) + " days")
        foundResults = {}
        finalResults = []
        # show = self
        frenchlist = []
        # get list of english episodes that we want to search in french
        myDB = db.DBConnection()
        today = datetime.date.today().toordinal()
        if show:
            frenchsql = myDB.select(
                "SELECT showid, season, episode from tv_episodes where audio_langs='eng' and tv_episodes.showid =? and (? - tv_episodes.airdate) > ? order by showid, airdate asc",
                [show, today, sickbeard.FRENCH_DELAY],
            )
            logger.log(
                "SELECT showid, season, episode from tv_episodes where audio_langs='eng' and tv_episodes.showid ="
                + str(show)
                + "and ("
                + str(today)
                + " - tv_episodes.airdate) > "
                + str(sickbeard.FRENCH_DELAY)
                + "order by showid, airdate asc"
            )
            count = myDB.select(
                "SELECT count(*) from tv_episodes where audio_langs='eng' and tv_episodes.showid =? and (? - tv_episodes.airdate) > ?",
                [show, today, sickbeard.FRENCH_DELAY],
            )
        else:
            frenchsql = myDB.select(
                "SELECT showid, season, episode from tv_episodes, tv_shows where audio_langs='eng' and tv_episodes.showid = tv_shows.indexer_id and tv_shows.frenchsearch = 1 and (? - tv_episodes.airdate) > ? order by showid, airdate asc",
                [today, sickbeard.FRENCH_DELAY],
            )
            count = myDB.select(
                "SELECT count(*) from tv_episodes, tv_shows where audio_langs='eng' and tv_episodes.showid = tv_shows.indexer_id and tv_shows.frenchsearch = 1 and (? - tv_episodes.airdate) > ?",
                [today, sickbeard.FRENCH_DELAY],
            )
        # make the episodes objects

        # logger.log("SELECT showid, season, episode from tv_episodes where audio_langs='eng' and tv_episodes.showid =" + str(show) +"and (" +str(today)+" - tv_episodes.airdate) > "+ str(sickbeard.FRENCH_DELAY) +"order by showid, airdate asc")
        logger.log(
            "SELECT showid, season, episode from tv_episodes, tv_shows where audio_langs='eng' and tv_episodes.showid = tv_shows.indexer_id and tv_shows.frenchsearch = 1 and ("
            + str(today)
            + " - tv_episodes.airdate) > "
            + str(sickbeard.FRENCH_DELAY)
            + " order by showid, airdate asc"
        )
        logger.log(u"Searching for " + str(count[0][0]) + " episodes in french")

        # logger.log(frenchsql)

        # logger.log(sickbeard.showList.)

        for episode in frenchsql:

            showObj = Show.find(sickbeard.showList, int(episode[0]))
            if showObj == None:
                logger.log("Show not in show list")

            # showObj = helpers.findCertainShow(sickbeard.showList, episode[0])
            epObj = showObj.getEpisode(episode[1], episode[2])

            # epObj = showObj.getEpisode(int(epInfo[0]), int(epInfo[1]))
            frenchlist.append(epObj)

        # for each episode in frenchlist fire a search in french
        delay = []
        temp = None
        rest = count[0][0]
        for frepisode in frenchlist:
            rest = rest - 1
            if frepisode.show.indexerid in delay:
                logger.log(
                    u"Previous episode for show "
                    + str(frepisode.show.name)
                    + " not found in french so skipping this search",
                    logger.DEBUG,
                )
                continue
            result = []
            for curProvider in providers.sortedProviderList():

                foundResults[curProvider.name] = {}

                if not curProvider.is_active():
                    continue

                logger.log(
                    u"Searching for french episode on "
                    + curProvider.name
                    + " for "
                    + frepisode.show.name
                    + " season "
                    + str(frepisode.season)
                    + " episode "
                    + str(frepisode.episode)
                )
                # try:
                #    logger.log(frepisode)
                #    temp = GenericProvider()
                #    curfrench = temp.findFrench(self, episode=frepisode, manualSearch=True)
                # curfrench =  GenericProvider.findFrench(episode=frepi  sode,manualSearch=True)
                # curProvider.findFrench(frepisode, manualSearch=True)
                # except:
                #    logger.log(u"Exception", logger.DEBUG)
                #    pass

                # for curProvider in providers:
                #    if curProvider.anime_only and not show.is_anime:
                #        logger.log(u"" + str(show.name) + " is not an anime, skipping", logger.DEBUG)
                #        continue

                curfrench = curProvider.find_search_results(frepisode.show, frenchlist, "sponly", True, True, "french")

                # curfrench = curProvider.findFrench(frepisode, True)

                # temp = GenericProvider('temp')
                # curfrench = temp.findFrench( episode=frepisode, manualSearch=True)

                if len(curfrench):
                    # make a list of all the results for this provider
                    for curEp in curfrench:
                        if curEp in foundResults:
                            foundResults[curProvider.name][curEp] += curfrench[curEp]
                        else:
                            foundResults[curProvider.name][curEp] = curfrench[curEp]

                if not foundResults[curProvider.name]:
                    continue

                bestSeasonResult = None
                # if SEASON_RESULT in foundResults[curProvider.name]:
                #    bestSeasonResult = search.pickBestResult(foundResults[curProvider.name][SEASON_RESULT], show)
                # _______________________________________________________
                test = 0
                if foundResults[curProvider.name]:
                    for cur_episode in foundResults[curProvider.name]:
                        for x in foundResults[curProvider.name][cur_episode]:
                            tmp = x
                            if not show_name_helpers.filterBadReleases(x.name):  # x.name):
                                logger.log(
                                    u"French " + x.name + " isn't a valid scene release that we want, ignoring it",
                                    logger.DEBUG,
                                )
                                test += 1
                                continue
                            if sickbeard.IGNORE_WORDS == "":
                                ignore_words = "ztreyfgut"
                            else:
                                ignore_words = str(sickbeard.IGNORE_WORDS)
                            for fil in resultFilters + ignore_words.split(","):
                                if fil == showLanguages.get(u"fre"):
                                    continue
                                if re.search("(^|[\W_])" + fil + "($|[\W_])", x.url, re.I) or re.search(
                                    "(^|[\W_])" + fil + "($|[\W_])", x.name, re.I
                                ):
                                    logger.log(
                                        u"Invalid scene release: " + x.url + " contains " + fil + ", ignoring it",
                                        logger.DEBUG,
                                    )
                                    test += 1

                    if test == 0:
                        result.append(x)

            best = None
            try:
                epi = {}
                epi[1] = frepisode
                best = search.pickBestResult(result, showObj)
            except:
                pass
            if best:
                best.name = best.name + " snatchedfr"
                logger.log(
                    u"Found french episode for "
                    + frepisode.show.name
                    + " season "
                    + str(frepisode.season)
                    + " episode "
                    + str(frepisode.episode)
                )
                try:
                    search.snatchEpisode(best, SNATCHED_FRENCH)
                except:
                    logger.log(u"Exception", logger.DEBUG)
                    pass
            else:
                delay.append(frepisode.show.indexerid)
                logger.log(
                    u"No french episode found for "
                    + frepisode.show.name
                    + " season "
                    + str(frepisode.season)
                    + " episode "
                    + str(frepisode.episode)
                )
            logger.log(str(rest) + u" episodes left")