Esempio n. 1
0
def processFile(fileName, downloadDir=None, nzbName=None):

    returnStr = ''

    folderName = None
    if downloadDir != None:
        folderName = downloadDir.split(os.path.sep)[-1]
    
    returnStr += logHelper("Processing file "+fileName+" (with folder name "+str(folderName)+" and NZB name "+str(nzbName)+")", logger.DEBUG)

    finalNameList = []

    for curName in (fileName, folderName, nzbName):
        if curName != None:
            for curSceneName in helpers.sceneToNormalShowNames(curName):
                if curSceneName not in finalNameList:
                    finalNameList.append(curSceneName)

    showResults = None
    result = None
    
    for curName in finalNameList:
    
        try:
            returnStr += logHelper("Attempting to parse name "+curName, logger.DEBUG)
            myParser = FileParser(curName)
            result = myParser.parse()
        except tvnamer_exceptions.InvalidFilename:
            returnStr += logHelper("Unable to parse the filename "+curName+" into a valid episode", logger.DEBUG)
            continue

        if not result.seriesname:
            returnStr += logHelper("Filename "+curName+" has no series name, unable to use this name for processing", logger.DEBUG)
            continue

        try:
            t = tvdb_api.Tvdb(custom_ui=classes.ShowListUI, **sickbeard.TVDB_API_PARMS)
            showObj = t[result.seriesname]
            showInfo = (int(showObj["id"]), showObj["seriesname"])
        except (tvdb_exceptions.tvdb_exception, IOError), e:

            returnStr += logHelper("TVDB didn't respond, trying to look up the show in the DB instead: "+str(e), logger.DEBUG)

            showInfo = helpers.searchDBForShow(result.seriesname)
            
        # if we didn't get anything from TVDB or the DB then try the next option
        if showInfo == None:
            continue

        # find the show in the showlist
        try:
            showResults = helpers.findCertainShow(sickbeard.showList, showInfo[0])
        except exceptions.MultipleShowObjectsException:
            raise #TODO: later I'll just log this, for now I want to know about it ASAP
        
        if showResults != None:
            returnStr += logHelper("Found the show in our list, continuing", logger.DEBUG)
            break
Esempio n. 2
0
def processFile(fileName, downloadDir=None, nzbName=None):

    returnStr = ''

    folderName = None
    if downloadDir != None:
        folderName = downloadDir.split(os.path.sep)[-1]
    
    returnStr += logHelper("Processing file "+fileName+" (with folder name "+str(folderName)+" and NZB name "+str(nzbName)+")", logger.DEBUG)

    finalNameList = []

    for curName in (fileName, folderName, nzbName):
        if curName != None:
            for curSceneName in helpers.sceneToNormalShowNames(curName):
                if curSceneName not in finalNameList:
                    finalNameList.append(curSceneName)

    showResults = None
    result = None
    
    tvdb_id = None
    season = None
    episodes = []
        
    # first try looking up every name in our history
    for curName in finalNameList:

        historyResult = findInHistory(curName)
        if historyResult:
            returnStr += logHelper("Result from history: "+str(historyResult)+" from "+curName, logger.DEBUG)
            (tvdb_id, season, episode) = historyResult
            episodes = [episode]
            showResults = helpers.findCertainShow(sickbeard.showList, tvdb_id)
            break

    # if that didn't work then try manually parsing and searching them on TVDB
    for curName in finalNameList:
        
        # if we already have the info from the history then don't bother with this
        if tvdb_id != None and season != None and episodes != []:
            break

        # set all search stuff to defaults so we don't carry results over from the last iteration
        tvdb_id = None
        season = None
        episodes = []
        
        try:
            returnStr += logHelper("Attempting to parse name "+curName, logger.DEBUG)
            myParser = FileParser(curName)
            result = myParser.parse()
            season = result.seasonnumber
            episodes = result.episodenumbers
        except tvnamer_exceptions.InvalidFilename:
            returnStr += logHelper("Unable to parse the filename "+curName+" into a valid episode", logger.DEBUG)
            continue

        if not result.seriesname:
            returnStr += logHelper("Filename "+curName+" has no series name, unable to use this name for processing", logger.DEBUG)
            continue

        # reverse-lookup the scene exceptions
        sceneID = None
        for exceptionID in sceneExceptions:
            if curName == sceneExceptions[exceptionID]:
                sceneID = exceptionID
                break

        try:
            if result.seriesname == "CSI":
                result.seriesname = "CSI: Crime Scene Investigation"
                returnStr += logHelper("Override CSI to CSI: Crime Scene Investigation", logger.DEBUG)

            returnStr += logHelper("Looking up name "+result.seriesname+" on TVDB", logger.DEBUG)
            t = tvdb_api.Tvdb(custom_ui=classes.ShowListUI, **sickbeard.TVDB_API_PARMS)

            # get the tvdb object from either the scene exception ID or the series name
            if sceneID:
                showObj = t[sceneID]
            else:
                showObj = t[result.seriesname]
            
            showInfo = (int(showObj["id"]), showObj["seriesname"])
        except (tvdb_exceptions.tvdb_exception, IOError), e:

            returnStr += logHelper("Unable to look up show on TVDB: "+str(e), logger.DEBUG)
            returnStr += logHelper("Looking up show in DB instead", logger.DEBUG)
            showInfo = helpers.searchDBForShow(result.seriesname)

        if showInfo:
            tvdb_id = showInfo[0]


        # if we couldn't get the necessary info from either of the above methods, try the next name
        if tvdb_id == None or season == None or episodes == []:
            continue

        # find the show in the showlist
        try:
            showResults = helpers.findCertainShow(sickbeard.showList, showInfo[0])
        except exceptions.MultipleShowObjectsException:
            raise #TODO: later I'll just log this, for now I want to know about it ASAP

        if showResults != None:
            returnStr += logHelper("Found the show in our list, continuing", logger.DEBUG)
            break
Esempio n. 3
0
def processFile(fileName, downloadDir=None, nzbName=None):

    returnStr = ''

    folderName = None
    if downloadDir != None:
        folderName = downloadDir.split(os.path.sep)[-1]
    
    returnStr += logHelper("Processing file "+fileName+" (with folder name "+str(folderName)+" and NZB name "+str(nzbName)+")", logger.DEBUG)

    finalNameList = []

    for curName in (fileName, folderName, nzbName):
        if curName != None:
            for curSceneName in helpers.sceneToNormalShowNames(curName):
                if curSceneName not in finalNameList:
                    finalNameList.append(curSceneName)

    showResults = None
    result = None
    
    tvdb_id = None
    season = None
    episodes = []
        
    # first try looking up every name in our history
    for curName in finalNameList:

        historyResult = findInHistory(curName)
        if historyResult:
            returnStr += logHelper("Result from history: "+str(historyResult)+" from "+curName, logger.DEBUG)
            (tvdb_id, season, episode) = historyResult
            episodes = [episode]
            showResults = helpers.findCertainShow(sickbeard.showList, tvdb_id)
            break

    # if that didn't work then try manually parsing and searching them on TVDB
    for curName in finalNameList:
        
        # if we already have the info from the history then don't bother with this
        if tvdb_id != None and season != None and episodes != []:
            break

        # set all search stuff to defaults so we don't carry results over from the last iteration
        tvdb_id = None
        season = None
        episodes = []
        
        try:
            returnStr += logHelper("Attempting to parse name "+curName, logger.DEBUG)
            myParser = FileParser(curName)
            result = myParser.parse()

            season = result.seasonnumber
            episodes = result.episodenumbers
            
        except tvnamer_exceptions.InvalidFilename:
            returnStr += logHelper("Unable to parse the filename "+curName+" into a valid episode", logger.DEBUG)
            continue

        if not result.seriesname:
            returnStr += logHelper("Filename "+curName+" has no series name, unable to use this name for processing", logger.DEBUG)
            continue

        # reverse-lookup the scene exceptions
        sceneID = None
        for exceptionID in sceneExceptions:
            if curName == sceneExceptions[exceptionID]:
                sceneID = exceptionID
                break

        try:
            returnStr += logHelper("Looking up name "+result.seriesname+" on TVDB", logger.DEBUG)
            t = tvdb_api.Tvdb(custom_ui=classes.ShowListUI, **sickbeard.TVDB_API_PARMS)

            # get the tvdb object from either the scene exception ID or the series name
            if sceneID:
                showObj = t[sceneID]
            else:
                showObj = t[result.seriesname]
            
            showInfo = (int(showObj["id"]), showObj["seriesname"])
        except (tvdb_exceptions.tvdb_exception, IOError), e:

            returnStr += logHelper("Unable to look up show on TVDB: "+str(e), logger.DEBUG)
            returnStr += logHelper("Looking up show in DB instead", logger.DEBUG)
            showInfo = helpers.searchDBForShow(result.seriesname)

        if showInfo:
            tvdb_id = showInfo[0]

        # if it is an air-by-date show and we successfully found it on TVDB, convert the date into a season/episode
        if season == -1 and showObj:
            try:
                epObj = showObj.airedOn(episodes[0])[0]
                season = int(epObj["seasonnumber"])
                episodes = [int(epObj["episodenumber"])]
            except tvdb_exceptions.tvdb_episodenotfound, e:
                returnStr += logHelper("Unable to find episode with date "+str(episodes[0])+" for show "+showObj["seriesname"]+", skipping", logger.DEBUG)
                continue