|
|
@ -56,13 +56,13 @@ from sickbeard.common import USER_AGENT, mediaExtensions, subtitleExtensions, XM |
|
|
|
from sickbeard import db |
|
|
|
from sickbeard import encodingKludge as ek |
|
|
|
from sickbeard import notifiers |
|
|
|
from sickbeard import exceptions |
|
|
|
from lib import subliminal |
|
|
|
|
|
|
|
urllib._urlopener = classes.SickBeardURLopener() |
|
|
|
|
|
|
|
session = requests.Session() |
|
|
|
|
|
|
|
|
|
|
|
def indentXML(elem, level=0): |
|
|
|
''' |
|
|
|
Does our pretty printing, makes Matt very happy |
|
|
@ -191,11 +191,13 @@ def getURL(url, post_data=None, headers=None, params=None, timeout=30, json=Fals |
|
|
|
proxies = { |
|
|
|
"http": sickbeard.PROXY_SETTING, |
|
|
|
"https": sickbeard.PROXY_SETTING, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
r = session.get(url, params=params, data=post_data, headers=dict(zip(it, it)), proxies=proxies, timeout=timeout, verify=False) |
|
|
|
r = session.get(url, params=params, data=post_data, headers=dict(zip(it, it)), proxies=proxies, |
|
|
|
timeout=timeout, verify=False) |
|
|
|
else: |
|
|
|
r = session.get(url, params=params, data=post_data, headers=dict(zip(it, it)), timeout=timeout, verify=False) |
|
|
|
r = session.get(url, params=params, data=post_data, headers=dict(zip(it, it)), timeout=timeout, |
|
|
|
verify=False) |
|
|
|
except requests.HTTPError, e: |
|
|
|
logger.log(u"HTTP error " + str(e.errno) + " while loading URL " + url, logger.WARNING) |
|
|
|
return None |
|
|
@ -288,28 +290,14 @@ def searchDBForShow(regShowName): |
|
|
|
yearRegex = "([^()]+?)\s*(\()?(\d{4})(?(2)\))$" |
|
|
|
|
|
|
|
for showName in showNames: |
|
|
|
|
|
|
|
show = get_show_by_name(showName, sickbeard.showList) |
|
|
|
if show: |
|
|
|
sqlResults = myDB.select("SELECT * FROM tv_shows WHERE show_name LIKE ? OR show_name LIKE ?", |
|
|
|
[show.name, show.name]) |
|
|
|
else: |
|
|
|
sqlResults = myDB.select("SELECT * FROM tv_shows WHERE show_name LIKE ? OR show_name LIKE ?", |
|
|
|
[showName, showName]) |
|
|
|
|
|
|
|
if len(sqlResults) == 1: |
|
|
|
return (int(sqlResults[0]["indexer"]), int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"]) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
# if we didn't get exactly one result then try again with the year stripped off if possible |
|
|
|
match = re.match(yearRegex, showName) |
|
|
|
if match and match.group(1): |
|
|
|
logger.log(u"Unable to match original name but trying to manually strip and specify show year", |
|
|
|
logger.DEBUG) |
|
|
|
sqlResults = myDB.select( |
|
|
|
"SELECT * FROM tv_shows WHERE (show_name LIKE ? OR show_name LIKE ?) AND startyear = ?", |
|
|
|
[match.group(1) + '%', match.group(1) + '%', match.group(3)]) |
|
|
|
# if we didn't get exactly one result then try again with the year stripped off if possible |
|
|
|
match = re.match(yearRegex, showName) |
|
|
|
if match and match.group(1): |
|
|
|
logger.log(u"Unable to match original name but trying to manually strip and specify show year", |
|
|
|
logger.DEBUG) |
|
|
|
sqlResults = myDB.select( |
|
|
|
"SELECT * FROM tv_shows WHERE (show_name LIKE ? OR show_name LIKE ?) AND startyear = ?", |
|
|
|
[match.group(1) + '%', match.group(1) + '%', match.group(3)]) |
|
|
|
|
|
|
|
if len(sqlResults) == 0: |
|
|
|
logger.log(u"Unable to match a record in the DB for " + showName, logger.DEBUG) |
|
|
@ -320,9 +308,6 @@ def searchDBForShow(regShowName): |
|
|
|
else: |
|
|
|
return (int(sqlResults[0]["indexer"]), int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"]) |
|
|
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=None): |
|
|
|
showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName])) |
|
|
|
|
|
|
@ -330,7 +315,7 @@ def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=None): |
|
|
|
for indexer in sickbeard.indexerApi().indexers if not indexer else [int(indexer)]: |
|
|
|
# Query Indexers for each search term and build the list of results |
|
|
|
lINDEXER_API_PARMS = sickbeard.indexerApi(indexer).api_params.copy() |
|
|
|
if ui:lINDEXER_API_PARMS['custom_ui'] = ui |
|
|
|
if ui: lINDEXER_API_PARMS['custom_ui'] = ui |
|
|
|
t = sickbeard.indexerApi(indexer).indexer(**lINDEXER_API_PARMS) |
|
|
|
|
|
|
|
for name in showNames: |
|
|
@ -354,6 +339,7 @@ def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=None): |
|
|
|
except Exception: |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
def sizeof_fmt(num): |
|
|
|
''' |
|
|
|
>>> sizeof_fmt(2) |
|
|
@ -430,11 +416,13 @@ def symlink(src, dst): |
|
|
|
if os.name == 'nt': |
|
|
|
import ctypes |
|
|
|
|
|
|
|
if ctypes.windll.kernel32.CreateSymbolicLinkW(unicode(dst), unicode(src), 1 if os.path.isdir(src) else 0) in [0,1280]: |
|
|
|
if ctypes.windll.kernel32.CreateSymbolicLinkW(unicode(dst), unicode(src), 1 if os.path.isdir(src) else 0) in [0, |
|
|
|
1280]: |
|
|
|
raise ctypes.WinError() |
|
|
|
else: |
|
|
|
os.symlink(src, dst) |
|
|
|
|
|
|
|
|
|
|
|
def moveAndSymlinkFile(srcFile, destFile): |
|
|
|
try: |
|
|
|
ek.ek(os.rename, srcFile, destFile) |
|
|
@ -652,7 +640,7 @@ def fixSetGroupID(childPath): |
|
|
|
except OSError: |
|
|
|
logger.log( |
|
|
|
u"Failed to respect the set-group-ID bit on the parent directory for %s (setting group ID %i)" % ( |
|
|
|
childPath, parentGID), logger.ERROR) |
|
|
|
childPath, parentGID), logger.ERROR) |
|
|
|
|
|
|
|
|
|
|
|
def sanitizeSceneName(name, ezrss=False): |
|
|
@ -944,21 +932,58 @@ def _check_against_names(name, show): |
|
|
|
|
|
|
|
for showName in showNames: |
|
|
|
nameFromList = full_sanitizeSceneName(showName) |
|
|
|
#logger.log(u"Comparing names: '"+nameFromList+"' vs '"+nameInQuestion+"'", logger.DEBUG) |
|
|
|
if nameFromList == nameInQuestion: |
|
|
|
return True |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def get_show_by_name(name, showList, useIndexer=False): |
|
|
|
if showList: |
|
|
|
for show in showList: |
|
|
|
def get_show_by_name(name, useIndexer=False): |
|
|
|
in_cache = False |
|
|
|
foundResult = None |
|
|
|
|
|
|
|
logger.log( |
|
|
|
u"Checking the cahe for:" + str(name), |
|
|
|
logger.DEBUG) |
|
|
|
|
|
|
|
cacheResult = sickbeard.name_cache.retrieveNameFromCache(name) |
|
|
|
if cacheResult: |
|
|
|
in_cache = True |
|
|
|
foundResult = findCertainShow(sickbeard.showList, cacheResult) |
|
|
|
logger.log( |
|
|
|
u"Cache lookup found Indexer ID:" + repr( |
|
|
|
foundResult.indexerid) + ", using that for " + name, |
|
|
|
logger.DEBUG) |
|
|
|
|
|
|
|
if not foundResult: |
|
|
|
logger.log( |
|
|
|
u"Checking the showlist for:" + str(name), |
|
|
|
logger.DEBUG) |
|
|
|
|
|
|
|
for show in sickbeard.showList: |
|
|
|
if _check_against_names(name, show): |
|
|
|
logger.log(u"Matched " + name + " in the showlist to the show " + show.name, logger.DEBUG) |
|
|
|
return show |
|
|
|
logger.log( |
|
|
|
u"Showlist lookup found Indexer ID:" + str(show.indexerid) + ", using that for " + name, |
|
|
|
logger.DEBUG) |
|
|
|
foundResult = show |
|
|
|
|
|
|
|
if not foundResult: |
|
|
|
logger.log( |
|
|
|
u"Checking the database for show:" + str(name), |
|
|
|
logger.DEBUG) |
|
|
|
|
|
|
|
dbResult = searchDBForShow(name) |
|
|
|
if dbResult: |
|
|
|
foundResult = findCertainShow(sickbeard.showList, dbResult[1]) |
|
|
|
logger.log( |
|
|
|
u"Database lookup found Indexer ID:" + str( |
|
|
|
foundResult.indexerid) + ", using that for " + name, logger.DEBUG) |
|
|
|
|
|
|
|
if not foundResult and useIndexer: |
|
|
|
logger.log( |
|
|
|
u"Checking the Indexers for:" + str(name), |
|
|
|
logger.DEBUG) |
|
|
|
|
|
|
|
if useIndexer: |
|
|
|
for indexer in sickbeard.indexerApi().indexers: |
|
|
|
try: |
|
|
|
lINDEXER_API_PARMS = sickbeard.indexerApi(indexer).api_params.copy() |
|
|
@ -967,14 +992,21 @@ def get_show_by_name(name, showList, useIndexer=False): |
|
|
|
|
|
|
|
t = sickbeard.indexerApi(indexer).indexer(**lINDEXER_API_PARMS) |
|
|
|
showObj = t[name] |
|
|
|
except:continue |
|
|
|
except: |
|
|
|
continue |
|
|
|
|
|
|
|
if showObj: |
|
|
|
showResult = findCertainShow(sickbeard.showList, int(showObj["id"])) |
|
|
|
if showResult is not None: |
|
|
|
return showResult |
|
|
|
foundResult = findCertainShow(sickbeard.showList, int(showObj["id"])) |
|
|
|
if foundResult: |
|
|
|
logger.log( |
|
|
|
u"Indexer lookup found Indexer ID:" + str( |
|
|
|
foundResult.indexerid) + ", using that for " + name, logger.DEBUG) |
|
|
|
|
|
|
|
return None |
|
|
|
# add to name cache if we didn't get it from the cache |
|
|
|
if foundResult and not in_cache: |
|
|
|
sickbeard.name_cache.addNameToCache(name, foundResult.indexerid) |
|
|
|
|
|
|
|
return foundResult |
|
|
|
|
|
|
|
def is_hidden_folder(folder): |
|
|
|
""" |
|
|
@ -995,6 +1027,7 @@ def real_path(path): |
|
|
|
""" |
|
|
|
return ek.ek(os.path.normpath, ek.ek(os.path.normcase, ek.ek(os.path.realpath, path))) |
|
|
|
|
|
|
|
|
|
|
|
def validateShow(show, season=None, episode=None): |
|
|
|
indexer_lang = show.lang |
|
|
|
|
|
|
|