Example #1
0
    def _get_season_search_strings(self, show, season=None):

        params = {}

        if not show:
            return params

        # search directly by tvrage id
        if show.tvrid:
            params['rid'] = show.tvrid
        # if we can't then fall back on a very basic name search
        else:
            params['q'] = sceneHelpers.sanitizeSceneName(show.name)

        if season != None:
            # air-by-date means &season=2010&q=2010.03, no other way to do it atm
            if show.is_air_by_date:
                params['season'] = season.split('-')[0]
                if 'q' in params:
                    params['q'] += '.' + season.replace('-', '.')
                else:
                    params['q'] = season.replace('-', '.')
            else:
                params['season'] = season

        return [params]
Example #2
0
	def _get_season_search_strings(self, show, season=None):

		params = {}

		if not show:
			return params
		
		# search directly by tvrage id
		if show.tvrid:
			params['rid'] = show.tvrid
		# if we can't then fall back on a very basic name search
		else:
			params['q'] = sceneHelpers.sanitizeSceneName(show.name)

		if season != None:
			# air-by-date means &season=2010&q=2010.03, no other way to do it atm
			if show.is_air_by_date:
				params['season'] = season.split('-')[0]
				if 'q' in params:
					params['q'] += '.' + season.replace('-', '.')
				else:
					params['q'] = season.replace('-', '.')
			else:
				params['season'] = season

		return [params]
Example #3
0
 def _get_season_search_strings(self, show, season=None):
 
     params = {}
 
     if not show:
         return params
     
     params['show_name'] = sceneHelpers.sanitizeSceneName(show.name).replace('.',' ').encode('utf-8')
       
     if season != None:
         params['season'] = season
 
     return [params]
Example #4
0
 def _get_episode_search_strings(self, ep_obj):
 
     params = {}
     
     if not ep_obj:
         return params
                
     params['show_name'] = sceneHelpers.sanitizeSceneName(ep_obj.show.name).replace('.',' ').encode('utf-8')
     
     if ep_obj.show.is_air_by_date:
         params['date'] = str(ep_obj.airdate)
     else:
         params['season'] = ep_obj.season
         params['episode'] = ep_obj.episode
 
     return [params]
Example #5
0
	def _get_episode_search_strings(self, ep_obj):
		
		params = {}

		if not ep_obj:
			return params
		
		# search directly by tvrage id
		if ep_obj.show.tvrid:
			params['rid'] = ep_obj.show.tvrid
		# if we can't then fall back on a very basic name search
		else:
			params['q'] = sceneHelpers.sanitizeSceneName(ep_obj.show.name)

		if ep_obj.show.is_air_by_date:
			date_str = str(ep_obj.airdate)
			
			params['season'] = date_str.partition('-')[0]
			params['ep'] = date_str.partition('-')[2].replace('-','/')
		else:
			params['season'] = ep_obj.season
			params['ep'] = ep_obj.episode

		return [params]
Example #6
0
    def _get_episode_search_strings(self, ep_obj):

        params = {}

        if not ep_obj:
            return params

        # search directly by tvrage id
        if ep_obj.show.tvrid:
            params['rid'] = ep_obj.show.tvrid
        # if we can't then fall back on a very basic name search
        else:
            params['q'] = sceneHelpers.sanitizeSceneName(ep_obj.show.name)

        if ep_obj.show.is_air_by_date:
            date_str = str(ep_obj.airdate)

            params['season'] = date_str.partition('-')[0]
            params['ep'] = date_str.partition('-')[2].replace('-', '/')
        else:
            params['season'] = ep_obj.season
            params['ep'] = ep_obj.episode

        return [params]
Example #7
0
    def _analyze_name(self, name, file=True):
        """
        Takes a name and tries to figure out a show, season, and episode from it.
        
        Returns a (tvdb_id, season, [episodes]) tuple. The first two may be None and episodes may be []
        if none were found.
        """

        logger.log(u"Analyzing name "+repr(name))
    
        to_return = (None, None, [])
    
        if not name:
            return to_return
    
        # parse the name to break it into show name, season, and episode
        np = NameParser(file)
        parse_result = np.parse(name)
        self._log("Parsed "+name+" into "+str(parse_result).decode('utf-8'), logger.DEBUG)

        if parse_result.air_by_date:
            season = -1
            episodes = [parse_result.air_date]
        else:
            season = parse_result.season_number
            episodes = parse_result.episode_numbers 

        to_return = (None, season, episodes)
    
        # do a scene reverse-lookup to get a list of all possible names
        name_list = sceneHelpers.sceneToNormalShowNames(parse_result.series_name)

        if not name_list:
            return (None, season, episodes)
        
        def _finalize(parse_result):
            self.release_group = parse_result.release_group
            if parse_result.extra_info:
                self.is_proper = re.search('(^|[\. _-])(proper|repack)([\. _-]|$)', parse_result.extra_info, re.I) != None
        
        # for each possible interpretation of that scene name
        for cur_name in name_list:
            self._log(u"Checking scene exceptions for a match on "+cur_name, logger.DEBUG)
            for exceptionID in common.sceneExceptions:
                # for each exception name
                for curException in common.sceneExceptions[exceptionID]:
                    if cur_name.lower() in (curException.lower(), sceneHelpers.sanitizeSceneName(curException).lower().replace('.',' ')):
                        self._log(u"Scene exception lookup got tvdb id "+str(exceptionID)+u", using that", logger.DEBUG)
                        _finalize(parse_result)
                        return (exceptionID, season, episodes)

        # see if we can find the name directly in the DB, if so use it
        for cur_name in name_list:
            self._log(u"Looking up "+cur_name+u" in the DB", logger.DEBUG)
            db_result = helpers.searchDBForShow(cur_name)
            if db_result:
                self._log(u"Lookup successful, using tvdb id "+str(db_result[0]), logger.DEBUG)
                _finalize(parse_result)
                return (int(db_result[0]), season, episodes)
        
        # see if we can find the name with a TVDB lookup
        for cur_name in name_list:
            try:
                t = tvdb_api.Tvdb(custom_ui=classes.ShowListUI, **sickbeard.TVDB_API_PARMS)
    
                self._log(u"Looking up name "+cur_name+u" on TVDB", logger.DEBUG)
                showObj = t[cur_name]
            except (tvdb_exceptions.tvdb_exception), e:
                # if none found, search on all languages
                try:
                    # There's gotta be a better way of doing this but we don't wanna
                    # change the language value elsewhere
                    ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()

                    ltvdb_api_parms['search_all_languages'] = True
                    t = tvdb_api.Tvdb(custom_ui=classes.ShowListUI, **ltvdb_api_parms)

                    self._log(u"Looking up name "+cur_name+u" in all languages on TVDB", logger.DEBUG)
                    showObj = t[cur_name]
                except (tvdb_exceptions.tvdb_exception, IOError), e:
                    pass

                continue
Example #8
0
    def _analyze_name(self, name, file=True):
        """
        Takes a name and tries to figure out a show, season, and episode from it.
        
        Returns a (tvdb_id, season, [episodes]) tuple. The first two may be None and episodes may be []
        if none were found.
        """

        logger.log(u"Analyzing name " + repr(name))

        to_return = (None, None, [])

        if not name:
            return to_return

        # parse the name to break it into show name, season, and episode
        np = NameParser(file)
        parse_result = np.parse(name)
        self._log(
            "Parsed " + name + " into " + str(parse_result).decode('utf-8'),
            logger.DEBUG)

        if parse_result.air_by_date:
            season = -1
            episodes = [parse_result.air_date]
        else:
            season = parse_result.season_number
            episodes = parse_result.episode_numbers

        to_return = (None, season, episodes)

        # do a scene reverse-lookup to get a list of all possible names
        name_list = sceneHelpers.sceneToNormalShowNames(
            parse_result.series_name)

        if not name_list:
            return (None, season, episodes)

        def _finalize(parse_result):
            self.release_group = parse_result.release_group
            if parse_result.extra_info:
                self.is_proper = re.search(
                    '(^|[\. _-])(proper|repack)([\. _-]|$)',
                    parse_result.extra_info, re.I) != None

        # for each possible interpretation of that scene name
        for cur_name in name_list:
            self._log(u"Checking scene exceptions for a match on " + cur_name,
                      logger.DEBUG)
            for exceptionID in common.sceneExceptions:
                # for each exception name
                for curException in common.sceneExceptions[exceptionID]:
                    if cur_name.lower() in (curException.lower(),
                                            sceneHelpers.sanitizeSceneName(
                                                curException).lower().replace(
                                                    '.', ' ')):
                        self._log(
                            u"Scene exception lookup got tvdb id " +
                            str(exceptionID) + u", using that", logger.DEBUG)
                        _finalize(parse_result)
                        return (exceptionID, season, episodes)

        # see if we can find the name directly in the DB, if so use it
        for cur_name in name_list:
            self._log(u"Looking up " + cur_name + u" in the DB", logger.DEBUG)
            db_result = helpers.searchDBForShow(cur_name)
            if db_result:
                self._log(
                    u"Lookup successful, using tvdb id " + str(db_result[0]),
                    logger.DEBUG)
                _finalize(parse_result)
                return (int(db_result[0]), season, episodes)

        # see if we can find the name with a TVDB lookup
        for cur_name in name_list:
            try:
                t = tvdb_api.Tvdb(custom_ui=classes.ShowListUI,
                                  **sickbeard.TVDB_API_PARMS)

                self._log(u"Looking up name " + cur_name + u" on TVDB",
                          logger.DEBUG)
                showObj = t[cur_name]
            except (tvdb_exceptions.tvdb_exception), e:
                # if none found, search on all languages
                try:
                    # There's gotta be a better way of doing this but we don't wanna
                    # change the language value elsewhere
                    ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()

                    ltvdb_api_parms['search_all_languages'] = True
                    t = tvdb_api.Tvdb(custom_ui=classes.ShowListUI,
                                      **ltvdb_api_parms)

                    self._log(
                        u"Looking up name " + cur_name +
                        u" in all languages on TVDB", logger.DEBUG)
                    showObj = t[cur_name]
                except (tvdb_exceptions.tvdb_exception, IOError), e:
                    pass

                continue