mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Fixed more issues with post processing TVRage shows
This commit is contained in:
parent
d282f76052
commit
688888b17c
6 changed files with 73 additions and 43 deletions
|
@ -1,4 +1,5 @@
|
|||
#import sickbeard
|
||||
#from sickbeard.common import indexerStrings
|
||||
#set global $header="Post Processing"
|
||||
#set global $title="Post Processing"
|
||||
|
||||
|
@ -15,7 +16,14 @@
|
|||
<form name="processForm" method="post" action="processEpisode" style="line-height: 44px">
|
||||
<input type="hidden" id="type" name="type" value="manual">
|
||||
<b>Enter the folder containing the episode:</b> <input type="text" name="dir" id="episodeDir" size="50" /><br/>
|
||||
<b>Process Method to be used:</b>
|
||||
<b>Show Indexer to be used:</b>
|
||||
<select name="indexer" id="indexer" class="indexer">
|
||||
#for $curIndexer in sorted($indexerStrings.items(), key=lambda x: x[1]):
|
||||
<option value="$curIndexer[0]" #if $curIndexer[0] in $indexerStrings then "selected=\"selected\"" else ""#>$curIndexer[1]</option>
|
||||
#end for
|
||||
</select>
|
||||
<br/>
|
||||
<b>Process Method to be used:</b>
|
||||
<select name="process_method" id="process_method" class="input-medium" >
|
||||
#set $process_method_text = {'copy': "Copy", 'move': "Move", 'hardlink': "Hard Link", 'symlink' : "Symbolic Link"}
|
||||
#for $curAction in ('copy', 'move', 'hardlink', 'symlink'):
|
||||
|
|
|
@ -263,6 +263,8 @@ class TVRage:
|
|||
|
||||
self.config['debug_enabled'] = debug # show debugging messages
|
||||
|
||||
self.config['custom_ui'] = custom_ui
|
||||
|
||||
if cache is True:
|
||||
self.config['cache_enabled'] = True
|
||||
self.config['cache_location'] = self._getTempDir()
|
||||
|
@ -487,15 +489,36 @@ class TVRage:
|
|||
"""This searches tvrage.com for the series name
|
||||
and returns the result list
|
||||
"""
|
||||
|
||||
remap_keys = {
|
||||
'showid': 'id',
|
||||
'epnum': 'id',
|
||||
'started': 'firstaired',
|
||||
'airdate': 'firstaired',
|
||||
'genres': 'genre',
|
||||
'airtime': 'airs_time',
|
||||
'name': 'seriesname',
|
||||
'image': 'image_type',
|
||||
'airday': 'airs_dayofweek',
|
||||
'title': 'episodename',
|
||||
'seasonnum': 'episodenumber'
|
||||
}
|
||||
|
||||
series = urllib.quote(series.encode("utf-8"))
|
||||
log().debug("Searching for show %s" % series)
|
||||
seriesEt = self._getetsrc(self.config['url_getSeries'] % (series))
|
||||
allSeries = []
|
||||
seriesResult = {}
|
||||
for series in seriesEt:
|
||||
result = dict((k.tag.lower(), k.text) for k in series.getchildren())
|
||||
result['showid'] = int(result['showid'])
|
||||
log().debug('Found series %(name)s' % result)
|
||||
allSeries.append(result)
|
||||
for k in series.getchildren():
|
||||
if k.tag.lower() in remap_keys:
|
||||
seriesResult.setdefault(remap_keys[k.tag.lower()], k.text)
|
||||
else:
|
||||
seriesResult.setdefault(k.tag.lower(), k.text)
|
||||
|
||||
seriesResult['id'] = int(seriesResult['id'])
|
||||
log().debug('Found series %s' % seriesResult['seriesname'])
|
||||
allSeries.append(seriesResult)
|
||||
|
||||
return allSeries
|
||||
|
||||
|
@ -511,8 +534,12 @@ class TVRage:
|
|||
log().debug('Series result returned zero')
|
||||
raise tvrage_shownotfound("Show-name search returned zero results (cannot find show on TVRAGE)")
|
||||
|
||||
log().debug('Auto-selecting first search result using BaseUI')
|
||||
ui = BaseUI(config = self.config)
|
||||
if self.config['custom_ui'] is not None:
|
||||
log().debug("Using custom UI %s" % (repr(self.config['custom_ui'])))
|
||||
ui = self.config['custom_ui'](config = self.config)
|
||||
else:
|
||||
log().debug('Auto-selecting first search result using BaseUI')
|
||||
ui = BaseUI(config = self.config)
|
||||
|
||||
return ui.selectSeries(allSeries)
|
||||
|
||||
|
|
|
@ -100,7 +100,8 @@ ep_regexes = [
|
|||
# Show.Name.2010.Nov.23rd.Source.Quality.Etc-Group
|
||||
# Show Name - 2010-Nov-23rd - Ep Name
|
||||
'''
|
||||
^((?P<series_name>.+?)[. _-]+)? # Show_Name and separator
|
||||
^((?P<series_name>.*?(UEFA|MLB|ESPN|WWE|MMA|UFC|TNA|EPL|NASCAR|NBA|NFL|NHL|NRL|PGA|SUPER LEAGUE|FORMULA|FIFA|NETBALL|MOTOGP).*?)[. _-]+)? # Show_Name and separator
|
||||
(?P<part_name>.+?)[. _-]+
|
||||
(?P<air_day>\d+)(?:[a-zA-Z]{2})[. _-]+ # 23rd and seperator
|
||||
(?P<air_month>[a-zA-Z]{3})[. _-]+ # Nov and seperator
|
||||
(?P<air_year>\d{4}) # 2010
|
||||
|
|
|
@ -65,7 +65,7 @@ class PostProcessor(object):
|
|||
FOLDER_NAME = 2
|
||||
FILE_NAME = 3
|
||||
|
||||
def __init__(self, file_path, nzb_name=None, process_method=None, is_priority=None):
|
||||
def __init__(self, file_path, nzb_name=None, process_method=None, is_priority=None, indexer=None):
|
||||
"""
|
||||
Creates a new post processor with the given file path and optionally an NZB name.
|
||||
|
||||
|
@ -95,12 +95,15 @@ class PostProcessor(object):
|
|||
|
||||
self.is_priority = is_priority
|
||||
|
||||
self.indexer = indexer
|
||||
|
||||
self.good_results = {self.NZB_NAME: False,
|
||||
self.FOLDER_NAME: False,
|
||||
self.FILE_NAME: False}
|
||||
|
||||
self.log = ''
|
||||
|
||||
|
||||
def _log(self, message, level=logger.MESSAGE):
|
||||
"""
|
||||
A wrapper for the internal logger which also keeps track of messages and saves them to a string for later.
|
||||
|
@ -514,42 +517,30 @@ class PostProcessor(object):
|
|||
# see if we can find the name with a TVDB lookup
|
||||
for cur_name in name_list:
|
||||
try:
|
||||
sickbeard.INDEXER_API_PARMS['indexer'] = 'Tvdb'
|
||||
t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **sickbeard.INDEXER_API_PARMS)
|
||||
|
||||
self._log(u"Looking up name " + cur_name + u" on " + t.name + "", logger.DEBUG)
|
||||
self._log(u"Looking up name " + cur_name + u" on " + self.indexer + "", logger.DEBUG)
|
||||
showObj = t[cur_name]
|
||||
except (indexer_exceptions.indexer_exception, IOError):
|
||||
# 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
|
||||
sickbeard.INDEXER_API_PARMS['indexer'] = 'Tvdb'
|
||||
lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy()
|
||||
|
||||
lINDEXER_API_PARMS['search_all_languages'] = True
|
||||
t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **lINDEXER_API_PARMS)
|
||||
|
||||
self._log(u"Looking up name " + cur_name + u" in all languages on " + t.name + "", logger.DEBUG)
|
||||
self._log(u"Looking up name " + cur_name + u" in all languages on " + self.indexer + "", logger.DEBUG)
|
||||
showObj = t[cur_name]
|
||||
except (indexer_exceptions.indexer_exception, IOError):
|
||||
# if none found, search on TVRage
|
||||
try:
|
||||
sickbeard.INDEXER_API_PARMS['indexer'] = 'TVRage'
|
||||
lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy()
|
||||
|
||||
t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **lINDEXER_API_PARMS)
|
||||
|
||||
self._log(u"Looking up name " + cur_name + u" in all languages on " + t.name + "", logger.DEBUG)
|
||||
showObj = t[cur_name]
|
||||
except (indexer_exceptions.indexer_exception, IOError):
|
||||
pass
|
||||
pass
|
||||
|
||||
continue
|
||||
except (IOError):
|
||||
continue
|
||||
|
||||
self._log(u"Lookup successful, using " + sickbeard.INDEXER_API_PARMS['indexer'] + " id " + str(showObj["id"]), logger.DEBUG)
|
||||
self._log(u"Lookup successful, using " + self.indexer + " id " + str(showObj["id"]), logger.DEBUG)
|
||||
_finalize(parse_result)
|
||||
return (int(showObj["id"]), season, episodes)
|
||||
|
||||
|
@ -563,7 +554,6 @@ class PostProcessor(object):
|
|||
"""
|
||||
|
||||
indexer_id = season = None
|
||||
indexer = 'Indexer'
|
||||
episodes = []
|
||||
|
||||
# try to look up the nzb in history
|
||||
|
@ -613,7 +603,6 @@ class PostProcessor(object):
|
|||
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
|
||||
if(showObj != None):
|
||||
indexer_lang = showObj.lang
|
||||
indexer = showObj.indexer
|
||||
except exceptions.MultipleShowObjectsException:
|
||||
raise #TODO: later I'll just log this, for now I want to know about it ASAP
|
||||
|
||||
|
@ -636,7 +625,7 @@ class PostProcessor(object):
|
|||
episodes = []
|
||||
continue
|
||||
except indexer_exceptions.indexer_error, e:
|
||||
logger.log(u"Unable to contact " + showObj.indexer + ": " + ex(e), logger.WARNING)
|
||||
logger.log(u"Unable to contact " + self.indexer + ": " + ex(e), logger.WARNING)
|
||||
episodes = []
|
||||
continue
|
||||
|
||||
|
@ -649,9 +638,9 @@ class PostProcessor(object):
|
|||
season = 1
|
||||
|
||||
if indexer_id and season != None and episodes:
|
||||
return (indexer, indexer_id, season, episodes)
|
||||
return (indexer_id, season, episodes)
|
||||
|
||||
return (indexer, indexer_id, season, episodes)
|
||||
return (indexer_id, season, episodes)
|
||||
|
||||
def _get_ep_obj(self, indexer_id, season, episodes):
|
||||
"""
|
||||
|
@ -814,6 +803,11 @@ class PostProcessor(object):
|
|||
Post-process a given file
|
||||
"""
|
||||
|
||||
if self.indexer is not None:
|
||||
sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer
|
||||
else:
|
||||
sickbeard.INDEXER_API_PARMS['indexer'] = 'Tvdb'
|
||||
|
||||
self._log(u"Processing " + self.file_path + " (" + str(self.nzb_name) + ")")
|
||||
|
||||
if ek.ek(os.path.isdir, self.file_path):
|
||||
|
@ -827,11 +821,11 @@ class PostProcessor(object):
|
|||
self.in_history = False
|
||||
|
||||
# try to find the file info
|
||||
(indexer, indexer_id, season, episodes) = self._find_info()
|
||||
(indexer_id, season, episodes) = self._find_info()
|
||||
|
||||
# if we don't have it then give up
|
||||
if not indexer_id or season == None or not episodes:
|
||||
self._log(u"Can't find show id from " + indexer + " or season or episode, skipping", logger.WARNING)
|
||||
self._log(u"Can't find show id from " + self.indexer + " or season or episode, skipping", logger.WARNING)
|
||||
return False
|
||||
|
||||
# retrieve/create the corresponding TVEpisode objects
|
||||
|
|
|
@ -40,7 +40,7 @@ def logHelper (logMessage, logLevel=logger.MESSAGE):
|
|||
logger.log(logMessage, logLevel)
|
||||
return logMessage + u"\n"
|
||||
|
||||
def processDir(dirName, nzbName=None, process_method=None, force=False, is_priority=None, failed=False, type="auto"):
|
||||
def processDir(dirName, nzbName=None, process_method=None, force=False, is_priority=None, failed=False, type="auto", indexer="Tvdb"):
|
||||
"""
|
||||
Scans through the files in dirName and processes whatever media files it finds
|
||||
|
||||
|
@ -102,13 +102,13 @@ def processDir(dirName, nzbName=None, process_method=None, force=False, is_prior
|
|||
|
||||
#Don't Link media when the media is extracted from a rar in the same path
|
||||
if process_method in ('hardlink', 'symlink') and videoInRar:
|
||||
process_media(path, videoInRar, nzbName, 'move', force, is_priority)
|
||||
process_media(path, videoInRar, nzbName, 'move', force, is_priority, indexer)
|
||||
delete_files(path, rarContent)
|
||||
for video in set(videoFiles) - set(videoInRar):
|
||||
process_media(path, [video], nzbName, process_method, force, is_priority)
|
||||
process_media(path, [video], nzbName, process_method, force, is_priority, indexer)
|
||||
else:
|
||||
for video in videoFiles:
|
||||
process_media(path, [video], nzbName, process_method, force, is_priority)
|
||||
process_media(path, [video], nzbName, process_method, force, is_priority, indexer)
|
||||
|
||||
#Process Video File in all TV Subdir
|
||||
for dir in [x for x in dirs if validateDir(path, x, nzbNameOriginal, failed)]:
|
||||
|
@ -126,11 +126,11 @@ def processDir(dirName, nzbName=None, process_method=None, force=False, is_prior
|
|||
|
||||
#Don't Link media when the media is extracted from a rar in the same path
|
||||
if process_method in ('hardlink', 'symlink') and videoInRar:
|
||||
process_media(processPath, videoInRar, nzbName, 'move', force, is_priority)
|
||||
process_media(processPath, set(videoFiles) - set(videoInRar), nzbName, process_method, force, is_priority)
|
||||
process_media(processPath, videoInRar, nzbName, 'move', force, is_priority, indexer)
|
||||
process_media(processPath, set(videoFiles) - set(videoInRar), nzbName, process_method, force, is_priority, indexer)
|
||||
delete_files(processPath, rarContent)
|
||||
else:
|
||||
process_media(processPath, videoFiles, nzbName, process_method, force, is_priority)
|
||||
process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, indexer)
|
||||
|
||||
#Delete all file not needed
|
||||
if process_method != "move" or not process_result \
|
||||
|
@ -289,7 +289,7 @@ def already_postprocessed(dirName, videofile, force):
|
|||
|
||||
return False
|
||||
|
||||
def process_media(processPath, videoFiles, nzbName, process_method, force, is_priority):
|
||||
def process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, indexer):
|
||||
|
||||
global process_result, returnStr
|
||||
|
||||
|
@ -301,7 +301,7 @@ def process_media(processPath, videoFiles, nzbName, process_method, force, is_pr
|
|||
cur_video_file_path = ek.ek(os.path.join, processPath, cur_video_file)
|
||||
|
||||
try:
|
||||
processor = postProcessor.PostProcessor(cur_video_file_path, nzbName, process_method, is_priority)
|
||||
processor = postProcessor.PostProcessor(cur_video_file_path, nzbName, process_method, is_priority, indexer)
|
||||
process_result = processor.process()
|
||||
process_fail_message = ""
|
||||
except exceptions.PostProcessingFailed, e:
|
||||
|
|
|
@ -1845,7 +1845,7 @@ class HomePostProcess:
|
|||
return _munge(t)
|
||||
|
||||
@cherrypy.expose
|
||||
def processEpisode(self, dir=None, nzbName=None, jobName=None, quiet=None, process_method=None, force=None, is_priority=None, failed="0", type="auto"):
|
||||
def processEpisode(self, dir=None, nzbName=None, jobName=None, quiet=None, process_method=None, force=None, is_priority=None, failed="0", type="auto", indexer="Tvdb"):
|
||||
|
||||
if failed == "0":
|
||||
failed = False
|
||||
|
@ -1865,7 +1865,7 @@ class HomePostProcess:
|
|||
if not dir:
|
||||
redirect("/home/postprocess/")
|
||||
else:
|
||||
result = processTV.processDir(dir, nzbName, process_method=process_method, force=force, is_priority=is_priority, failed=failed, type=type)
|
||||
result = processTV.processDir(dir, nzbName, process_method=process_method, force=force, is_priority=is_priority, failed=failed, type=type, indexer=indexer)
|
||||
if quiet != None and int(quiet) == 1:
|
||||
return result
|
||||
|
||||
|
|
Loading…
Reference in a new issue