Ejemplo n.º 1
0
def searchForNeededEpisodes():
	
	logger.log("Searching all providers for any needed episodes")

	foundResults = {}

	didSearch = False

	# ask all providers for any episodes it finds
	for curProvider in providers.getAllModules():
		
		if not curProvider.isActive():
			continue
		
		curFoundResults = {}
		
		try:
			curFoundResults = curProvider.searchRSS()
		except exceptions.AuthException, e:
			logger.log("Authentication error: "+str(e), logger.ERROR)
			continue
		except Exception, e:
			logger.log("Error while searching "+curProvider.providerName+", skipping: "+str(e), logger.ERROR)
			logger.log(traceback.format_exc(), logger.DEBUG)
			continue
Ejemplo n.º 2
0
def findSeason(show, season):
	
	logger.log("Searching for stuff we need from "+show.name+" season "+str(season))
	
	foundResults = {}
	
	for curProvider in providers.getAllModules():
		
		if not curProvider.isActive():
			continue
		
		try:
			curResults = curProvider.findSeasonResults(show, season)

			for curEp in curResults:
				# skip non-tv crap
				curResults[curEp] = filter(lambda x: all([y not in x.extraInfo[0].lower() for y in resultFilters]), curResults[curEp])
				
				if curEp in foundResults:
					foundResults[curEp] += curResults[curEp]
				else:
					foundResults[curEp] = curResults[curEp]
		except exceptions.AuthException, e:
			logger.log("Authentication error: "+str(e), logger.ERROR)
			continue
		except Exception, e:
			logger.log("Error while searching "+curProvider.providerName+", skipping: "+str(e), logger.ERROR)
			logger.log(traceback.format_exc(), logger.DEBUG)
			continue
Ejemplo n.º 3
0
def findSeason(show, season):
	
	logger.log("Searching for stuff we need from "+show.name+" season "+str(season))
	
	foundResults = {}
	
	didSearch = False
	
	for curProvider in providers.getAllModules():
		
		if not curProvider.isActive():
			continue
		
		try:
			curResults = curProvider.findSeasonResults(show, season)

			# make a list of all the results for this provider
			for curEp in curResults:
				
				# skip non-tv crap
				curResults[curEp] = filter(lambda x:  sceneHelpers.filterBadReleases(x.name) and isGoodResult(x, show), curResults[curEp])

				if curEp in foundResults:
					foundResults[curEp] += curResults[curEp]
				else:
					foundResults[curEp] = curResults[curEp]
		
		except exceptions.AuthException, e:
			logger.log("Authentication error: "+str(e), logger.ERROR)
			continue
		except Exception, e:
			logger.log("Error while searching "+curProvider.providerName+", skipping: "+str(e), logger.ERROR)
			logger.log(traceback.format_exc(), logger.DEBUG)
			continue
Ejemplo n.º 4
0
def findEpisode(episode, manualSearch=False):

	logger.log("Searching for " + episode.prettyName(True))

	foundResults = []

	didSearch = False

	for curProvider in providers.getAllModules():
		
		if not curProvider.isActive():
			continue
		
		try:
			foundResults = curProvider.findEpisode(episode, manualSearch=manualSearch)
		except exceptions.AuthException, e:
			logger.log("Authentication error: "+str(e), logger.ERROR)
			continue
		except Exception, e:
			logger.log("Error while searching "+curProvider.providerName+", skipping: "+str(e), logger.ERROR)
			logger.log(traceback.format_exc(), logger.DEBUG)
			continue
Ejemplo n.º 5
0
def findEpisode(episode):

	logger.log("Searching for " + episode.prettyName(True))

	foundEps = []

	didSearch = False

	for curProvider in providers.getAllModules():
		
		if not curProvider.isActive():
			continue
		
		try:
			foundEps = _doSearch(episode, curProvider)
		except exceptions.AuthException, e:
			logger.log("Authentication error: "+str(e), logger.ERROR)
			continue
		
		didSearch = True
		
		if len(foundEps) > 0:
			break
Ejemplo n.º 6
0
    def _getProperList(self):
    
        propers = {}
        
        # for each provider get a list of the propers
        for curProvider in providers.getAllModules():
            
            if not curProvider.isActive():
                continue

            date = datetime.datetime.today() - datetime.timedelta(days=2)

            logger.log("Searching for any new PROPER releases from "+curProvider.providerName)
            curPropers = curProvider.findPropers(date)
            
            # if they haven't been added by a different provider than add the proper to the list
            for x in curPropers:
                name = self._genericName(x.name)

                if not name in propers:
                    logger.log("Found new proper: "+x.name, logger.DEBUG)
                    x.provider = curProvider
                    propers[name] = x

        # take the list of unique propers and get it sorted by 
        sortedPropers = sorted(propers.values(), key=operator.attrgetter('date'), reverse=True)
        finalPropers = []

        for curProper in sortedPropers:

            # parse the file name
            try:
                myParser = FileParser(curProper.name)
                epInfo = myParser.parse()
            except tvnamer_exceptions.InvalidFilename:
                logger.log("Unable to parse the filename "+curProper.name+" into a valid episode", logger.ERROR)
                continue
    
            if not epInfo.episodenumbers:
                logger.log("Ignoring "+curProper.name+" because it's for a full season rather than specific episode", logger.DEBUG)
                continue
    
            # populate our Proper instance
            curProper.season = epInfo.seasonnumber
            curProper.episode = epInfo.episodenumbers[0]
            curProper.quality = Quality.nameQuality(curProper.name)
    
            # for each show in our list
            for curShow in sickbeard.showList:
        
                genericName = self._genericName(epInfo.seriesname)
        
                # get the scene name masks
                sceneNames = set(sceneHelpers.makeSceneShowSearchStrings(curShow))
        
                # for each scene name mask
                for curSceneName in sceneNames:
        
                    # if it matches
                    if genericName == self._genericName(curSceneName):
                        logger.log("Successful match! Result "+epInfo.seriesname+" matched to show "+curShow.name, logger.DEBUG)
                        
                        # set the tvdbid in the db to the show's tvdbid
                        curProper.tvdbid = curShow.tvdbid
                        
                        # since we found it, break out
                        break
                
                # if we found something in the inner for loop break out of this one
                if curProper.tvdbid != -1:
                    break

            if curProper.tvdbid == -1:
                continue

            # if we have an air-by-date show then get the real season/episode numbers
            if curProper.season == -1 and curProper.tvdbid:
                try:
                    t = tvdb_api.Tvdb(**sickbeard.TVDB_API_PARMS)
                    epObj = t[curProper.tvdbid].airedOn(curProper.episode)[0]
                    season = int(epObj["seasonnumber"])
                    episodes = [int(epObj["episodenumber"])]
                except tvdb_exceptions.tvdb_episodenotfound, e:
                    logger.log("Unable to find episode with date "+str(curProper.episode)+" for show "+epInfo.seriesname+", skipping", logger.WARNING)
                    continue

            # check if we actually want this proper (if it's the right quality)
            sqlResults = db.DBConnection().select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?", [curProper.tvdbid, curProper.season, curProper.episode])
            if not sqlResults:
                continue
            oldStatus, oldQuality = Quality.splitCompositeStatus(int(sqlResults[0]["status"]))
            
            # only keep the proper if we have already retrieved the same quality ep (don't get better/worse ones) 
            if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != curProper.quality:
                continue

            # if the show is in our list and there hasn't been a proper already added for that particular episode then add it to our list of propers
            if curProper.tvdbid != -1 and (curProper.tvdbid, curProper.season, curProper.episode) not in map(operator.attrgetter('tvdbid', 'season', 'episode'), finalPropers):
                logger.log("Found a proper that we need: "+str(curProper.name))
                finalPropers.append(curProper)
Ejemplo n.º 7
0
    def _getProperList(self):
    
        propers = {}
        
        # for each provider get a list of the propers
        for curProvider in providers.getAllModules():
            
            if not curProvider.isActive():
                continue

            date = datetime.datetime.today() - datetime.timedelta(days=2)

            logger.log("Searching for any new PROPER releases from "+curProvider.providerName)
            curPropers = curProvider.findPropers(date)
            
            # if they haven't been added by a different provider than add the proper to the list
            for x in curPropers:
                name = self._genericName(x.name)

                if not name in propers:
                    logger.log("Found new proper: "+x.name, logger.DEBUG)
                    x.provider = curProvider
                    propers[name] = x

        # take the list of unique propers and get it sorted by 
        sortedPropers = sorted(propers.values(), key=operator.attrgetter('date'), reverse=True)
        finalPropers = []

        for curProper in sortedPropers:

            try:
                myParser = FileParser(curProper.name)
                epInfo = myParser.parse()
            except tvnamer_exceptions.InvalidFilename:
                logger.log("Unable to parse the filename "+curProper.name+" into a valid episode", logger.ERROR)
                continue
    
            curProper.season = epInfo.seasonnumber
            curProper.episode = epInfo.episodenumbers[0]
    
            curProper.quality = helpers.guessSceneEpisodeQuality(curProper.name)
    
            # for each show in our list
            for curShow in sickbeard.showList:
        
                genericName = self._genericName(epInfo.seriesname)
        
                # get the scene name masks
                sceneNames = set(helpers.makeSceneShowSearchStrings(curShow))
        
                # for each scene name mask
                for curSceneName in sceneNames:
        
                    # if it matches
                    if genericName == self._genericName(curSceneName):
                        logger.log("Successful match! Result "+epInfo.seriesname+" matched to show "+curShow.name, logger.DEBUG)
                        
                        # set the tvdbid in the db to the show's tvdbid
                        curProper.tvdbid = curShow.tvdbid
                        
                        # since we found it, break out
                        break
                
                # if we found something in the inner for loop break out of this one
                if curProper.tvdbid != -1:
                    break

            # if the show is in our list and there hasn't been a proper already added for that particular episode then add it to our list of propers
            if curProper.tvdbid != -1 and (curProper.tvdbid, curProper.season, curProper.episode) not in map(operator.attrgetter('tvdbid', 'season', 'episode'), finalPropers):
                logger.log("Found a proper that we need: "+str(curProper.name))
                finalPropers.append(curProper)
        
        return finalPropers