mirror of
https://github.com/moparisthebest/SickRage
synced 2025-01-08 12:28:05 -05:00
Database now closes connection after each query and reconnects if closed to ensure no more connection and locked database problems.
Fixed more internal 500 errors.
This commit is contained in:
parent
2f73ab1e41
commit
7e0bb651b2
29
SickBeard.py
29
SickBeard.py
@ -82,20 +82,20 @@ def loadShowsFromDB():
|
|||||||
Populates the showList with shows from the database
|
Populates the showList with shows from the database
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_shows")
|
sqlResults = myDB.select("SELECT * FROM tv_shows")
|
||||||
|
|
||||||
for sqlShow in sqlResults:
|
for sqlShow in sqlResults:
|
||||||
try:
|
try:
|
||||||
curShow = TVShow(int(sqlShow["indexer"]), int(sqlShow["indexer_id"]))
|
curShow = TVShow(int(sqlShow["indexer"]), int(sqlShow["indexer_id"]))
|
||||||
sickbeard.showList.append(curShow)
|
sickbeard.showList.append(curShow)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.log(
|
logger.log(
|
||||||
u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'),
|
u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'),
|
||||||
logger.ERROR)
|
logger.ERROR)
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
|
|
||||||
# TODO: update the existing shows if the showlist has something in it
|
# TODO: update the existing shows if the showlist has something in it
|
||||||
|
|
||||||
def daemonize():
|
def daemonize():
|
||||||
try:
|
try:
|
||||||
@ -310,8 +310,9 @@ def main():
|
|||||||
|
|
||||||
sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE)
|
sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
CUR_DB_VERSION = myDB.checkDBVersion()
|
|
||||||
|
CUR_DB_VERSION = myDB.checkDBVersion()
|
||||||
|
|
||||||
if CUR_DB_VERSION > 0:
|
if CUR_DB_VERSION > 0:
|
||||||
if CUR_DB_VERSION < MIN_DB_VERSION:
|
if CUR_DB_VERSION < MIN_DB_VERSION:
|
||||||
|
@ -907,20 +907,20 @@ def initialize(consoleLogging=True):
|
|||||||
logger.sb_log_instance.initLogging(consoleLogging=consoleLogging)
|
logger.sb_log_instance.initLogging(consoleLogging=consoleLogging)
|
||||||
|
|
||||||
# initialize the main SB database
|
# initialize the main SB database
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
db.upgradeDatabase(myDB, mainDB.InitialSchema)
|
db.upgradeDatabase(myDB, mainDB.InitialSchema)
|
||||||
|
|
||||||
# initialize the cache database
|
# initialize the cache database
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
db.upgradeDatabase(myDB, cache_db.InitialSchema)
|
db.upgradeDatabase(myDB, cache_db.InitialSchema)
|
||||||
|
|
||||||
# initialize the failed downloads database
|
# initialize the failed downloads database
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
db.upgradeDatabase(myDB, failed_db.InitialSchema)
|
db.upgradeDatabase(myDB, failed_db.InitialSchema)
|
||||||
|
|
||||||
# fix up any db problems
|
# fix up any db problems
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
db.sanityCheckDatabase(myDB, mainDB.MainSanityCheck)
|
db.sanityCheckDatabase(myDB, mainDB.MainSanityCheck)
|
||||||
|
|
||||||
# migrate the config if it needs it
|
# migrate the config if it needs it
|
||||||
migrator = ConfigMigrator(CFG)
|
migrator = ConfigMigrator(CFG)
|
||||||
@ -1820,8 +1820,8 @@ def getEpList(epIDs, showid=None):
|
|||||||
query += " AND showid = ?"
|
query += " AND showid = ?"
|
||||||
params.append(showid)
|
params.append(showid)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(query, params)
|
sqlResults = myDB.select(query, params)
|
||||||
|
|
||||||
epList = []
|
epList = []
|
||||||
|
|
||||||
|
@ -96,9 +96,10 @@ class BlackAndWhiteList(object):
|
|||||||
return "Blacklist: " + blackResult + ", Whitelist: " + whiteResult
|
return "Blacklist: " + blackResult + ", Whitelist: " + whiteResult
|
||||||
|
|
||||||
def _add_keywords(self, table, range, values):
|
def _add_keywords(self, table, range, values):
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for value in values:
|
for value in values:
|
||||||
myDB.action("INSERT INTO " + table + " (show_id, range , keyword) VALUES (?,?,?)", [self.show_id, range, value])
|
myDB.action("INSERT INTO " + table + " (show_id, range , keyword) VALUES (?,?,?)", [self.show_id, range, value])
|
||||||
|
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def _del_all_black_keywords(self):
|
def _del_all_black_keywords(self):
|
||||||
@ -115,19 +116,19 @@ class BlackAndWhiteList(object):
|
|||||||
|
|
||||||
def _del_all_keywords(self, table):
|
def _del_all_keywords(self, table):
|
||||||
logger.log(u"Deleting all " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
logger.log(u"Deleting all " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.action("DELETE FROM " + table + " WHERE show_id = ?", [self.show_id])
|
myDB.action("DELETE FROM " + table + " WHERE show_id = ?", [self.show_id])
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def _del_all_keywords_for(self, table, range):
|
def _del_all_keywords_for(self, table, range):
|
||||||
logger.log(u"Deleting all " + range + " " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
logger.log(u"Deleting all " + range + " " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.action("DELETE FROM " + table + " WHERE show_id = ? and range = ?", [self.show_id, range])
|
myDB.action("DELETE FROM " + table + " WHERE show_id = ? and range = ?", [self.show_id, range])
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def _load_list(self, table):
|
def _load_list(self, table):
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT range,keyword FROM " + table + " WHERE show_id = ? ", [self.show_id])
|
sqlResults = myDB.select("SELECT range,keyword FROM " + table + " WHERE show_id = ? ", [self.show_id])
|
||||||
if not sqlResults or not len(sqlResults):
|
if not sqlResults or not len(sqlResults):
|
||||||
return ([], {})
|
return ([], {})
|
||||||
|
|
||||||
|
@ -456,8 +456,8 @@ class ConfigMigrator():
|
|||||||
sickbeard.NAMING_MULTI_EP = int(check_setting_int(self.config_obj, 'General', 'naming_multi_ep_type', 1))
|
sickbeard.NAMING_MULTI_EP = int(check_setting_int(self.config_obj, 'General', 'naming_multi_ep_type', 1))
|
||||||
|
|
||||||
# see if any of their shows used season folders
|
# see if any of their shows used season folders
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
season_folder_shows = myDB.select("SELECT * FROM tv_shows WHERE flatten_folders = 0")
|
season_folder_shows = myDB.select("SELECT * FROM tv_shows WHERE flatten_folders = 0")
|
||||||
|
|
||||||
# if any shows had season folders on then prepend season folder to the pattern
|
# if any shows had season folders on then prepend season folder to the pattern
|
||||||
if season_folder_shows:
|
if season_folder_shows:
|
||||||
|
@ -43,9 +43,9 @@ class DailySearcher():
|
|||||||
fromDate = datetime.date.today() - datetime.timedelta(weeks=1)
|
fromDate = datetime.date.today() - datetime.timedelta(weeks=1)
|
||||||
curDate = datetime.date.today()
|
curDate = datetime.date.today()
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE status in (?,?) AND airdate >= ? AND airdate <= ?",
|
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE status in (?,?) AND airdate >= ? AND airdate <= ?",
|
||||||
[common.UNAIRED, common.WANTED, fromDate.toordinal(), curDate.toordinal()])
|
[common.UNAIRED, common.WANTED, fromDate.toordinal(), curDate.toordinal()])
|
||||||
|
|
||||||
sql_l = []
|
sql_l = []
|
||||||
todaysEps = {}
|
todaysEps = {}
|
||||||
@ -80,8 +80,8 @@ class DailySearcher():
|
|||||||
sql_l.append(ep.get_sql())
|
sql_l.append(ep.get_sql())
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
if len(todaysEps):
|
if len(todaysEps):
|
||||||
for show in todaysEps:
|
for show in todaysEps:
|
||||||
|
@ -50,13 +50,58 @@ class DBConnection(object):
|
|||||||
def __init__(self, filename="sickbeard.db", suffix=None, row_type=None):
|
def __init__(self, filename="sickbeard.db", suffix=None, row_type=None):
|
||||||
|
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.connection = sqlite3.connect(dbFilename(filename, suffix), 20)
|
self.suffix = suffix
|
||||||
if row_type == "dict":
|
self.row_type = row_type
|
||||||
|
self.connection = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.reconnect()
|
||||||
|
except Exception as e:
|
||||||
|
logger.log(u"DB error: " + ex(e), logger.ERROR)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def reconnect(self):
|
||||||
|
"""Closes the existing database connection and re-opens it."""
|
||||||
|
self.close()
|
||||||
|
self.connection = sqlite3.connect(dbFilename(self.filename, self.suffix), 20)
|
||||||
|
self.connection.isolation_level = None
|
||||||
|
|
||||||
|
if self.row_type == "dict":
|
||||||
self.connection.row_factory = self._dict_factory
|
self.connection.row_factory = self._dict_factory
|
||||||
else:
|
else:
|
||||||
self.connection.row_factory = sqlite3.Row
|
self.connection.row_factory = sqlite3.Row
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def _cursor(self):
|
||||||
|
"""Returns the cursor; reconnects if disconnected."""
|
||||||
|
if self.connection is None: self.reconnect()
|
||||||
|
return self.connection.cursor()
|
||||||
|
|
||||||
|
def execute(self, query, args=None, fetchall=False):
|
||||||
|
"""Executes the given query, returning the lastrowid from the query."""
|
||||||
|
cursor = self._cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if fetchall:
|
||||||
|
return self._execute(cursor, query, args).fetchall()
|
||||||
|
return self._execute(cursor, query, args)
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
def _execute(self, cursor, query, args):
|
||||||
|
try:
|
||||||
|
if args == None:
|
||||||
|
return cursor.execute(query)
|
||||||
|
return cursor.execute(query, args)
|
||||||
|
except sqlite3.OperationalError as e:
|
||||||
|
logger.log(u"DB error: " + ex(e), logger.ERROR)
|
||||||
|
self.close()
|
||||||
|
raise
|
||||||
|
|
||||||
def checkDBVersion(self):
|
def checkDBVersion(self):
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -83,8 +128,7 @@ class DBConnection(object):
|
|||||||
attempt = 0
|
attempt = 0
|
||||||
|
|
||||||
# Transaction
|
# Transaction
|
||||||
self.connection.isolation_level = None
|
#self.execute('BEGIN')
|
||||||
self.connection.execute('BEGIN')
|
|
||||||
|
|
||||||
while attempt < 5:
|
while attempt < 5:
|
||||||
try:
|
try:
|
||||||
@ -93,13 +137,11 @@ class DBConnection(object):
|
|||||||
if len(qu) == 1:
|
if len(qu) == 1:
|
||||||
if logTransaction:
|
if logTransaction:
|
||||||
logger.log(qu[0], logger.DEBUG)
|
logger.log(qu[0], logger.DEBUG)
|
||||||
sqlResult.append(self.connection.execute(qu[0]))
|
sqlResult.append(self.execute(qu[0]))
|
||||||
elif len(qu) > 1:
|
elif len(qu) > 1:
|
||||||
if logTransaction:
|
if logTransaction:
|
||||||
logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG)
|
logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG)
|
||||||
sqlResult.append(self.connection.execute(qu[0], qu[1]))
|
sqlResult.append(self.execute(qu[0], qu[1]))
|
||||||
|
|
||||||
self.connection.commit()
|
|
||||||
|
|
||||||
logger.log(u"Transaction with " + str(len(querylist)) + u" queries executed", logger.DEBUG)
|
logger.log(u"Transaction with " + str(len(querylist)) + u" queries executed", logger.DEBUG)
|
||||||
return sqlResult
|
return sqlResult
|
||||||
@ -123,7 +165,7 @@ class DBConnection(object):
|
|||||||
|
|
||||||
return sqlResult
|
return sqlResult
|
||||||
|
|
||||||
def action(self, query, args=None):
|
def action(self, query, args=None, fetchall=False):
|
||||||
|
|
||||||
with db_lock:
|
with db_lock:
|
||||||
|
|
||||||
@ -137,11 +179,11 @@ class DBConnection(object):
|
|||||||
try:
|
try:
|
||||||
if args == None:
|
if args == None:
|
||||||
logger.log(self.filename + ": " + query, logger.DB)
|
logger.log(self.filename + ": " + query, logger.DB)
|
||||||
sqlResult = self.connection.execute(query)
|
|
||||||
else:
|
else:
|
||||||
logger.log(self.filename + ": " + query + " with args " + str(args), logger.DB)
|
logger.log(self.filename + ": " + query + " with args " + str(args), logger.DB)
|
||||||
sqlResult = self.connection.execute(query, args)
|
|
||||||
self.connection.commit()
|
sqlResult = self.execute(query, args, fetchall=fetchall)
|
||||||
|
|
||||||
# get out of the connection attempt loop since we were successful
|
# get out of the connection attempt loop since we were successful
|
||||||
break
|
break
|
||||||
except sqlite3.OperationalError, e:
|
except sqlite3.OperationalError, e:
|
||||||
@ -158,10 +200,9 @@ class DBConnection(object):
|
|||||||
|
|
||||||
return sqlResult
|
return sqlResult
|
||||||
|
|
||||||
|
|
||||||
def select(self, query, args=None):
|
def select(self, query, args=None):
|
||||||
|
|
||||||
sqlResults = self.action(query, args).fetchall()
|
sqlResults = self.action(query, args, fetchall=True)
|
||||||
|
|
||||||
if sqlResults == None:
|
if sqlResults == None:
|
||||||
return []
|
return []
|
||||||
@ -185,10 +226,11 @@ class DBConnection(object):
|
|||||||
self.action(query, valueDict.values() + keyDict.values())
|
self.action(query, valueDict.values() + keyDict.values())
|
||||||
|
|
||||||
def tableInfo(self, tableName):
|
def tableInfo(self, tableName):
|
||||||
|
|
||||||
# FIXME ? binding is not supported here, but I cannot find a way to escape a string manually
|
# FIXME ? binding is not supported here, but I cannot find a way to escape a string manually
|
||||||
cursor = self.connection.execute("PRAGMA table_info(%s)" % tableName)
|
sqlResult = self.select("PRAGMA table_info(%s)" % tableName)
|
||||||
columns = {}
|
columns = {}
|
||||||
for column in cursor:
|
for column in sqlResult:
|
||||||
columns[column['name']] = {'type': column['type']}
|
columns[column['name']] = {'type': column['type']}
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
@ -200,16 +242,13 @@ class DBConnection(object):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def hasTable(self, tableName):
|
def hasTable(self, tableName):
|
||||||
return len(self.action("SELECT 1 FROM sqlite_master WHERE name = ?;", (tableName, )).fetchall()) > 0
|
return len(self.select("SELECT 1 FROM sqlite_master WHERE name = ?;", (tableName, ))) > 0
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.connection.close()
|
"""Close database connection"""
|
||||||
|
if getattr(self, "connection", None) is not None:
|
||||||
def __enter__(self):
|
self.connection.close()
|
||||||
return self
|
self.connection = None
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
||||||
self.close()
|
|
||||||
|
|
||||||
def sanityCheckDatabase(connection, sanity_check):
|
def sanityCheckDatabase(connection, sanity_check):
|
||||||
sanity_check(connection).check()
|
sanity_check(connection).check()
|
||||||
@ -235,14 +274,16 @@ def upgradeDatabase(connection, schema):
|
|||||||
def prettyName(class_name):
|
def prettyName(class_name):
|
||||||
return ' '.join([x.group() for x in re.finditer("([A-Z])([a-z0-9]+)", class_name)])
|
return ' '.join([x.group() for x in re.finditer("([A-Z])([a-z0-9]+)", class_name)])
|
||||||
|
|
||||||
|
|
||||||
def restoreDatabase(version):
|
def restoreDatabase(version):
|
||||||
logger.log(u"Restoring database before trying upgrade again")
|
logger.log(u"Restoring database before trying upgrade again")
|
||||||
if not sickbeard.helpers.restoreVersionedFile(dbFilename(suffix='v'+ str(version)), version):
|
if not sickbeard.helpers.restoreVersionedFile(dbFilename(suffix='v' + str(version)), version):
|
||||||
logger.log_error_and_exit(u"Database restore failed, abort upgrading database")
|
logger.log_error_and_exit(u"Database restore failed, abort upgrading database")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _processUpgrade(connection, upgradeClass):
|
def _processUpgrade(connection, upgradeClass):
|
||||||
instance = upgradeClass(connection)
|
instance = upgradeClass(connection)
|
||||||
logger.log(u"Checking " + prettyName(upgradeClass.__name__) + " database upgrade", logger.DEBUG)
|
logger.log(u"Checking " + prettyName(upgradeClass.__name__) + " database upgrade", logger.DEBUG)
|
||||||
@ -259,7 +300,6 @@ def _processUpgrade(connection, upgradeClass):
|
|||||||
result = connection.select("SELECT db_version FROM db_version")
|
result = connection.select("SELECT db_version FROM db_version")
|
||||||
if result:
|
if result:
|
||||||
version = int(result[0]["db_version"])
|
version = int(result[0]["db_version"])
|
||||||
connection.close()
|
|
||||||
if restoreDatabase(version):
|
if restoreDatabase(version):
|
||||||
# initialize the main SB database
|
# initialize the main SB database
|
||||||
upgradeDatabase(DBConnection(), sickbeard.mainDB.InitialSchema)
|
upgradeDatabase(DBConnection(), sickbeard.mainDB.InitialSchema)
|
||||||
@ -282,7 +322,7 @@ class SchemaUpgrade(object):
|
|||||||
self.connection = connection
|
self.connection = connection
|
||||||
|
|
||||||
def hasTable(self, tableName):
|
def hasTable(self, tableName):
|
||||||
return len(self.connection.action("SELECT 1 FROM sqlite_master WHERE name = ?;", (tableName, )).fetchall()) > 0
|
return len(self.connection.select("SELECT 1 FROM sqlite_master WHERE name = ?;", (tableName, ))) > 0
|
||||||
|
|
||||||
def hasColumn(self, tableName, column):
|
def hasColumn(self, tableName, column):
|
||||||
return column in self.connection.tableInfo(tableName)
|
return column in self.connection.tableInfo(tableName)
|
||||||
|
@ -50,8 +50,8 @@ def logFailed(release):
|
|||||||
|
|
||||||
release = prepareFailedName(release)
|
release = prepareFailedName(release)
|
||||||
|
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
sql_results = myDB.select("SELECT * FROM history WHERE release=?", [release])
|
sql_results = myDB.select("SELECT * FROM history WHERE release=?", [release])
|
||||||
|
|
||||||
if len(sql_results) == 0:
|
if len(sql_results) == 0:
|
||||||
logger.log(
|
logger.log(
|
||||||
@ -78,8 +78,8 @@ def logFailed(release):
|
|||||||
provider = sql_results[0]["provider"]
|
provider = sql_results[0]["provider"]
|
||||||
|
|
||||||
if not hasFailed(release, size, provider):
|
if not hasFailed(release, size, provider):
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
myDB.action("INSERT INTO failed (release, size, provider) VALUES (?, ?, ?)", [release, size, provider])
|
myDB.action("INSERT INTO failed (release, size, provider) VALUES (?, ?, ?)", [release, size, provider])
|
||||||
|
|
||||||
deleteLoggedSnatch(release, size, provider)
|
deleteLoggedSnatch(release, size, provider)
|
||||||
|
|
||||||
@ -89,8 +89,8 @@ def logFailed(release):
|
|||||||
def logSuccess(release):
|
def logSuccess(release):
|
||||||
release = prepareFailedName(release)
|
release = prepareFailedName(release)
|
||||||
|
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
myDB.action("DELETE FROM history WHERE release=?", [release])
|
myDB.action("DELETE FROM history WHERE release=?", [release])
|
||||||
|
|
||||||
|
|
||||||
def hasFailed(release, size, provider="%"):
|
def hasFailed(release, size, provider="%"):
|
||||||
@ -104,19 +104,19 @@ def hasFailed(release, size, provider="%"):
|
|||||||
|
|
||||||
release = prepareFailedName(release)
|
release = prepareFailedName(release)
|
||||||
|
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
sql_results = myDB.select(
|
sql_results = myDB.select(
|
||||||
"SELECT * FROM failed WHERE release=? AND size=? AND provider LIKE ?",
|
"SELECT * FROM failed WHERE release=? AND size=? AND provider LIKE ?",
|
||||||
[release, size, provider])
|
[release, size, provider])
|
||||||
|
|
||||||
return (len(sql_results) > 0)
|
return (len(sql_results) > 0)
|
||||||
|
|
||||||
|
|
||||||
def revertEpisode(epObj):
|
def revertEpisode(epObj):
|
||||||
"""Restore the episodes of a failed download to their original state"""
|
"""Restore the episodes of a failed download to their original state"""
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
sql_results = myDB.select("SELECT * FROM history WHERE showid=? AND season=?",
|
sql_results = myDB.select("SELECT * FROM history WHERE showid=? AND season=?",
|
||||||
[epObj.show.indexerid, epObj.season])
|
[epObj.show.indexerid, epObj.season])
|
||||||
|
|
||||||
history_eps = dict([(res["episode"], res) for res in sql_results])
|
history_eps = dict([(res["episode"], res) for res in sql_results])
|
||||||
|
|
||||||
@ -164,27 +164,27 @@ def logSnatch(searchResult):
|
|||||||
|
|
||||||
show_obj = searchResult.episodes[0].show
|
show_obj = searchResult.episodes[0].show
|
||||||
|
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
for episode in searchResult.episodes:
|
for episode in searchResult.episodes:
|
||||||
myDB.action(
|
myDB.action(
|
||||||
"INSERT INTO history (date, size, release, provider, showid, season, episode, old_status)"
|
"INSERT INTO history (date, size, release, provider, showid, season, episode, old_status)"
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
[logDate, searchResult.size, release, provider, show_obj.indexerid, episode.season, episode.episode,
|
[logDate, searchResult.size, release, provider, show_obj.indexerid, episode.season, episode.episode,
|
||||||
episode.status])
|
episode.status])
|
||||||
|
|
||||||
|
|
||||||
def deleteLoggedSnatch(release, size, provider):
|
def deleteLoggedSnatch(release, size, provider):
|
||||||
release = prepareFailedName(release)
|
release = prepareFailedName(release)
|
||||||
|
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
myDB.action("DELETE FROM history WHERE release=? AND size=? AND provider=?",
|
myDB.action("DELETE FROM history WHERE release=? AND size=? AND provider=?",
|
||||||
[release, size, provider])
|
[release, size, provider])
|
||||||
|
|
||||||
|
|
||||||
def trimHistory():
|
def trimHistory():
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
myDB.action("DELETE FROM history WHERE date < " + str(
|
myDB.action("DELETE FROM history WHERE date < " + str(
|
||||||
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(dateFormat)))
|
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(dateFormat)))
|
||||||
|
|
||||||
|
|
||||||
def findRelease(epObj):
|
def findRelease(epObj):
|
||||||
@ -198,27 +198,27 @@ def findRelease(epObj):
|
|||||||
|
|
||||||
|
|
||||||
# Clear old snatches for this release if any exist
|
# Clear old snatches for this release if any exist
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
myDB.action("DELETE FROM history WHERE showid=" + str(epObj.show.indexerid) + " AND season=" + str(
|
myDB.action("DELETE FROM history WHERE showid=" + str(epObj.show.indexerid) + " AND season=" + str(
|
||||||
epObj.season) + " AND episode=" + str(
|
epObj.season) + " AND episode=" + str(
|
||||||
epObj.episode) + " AND date < (SELECT max(date) FROM history WHERE showid=" + str(
|
epObj.episode) + " AND date < (SELECT max(date) FROM history WHERE showid=" + str(
|
||||||
epObj.show.indexerid) + " AND season=" + str(epObj.season) + " AND episode=" + str(epObj.episode) + ")")
|
epObj.show.indexerid) + " AND season=" + str(epObj.season) + " AND episode=" + str(epObj.episode) + ")")
|
||||||
|
|
||||||
# Search for release in snatch history
|
# Search for release in snatch history
|
||||||
results = myDB.select("SELECT release, provider, date FROM history WHERE showid=? AND season=? AND episode=?",
|
results = myDB.select("SELECT release, provider, date FROM history WHERE showid=? AND season=? AND episode=?",
|
||||||
[epObj.show.indexerid, epObj.season, epObj.episode])
|
[epObj.show.indexerid, epObj.season, epObj.episode])
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
release = str(result["release"])
|
release = str(result["release"])
|
||||||
provider = str(result["provider"])
|
provider = str(result["provider"])
|
||||||
date = result["date"]
|
date = result["date"]
|
||||||
|
|
||||||
# Clear any incomplete snatch records for this release if any exist
|
# Clear any incomplete snatch records for this release if any exist
|
||||||
myDB.action("DELETE FROM history WHERE release=? AND date!=?", [release, date])
|
myDB.action("DELETE FROM history WHERE release=? AND date!=?", [release, date])
|
||||||
|
|
||||||
# Found a previously failed release
|
# Found a previously failed release
|
||||||
logger.log(u"Failed release found for season (%s): (%s)" % (epObj.season, result["release"]), logger.DEBUG)
|
logger.log(u"Failed release found for season (%s): (%s)" % (epObj.season, result["release"]), logger.DEBUG)
|
||||||
return (release, provider)
|
return (release, provider)
|
||||||
|
|
||||||
# Release was not found
|
# Release was not found
|
||||||
logger.log(u"No releases found for season (%s) of (%s)" % (epObj.season, epObj.show.indexerid), logger.DEBUG)
|
logger.log(u"No releases found for season (%s) of (%s)" % (epObj.season, epObj.show.indexerid), logger.DEBUG)
|
||||||
|
@ -291,37 +291,37 @@ def searchDBForShow(regShowName, log=False):
|
|||||||
|
|
||||||
yearRegex = "([^()]+?)\s*(\()?(\d{4})(?(2)\))$"
|
yearRegex = "([^()]+?)\s*(\()?(\d{4})(?(2)\))$"
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for showName in showNames:
|
for showName in showNames:
|
||||||
|
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_shows WHERE show_name LIKE ?",
|
sqlResults = myDB.select("SELECT * FROM tv_shows WHERE show_name LIKE ?",
|
||||||
[showName])
|
[showName])
|
||||||
|
|
||||||
if len(sqlResults) == 1:
|
if len(sqlResults) == 1:
|
||||||
return (int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"])
|
return (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):
|
||||||
|
if log:
|
||||||
|
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 ?) AND startyear = ?",
|
||||||
|
[match.group(1) + '%', match.group(3)])
|
||||||
|
|
||||||
|
if len(sqlResults) == 0:
|
||||||
|
if log:
|
||||||
|
logger.log(u"Unable to match a record in the DB for " + showName, logger.DEBUG)
|
||||||
|
continue
|
||||||
|
elif len(sqlResults) > 1:
|
||||||
|
if log:
|
||||||
|
logger.log(u"Multiple results for " + showName + " in the DB, unable to match show name",
|
||||||
|
logger.DEBUG)
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
# if we didn't get exactly one result then try again with the year stripped off if possible
|
return (int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"])
|
||||||
match = re.match(yearRegex, showName)
|
|
||||||
if match and match.group(1):
|
|
||||||
if log:
|
|
||||||
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 ?) AND startyear = ?",
|
|
||||||
[match.group(1) + '%', match.group(3)])
|
|
||||||
|
|
||||||
if len(sqlResults) == 0:
|
|
||||||
if log:
|
|
||||||
logger.log(u"Unable to match a record in the DB for " + showName, logger.DEBUG)
|
|
||||||
continue
|
|
||||||
elif len(sqlResults) > 1:
|
|
||||||
if log:
|
|
||||||
logger.log(u"Multiple results for " + showName + " in the DB, unable to match show name",
|
|
||||||
logger.DEBUG)
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
return (int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"])
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -682,9 +682,9 @@ def update_anime_support():
|
|||||||
|
|
||||||
|
|
||||||
def get_absolute_number_from_season_and_episode(show, season, episode):
|
def get_absolute_number_from_season_and_episode(show, season, episode):
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql = "SELECT * FROM tv_episodes WHERE showid = ? and season = ? and episode = ?"
|
sql = "SELECT * FROM tv_episodes WHERE showid = ? and season = ? and episode = ?"
|
||||||
sqlResults = myDB.select(sql, [show.indexerid, season, episode])
|
sqlResults = myDB.select(sql, [show.indexerid, season, episode])
|
||||||
|
|
||||||
if len(sqlResults) == 1:
|
if len(sqlResults) == 1:
|
||||||
absolute_number = int(sqlResults[0]["absolute_number"])
|
absolute_number = int(sqlResults[0]["absolute_number"])
|
||||||
|
@ -31,10 +31,10 @@ def _logHistoryItem(action, showid, season, episode, quality, resource, provider
|
|||||||
if not isinstance(resource, unicode):
|
if not isinstance(resource, unicode):
|
||||||
resource = unicode(resource, 'utf-8')
|
resource = unicode(resource, 'utf-8')
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.action(
|
myDB.action(
|
||||||
"INSERT INTO history (action, date, showid, season, episode, quality, resource, provider) VALUES (?,?,?,?,?,?,?,?)",
|
"INSERT INTO history (action, date, showid, season, episode, quality, resource, provider) VALUES (?,?,?,?,?,?,?,?)",
|
||||||
[action, logDate, showid, season, episode, quality, resource, provider])
|
[action, logDate, showid, season, episode, quality, resource, provider])
|
||||||
|
|
||||||
|
|
||||||
def logSnatch(searchResult):
|
def logSnatch(searchResult):
|
||||||
|
@ -32,8 +32,8 @@ def addNameToCache(name, indexer_id=0):
|
|||||||
|
|
||||||
# standardize the name we're using to account for small differences in providers
|
# standardize the name we're using to account for small differences in providers
|
||||||
name = sanitizeSceneName(name)
|
name = sanitizeSceneName(name)
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
myDB.action("INSERT INTO scene_names (indexer_id, name) VALUES (?, ?)", [indexer_id, name])
|
myDB.action("INSERT INTO scene_names (indexer_id, name) VALUES (?, ?)", [indexer_id, name])
|
||||||
|
|
||||||
|
|
||||||
def retrieveNameFromCache(name):
|
def retrieveNameFromCache(name):
|
||||||
@ -50,9 +50,9 @@ def retrieveNameFromCache(name):
|
|||||||
# standardize the name we're using to account for small differences in providers
|
# standardize the name we're using to account for small differences in providers
|
||||||
name = sanitizeSceneName(name)
|
name = sanitizeSceneName(name)
|
||||||
|
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
if myDB.hasTable('scene_names'):
|
if myDB.hasTable('scene_names'):
|
||||||
cache_results = myDB.select("SELECT * FROM scene_names WHERE name = ?", [name])
|
cache_results = myDB.select("SELECT * FROM scene_names WHERE name = ?", [name])
|
||||||
|
|
||||||
if cache_results:
|
if cache_results:
|
||||||
return int(cache_results[0]["indexer_id"])
|
return int(cache_results[0]["indexer_id"])
|
||||||
@ -67,10 +67,10 @@ def clearCache(show=None, season=-1, indexer_id=0):
|
|||||||
Deletes all "unknown" entries from the cache (names with indexer_id of 0).
|
Deletes all "unknown" entries from the cache (names with indexer_id of 0).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
if show:
|
if show:
|
||||||
showNames = sickbeard.show_name_helpers.allPossibleShowNames(show, season=season)
|
showNames = sickbeard.show_name_helpers.allPossibleShowNames(show, season=season)
|
||||||
for showName in showNames:
|
for showName in showNames:
|
||||||
myDB.action("DELETE FROM scene_names WHERE name = ? and indexer_id = ?", [showName, indexer_id])
|
myDB.action("DELETE FROM scene_names WHERE name = ? and indexer_id = ?", [showName, indexer_id])
|
||||||
else:
|
else:
|
||||||
myDB.action("DELETE FROM scene_names WHERE indexer_id = ?", [indexer_id])
|
myDB.action("DELETE FROM scene_names WHERE indexer_id = ?", [indexer_id])
|
@ -164,42 +164,42 @@ def update_network_dict():
|
|||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
# load current network timezones
|
# load current network timezones
|
||||||
old_d = dict(myDB.select("SELECT * FROM network_timezones"))
|
old_d = dict(myDB.select("SELECT * FROM network_timezones"))
|
||||||
|
|
||||||
# list of sql commands to update the network_timezones table
|
# list of sql commands to update the network_timezones table
|
||||||
ql = []
|
ql = []
|
||||||
for cur_d, cur_t in d.iteritems():
|
for cur_d, cur_t in d.iteritems():
|
||||||
h_k = old_d.has_key(cur_d)
|
h_k = old_d.has_key(cur_d)
|
||||||
if h_k and cur_t != old_d[cur_d]:
|
if h_k and cur_t != old_d[cur_d]:
|
||||||
# update old record
|
# update old record
|
||||||
ql.append(
|
ql.append(
|
||||||
["UPDATE network_timezones SET network_name=?, timezone=? WHERE network_name=?", [cur_d, cur_t, cur_d]])
|
["UPDATE network_timezones SET network_name=?, timezone=? WHERE network_name=?", [cur_d, cur_t, cur_d]])
|
||||||
elif not h_k:
|
elif not h_k:
|
||||||
# add new record
|
# add new record
|
||||||
ql.append(["INSERT INTO network_timezones (network_name, timezone) VALUES (?,?)", [cur_d, cur_t]])
|
ql.append(["INSERT INTO network_timezones (network_name, timezone) VALUES (?,?)", [cur_d, cur_t]])
|
||||||
if h_k:
|
if h_k:
|
||||||
del old_d[cur_d]
|
del old_d[cur_d]
|
||||||
# remove deleted records
|
# remove deleted records
|
||||||
if len(old_d) > 0:
|
if len(old_d) > 0:
|
||||||
L = list(va for va in old_d)
|
L = list(va for va in old_d)
|
||||||
ql.append(["DELETE FROM network_timezones WHERE network_name IN (" + ','.join(['?'] * len(L)) + ")", L])
|
ql.append(["DELETE FROM network_timezones WHERE network_name IN (" + ','.join(['?'] * len(L)) + ")", L])
|
||||||
# change all network timezone infos at once (much faster)
|
# change all network timezone infos at once (much faster)
|
||||||
if ql:
|
if ql:
|
||||||
myDB.mass_action(ql)
|
myDB.mass_action(ql)
|
||||||
load_network_dict()
|
load_network_dict()
|
||||||
|
|
||||||
|
|
||||||
# load network timezones from db into dict
|
# load network timezones from db into dict
|
||||||
def load_network_dict():
|
def load_network_dict():
|
||||||
d = {}
|
d = {}
|
||||||
try:
|
try:
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
|
cur_network_list = myDB.select("SELECT * FROM network_timezones")
|
||||||
|
if cur_network_list is None or len(cur_network_list) < 1:
|
||||||
|
update_network_dict()
|
||||||
cur_network_list = myDB.select("SELECT * FROM network_timezones")
|
cur_network_list = myDB.select("SELECT * FROM network_timezones")
|
||||||
if cur_network_list is None or len(cur_network_list) < 1:
|
|
||||||
update_network_dict()
|
|
||||||
cur_network_list = myDB.select("SELECT * FROM network_timezones")
|
|
||||||
d = dict(cur_network_list)
|
d = dict(cur_network_list)
|
||||||
except:
|
except:
|
||||||
d = {}
|
d = {}
|
||||||
|
@ -151,13 +151,13 @@ class EmailNotifier:
|
|||||||
addrs.append(addr)
|
addrs.append(addr)
|
||||||
|
|
||||||
# Grab the recipients for the show
|
# Grab the recipients for the show
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for s in show:
|
for s in show:
|
||||||
for subs in myDB.select("SELECT notify_list FROM tv_shows WHERE show_name = ?", (s,)):
|
for subs in myDB.select("SELECT notify_list FROM tv_shows WHERE show_name = ?", (s,)):
|
||||||
if subs['notify_list']:
|
if subs['notify_list']:
|
||||||
for addr in subs['notify_list'].split(','):
|
for addr in subs['notify_list'].split(','):
|
||||||
if (len(addr.strip()) > 0):
|
if (len(addr.strip()) > 0):
|
||||||
addrs.append(addr)
|
addrs.append(addr)
|
||||||
|
|
||||||
addrs = set(addrs)
|
addrs = set(addrs)
|
||||||
logger.log('Notification recepients: %s' % addrs, logger.DEBUG)
|
logger.log('Notification recepients: %s' % addrs, logger.DEBUG)
|
||||||
|
@ -406,29 +406,29 @@ class PostProcessor(object):
|
|||||||
names.append(self.folder_name)
|
names.append(self.folder_name)
|
||||||
|
|
||||||
# search the database for a possible match and return immediately if we find one
|
# search the database for a possible match and return immediately if we find one
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for curName in names:
|
for curName in names:
|
||||||
search_name = re.sub("[\.\-\ ]", "_", curName)
|
search_name = re.sub("[\.\-\ ]", "_", curName)
|
||||||
sql_results = myDB.select("SELECT * FROM history WHERE resource LIKE ?", [search_name])
|
sql_results = myDB.select("SELECT * FROM history WHERE resource LIKE ?", [search_name])
|
||||||
|
|
||||||
if len(sql_results) == 0:
|
if len(sql_results) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
show = helpers.findCertainShow(sickbeard.showList, int(sql_results[0]["showid"]))
|
show = helpers.findCertainShow(sickbeard.showList, int(sql_results[0]["showid"]))
|
||||||
if not show:
|
if not show:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
season = int(sql_results[0]["season"])
|
season = int(sql_results[0]["season"])
|
||||||
quality = int(sql_results[0]["quality"])
|
quality = int(sql_results[0]["quality"])
|
||||||
|
|
||||||
if quality == common.Quality.UNKNOWN:
|
if quality == common.Quality.UNKNOWN:
|
||||||
quality = None
|
quality = None
|
||||||
|
|
||||||
self.in_history = True
|
self.in_history = True
|
||||||
to_return = (show, season, [], quality)
|
to_return = (show, season, [], quality)
|
||||||
self._log("Found result in history: " + str(to_return), logger.DEBUG)
|
self._log("Found result in history: " + str(to_return), logger.DEBUG)
|
||||||
|
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
self.in_history = False
|
self.in_history = False
|
||||||
return to_return
|
return to_return
|
||||||
@ -621,9 +621,9 @@ class PostProcessor(object):
|
|||||||
self._log(u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
self._log(u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
||||||
logger.DEBUG)
|
logger.DEBUG)
|
||||||
airdate = episodes[0].toordinal()
|
airdate = episodes[0].toordinal()
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_result = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
|
sql_result = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
|
||||||
[show.indexerid, show.indexer, airdate])
|
[show.indexerid, show.indexer, airdate])
|
||||||
|
|
||||||
if sql_result:
|
if sql_result:
|
||||||
season = int(sql_result[0][0])
|
season = int(sql_result[0][0])
|
||||||
@ -637,10 +637,10 @@ class PostProcessor(object):
|
|||||||
|
|
||||||
# if there's no season then we can hopefully just use 1 automatically
|
# if there's no season then we can hopefully just use 1 automatically
|
||||||
elif season == None and show:
|
elif season == None and show:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
numseasonsSQlResult = myDB.select(
|
numseasonsSQlResult = myDB.select(
|
||||||
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and indexer = ? and season != 0",
|
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and indexer = ? and season != 0",
|
||||||
[show.indexerid, show.indexer])
|
[show.indexerid, show.indexer])
|
||||||
if int(numseasonsSQlResult[0][0]) == 1 and season == None:
|
if int(numseasonsSQlResult[0][0]) == 1 and season == None:
|
||||||
self._log(
|
self._log(
|
||||||
u"Don't have a season number, but this show appears to only have 1 season, setting season number to 1...",
|
u"Don't have a season number, but this show appears to only have 1 season, setting season number to 1...",
|
||||||
@ -963,8 +963,8 @@ class PostProcessor(object):
|
|||||||
self._log(u"Couldn't find release in snatch history", logger.WARNING)
|
self._log(u"Couldn't find release in snatch history", logger.WARNING)
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
# find the destination folder
|
# find the destination folder
|
||||||
try:
|
try:
|
||||||
@ -1040,8 +1040,8 @@ class PostProcessor(object):
|
|||||||
sql_l.append(ep_obj.get_sql())
|
sql_l.append(ep_obj.get_sql())
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
# log it to history
|
# log it to history
|
||||||
history.logDownload(ep_obj, self.file_path, new_ep_quality, self.release_group)
|
history.logDownload(ep_obj, self.file_path, new_ep_quality, self.release_group)
|
||||||
|
@ -242,8 +242,8 @@ def validateDir(path, dirName, nzbNameOriginal, failed):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# make sure the dir isn't inside a show dir
|
# make sure the dir isn't inside a show dir
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_shows")
|
sqlResults = myDB.select("SELECT * FROM tv_shows")
|
||||||
|
|
||||||
for sqlShow in sqlResults:
|
for sqlShow in sqlResults:
|
||||||
if dirName.lower().startswith(
|
if dirName.lower().startswith(
|
||||||
@ -345,12 +345,12 @@ def already_postprocessed(dirName, videofile, force):
|
|||||||
dirName = unicode(dirName, 'utf_8')
|
dirName = unicode(dirName, 'utf_8')
|
||||||
|
|
||||||
# Avoid processing the same dir again if we use a process method <> move
|
# Avoid processing the same dir again if we use a process method <> move
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResult = myDB.select("SELECT * FROM tv_episodes WHERE release_name = ?", [dirName])
|
sqlResult = myDB.select("SELECT * FROM tv_episodes WHERE release_name = ?", [dirName])
|
||||||
if sqlResult:
|
if sqlResult:
|
||||||
returnStr += logHelper(u"You're trying to post process a dir that's already been processed, skipping",
|
returnStr += logHelper(u"You're trying to post process a dir that's already been processed, skipping",
|
||||||
logger.DEBUG)
|
logger.DEBUG)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# This is needed for video whose name differ from dirName
|
# This is needed for video whose name differ from dirName
|
||||||
if not isinstance(videofile, unicode):
|
if not isinstance(videofile, unicode):
|
||||||
|
@ -166,10 +166,10 @@ class ProperFinder():
|
|||||||
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
||||||
logger.DEBUG)
|
logger.DEBUG)
|
||||||
airdate = curProper.episode.toordinal()
|
airdate = curProper.episode.toordinal()
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_result = myDB.select(
|
sql_result = myDB.select(
|
||||||
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
|
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
|
||||||
[curProper.indexerid, curProper.indexer, airdate])
|
[curProper.indexerid, curProper.indexer, airdate])
|
||||||
|
|
||||||
if sql_result:
|
if sql_result:
|
||||||
curProper.season = int(sql_result[0][0])
|
curProper.season = int(sql_result[0][0])
|
||||||
@ -180,10 +180,10 @@ class ProperFinder():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# check if we actually want this proper (if it's the right quality)
|
# check if we actually want this proper (if it's the right quality)
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
"SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||||
[curProper.indexerid, curProper.season, curProper.episode])
|
[curProper.indexerid, curProper.season, curProper.episode])
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
continue
|
continue
|
||||||
@ -209,13 +209,13 @@ class ProperFinder():
|
|||||||
historyLimit = datetime.datetime.today() - datetime.timedelta(days=30)
|
historyLimit = datetime.datetime.today() - datetime.timedelta(days=30)
|
||||||
|
|
||||||
# make sure the episode has been downloaded before
|
# make sure the episode has been downloaded before
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
historyResults = myDB.select(
|
historyResults = myDB.select(
|
||||||
"SELECT resource FROM history "
|
"SELECT resource FROM history "
|
||||||
"WHERE showid = ? AND season = ? AND episode = ? AND quality = ? AND date >= ? "
|
"WHERE showid = ? AND season = ? AND episode = ? AND quality = ? AND date >= ? "
|
||||||
"AND action IN (" + ",".join([str(x) for x in Quality.SNATCHED]) + ")",
|
"AND action IN (" + ",".join([str(x) for x in Quality.SNATCHED]) + ")",
|
||||||
[curProper.indexerid, curProper.season, curProper.episode, curProper.quality,
|
[curProper.indexerid, curProper.season, curProper.episode, curProper.quality,
|
||||||
historyLimit.strftime(history.dateFormat)])
|
historyLimit.strftime(history.dateFormat)])
|
||||||
|
|
||||||
# if we didn't download this episode in the first place we don't know what quality to use for the proper so we can't do it
|
# if we didn't download this episode in the first place we don't know what quality to use for the proper so we can't do it
|
||||||
if len(historyResults) == 0:
|
if len(historyResults) == 0:
|
||||||
@ -260,19 +260,19 @@ class ProperFinder():
|
|||||||
|
|
||||||
logger.log(u"Setting the last Proper search in the DB to " + str(when), logger.DEBUG)
|
logger.log(u"Setting the last Proper search in the DB to " + str(when), logger.DEBUG)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM info")
|
sqlResults = myDB.select("SELECT * FROM info")
|
||||||
|
|
||||||
if len(sqlResults) == 0:
|
if len(sqlResults) == 0:
|
||||||
myDB.action("INSERT INTO info (last_backlog, last_indexer, last_proper_search) VALUES (?,?,?)",
|
myDB.action("INSERT INTO info (last_backlog, last_indexer, last_proper_search) VALUES (?,?,?)",
|
||||||
[0, 0, str(when)])
|
[0, 0, str(when)])
|
||||||
else:
|
else:
|
||||||
myDB.action("UPDATE info SET last_proper_search=" + str(when))
|
myDB.action("UPDATE info SET last_proper_search=" + str(when))
|
||||||
|
|
||||||
def _get_lastProperSearch(self):
|
def _get_lastProperSearch(self):
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM info")
|
sqlResults = myDB.select("SELECT * FROM info")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
last_proper_search = datetime.date.fromordinal(int(sqlResults[0]["last_proper_search"]))
|
last_proper_search = datetime.date.fromordinal(int(sqlResults[0]["last_proper_search"]))
|
||||||
|
@ -321,11 +321,11 @@ class GenericProvider:
|
|||||||
logger.DEBUG)
|
logger.DEBUG)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_results = myDB.select(
|
sql_results = myDB.select(
|
||||||
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
|
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
|
||||||
[show.indexerid,
|
[show.indexerid,
|
||||||
parse_result.air_date.toordinal() or parse_result.sports_event_date.toordinal()])
|
parse_result.air_date.toordinal() or parse_result.sports_event_date.toordinal()])
|
||||||
|
|
||||||
if len(sql_results) != 1:
|
if len(sql_results) != 1:
|
||||||
logger.log(
|
logger.log(
|
||||||
|
@ -314,14 +314,14 @@ class HDTorrentsProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -257,14 +257,14 @@ class IPTorrentsProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -393,14 +393,14 @@ class KATProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate, s.indexer FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate, s.indexer FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -305,14 +305,14 @@ class NextGenProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -277,14 +277,14 @@ class PublicHDProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -299,14 +299,14 @@ class SCCProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -239,14 +239,14 @@ class SpeedCDProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -371,14 +371,14 @@ class ThePirateBayProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -263,14 +263,14 @@ class TorrentDayProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -258,14 +258,14 @@ class TorrentLeechProvider(generic.TorrentProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
|
||||||
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
|
||||||
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
|
||||||
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
|
||||||
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
|
||||||
)
|
)
|
||||||
|
|
||||||
if not sqlResults:
|
if not sqlResults:
|
||||||
return []
|
return []
|
||||||
|
@ -41,9 +41,9 @@ def get_scene_exceptions(indexer_id, season=-1):
|
|||||||
global exceptionCache
|
global exceptionCache
|
||||||
|
|
||||||
if indexer_id not in exceptionCache or season not in exceptionCache[indexer_id]:
|
if indexer_id not in exceptionCache or season not in exceptionCache[indexer_id]:
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
exceptions = myDB.select("SELECT show_name FROM scene_exceptions WHERE indexer_id = ? and season = ?",
|
exceptions = myDB.select("SELECT show_name FROM scene_exceptions WHERE indexer_id = ? and season = ?",
|
||||||
[indexer_id, season])
|
[indexer_id, season])
|
||||||
exceptionsList = list(set([cur_exception["show_name"] for cur_exception in exceptions]))
|
exceptionsList = list(set([cur_exception["show_name"] for cur_exception in exceptions]))
|
||||||
|
|
||||||
if len(exceptionsList):
|
if len(exceptionsList):
|
||||||
@ -60,8 +60,8 @@ def get_scene_exceptions(indexer_id, season=-1):
|
|||||||
return exceptionsList
|
return exceptionsList
|
||||||
|
|
||||||
def get_all_scene_exceptions(indexer_id):
|
def get_all_scene_exceptions(indexer_id):
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
exceptions = myDB.select("SELECT show_name,season FROM scene_exceptions WHERE indexer_id = ?", [indexer_id])
|
exceptions = myDB.select("SELECT show_name,season FROM scene_exceptions WHERE indexer_id = ?", [indexer_id])
|
||||||
exceptionsList = {}
|
exceptionsList = {}
|
||||||
[cur_exception["show_name"] for cur_exception in exceptions]
|
[cur_exception["show_name"] for cur_exception in exceptions]
|
||||||
for cur_exception in exceptions:
|
for cur_exception in exceptions:
|
||||||
@ -77,9 +77,9 @@ def get_scene_seasons(indexer_id):
|
|||||||
"""
|
"""
|
||||||
global exceptionSeasonCache
|
global exceptionSeasonCache
|
||||||
if indexer_id not in exceptionSeasonCache:
|
if indexer_id not in exceptionSeasonCache:
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
sqlResults = myDB.select("SELECT DISTINCT(season) as season FROM scene_exceptions WHERE indexer_id = ?",
|
sqlResults = myDB.select("SELECT DISTINCT(season) as season FROM scene_exceptions WHERE indexer_id = ?",
|
||||||
[indexer_id])
|
[indexer_id])
|
||||||
exceptionSeasonCache[indexer_id] = [int(x["season"]) for x in sqlResults]
|
exceptionSeasonCache[indexer_id] = [int(x["season"]) for x in sqlResults]
|
||||||
|
|
||||||
return exceptionSeasonCache[indexer_id]
|
return exceptionSeasonCache[indexer_id]
|
||||||
@ -96,15 +96,15 @@ def get_scene_exception_by_name_multiple(show_name):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# try the obvious case first
|
# try the obvious case first
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
exception_result = myDB.select(
|
exception_result = myDB.select(
|
||||||
"SELECT indexer_id, season FROM scene_exceptions WHERE LOWER(show_name) = ? ORDER BY season ASC",
|
"SELECT indexer_id, season FROM scene_exceptions WHERE LOWER(show_name) = ? ORDER BY season ASC",
|
||||||
[show_name.lower()])
|
[show_name.lower()])
|
||||||
if exception_result:
|
if exception_result:
|
||||||
return [(int(x["indexer_id"]), int(x["season"])) for x in exception_result]
|
return [(int(x["indexer_id"]), int(x["season"])) for x in exception_result]
|
||||||
|
|
||||||
out = []
|
out = []
|
||||||
all_exception_results = myDB.select("SELECT show_name, indexer_id, season FROM scene_exceptions")
|
all_exception_results = myDB.select("SELECT show_name, indexer_id, season FROM scene_exceptions")
|
||||||
|
|
||||||
for cur_exception in all_exception_results:
|
for cur_exception in all_exception_results:
|
||||||
|
|
||||||
@ -183,21 +183,21 @@ def retrieve_exceptions():
|
|||||||
changed_exceptions = False
|
changed_exceptions = False
|
||||||
|
|
||||||
# write all the exceptions we got off the net into the database
|
# write all the exceptions we got off the net into the database
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
for cur_indexer_id in exception_dict:
|
for cur_indexer_id in exception_dict:
|
||||||
|
|
||||||
# get a list of the existing exceptions for this ID
|
# get a list of the existing exceptions for this ID
|
||||||
existing_exceptions = [x["show_name"] for x in
|
existing_exceptions = [x["show_name"] for x in
|
||||||
myDB.select("SELECT * FROM scene_exceptions WHERE indexer_id = ?", [cur_indexer_id])]
|
myDB.select("SELECT * FROM scene_exceptions WHERE indexer_id = ?", [cur_indexer_id])]
|
||||||
|
|
||||||
for cur_exception_dict in exception_dict[cur_indexer_id]:
|
for cur_exception_dict in exception_dict[cur_indexer_id]:
|
||||||
cur_exception, curSeason = cur_exception_dict.items()[0]
|
cur_exception, curSeason = cur_exception_dict.items()[0]
|
||||||
|
|
||||||
# if this exception isn't already in the DB then add it
|
# if this exception isn't already in the DB then add it
|
||||||
if cur_exception not in existing_exceptions:
|
if cur_exception not in existing_exceptions:
|
||||||
myDB.action("INSERT INTO scene_exceptions (indexer_id, show_name, season) VALUES (?,?,?)",
|
myDB.action("INSERT INTO scene_exceptions (indexer_id, show_name, season) VALUES (?,?,?)",
|
||||||
[cur_indexer_id, cur_exception, curSeason])
|
[cur_indexer_id, cur_exception, curSeason])
|
||||||
changed_exceptions = True
|
changed_exceptions = True
|
||||||
|
|
||||||
# since this could invalidate the results of the cache we clear it out after updating
|
# since this could invalidate the results of the cache we clear it out after updating
|
||||||
if changed_exceptions:
|
if changed_exceptions:
|
||||||
@ -216,15 +216,15 @@ def update_scene_exceptions(indexer_id, scene_exceptions):
|
|||||||
|
|
||||||
global exceptionIndexerCache
|
global exceptionIndexerCache
|
||||||
|
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
myDB.action('DELETE FROM scene_exceptions WHERE indexer_id=? and custom=1', [indexer_id])
|
myDB.action('DELETE FROM scene_exceptions WHERE indexer_id=? and custom=1', [indexer_id])
|
||||||
|
|
||||||
logger.log(u"Updating internal scene name cache", logger.MESSAGE)
|
logger.log(u"Updating internal scene name cache", logger.MESSAGE)
|
||||||
for cur_season in [-1] + sickbeard.scene_exceptions.get_scene_seasons(indexer_id):
|
for cur_season in [-1] + sickbeard.scene_exceptions.get_scene_seasons(indexer_id):
|
||||||
for cur_exception in scene_exceptions:
|
for cur_exception in scene_exceptions:
|
||||||
exceptionIndexerCache[helpers.full_sanitizeSceneName(cur_exception)] = indexer_id
|
exceptionIndexerCache[helpers.full_sanitizeSceneName(cur_exception)] = indexer_id
|
||||||
myDB.action("INSERT INTO scene_exceptions (indexer_id, show_name, season, custom) VALUES (?,?,?,?)",
|
myDB.action("INSERT INTO scene_exceptions (indexer_id, show_name, season, custom) VALUES (?,?,?,?)",
|
||||||
[indexer_id, cur_exception, cur_season, 1])
|
[indexer_id, cur_exception, cur_season, 1])
|
||||||
|
|
||||||
name_cache.clearCache()
|
name_cache.clearCache()
|
||||||
|
|
||||||
@ -235,30 +235,30 @@ def _retrieve_anidb_mainnames():
|
|||||||
|
|
||||||
anidb_mainNames = {}
|
anidb_mainNames = {}
|
||||||
|
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
rows = myDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?",
|
rows = myDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?",
|
||||||
['anidb'])
|
['anidb'])
|
||||||
if rows:
|
if rows:
|
||||||
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_ANIDB_AGE_SECS)
|
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_ANIDB_AGE_SECS)
|
||||||
else:
|
else:
|
||||||
refresh = True
|
refresh = True
|
||||||
|
|
||||||
if refresh:
|
if refresh:
|
||||||
for show in sickbeard.showList:
|
for show in sickbeard.showList:
|
||||||
if show.is_anime and show.indexer == 1:
|
if show.is_anime and show.indexer == 1:
|
||||||
try:
|
try:
|
||||||
anime = adba.Anime(None, name=show.name, tvdbid=show.indexerid, autoCorrectName=True)
|
anime = adba.Anime(None, name=show.name, tvdbid=show.indexerid, autoCorrectName=True)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
success = True
|
success = True
|
||||||
|
|
||||||
if anime.name and anime.name != show.name:
|
if anime.name and anime.name != show.name:
|
||||||
anidb_mainNames[show.indexerid] = [{anime.name: -1}]
|
anidb_mainNames[show.indexerid] = [{anime.name: -1}]
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
myDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)",
|
myDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)",
|
||||||
['anidb', time.time()])
|
['anidb', time.time()])
|
||||||
|
|
||||||
return anidb_mainNames
|
return anidb_mainNames
|
||||||
|
|
||||||
@ -268,30 +268,30 @@ def _xem_excpetions_fetcher(indexer):
|
|||||||
|
|
||||||
exception_dict = {}
|
exception_dict = {}
|
||||||
|
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
rows = myDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?",
|
rows = myDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?",
|
||||||
['xem'])
|
['xem'])
|
||||||
if rows:
|
if rows:
|
||||||
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS)
|
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS)
|
||||||
else:
|
else:
|
||||||
refresh = True
|
refresh = True
|
||||||
|
|
||||||
if refresh:
|
if refresh:
|
||||||
url = "http://thexem.de/map/allNames?origin=%s&seasonNumbers=1" % sickbeard.indexerApi(indexer).config['xem_origin']
|
url = "http://thexem.de/map/allNames?origin=%s&seasonNumbers=1" % sickbeard.indexerApi(indexer).config['xem_origin']
|
||||||
|
|
||||||
url_data = helpers.getURL(url, json=True)
|
url_data = helpers.getURL(url, json=True)
|
||||||
if url_data is None:
|
if url_data is None:
|
||||||
logger.log(u"Check scene exceptions update failed. Unable to get URL: " + url, logger.ERROR)
|
logger.log(u"Check scene exceptions update failed. Unable to get URL: " + url, logger.ERROR)
|
||||||
return exception_dict
|
return exception_dict
|
||||||
|
|
||||||
if url_data['result'] == 'failure':
|
if url_data['result'] == 'failure':
|
||||||
return exception_dict
|
return exception_dict
|
||||||
|
|
||||||
myDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)",
|
myDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)",
|
||||||
['xem', time.time()])
|
['xem', time.time()])
|
||||||
|
|
||||||
for indexerid, names in url_data['data'].items():
|
for indexerid, names in url_data['data'].items():
|
||||||
exception_dict[int(indexerid)] = names
|
exception_dict[int(indexerid)] = names
|
||||||
|
|
||||||
return exception_dict
|
return exception_dict
|
||||||
|
|
||||||
@ -299,8 +299,8 @@ def _xem_excpetions_fetcher(indexer):
|
|||||||
def getSceneSeasons(indexer_id):
|
def getSceneSeasons(indexer_id):
|
||||||
"""get a list of season numbers that have scene excpetions
|
"""get a list of season numbers that have scene excpetions
|
||||||
"""
|
"""
|
||||||
with db.DBConnection('cache.db') as myDB:
|
myDB = db.DBConnection('cache.db')
|
||||||
seasons = myDB.select("SELECT DISTINCT season FROM scene_exceptions WHERE indexer_id = ?", [indexer_id])
|
seasons = myDB.select("SELECT DISTINCT season FROM scene_exceptions WHERE indexer_id = ?", [indexer_id])
|
||||||
return [cur_exception["season"] for cur_exception in seasons]
|
return [cur_exception["season"] for cur_exception in seasons]
|
||||||
|
|
||||||
def buildIndexerCache():
|
def buildIndexerCache():
|
||||||
|
@ -82,10 +82,10 @@ def find_scene_numbering(indexer_id, indexer, season, episode):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT scene_season, scene_episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and season = ? and episode = ? and (scene_season or scene_episode) != 0",
|
"SELECT scene_season, scene_episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and season = ? and episode = ? and (scene_season or scene_episode) != 0",
|
||||||
[indexer, indexer_id, season, episode])
|
[indexer, indexer_id, season, episode])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return (int(rows[0]["scene_season"]), int(rows[0]["scene_episode"]))
|
return (int(rows[0]["scene_season"]), int(rows[0]["scene_episode"]))
|
||||||
@ -134,10 +134,10 @@ def find_scene_absolute_numbering(indexer_id, indexer, absolute_number):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT scene_absolute_number FROM scene_numbering WHERE indexer = ? and indexer_id = ? and absolute_number = ? and scene_absolute_number != 0",
|
"SELECT scene_absolute_number FROM scene_numbering WHERE indexer = ? and indexer_id = ? and absolute_number = ? and scene_absolute_number != 0",
|
||||||
[indexer, indexer_id, absolute_number])
|
[indexer, indexer_id, absolute_number])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return int(rows[0]["scene_absolute_number"])
|
return int(rows[0]["scene_absolute_number"])
|
||||||
@ -154,10 +154,10 @@ def get_indexer_numbering(indexer_id, indexer, sceneSeason, sceneEpisode, fallba
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ?",
|
"SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ?",
|
||||||
[indexer, indexer_id, sceneSeason, sceneEpisode])
|
[indexer, indexer_id, sceneSeason, sceneEpisode])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return (int(rows[0]["season"]), int(rows[0]["episode"]))
|
return (int(rows[0]["season"]), int(rows[0]["episode"]))
|
||||||
@ -178,10 +178,10 @@ def get_indexer_absolute_numbering(indexer_id, indexer, sceneAbsoluteNumber, fal
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT absolute_number FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_absolute_number = ?",
|
"SELECT absolute_number FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_absolute_number = ?",
|
||||||
[indexer, indexer_id, sceneAbsoluteNumber])
|
[indexer, indexer_id, sceneAbsoluteNumber])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return int(rows[0]["absolute_number"])
|
return int(rows[0]["absolute_number"])
|
||||||
@ -203,23 +203,23 @@ def set_scene_numbering(indexer_id, indexer, season=None, episode=None, absolute
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
if season and episode:
|
if season and episode:
|
||||||
myDB.action(
|
myDB.action(
|
||||||
"INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, season, episode) VALUES (?,?,?,?)",
|
"INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, season, episode) VALUES (?,?,?,?)",
|
||||||
[indexer, indexer_id, season, episode])
|
[indexer, indexer_id, season, episode])
|
||||||
|
|
||||||
myDB.action(
|
myDB.action(
|
||||||
"UPDATE scene_numbering SET scene_season = ?, scene_episode = ? WHERE indexer = ? and indexer_id = ? and season = ? and episode = ?",
|
"UPDATE scene_numbering SET scene_season = ?, scene_episode = ? WHERE indexer = ? and indexer_id = ? and season = ? and episode = ?",
|
||||||
[sceneSeason, sceneEpisode, indexer, indexer_id, season, episode])
|
[sceneSeason, sceneEpisode, indexer, indexer_id, season, episode])
|
||||||
elif absolute_number:
|
elif absolute_number:
|
||||||
myDB.action(
|
myDB.action(
|
||||||
"INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, absolute_number) VALUES (?,?,?)",
|
"INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, absolute_number) VALUES (?,?,?)",
|
||||||
[indexer, indexer_id, absolute_number])
|
[indexer, indexer_id, absolute_number])
|
||||||
|
|
||||||
myDB.action(
|
myDB.action(
|
||||||
"UPDATE scene_numbering SET scene_absolute_number = ? WHERE indexer = ? and indexer_id = ? and absolute_number = ?",
|
"UPDATE scene_numbering SET scene_absolute_number = ? WHERE indexer = ? and indexer_id = ? and absolute_number = ?",
|
||||||
[sceneAbsolute, indexer, indexer_id, absolute_number])
|
[sceneAbsolute, indexer, indexer_id, absolute_number])
|
||||||
|
|
||||||
|
|
||||||
def find_xem_numbering(indexer_id, indexer, season, episode):
|
def find_xem_numbering(indexer_id, indexer, season, episode):
|
||||||
@ -240,10 +240,10 @@ def find_xem_numbering(indexer_id, indexer, season, episode):
|
|||||||
|
|
||||||
xem_refresh(indexer_id, indexer)
|
xem_refresh(indexer_id, indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT scene_season, scene_episode FROM tv_episodes WHERE indexer = ? and showid = ? and season = ? and episode = ? and (scene_season or scene_episode) != 0",
|
"SELECT scene_season, scene_episode FROM tv_episodes WHERE indexer = ? and showid = ? and season = ? and episode = ? and (scene_season or scene_episode) != 0",
|
||||||
[indexer, indexer_id, season, episode])
|
[indexer, indexer_id, season, episode])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return (int(rows[0]["scene_season"]), int(rows[0]["scene_episode"]))
|
return (int(rows[0]["scene_season"]), int(rows[0]["scene_episode"]))
|
||||||
@ -266,10 +266,10 @@ def find_xem_absolute_numbering(indexer_id, indexer, absolute_number):
|
|||||||
|
|
||||||
xem_refresh(indexer_id, indexer)
|
xem_refresh(indexer_id, indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and absolute_number = ? and scene_absolute_number != 0",
|
"SELECT scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and absolute_number = ? and scene_absolute_number != 0",
|
||||||
[indexer, indexer_id, absolute_number])
|
[indexer, indexer_id, absolute_number])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return int(rows[0]["scene_absolute_number"])
|
return int(rows[0]["scene_absolute_number"])
|
||||||
@ -292,10 +292,10 @@ def get_indexer_numbering_for_xem(indexer_id, indexer, sceneSeason, sceneEpisode
|
|||||||
|
|
||||||
xem_refresh(indexer_id, indexer)
|
xem_refresh(indexer_id, indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ?",
|
"SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ?",
|
||||||
[indexer, indexer_id, sceneSeason, sceneEpisode])
|
[indexer, indexer_id, sceneSeason, sceneEpisode])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return (int(rows[0]["season"]), int(rows[0]["episode"]))
|
return (int(rows[0]["season"]), int(rows[0]["episode"]))
|
||||||
@ -319,10 +319,10 @@ def get_indexer_absolute_numbering_for_xem(indexer_id, indexer, sceneAbsoluteNum
|
|||||||
|
|
||||||
xem_refresh(indexer_id, indexer)
|
xem_refresh(indexer_id, indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
"SELECT absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and scene_absolute_number = ?",
|
"SELECT absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and scene_absolute_number = ?",
|
||||||
[indexer, indexer_id, sceneAbsoluteNumber])
|
[indexer, indexer_id, sceneAbsoluteNumber])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
return int(rows[0]["absolute_number"])
|
return int(rows[0]["absolute_number"])
|
||||||
@ -342,10 +342,10 @@ def get_scene_numbering_for_show(indexer_id, indexer):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
'SELECT season, episode, scene_season, scene_episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and (scene_season or scene_episode) != 0 ORDER BY season, episode',
|
'SELECT season, episode, scene_season, scene_episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and (scene_season or scene_episode) != 0 ORDER BY season, episode',
|
||||||
[indexer, indexer_id])
|
[indexer, indexer_id])
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@ -373,10 +373,10 @@ def get_xem_numbering_for_show(indexer_id, indexer):
|
|||||||
|
|
||||||
xem_refresh(indexer_id, indexer)
|
xem_refresh(indexer_id, indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
'SELECT season, episode, scene_season, scene_episode FROM tv_episodes WHERE indexer = ? and showid = ? and (scene_season or scene_episode) != 0 ORDER BY season, episode',
|
'SELECT season, episode, scene_season, scene_episode FROM tv_episodes WHERE indexer = ? and showid = ? and (scene_season or scene_episode) != 0 ORDER BY season, episode',
|
||||||
[indexer, indexer_id])
|
[indexer, indexer_id])
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@ -402,10 +402,10 @@ def get_scene_absolute_numbering_for_show(indexer_id, indexer):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
'SELECT absolute_number, scene_absolute_number FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_absolute_number != 0 ORDER BY absolute_number',
|
'SELECT absolute_number, scene_absolute_number FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_absolute_number != 0 ORDER BY absolute_number',
|
||||||
[indexer, indexer_id])
|
[indexer, indexer_id])
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@ -433,10 +433,10 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer):
|
|||||||
|
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
'SELECT absolute_number, scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and scene_absolute_number != 0 ORDER BY absolute_number',
|
'SELECT absolute_number, scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and scene_absolute_number != 0 ORDER BY absolute_number',
|
||||||
[indexer, indexer_id])
|
[indexer, indexer_id])
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
absolute_number = int(row['absolute_number'])
|
absolute_number = int(row['absolute_number'])
|
||||||
@ -458,9 +458,9 @@ def xem_refresh(indexer_id, indexer, force=False):
|
|||||||
indexer_id = int(indexer_id)
|
indexer_id = int(indexer_id)
|
||||||
indexer = int(indexer)
|
indexer = int(indexer)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select("SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ?",
|
rows = myDB.select("SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ?",
|
||||||
[indexer, indexer_id])
|
[indexer, indexer_id])
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS)
|
refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS)
|
||||||
@ -526,8 +526,8 @@ def xem_refresh(indexer_id, indexer, force=False):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if ql:
|
if ql:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(ql)
|
myDB.mass_action(ql)
|
||||||
|
|
||||||
# fix xem scene numbering issues
|
# fix xem scene numbering issues
|
||||||
# fix_xem_numbering(indexer_id, indexer)
|
# fix_xem_numbering(indexer_id, indexer)
|
||||||
@ -585,10 +585,10 @@ def fix_xem_numbering(indexer_id, indexer):
|
|||||||
# # Get query results
|
# # Get query results
|
||||||
# tmp = get_from_api(url, params=params)['result']
|
# tmp = get_from_api(url, params=params)['result']
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
'SELECT season, episode, absolute_number, scene_season, scene_episode, scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ?',
|
'SELECT season, episode, absolute_number, scene_season, scene_episode, scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ?',
|
||||||
[indexer, indexer_id])
|
[indexer, indexer_id])
|
||||||
|
|
||||||
last_absolute_number = None
|
last_absolute_number = None
|
||||||
last_scene_season = None
|
last_scene_season = None
|
||||||
@ -693,5 +693,5 @@ def fix_xem_numbering(indexer_id, indexer):
|
|||||||
update_scene_absolute_number = False
|
update_scene_absolute_number = False
|
||||||
|
|
||||||
if ql:
|
if ql:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(ql)
|
myDB.mass_action(ql)
|
@ -173,8 +173,8 @@ def snatchEpisode(result, endStatus=SNATCHED):
|
|||||||
notifiers.notify_snatch(curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN'))
|
notifiers.notify_snatch(curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN'))
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -509,10 +509,10 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
|||||||
u"The quality of the season " + bestSeasonNZB.provider.providerType + " is " + Quality.qualityStrings[
|
u"The quality of the season " + bestSeasonNZB.provider.providerType + " is " + Quality.qualityStrings[
|
||||||
seasonQual], logger.DEBUG)
|
seasonQual], logger.DEBUG)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
allEps = [int(x["episode"]) for x in
|
allEps = [int(x["episode"]) for x in
|
||||||
myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND season = ?",
|
myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND season = ?",
|
||||||
[show.indexerid, season])]
|
[show.indexerid, season])]
|
||||||
logger.log(u"Episode list: " + str(allEps), logger.DEBUG)
|
logger.log(u"Episode list: " + str(allEps), logger.DEBUG)
|
||||||
|
|
||||||
allWanted = True
|
allWanted = True
|
||||||
|
@ -117,8 +117,8 @@ class BacklogSearcher:
|
|||||||
|
|
||||||
logger.log(u"Retrieving the last check time from the DB", logger.DEBUG)
|
logger.log(u"Retrieving the last check time from the DB", logger.DEBUG)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM info")
|
sqlResults = myDB.select("SELECT * FROM info")
|
||||||
|
|
||||||
if len(sqlResults) == 0:
|
if len(sqlResults) == 0:
|
||||||
lastBacklog = 1
|
lastBacklog = 1
|
||||||
@ -137,15 +137,15 @@ class BacklogSearcher:
|
|||||||
|
|
||||||
logger.log(u"Seeing if we need anything from " + show.name)
|
logger.log(u"Seeing if we need anything from " + show.name)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
if show.air_by_date:
|
if show.air_by_date:
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT ep.status, ep.season, ep.episode FROM tv_episodes ep, tv_shows show WHERE season != 0 AND ep.showid = show.indexer_id AND show.paused = 0 ANd ep.airdate > ? AND ep.showid = ? AND show.air_by_date = 1",
|
"SELECT ep.status, ep.season, ep.episode FROM tv_episodes ep, tv_shows show WHERE season != 0 AND ep.showid = show.indexer_id AND show.paused = 0 ANd ep.airdate > ? AND ep.showid = ? AND show.air_by_date = 1",
|
||||||
[fromDate.toordinal(), show.indexerid])
|
[fromDate.toordinal(), show.indexerid])
|
||||||
else:
|
else:
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT status, season, episode FROM tv_episodes WHERE showid = ? AND season > 0 and airdate > ?",
|
"SELECT status, season, episode FROM tv_episodes WHERE showid = ? AND season > 0 and airdate > ?",
|
||||||
[show.indexerid, fromDate.toordinal()])
|
[show.indexerid, fromDate.toordinal()])
|
||||||
|
|
||||||
# check through the list of statuses to see if we want any
|
# check through the list of statuses to see if we want any
|
||||||
wanted = {}
|
wanted = {}
|
||||||
@ -175,13 +175,13 @@ class BacklogSearcher:
|
|||||||
|
|
||||||
logger.log(u"Setting the last backlog in the DB to " + str(when), logger.DEBUG)
|
logger.log(u"Setting the last backlog in the DB to " + str(when), logger.DEBUG)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM info")
|
sqlResults = myDB.select("SELECT * FROM info")
|
||||||
|
|
||||||
if len(sqlResults) == 0:
|
if len(sqlResults) == 0:
|
||||||
myDB.action("INSERT INTO info (last_backlog, last_indexer) VALUES (?,?)", [str(when), 0])
|
myDB.action("INSERT INTO info (last_backlog, last_indexer) VALUES (?,?)", [str(when), 0])
|
||||||
else:
|
else:
|
||||||
myDB.action("UPDATE info SET last_backlog=" + str(when))
|
myDB.action("UPDATE info SET last_backlog=" + str(when))
|
||||||
|
|
||||||
|
|
||||||
def run(self, force=False):
|
def run(self, force=False):
|
||||||
|
@ -73,10 +73,10 @@ class ShowUpdater():
|
|||||||
stale_update_date = (update_date - datetime.timedelta(days=90)).toordinal()
|
stale_update_date = (update_date - datetime.timedelta(days=90)).toordinal()
|
||||||
|
|
||||||
# last_update_date <= 90 days, sorted ASC because dates are ordinal
|
# last_update_date <= 90 days, sorted ASC because dates are ordinal
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_result = myDB.select(
|
sql_result = myDB.select(
|
||||||
"SELECT indexer_id FROM tv_shows WHERE status = 'Ended' AND last_update_indexer <= ? ORDER BY last_update_indexer ASC LIMIT 10;",
|
"SELECT indexer_id FROM tv_shows WHERE status = 'Ended' AND last_update_indexer <= ? ORDER BY last_update_indexer ASC LIMIT 10;",
|
||||||
[stale_update_date])
|
[stale_update_date])
|
||||||
|
|
||||||
for cur_result in sql_result:
|
for cur_result in sql_result:
|
||||||
stale_should_update.append(int(cur_result['indexer_id']))
|
stale_should_update.append(int(cur_result['indexer_id']))
|
||||||
|
@ -143,10 +143,10 @@ def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None):
|
|||||||
seasonStrings.append("%d" % ab_number)
|
seasonStrings.append("%d" % ab_number)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
numseasonsSQlResult = myDB.select(
|
numseasonsSQlResult = myDB.select(
|
||||||
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and season != 0",
|
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and season != 0",
|
||||||
[show.indexerid])
|
[show.indexerid])
|
||||||
|
|
||||||
numseasons = int(numseasonsSQlResult[0][0])
|
numseasons = int(numseasonsSQlResult[0][0])
|
||||||
seasonStrings = ["S%02d" % int(ep_obj.scene_season)]
|
seasonStrings = ["S%02d" % int(ep_obj.scene_season)]
|
||||||
@ -177,10 +177,10 @@ def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None):
|
|||||||
|
|
||||||
|
|
||||||
def makeSceneSearchString(show, ep_obj):
|
def makeSceneSearchString(show, ep_obj):
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
numseasonsSQlResult = myDB.select(
|
numseasonsSQlResult = myDB.select(
|
||||||
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and season != 0",
|
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and season != 0",
|
||||||
[show.indexerid])
|
[show.indexerid])
|
||||||
numseasons = int(numseasonsSQlResult[0][0])
|
numseasons = int(numseasonsSQlResult[0][0])
|
||||||
|
|
||||||
# see if we should use dates instead of episodes
|
# see if we should use dates instead of episodes
|
||||||
|
@ -370,9 +370,9 @@ class QueueItemAdd(ShowQueueItem):
|
|||||||
# if they gave a custom status then change all the eps to it
|
# if they gave a custom status then change all the eps to it
|
||||||
if self.default_status != SKIPPED:
|
if self.default_status != SKIPPED:
|
||||||
logger.log(u"Setting all episodes to the specified default status: " + str(self.default_status))
|
logger.log(u"Setting all episodes to the specified default status: " + str(self.default_status))
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.action("UPDATE tv_episodes SET status = ? WHERE status = ? AND showid = ? AND season != 0",
|
myDB.action("UPDATE tv_episodes SET status = ? WHERE status = ? AND showid = ? AND season != 0",
|
||||||
[self.default_status, SKIPPED, self.show.indexerid])
|
[self.default_status, SKIPPED, self.show.indexerid])
|
||||||
|
|
||||||
# if they started with WANTED eps then run the backlog
|
# if they started with WANTED eps then run the backlog
|
||||||
if self.default_status == WANTED:
|
if self.default_status == WANTED:
|
||||||
|
@ -107,8 +107,8 @@ class SubtitlesFinder():
|
|||||||
today = datetime.date.today().toordinal()
|
today = datetime.date.today().toordinal()
|
||||||
|
|
||||||
# you have 5 minutes to understand that one. Good luck
|
# you have 5 minutes to understand that one. Good luck
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select('SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.subtitles, e.subtitles_searchcount AS searchcount, e.subtitles_lastsearch AS lastsearch, e.location, (? - e.airdate) AS airdate_daydiff FROM tv_episodes AS e INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id) WHERE s.subtitles = 1 AND e.subtitles NOT LIKE (?) AND ((e.subtitles_searchcount <= 2 AND (? - e.airdate) > 7) OR (e.subtitles_searchcount <= 7 AND (? - e.airdate) <= 7)) AND (e.status IN ('+','.join([str(x) for x in Quality.DOWNLOADED])+') OR (e.status IN ('+','.join([str(x) for x in Quality.SNATCHED + Quality.SNATCHED_PROPER])+') AND e.location != ""))', [today, wantedLanguages(True), today, today])
|
sqlResults = myDB.select('SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.subtitles, e.subtitles_searchcount AS searchcount, e.subtitles_lastsearch AS lastsearch, e.location, (? - e.airdate) AS airdate_daydiff FROM tv_episodes AS e INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id) WHERE s.subtitles = 1 AND e.subtitles NOT LIKE (?) AND ((e.subtitles_searchcount <= 2 AND (? - e.airdate) > 7) OR (e.subtitles_searchcount <= 7 AND (? - e.airdate) <= 7)) AND (e.status IN ('+','.join([str(x) for x in Quality.DOWNLOADED])+') OR (e.status IN ('+','.join([str(x) for x in Quality.SNATCHED + Quality.SNATCHED_PROPER])+') AND e.location != ""))', [today, wantedLanguages(True), today, today])
|
||||||
if len(sqlResults) == 0:
|
if len(sqlResults) == 0:
|
||||||
logger.log('No subtitles to download', logger.MESSAGE)
|
logger.log('No subtitles to download', logger.MESSAGE)
|
||||||
return
|
return
|
||||||
|
188
sickbeard/tv.py
188
sickbeard/tv.py
@ -169,25 +169,25 @@ class TVShow(object):
|
|||||||
# need ORDER episode ASC to rename multi-episodes in order S01E01-02
|
# need ORDER episode ASC to rename multi-episodes in order S01E01-02
|
||||||
sql_selection = sql_selection + " ORDER BY season ASC, episode ASC"
|
sql_selection = sql_selection + " ORDER BY season ASC, episode ASC"
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
results = myDB.select(sql_selection)
|
results = myDB.select(sql_selection)
|
||||||
|
|
||||||
ep_list = []
|
ep_list = []
|
||||||
for cur_result in results:
|
for cur_result in results:
|
||||||
cur_ep = self.getEpisode(int(cur_result["season"]), int(cur_result["episode"]))
|
cur_ep = self.getEpisode(int(cur_result["season"]), int(cur_result["episode"]))
|
||||||
if cur_ep:
|
if cur_ep:
|
||||||
cur_ep.relatedEps = []
|
cur_ep.relatedEps = []
|
||||||
if cur_ep.location:
|
if cur_ep.location:
|
||||||
# if there is a location, check if it's a multi-episode (share_location > 0) and put them in relatedEps
|
# if there is a location, check if it's a multi-episode (share_location > 0) and put them in relatedEps
|
||||||
if cur_result["share_location"] > 0:
|
if cur_result["share_location"] > 0:
|
||||||
related_eps_result = myDB.select(
|
related_eps_result = myDB.select(
|
||||||
"SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND location = ? AND episode != ? ORDER BY episode ASC",
|
"SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND location = ? AND episode != ? ORDER BY episode ASC",
|
||||||
[self.indexerid, cur_ep.season, cur_ep.location, cur_ep.episode])
|
[self.indexerid, cur_ep.season, cur_ep.location, cur_ep.episode])
|
||||||
for cur_related_ep in related_eps_result:
|
for cur_related_ep in related_eps_result:
|
||||||
related_ep = self.getEpisode(int(cur_related_ep["season"]), int(cur_related_ep["episode"]))
|
related_ep = self.getEpisode(int(cur_related_ep["season"]), int(cur_related_ep["episode"]))
|
||||||
if related_ep not in cur_ep.relatedEps:
|
if related_ep not in cur_ep.relatedEps:
|
||||||
cur_ep.relatedEps.append(related_ep)
|
cur_ep.relatedEps.append(related_ep)
|
||||||
ep_list.append(cur_ep)
|
ep_list.append(cur_ep)
|
||||||
|
|
||||||
return ep_list
|
return ep_list
|
||||||
|
|
||||||
@ -201,9 +201,9 @@ class TVShow(object):
|
|||||||
|
|
||||||
# if we get an anime get the real season and episode
|
# if we get an anime get the real season and episode
|
||||||
if self.is_anime and absolute_number and not season and not episode:
|
if self.is_anime and absolute_number and not season and not episode:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql = "SELECT * FROM tv_episodes WHERE showid = ? and absolute_number = ? and season != 0"
|
sql = "SELECT * FROM tv_episodes WHERE showid = ? and absolute_number = ? and season != 0"
|
||||||
sqlResults = myDB.select(sql, [self.indexerid, absolute_number])
|
sqlResults = myDB.select(sql, [self.indexerid, absolute_number])
|
||||||
|
|
||||||
if len(sqlResults) == 1:
|
if len(sqlResults) == 1:
|
||||||
episode = int(sqlResults[0]["episode"])
|
episode = int(sqlResults[0]["episode"])
|
||||||
@ -266,25 +266,25 @@ class TVShow(object):
|
|||||||
last_airdate = datetime.date.fromordinal(1)
|
last_airdate = datetime.date.fromordinal(1)
|
||||||
|
|
||||||
# get latest aired episode to compare against today - graceperiod and today + graceperiod
|
# get latest aired episode to compare against today - graceperiod and today + graceperiod
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_result = myDB.select(
|
sql_result = myDB.select(
|
||||||
"SELECT * FROM tv_episodes WHERE showid = ? AND season > '0' AND airdate > '1' AND status > '1' ORDER BY airdate DESC LIMIT 1",
|
"SELECT * FROM tv_episodes WHERE showid = ? AND season > '0' AND airdate > '1' AND status > '1' ORDER BY airdate DESC LIMIT 1",
|
||||||
[cur_indexerid])
|
[cur_indexerid])
|
||||||
|
|
||||||
if sql_result:
|
if sql_result:
|
||||||
last_airdate = datetime.date.fromordinal(sql_result[0]['airdate'])
|
last_airdate = datetime.date.fromordinal(sql_result[0]['airdate'])
|
||||||
if last_airdate >= (update_date - graceperiod) and last_airdate <= (update_date + graceperiod):
|
if last_airdate >= (update_date - graceperiod) and last_airdate <= (update_date + graceperiod):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# get next upcoming UNAIRED episode to compare against today + graceperiod
|
# get next upcoming UNAIRED episode to compare against today + graceperiod
|
||||||
sql_result = myDB.select(
|
sql_result = myDB.select(
|
||||||
"SELECT * FROM tv_episodes WHERE showid = ? AND season > '0' AND airdate > '1' AND status = '1' ORDER BY airdate ASC LIMIT 1",
|
"SELECT * FROM tv_episodes WHERE showid = ? AND season > '0' AND airdate > '1' AND status = '1' ORDER BY airdate ASC LIMIT 1",
|
||||||
[cur_indexerid])
|
[cur_indexerid])
|
||||||
|
|
||||||
if sql_result:
|
if sql_result:
|
||||||
next_airdate = datetime.date.fromordinal(sql_result[0]['airdate'])
|
next_airdate = datetime.date.fromordinal(sql_result[0]['airdate'])
|
||||||
if next_airdate <= (update_date + graceperiod):
|
if next_airdate <= (update_date + graceperiod):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
last_update_indexer = datetime.date.fromordinal(self.last_update_indexer)
|
last_update_indexer = datetime.date.fromordinal(self.last_update_indexer)
|
||||||
|
|
||||||
@ -330,8 +330,8 @@ class TVShow(object):
|
|||||||
|
|
||||||
logger.log(str(self.indexerid) + u": Writing NFOs for all episodes")
|
logger.log(str(self.indexerid) + u": Writing NFOs for all episodes")
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND location != ''", [self.indexerid])
|
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND location != ''", [self.indexerid])
|
||||||
|
|
||||||
for epResult in sqlResults:
|
for epResult in sqlResults:
|
||||||
logger.log(str(self.indexerid) + u": Retrieving/creating episode " + str(epResult["season"]) + "x" + str(
|
logger.log(str(self.indexerid) + u": Retrieving/creating episode " + str(epResult["season"]) + "x" + str(
|
||||||
@ -421,16 +421,16 @@ class TVShow(object):
|
|||||||
sql_l.append(curEpisode.get_sql())
|
sql_l.append(curEpisode.get_sql())
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
def loadEpisodesFromDB(self):
|
def loadEpisodesFromDB(self):
|
||||||
|
|
||||||
logger.log(u"Loading all episodes from the DB")
|
logger.log(u"Loading all episodes from the DB")
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql = "SELECT * FROM tv_episodes WHERE showid = ?"
|
sql = "SELECT * FROM tv_episodes WHERE showid = ?"
|
||||||
sqlResults = myDB.select(sql, [self.indexerid])
|
sqlResults = myDB.select(sql, [self.indexerid])
|
||||||
|
|
||||||
scannedEps = {}
|
scannedEps = {}
|
||||||
|
|
||||||
@ -542,8 +542,8 @@ class TVShow(object):
|
|||||||
scannedEps[season][episode] = True
|
scannedEps[season][episode] = True
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
# Done updating save last update date
|
# Done updating save last update date
|
||||||
self.last_update_indexer = datetime.date.today().toordinal()
|
self.last_update_indexer = datetime.date.today().toordinal()
|
||||||
@ -602,10 +602,10 @@ class TVShow(object):
|
|||||||
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
||||||
logger.DEBUG)
|
logger.DEBUG)
|
||||||
airdate = parse_result.air_date.toordinal() or parse_result.sports_event_date.toordinal()
|
airdate = parse_result.air_date.toordinal() or parse_result.sports_event_date.toordinal()
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_result = myDB.select(
|
sql_result = myDB.select(
|
||||||
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
|
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
|
||||||
[self.indexerid, self.indexer, airdate])
|
[self.indexerid, self.indexer, airdate])
|
||||||
|
|
||||||
if sql_result:
|
if sql_result:
|
||||||
season = int(sql_result[0][0])
|
season = int(sql_result[0][0])
|
||||||
@ -712,8 +712,8 @@ class TVShow(object):
|
|||||||
sql_l.append(curEp.get_sql())
|
sql_l.append(curEp.get_sql())
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
# creating metafiles on the root should be good enough
|
# creating metafiles on the root should be good enough
|
||||||
if sickbeard.USE_FAILED_DOWNLOADS and rootEp is not None:
|
if sickbeard.USE_FAILED_DOWNLOADS and rootEp is not None:
|
||||||
@ -726,8 +726,8 @@ class TVShow(object):
|
|||||||
|
|
||||||
logger.log(str(self.indexerid) + u": Loading show info from database")
|
logger.log(str(self.indexerid) + u": Loading show info from database")
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_shows WHERE indexer_id = ?", [self.indexerid])
|
sqlResults = myDB.select("SELECT * FROM tv_shows WHERE indexer_id = ?", [self.indexerid])
|
||||||
|
|
||||||
if len(sqlResults) > 1:
|
if len(sqlResults) > 1:
|
||||||
raise exceptions.MultipleDBShowsException()
|
raise exceptions.MultipleDBShowsException()
|
||||||
@ -806,8 +806,8 @@ class TVShow(object):
|
|||||||
self.imdbid = sqlResults[0]["imdb_id"]
|
self.imdbid = sqlResults[0]["imdb_id"]
|
||||||
|
|
||||||
# Get IMDb_info from database
|
# Get IMDb_info from database
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM imdb_info WHERE indexer_id = ?", [self.indexerid])
|
sqlResults = myDB.select("SELECT * FROM imdb_info WHERE indexer_id = ?", [self.indexerid])
|
||||||
|
|
||||||
if len(sqlResults) == 0:
|
if len(sqlResults) == 0:
|
||||||
logger.log(str(self.indexerid) + ": Unable to find IMDb show info in the database")
|
logger.log(str(self.indexerid) + ": Unable to find IMDb show info in the database")
|
||||||
@ -936,12 +936,12 @@ class TVShow(object):
|
|||||||
def nextEpisode(self):
|
def nextEpisode(self):
|
||||||
logger.log(str(self.indexerid) + ": Finding the episode which airs next", logger.DEBUG)
|
logger.log(str(self.indexerid) + ": Finding the episode which airs next", logger.DEBUG)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
innerQuery = "SELECT airdate FROM tv_episodes WHERE showid = ? AND airdate >= ? AND status in (?,?) ORDER BY airdate ASC LIMIT 1"
|
innerQuery = "SELECT airdate FROM tv_episodes WHERE showid = ? AND airdate >= ? AND status in (?,?) ORDER BY airdate ASC LIMIT 1"
|
||||||
innerParams = [self.indexerid, datetime.date.today().toordinal(), UNAIRED, WANTED]
|
innerParams = [self.indexerid, datetime.date.today().toordinal(), UNAIRED, WANTED]
|
||||||
query = "SELECT * FROM tv_episodes WHERE showid = ? AND airdate >= ? AND airdate <= (" + innerQuery + ") and status in (?,?)"
|
query = "SELECT * FROM tv_episodes WHERE showid = ? AND airdate >= ? AND airdate <= (" + innerQuery + ") and status in (?,?)"
|
||||||
params = [self.indexerid, datetime.date.today().toordinal()] + innerParams + [UNAIRED, WANTED]
|
params = [self.indexerid, datetime.date.today().toordinal()] + innerParams + [UNAIRED, WANTED]
|
||||||
sqlResults = myDB.select(query, params)
|
sqlResults = myDB.select(query, params)
|
||||||
|
|
||||||
if sqlResults == None or len(sqlResults) == 0:
|
if sqlResults == None or len(sqlResults) == 0:
|
||||||
logger.log(str(self.indexerid) + u": No episode found... need to implement a show status",
|
logger.log(str(self.indexerid) + u": No episode found... need to implement a show status",
|
||||||
@ -964,8 +964,8 @@ class TVShow(object):
|
|||||||
["DELETE FROM xem_refresh WHERE indexer_id = ?", [self.indexerid]],
|
["DELETE FROM xem_refresh WHERE indexer_id = ?", [self.indexerid]],
|
||||||
["DELETE FROM scene_numbering WHERE indexer_id = ?", [self.indexerid]]]
|
["DELETE FROM scene_numbering WHERE indexer_id = ?", [self.indexerid]]]
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
# remove self from show list
|
# remove self from show list
|
||||||
sickbeard.showList = [x for x in sickbeard.showList if int(x.indexerid) != self.indexerid]
|
sickbeard.showList = [x for x in sickbeard.showList if int(x.indexerid) != self.indexerid]
|
||||||
@ -994,8 +994,8 @@ class TVShow(object):
|
|||||||
# run through all locations from DB, check that they exist
|
# run through all locations from DB, check that they exist
|
||||||
logger.log(str(self.indexerid) + u": Loading all episodes with a location from the database")
|
logger.log(str(self.indexerid) + u": Loading all episodes with a location from the database")
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND location != ''", [self.indexerid])
|
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND location != ''", [self.indexerid])
|
||||||
|
|
||||||
sql_l = []
|
sql_l = []
|
||||||
for ep in sqlResults:
|
for ep in sqlResults:
|
||||||
@ -1038,8 +1038,8 @@ class TVShow(object):
|
|||||||
self.airdateModifyStamp(curEp)
|
self.airdateModifyStamp(curEp)
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
def airdateModifyStamp(self, ep_obj):
|
def airdateModifyStamp(self, ep_obj):
|
||||||
"""
|
"""
|
||||||
@ -1088,10 +1088,10 @@ class TVShow(object):
|
|||||||
logger.log(str(self.indexerid) + ": Downloading subtitles", logger.DEBUG)
|
logger.log(str(self.indexerid) + ": Downloading subtitles", logger.DEBUG)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
episodes = myDB.select(
|
episodes = myDB.select(
|
||||||
"SELECT location FROM tv_episodes WHERE showid = ? AND location NOT LIKE '' ORDER BY season DESC, episode DESC",
|
"SELECT location FROM tv_episodes WHERE showid = ? AND location NOT LIKE '' ORDER BY season DESC, episode DESC",
|
||||||
[self.indexerid])
|
[self.indexerid])
|
||||||
|
|
||||||
for episodeLoc in episodes:
|
for episodeLoc in episodes:
|
||||||
episode = self.makeEpFromFile(episodeLoc['location'])
|
episode = self.makeEpFromFile(episodeLoc['location'])
|
||||||
@ -1132,8 +1132,8 @@ class TVShow(object):
|
|||||||
"rls_require_words": self.rls_require_words
|
"rls_require_words": self.rls_require_words
|
||||||
}
|
}
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.upsert("tv_shows", newValueDict, controlValueDict)
|
myDB.upsert("tv_shows", newValueDict, controlValueDict)
|
||||||
|
|
||||||
helpers.update_anime_support()
|
helpers.update_anime_support()
|
||||||
|
|
||||||
@ -1141,8 +1141,8 @@ class TVShow(object):
|
|||||||
controlValueDict = {"indexer_id": self.indexerid}
|
controlValueDict = {"indexer_id": self.indexerid}
|
||||||
newValueDict = self.imdb_info
|
newValueDict = self.imdb_info
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.upsert("imdb_info", newValueDict, controlValueDict)
|
myDB.upsert("imdb_info", newValueDict, controlValueDict)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
toReturn = ""
|
toReturn = ""
|
||||||
@ -1182,9 +1182,9 @@ class TVShow(object):
|
|||||||
logger.log(u"Don't want this quality, ignoring found episode", logger.DEBUG)
|
logger.log(u"Don't want this quality, ignoring found episode", logger.DEBUG)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
sqlResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||||
[self.indexerid, season, episode])
|
[self.indexerid, season, episode])
|
||||||
|
|
||||||
if not sqlResults or not len(sqlResults):
|
if not sqlResults or not len(sqlResults):
|
||||||
logger.log(u"Unable to find a matching episode in database, ignoring found episode", logger.DEBUG)
|
logger.log(u"Unable to find a matching episode in database, ignoring found episode", logger.DEBUG)
|
||||||
@ -1474,9 +1474,9 @@ class TVEpisode(object):
|
|||||||
str(self.show.indexerid) + u": Loading episode details from DB for episode " + str(season) + "x" + str(
|
str(self.show.indexerid) + u": Loading episode details from DB for episode " + str(season) + "x" + str(
|
||||||
episode), logger.DEBUG)
|
episode), logger.DEBUG)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||||
[self.show.indexerid, season, episode])
|
[self.show.indexerid, season, episode])
|
||||||
|
|
||||||
if len(sqlResults) > 1:
|
if len(sqlResults) > 1:
|
||||||
raise exceptions.MultipleDBEpisodesException("Your DB has two records for the same show somehow.")
|
raise exceptions.MultipleDBEpisodesException("Your DB has two records for the same show somehow.")
|
||||||
@ -1827,10 +1827,10 @@ class TVEpisode(object):
|
|||||||
|
|
||||||
# delete myself from the DB
|
# delete myself from the DB
|
||||||
logger.log(u"Deleting myself from the database", logger.DEBUG)
|
logger.log(u"Deleting myself from the database", logger.DEBUG)
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql = "DELETE FROM tv_episodes WHERE showid=" + str(self.show.indexerid) + " AND season=" + str(
|
sql = "DELETE FROM tv_episodes WHERE showid=" + str(self.show.indexerid) + " AND season=" + str(
|
||||||
self.season) + " AND episode=" + str(self.episode)
|
self.season) + " AND episode=" + str(self.episode)
|
||||||
myDB.action(sql)
|
myDB.action(sql)
|
||||||
|
|
||||||
raise exceptions.EpisodeDeletedException()
|
raise exceptions.EpisodeDeletedException()
|
||||||
|
|
||||||
@ -1846,10 +1846,10 @@ class TVEpisode(object):
|
|||||||
logger.log(str(self.show.indexerid) + u": Not creating SQL queue - record is not dirty", logger.DEBUG)
|
logger.log(str(self.show.indexerid) + u": Not creating SQL queue - record is not dirty", logger.DEBUG)
|
||||||
return
|
return
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select(
|
rows = myDB.select(
|
||||||
'SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?',
|
'SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?',
|
||||||
[self.show.indexerid, self.season, self.episode])
|
[self.show.indexerid, self.season, self.episode])
|
||||||
|
|
||||||
epID = None
|
epID = None
|
||||||
if rows:
|
if rows:
|
||||||
@ -1917,8 +1917,8 @@ class TVEpisode(object):
|
|||||||
"episode": self.episode}
|
"episode": self.episode}
|
||||||
|
|
||||||
# use a custom update/insert method to get the data into the DB
|
# use a custom update/insert method to get the data into the DB
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.upsert("tv_episodes", newValueDict, controlValueDict)
|
myDB.upsert("tv_episodes", newValueDict, controlValueDict)
|
||||||
|
|
||||||
def fullPath(self):
|
def fullPath(self):
|
||||||
if self.location == None or self.location == "":
|
if self.location == None or self.location == "":
|
||||||
@ -2382,5 +2382,5 @@ class TVEpisode(object):
|
|||||||
sql_l.append(relEp.get_sql())
|
sql_l.append(relEp.get_sql())
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
@ -83,8 +83,8 @@ class TVCache():
|
|||||||
|
|
||||||
curDate = datetime.date.today() - datetime.timedelta(weeks=1)
|
curDate = datetime.date.today() - datetime.timedelta(weeks=1)
|
||||||
|
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
myDB.action("DELETE FROM [" + self.providerID + "] WHERE time < ?", [int(time.mktime(curDate.timetuple()))])
|
myDB.action("DELETE FROM [" + self.providerID + "] WHERE time < ?", [int(time.mktime(curDate.timetuple()))])
|
||||||
|
|
||||||
def _getRSSData(self):
|
def _getRSSData(self):
|
||||||
|
|
||||||
@ -125,8 +125,8 @@ class TVCache():
|
|||||||
cl.append(ci)
|
cl.append(ci)
|
||||||
|
|
||||||
if cl:
|
if cl:
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
myDB.mass_action(cl)
|
myDB.mass_action(cl)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise AuthException(
|
raise AuthException(
|
||||||
@ -192,8 +192,8 @@ class TVCache():
|
|||||||
|
|
||||||
|
|
||||||
def _getLastUpdate(self):
|
def _getLastUpdate(self):
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
sqlResults = myDB.select("SELECT time FROM lastUpdate WHERE provider = ?", [self.providerID])
|
sqlResults = myDB.select("SELECT time FROM lastUpdate WHERE provider = ?", [self.providerID])
|
||||||
|
|
||||||
if sqlResults:
|
if sqlResults:
|
||||||
lastTime = int(sqlResults[0]["time"])
|
lastTime = int(sqlResults[0]["time"])
|
||||||
@ -205,8 +205,8 @@ class TVCache():
|
|||||||
return datetime.datetime.fromtimestamp(lastTime)
|
return datetime.datetime.fromtimestamp(lastTime)
|
||||||
|
|
||||||
def _getLastSearch(self):
|
def _getLastSearch(self):
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
sqlResults = myDB.select("SELECT time FROM lastSearch WHERE provider = ?", [self.providerID])
|
sqlResults = myDB.select("SELECT time FROM lastSearch WHERE provider = ?", [self.providerID])
|
||||||
|
|
||||||
if sqlResults:
|
if sqlResults:
|
||||||
lastTime = int(sqlResults[0]["time"])
|
lastTime = int(sqlResults[0]["time"])
|
||||||
@ -222,19 +222,19 @@ class TVCache():
|
|||||||
if not toDate:
|
if not toDate:
|
||||||
toDate = datetime.datetime.today()
|
toDate = datetime.datetime.today()
|
||||||
|
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
myDB.upsert("lastUpdate",
|
myDB.upsert("lastUpdate",
|
||||||
{'time': int(time.mktime(toDate.timetuple()))},
|
{'time': int(time.mktime(toDate.timetuple()))},
|
||||||
{'provider': self.providerID})
|
{'provider': self.providerID})
|
||||||
|
|
||||||
def setLastSearch(self, toDate=None):
|
def setLastSearch(self, toDate=None):
|
||||||
if not toDate:
|
if not toDate:
|
||||||
toDate = datetime.datetime.today()
|
toDate = datetime.datetime.today()
|
||||||
|
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
myDB.upsert("lastSearch",
|
myDB.upsert("lastSearch",
|
||||||
{'time': int(time.mktime(toDate.timetuple()))},
|
{'time': int(time.mktime(toDate.timetuple()))},
|
||||||
{'provider': self.providerID})
|
{'provider': self.providerID})
|
||||||
|
|
||||||
lastUpdate = property(_getLastUpdate)
|
lastUpdate = property(_getLastUpdate)
|
||||||
lastSearch = property(_getLastSearch)
|
lastSearch = property(_getLastSearch)
|
||||||
@ -277,10 +277,10 @@ class TVCache():
|
|||||||
if parse_result.air_by_date or parse_result.sports:
|
if parse_result.air_by_date or parse_result.sports:
|
||||||
airdate = parse_result.air_date.toordinal() or parse_result.sports_event_date.toordinal()
|
airdate = parse_result.air_date.toordinal() or parse_result.sports_event_date.toordinal()
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_results = myDB.select(
|
sql_results = myDB.select(
|
||||||
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND indexer = ? AND airdate = ?",
|
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND indexer = ? AND airdate = ?",
|
||||||
[parse_result.show.indexerid, parse_result.show.indexer, airdate])
|
[parse_result.show.indexerid, parse_result.show.indexer, airdate])
|
||||||
if sql_results > 0:
|
if sql_results > 0:
|
||||||
season = int(sql_results[0]["season"])
|
season = int(sql_results[0]["season"])
|
||||||
episodes = [int(sql_results[0]["episode"])]
|
episodes = [int(sql_results[0]["episode"])]
|
||||||
@ -314,23 +314,23 @@ class TVCache():
|
|||||||
return neededEps
|
return neededEps
|
||||||
|
|
||||||
def listPropers(self, date=None, delimiter="."):
|
def listPropers(self, date=None, delimiter="."):
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
sql = "SELECT * FROM [" + self.providerID + "] WHERE name LIKE '%.PROPER.%' OR name LIKE '%.REPACK.%'"
|
sql = "SELECT * FROM [" + self.providerID + "] WHERE name LIKE '%.PROPER.%' OR name LIKE '%.REPACK.%'"
|
||||||
|
|
||||||
if date != None:
|
if date != None:
|
||||||
sql += " AND time >= " + str(int(time.mktime(date.timetuple())))
|
sql += " AND time >= " + str(int(time.mktime(date.timetuple())))
|
||||||
|
|
||||||
return filter(lambda x: x['indexerid'] != 0, myDB.select(sql))
|
return filter(lambda x: x['indexerid'] != 0, myDB.select(sql))
|
||||||
|
|
||||||
|
|
||||||
def findNeededEpisodes(self, episodes, manualSearch=False):
|
def findNeededEpisodes(self, episodes, manualSearch=False):
|
||||||
neededEps = {}
|
neededEps = {}
|
||||||
|
|
||||||
for epObj in episodes:
|
for epObj in episodes:
|
||||||
with self._getDB() as myDB:
|
myDB = self._getDB()
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?",
|
"SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?",
|
||||||
[epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"])
|
[epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"])
|
||||||
|
|
||||||
# for each cache entry
|
# for each cache entry
|
||||||
for curResult in sqlResults:
|
for curResult in sqlResults:
|
||||||
|
@ -138,18 +138,18 @@ class Api(webserve.MainHandler):
|
|||||||
seasonSQLResults = {}
|
seasonSQLResults = {}
|
||||||
episodeSQLResults = {}
|
episodeSQLResults = {}
|
||||||
|
|
||||||
with db.DBConnection(row_type="dict") as myDB:
|
myDB = db.DBConnection(row_type="dict")
|
||||||
for curShow in t.sortedShowList:
|
for curShow in t.sortedShowList:
|
||||||
seasonSQLResults[curShow.indexerid] = myDB.select(
|
seasonSQLResults[curShow.indexerid] = myDB.select(
|
||||||
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season DESC", [curShow.indexerid])
|
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season DESC", [curShow.indexerid])
|
||||||
|
|
||||||
for curShow in t.sortedShowList:
|
for curShow in t.sortedShowList:
|
||||||
episodeSQLResults[curShow.indexerid] = myDB.select(
|
episodeSQLResults[curShow.indexerid] = myDB.select(
|
||||||
"SELECT DISTINCT season,episode FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
|
"SELECT DISTINCT season,episode FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
|
||||||
[curShow.indexerid])
|
[curShow.indexerid])
|
||||||
|
|
||||||
t.seasonSQLResults = seasonSQLResults
|
t.seasonSQLResults = seasonSQLResults
|
||||||
t.episodeSQLResults = episodeSQLResults
|
t.episodeSQLResults = episodeSQLResults
|
||||||
|
|
||||||
if len(sickbeard.API_KEY) == 32:
|
if len(sickbeard.API_KEY) == 32:
|
||||||
t.apikey = sickbeard.API_KEY
|
t.apikey = sickbeard.API_KEY
|
||||||
@ -805,7 +805,7 @@ class CMD_ComingEpisodes(ApiCall):
|
|||||||
finalEpResults[status] = []
|
finalEpResults[status] = []
|
||||||
|
|
||||||
finalEpResults[status].append(ep)
|
finalEpResults[status].append(ep)
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, finalEpResults)
|
return _responds(RESULT_SUCCESS, finalEpResults)
|
||||||
|
|
||||||
|
|
||||||
@ -866,7 +866,6 @@ class CMD_Episode(ApiCall):
|
|||||||
episode["quality"] = _get_quality_string(quality)
|
episode["quality"] = _get_quality_string(quality)
|
||||||
episode["file_size_human"] = _sizeof_fmt(episode["file_size"])
|
episode["file_size_human"] = _sizeof_fmt(episode["file_size"])
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, episode)
|
return _responds(RESULT_SUCCESS, episode)
|
||||||
|
|
||||||
|
|
||||||
@ -1113,7 +1112,6 @@ class CMD_Exceptions(ApiCall):
|
|||||||
for row in sqlResults:
|
for row in sqlResults:
|
||||||
scene_exceptions.append(row["show_name"])
|
scene_exceptions.append(row["show_name"])
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, scene_exceptions)
|
return _responds(RESULT_SUCCESS, scene_exceptions)
|
||||||
|
|
||||||
|
|
||||||
@ -1174,7 +1172,6 @@ class CMD_History(ApiCall):
|
|||||||
row['tvdbid'] = row['indexerid']
|
row['tvdbid'] = row['indexerid']
|
||||||
results.append(row)
|
results.append(row)
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, results)
|
return _responds(RESULT_SUCCESS, results)
|
||||||
|
|
||||||
|
|
||||||
@ -1193,7 +1190,6 @@ class CMD_HistoryClear(ApiCall):
|
|||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
myDB.action("DELETE FROM history WHERE 1=1")
|
myDB.action("DELETE FROM history WHERE 1=1")
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, msg="History cleared")
|
return _responds(RESULT_SUCCESS, msg="History cleared")
|
||||||
|
|
||||||
|
|
||||||
@ -1213,7 +1209,7 @@ class CMD_HistoryTrim(ApiCall):
|
|||||||
myDB.action("DELETE FROM history WHERE date < " + str(
|
myDB.action("DELETE FROM history WHERE date < " + str(
|
||||||
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(history.dateFormat)))
|
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(history.dateFormat)))
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, msg="Removed history entries greater than 30 days old")
|
return _responds(RESULT_SUCCESS, msg="Removed history entries greater than 30 days old")
|
||||||
|
|
||||||
|
|
||||||
@ -1370,7 +1366,7 @@ class CMD_SickBeardCheckScheduler(ApiCall):
|
|||||||
backlogRunning = sickbeard.searchQueueScheduler.action.is_backlog_in_progress() #@UndefinedVariable
|
backlogRunning = sickbeard.searchQueueScheduler.action.is_backlog_in_progress() #@UndefinedVariable
|
||||||
nextBacklog = sickbeard.backlogSearchScheduler.nextRun().strftime(dateFormat).decode(sickbeard.SYS_ENCODING)
|
nextBacklog = sickbeard.backlogSearchScheduler.nextRun().strftime(dateFormat).decode(sickbeard.SYS_ENCODING)
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
data = {"backlog_is_paused": int(backlogPaused), "backlog_is_running": int(backlogRunning),
|
data = {"backlog_is_paused": int(backlogPaused), "backlog_is_running": int(backlogRunning),
|
||||||
"last_backlog": _ordinal_to_dateForm(sqlResults[0]["last_backlog"]),
|
"last_backlog": _ordinal_to_dateForm(sqlResults[0]["last_backlog"]),
|
||||||
"next_backlog": nextBacklog}
|
"next_backlog": nextBacklog}
|
||||||
@ -2221,7 +2217,7 @@ class CMD_ShowSeasonList(ApiCall):
|
|||||||
for row in sqlResults:
|
for row in sqlResults:
|
||||||
seasonList.append(int(row["season"]))
|
seasonList.append(int(row["season"]))
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, seasonList)
|
return _responds(RESULT_SUCCESS, seasonList)
|
||||||
|
|
||||||
|
|
||||||
@ -2284,7 +2280,7 @@ class CMD_ShowSeasons(ApiCall):
|
|||||||
seasons[curEpisode] = {}
|
seasons[curEpisode] = {}
|
||||||
seasons[curEpisode] = row
|
seasons[curEpisode] = row
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, seasons)
|
return _responds(RESULT_SUCCESS, seasons)
|
||||||
|
|
||||||
|
|
||||||
@ -2453,7 +2449,7 @@ class CMD_ShowStats(ApiCall):
|
|||||||
")", "")
|
")", "")
|
||||||
episodes_stats[statusString] = episode_status_counts_total[statusCode]
|
episodes_stats[statusString] = episode_status_counts_total[statusCode]
|
||||||
|
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, episodes_stats)
|
return _responds(RESULT_SUCCESS, episodes_stats)
|
||||||
|
|
||||||
|
|
||||||
@ -2559,7 +2555,7 @@ class CMD_ShowsStats(ApiCall):
|
|||||||
"SELECT COUNT(*) FROM tv_episodes WHERE season != 0 AND episode != 0 AND (airdate != 1 OR status IN (" + ",".join(
|
"SELECT COUNT(*) FROM tv_episodes WHERE season != 0 AND episode != 0 AND (airdate != 1 OR status IN (" + ",".join(
|
||||||
[str(show) for show in (Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_PROPER) + [
|
[str(show) for show in (Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_PROPER) + [
|
||||||
ARCHIVED]]) + ")) AND airdate <= " + today + " AND status != " + str(IGNORED) + "")[0][0]
|
ARCHIVED]]) + ")) AND airdate <= " + today + " AND status != " + str(IGNORED) + "")[0][0]
|
||||||
myDB.connection.close()
|
|
||||||
return _responds(RESULT_SUCCESS, stats)
|
return _responds(RESULT_SUCCESS, stats)
|
||||||
|
|
||||||
# WARNING: never define a cmd call string that contains a "_" (underscore)
|
# WARNING: never define a cmd call string that contains a "_" (underscore)
|
||||||
|
@ -213,11 +213,11 @@ class MainHandler(RequestHandler):
|
|||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
response = self._dispatch()
|
response = self._dispatch()
|
||||||
self.write(response)
|
self.finish(response)
|
||||||
|
|
||||||
def post(self, *args, **kwargs):
|
def post(self, *args, **kwargs):
|
||||||
response = self._dispatch()
|
response = self._dispatch()
|
||||||
self.write(response)
|
self.finish(response)
|
||||||
|
|
||||||
def robots_txt(self, *args, **kwargs):
|
def robots_txt(self, *args, **kwargs):
|
||||||
""" Keep web crawlers out """
|
""" Keep web crawlers out """
|
||||||
@ -309,26 +309,26 @@ class MainHandler(RequestHandler):
|
|||||||
done_show_list = []
|
done_show_list = []
|
||||||
qualList = Quality.DOWNLOADED + Quality.SNATCHED + [ARCHIVED, IGNORED]
|
qualList = Quality.DOWNLOADED + Quality.SNATCHED + [ARCHIVED, IGNORED]
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
sql_results = myDB.select(
|
sql_results = myDB.select(
|
||||||
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND airdate >= ? AND airdate < ? AND tv_shows.indexer_id = tv_episodes.showid AND tv_episodes.status NOT IN (" + ','.join(
|
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND airdate >= ? AND airdate < ? AND tv_shows.indexer_id = tv_episodes.showid AND tv_episodes.status NOT IN (" + ','.join(
|
||||||
['?'] * len(qualList)) + ")", [today, next_week] + qualList)
|
['?'] * len(qualList)) + ")", [today, next_week] + qualList)
|
||||||
|
|
||||||
for cur_result in sql_results:
|
for cur_result in sql_results:
|
||||||
done_show_list.append(int(cur_result["showid"]))
|
done_show_list.append(int(cur_result["showid"]))
|
||||||
|
|
||||||
more_sql_results = myDB.select(
|
more_sql_results = myDB.select(
|
||||||
"SELECT *, tv_shows.status as show_status FROM tv_episodes outer_eps, tv_shows WHERE season != 0 AND showid NOT IN (" + ','.join(
|
"SELECT *, tv_shows.status as show_status FROM tv_episodes outer_eps, tv_shows WHERE season != 0 AND showid NOT IN (" + ','.join(
|
||||||
['?'] * len(
|
['?'] * len(
|
||||||
done_show_list)) + ") AND tv_shows.indexer_id = outer_eps.showid AND airdate = (SELECT airdate FROM tv_episodes inner_eps WHERE inner_eps.season != 0 AND inner_eps.showid = outer_eps.showid AND inner_eps.airdate >= ? ORDER BY inner_eps.airdate ASC LIMIT 1) AND outer_eps.status NOT IN (" + ','.join(
|
done_show_list)) + ") AND tv_shows.indexer_id = outer_eps.showid AND airdate = (SELECT airdate FROM tv_episodes inner_eps WHERE inner_eps.season != 0 AND inner_eps.showid = outer_eps.showid AND inner_eps.airdate >= ? ORDER BY inner_eps.airdate ASC LIMIT 1) AND outer_eps.status NOT IN (" + ','.join(
|
||||||
['?'] * len(Quality.DOWNLOADED + Quality.SNATCHED)) + ")",
|
['?'] * len(Quality.DOWNLOADED + Quality.SNATCHED)) + ")",
|
||||||
done_show_list + [next_week] + Quality.DOWNLOADED + Quality.SNATCHED)
|
done_show_list + [next_week] + Quality.DOWNLOADED + Quality.SNATCHED)
|
||||||
sql_results += more_sql_results
|
sql_results += more_sql_results
|
||||||
|
|
||||||
more_sql_results = myDB.select(
|
more_sql_results = myDB.select(
|
||||||
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND tv_shows.indexer_id = tv_episodes.showid AND airdate < ? AND airdate >= ? AND tv_episodes.status = ? AND tv_episodes.status NOT IN (" + ','.join(
|
"SELECT *, tv_shows.status as show_status FROM tv_episodes, tv_shows WHERE season != 0 AND tv_shows.indexer_id = tv_episodes.showid AND airdate < ? AND airdate >= ? AND tv_episodes.status = ? AND tv_episodes.status NOT IN (" + ','.join(
|
||||||
['?'] * len(qualList)) + ")", [today, recently, WANTED] + qualList)
|
['?'] * len(qualList)) + ")", [today, recently, WANTED] + qualList)
|
||||||
sql_results += more_sql_results
|
sql_results += more_sql_results
|
||||||
|
|
||||||
# sort by localtime
|
# sort by localtime
|
||||||
sorts = {
|
sorts = {
|
||||||
@ -404,43 +404,43 @@ class MainHandler(RequestHandler):
|
|||||||
future_date = (datetime.date.today() + datetime.timedelta(weeks=52)).toordinal()
|
future_date = (datetime.date.today() + datetime.timedelta(weeks=52)).toordinal()
|
||||||
|
|
||||||
# Get all the shows that are not paused and are currently on air (from kjoconnor Fork)
|
# Get all the shows that are not paused and are currently on air (from kjoconnor Fork)
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
calendar_shows = myDB.select(
|
calendar_shows = myDB.select(
|
||||||
"SELECT show_name, indexer_id, network, airs, runtime FROM tv_shows WHERE ( status = 'Continuing' OR status = 'Returning Series' ) AND paused != '1'")
|
"SELECT show_name, indexer_id, network, airs, runtime FROM tv_shows WHERE ( status = 'Continuing' OR status = 'Returning Series' ) AND paused != '1'")
|
||||||
for show in calendar_shows:
|
for show in calendar_shows:
|
||||||
# Get all episodes of this show airing between today and next month
|
# Get all episodes of this show airing between today and next month
|
||||||
episode_list = myDB.select(
|
episode_list = myDB.select(
|
||||||
"SELECT indexerid, name, season, episode, description, airdate FROM tv_episodes WHERE airdate >= ? AND airdate < ? AND showid = ?",
|
"SELECT indexerid, name, season, episode, description, airdate FROM tv_episodes WHERE airdate >= ? AND airdate < ? AND showid = ?",
|
||||||
(past_date, future_date, int(show["indexer_id"])))
|
(past_date, future_date, int(show["indexer_id"])))
|
||||||
|
|
||||||
utc = tz.gettz('GMT')
|
utc = tz.gettz('GMT')
|
||||||
|
|
||||||
for episode in episode_list:
|
for episode in episode_list:
|
||||||
|
|
||||||
air_date_time = network_timezones.parse_date_time(episode['airdate'], show["airs"],
|
air_date_time = network_timezones.parse_date_time(episode['airdate'], show["airs"],
|
||||||
show['network']).astimezone(utc)
|
show['network']).astimezone(utc)
|
||||||
air_date_time_end = air_date_time + datetime.timedelta(
|
air_date_time_end = air_date_time + datetime.timedelta(
|
||||||
minutes=helpers.tryInt(show["runtime"], 60))
|
minutes=helpers.tryInt(show["runtime"], 60))
|
||||||
|
|
||||||
# Create event for episode
|
# Create event for episode
|
||||||
ical = ical + 'BEGIN:VEVENT\r\n'
|
ical = ical + 'BEGIN:VEVENT\r\n'
|
||||||
ical = ical + 'DTSTART:' + air_date_time.strftime("%Y%m%d") + 'T' + air_date_time.strftime(
|
ical = ical + 'DTSTART:' + air_date_time.strftime("%Y%m%d") + 'T' + air_date_time.strftime(
|
||||||
"%H%M%S") + 'Z\r\n'
|
"%H%M%S") + 'Z\r\n'
|
||||||
ical = ical + 'DTEND:' + air_date_time_end.strftime(
|
ical = ical + 'DTEND:' + air_date_time_end.strftime(
|
||||||
"%Y%m%d") + 'T' + air_date_time_end.strftime(
|
"%Y%m%d") + 'T' + air_date_time_end.strftime(
|
||||||
"%H%M%S") + 'Z\r\n'
|
"%H%M%S") + 'Z\r\n'
|
||||||
ical = ical + 'SUMMARY:' + show['show_name'] + ': ' + episode['name'] + '\r\n'
|
ical = ical + 'SUMMARY:' + show['show_name'] + ': ' + episode['name'] + '\r\n'
|
||||||
ical = ical + 'UID:Sick-Beard-' + str(datetime.date.today().isoformat()) + '-' + show[
|
ical = ical + 'UID:Sick-Beard-' + str(datetime.date.today().isoformat()) + '-' + show[
|
||||||
'show_name'].replace(" ", "-") + '-E' + str(episode['episode']) + 'S' + str(
|
'show_name'].replace(" ", "-") + '-E' + str(episode['episode']) + 'S' + str(
|
||||||
episode['season']) + '\r\n'
|
episode['season']) + '\r\n'
|
||||||
if (episode['description'] is not None and episode['description'] != ''):
|
if (episode['description'] is not None and episode['description'] != ''):
|
||||||
ical = ical + 'DESCRIPTION:' + show['airs'] + ' on ' + show['network'] + '\\n\\n' + \
|
ical = ical + 'DESCRIPTION:' + show['airs'] + ' on ' + show['network'] + '\\n\\n' + \
|
||||||
episode['description'].splitlines()[0] + '\r\n'
|
episode['description'].splitlines()[0] + '\r\n'
|
||||||
else:
|
else:
|
||||||
ical = ical + 'DESCRIPTION:' + show['airs'] + ' on ' + show['network'] + '\r\n'
|
ical = ical + 'DESCRIPTION:' + show['airs'] + ' on ' + show['network'] + '\r\n'
|
||||||
ical = ical + 'LOCATION:' + 'Episode ' + str(episode['episode']) + ' - Season ' + str(
|
ical = ical + 'LOCATION:' + 'Episode ' + str(episode['episode']) + ' - Season ' + str(
|
||||||
episode['season']) + '\r\n'
|
episode['season']) + '\r\n'
|
||||||
ical = ical + 'END:VEVENT\r\n'
|
ical = ical + 'END:VEVENT\r\n'
|
||||||
|
|
||||||
# Ending the iCal
|
# Ending the iCal
|
||||||
ical += 'END:VCALENDAR'
|
ical += 'END:VCALENDAR'
|
||||||
@ -626,10 +626,10 @@ class Manage(MainHandler):
|
|||||||
if status_list[0] == SNATCHED:
|
if status_list[0] == SNATCHED:
|
||||||
status_list = Quality.SNATCHED + Quality.SNATCHED_PROPER
|
status_list = Quality.SNATCHED + Quality.SNATCHED_PROPER
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
cur_show_results = myDB.select(
|
cur_show_results = myDB.select(
|
||||||
"SELECT season, episode, name FROM tv_episodes WHERE showid = ? AND season != 0 AND status IN (" + ','.join(
|
"SELECT season, episode, name FROM tv_episodes WHERE showid = ? AND season != 0 AND status IN (" + ','.join(
|
||||||
['?'] * len(status_list)) + ")", [int(indexer_id)] + status_list)
|
['?'] * len(status_list)) + ")", [int(indexer_id)] + status_list)
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for cur_result in cur_show_results:
|
for cur_result in cur_show_results:
|
||||||
@ -662,12 +662,12 @@ class Manage(MainHandler):
|
|||||||
if not status_list:
|
if not status_list:
|
||||||
return _munge(t)
|
return _munge(t)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
status_results = myDB.select(
|
status_results = myDB.select(
|
||||||
"SELECT show_name, tv_shows.indexer_id as indexer_id FROM tv_episodes, tv_shows WHERE tv_episodes.status IN (" + ','.join(
|
"SELECT show_name, tv_shows.indexer_id as indexer_id FROM tv_episodes, tv_shows WHERE tv_episodes.status IN (" + ','.join(
|
||||||
['?'] * len(
|
['?'] * len(
|
||||||
status_list)) + ") AND season != 0 AND tv_episodes.showid = tv_shows.indexer_id ORDER BY show_name",
|
status_list)) + ") AND season != 0 AND tv_episodes.showid = tv_shows.indexer_id ORDER BY show_name",
|
||||||
status_list)
|
status_list)
|
||||||
|
|
||||||
ep_counts = {}
|
ep_counts = {}
|
||||||
show_names = {}
|
show_names = {}
|
||||||
@ -710,29 +710,29 @@ class Manage(MainHandler):
|
|||||||
|
|
||||||
to_change[indexer_id].append(what)
|
to_change[indexer_id].append(what)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for cur_indexer_id in to_change:
|
for cur_indexer_id in to_change:
|
||||||
|
|
||||||
# get a list of all the eps we want to change if they just said "all"
|
# get a list of all the eps we want to change if they just said "all"
|
||||||
if 'all' in to_change[cur_indexer_id]:
|
if 'all' in to_change[cur_indexer_id]:
|
||||||
all_eps_results = myDB.select(
|
all_eps_results = myDB.select(
|
||||||
"SELECT season, episode FROM tv_episodes WHERE status IN (" + ','.join(
|
"SELECT season, episode FROM tv_episodes WHERE status IN (" + ','.join(
|
||||||
['?'] * len(status_list)) + ") AND season != 0 AND showid = ?",
|
['?'] * len(status_list)) + ") AND season != 0 AND showid = ?",
|
||||||
status_list + [cur_indexer_id])
|
status_list + [cur_indexer_id])
|
||||||
all_eps = [str(x["season"]) + 'x' + str(x["episode"]) for x in all_eps_results]
|
all_eps = [str(x["season"]) + 'x' + str(x["episode"]) for x in all_eps_results]
|
||||||
to_change[cur_indexer_id] = all_eps
|
to_change[cur_indexer_id] = all_eps
|
||||||
|
|
||||||
Home(self.application, self.request).setStatus(cur_indexer_id, '|'.join(to_change[cur_indexer_id]),
|
Home(self.application, self.request).setStatus(cur_indexer_id, '|'.join(to_change[cur_indexer_id]),
|
||||||
newStatus, direct=True)
|
newStatus, direct=True)
|
||||||
|
|
||||||
return self.redirect('/manage/episodeStatuses/')
|
return self.redirect('/manage/episodeStatuses/')
|
||||||
|
|
||||||
|
|
||||||
def showSubtitleMissed(self, indexer_id, whichSubs):
|
def showSubtitleMissed(self, indexer_id, whichSubs):
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
cur_show_results = myDB.select(
|
cur_show_results = myDB.select(
|
||||||
"SELECT season, episode, name, subtitles FROM tv_episodes WHERE showid = ? AND season != 0 AND status LIKE '%4'",
|
"SELECT season, episode, name, subtitles FROM tv_episodes WHERE showid = ? AND season != 0 AND status LIKE '%4'",
|
||||||
[int(indexer_id)])
|
[int(indexer_id)])
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for cur_result in cur_show_results:
|
for cur_result in cur_show_results:
|
||||||
@ -770,9 +770,9 @@ class Manage(MainHandler):
|
|||||||
if not whichSubs:
|
if not whichSubs:
|
||||||
return _munge(t)
|
return _munge(t)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
status_results = myDB.select(
|
status_results = myDB.select(
|
||||||
"SELECT show_name, tv_shows.indexer_id as indexer_id, tv_episodes.subtitles subtitles FROM tv_episodes, tv_shows WHERE tv_shows.subtitles = 1 AND tv_episodes.status LIKE '%4' AND tv_episodes.season != 0 AND tv_episodes.showid = tv_shows.indexer_id ORDER BY show_name")
|
"SELECT show_name, tv_shows.indexer_id as indexer_id, tv_episodes.subtitles subtitles FROM tv_episodes, tv_shows WHERE tv_shows.subtitles = 1 AND tv_episodes.status LIKE '%4' AND tv_episodes.season != 0 AND tv_episodes.showid = tv_shows.indexer_id ORDER BY show_name")
|
||||||
|
|
||||||
ep_counts = {}
|
ep_counts = {}
|
||||||
show_names = {}
|
show_names = {}
|
||||||
@ -821,10 +821,10 @@ class Manage(MainHandler):
|
|||||||
for cur_indexer_id in to_download:
|
for cur_indexer_id in to_download:
|
||||||
# get a list of all the eps we want to download subtitles if they just said "all"
|
# get a list of all the eps we want to download subtitles if they just said "all"
|
||||||
if 'all' in to_download[cur_indexer_id]:
|
if 'all' in to_download[cur_indexer_id]:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
all_eps_results = myDB.select(
|
all_eps_results = myDB.select(
|
||||||
"SELECT season, episode FROM tv_episodes WHERE status LIKE '%4' AND season != 0 AND showid = ?",
|
"SELECT season, episode FROM tv_episodes WHERE status LIKE '%4' AND season != 0 AND showid = ?",
|
||||||
[cur_indexer_id])
|
[cur_indexer_id])
|
||||||
to_download[cur_indexer_id] = [str(x["season"]) + 'x' + str(x["episode"]) for x in all_eps_results]
|
to_download[cur_indexer_id] = [str(x["season"]) + 'x' + str(x["episode"]) for x in all_eps_results]
|
||||||
|
|
||||||
for epResult in to_download[cur_indexer_id]:
|
for epResult in to_download[cur_indexer_id]:
|
||||||
@ -855,30 +855,30 @@ class Manage(MainHandler):
|
|||||||
showCats = {}
|
showCats = {}
|
||||||
showSQLResults = {}
|
showSQLResults = {}
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for curShow in sickbeard.showList:
|
for curShow in sickbeard.showList:
|
||||||
|
|
||||||
epCounts = {}
|
epCounts = {}
|
||||||
epCats = {}
|
epCats = {}
|
||||||
epCounts[Overview.SKIPPED] = 0
|
epCounts[Overview.SKIPPED] = 0
|
||||||
epCounts[Overview.WANTED] = 0
|
epCounts[Overview.WANTED] = 0
|
||||||
epCounts[Overview.QUAL] = 0
|
epCounts[Overview.QUAL] = 0
|
||||||
epCounts[Overview.GOOD] = 0
|
epCounts[Overview.GOOD] = 0
|
||||||
epCounts[Overview.UNAIRED] = 0
|
epCounts[Overview.UNAIRED] = 0
|
||||||
epCounts[Overview.SNATCHED] = 0
|
epCounts[Overview.SNATCHED] = 0
|
||||||
|
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT * FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
|
"SELECT * FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
|
||||||
[curShow.indexerid])
|
[curShow.indexerid])
|
||||||
|
|
||||||
for curResult in sqlResults:
|
for curResult in sqlResults:
|
||||||
curEpCat = curShow.getOverview(int(curResult["status"]))
|
curEpCat = curShow.getOverview(int(curResult["status"]))
|
||||||
epCats[str(curResult["season"]) + "x" + str(curResult["episode"])] = curEpCat
|
epCats[str(curResult["season"]) + "x" + str(curResult["episode"])] = curEpCat
|
||||||
epCounts[curEpCat] += 1
|
epCounts[curEpCat] += 1
|
||||||
|
|
||||||
showCounts[curShow.indexerid] = epCounts
|
showCounts[curShow.indexerid] = epCounts
|
||||||
showCats[curShow.indexerid] = epCats
|
showCats[curShow.indexerid] = epCats
|
||||||
showSQLResults[curShow.indexerid] = sqlResults
|
showSQLResults[curShow.indexerid] = sqlResults
|
||||||
|
|
||||||
t.showCounts = showCounts
|
t.showCounts = showCounts
|
||||||
t.showCats = showCats
|
t.showCats = showCats
|
||||||
@ -1198,17 +1198,17 @@ class Manage(MainHandler):
|
|||||||
|
|
||||||
def failedDownloads(self, limit=100, toRemove=None):
|
def failedDownloads(self, limit=100, toRemove=None):
|
||||||
|
|
||||||
with db.DBConnection('failed.db') as myDB:
|
myDB = db.DBConnection('failed.db')
|
||||||
|
|
||||||
if limit == "0":
|
if limit == "0":
|
||||||
sqlResults = myDB.select("SELECT * FROM failed")
|
sqlResults = myDB.select("SELECT * FROM failed")
|
||||||
else:
|
else:
|
||||||
sqlResults = myDB.select("SELECT * FROM failed LIMIT ?", [limit])
|
sqlResults = myDB.select("SELECT * FROM failed LIMIT ?", [limit])
|
||||||
|
|
||||||
toRemove = toRemove.split("|") if toRemove is not None else []
|
toRemove = toRemove.split("|") if toRemove is not None else []
|
||||||
|
|
||||||
for release in toRemove:
|
for release in toRemove:
|
||||||
myDB.action('DELETE FROM failed WHERE release = ?', [release])
|
myDB.action('DELETE FROM failed WHERE release = ?', [release])
|
||||||
|
|
||||||
if toRemove:
|
if toRemove:
|
||||||
raise self.redirect('/manage/failedDownloads/')
|
raise self.redirect('/manage/failedDownloads/')
|
||||||
@ -1225,14 +1225,14 @@ class History(MainHandler):
|
|||||||
def index(self, limit=100):
|
def index(self, limit=100):
|
||||||
|
|
||||||
# sqlResults = myDB.select("SELECT h.*, show_name, name FROM history h, tv_shows s, tv_episodes e WHERE h.showid=s.indexer_id AND h.showid=e.showid AND h.season=e.season AND h.episode=e.episode ORDER BY date DESC LIMIT "+str(numPerPage*(p-1))+", "+str(numPerPage))
|
# sqlResults = myDB.select("SELECT h.*, show_name, name FROM history h, tv_shows s, tv_episodes e WHERE h.showid=s.indexer_id AND h.showid=e.showid AND h.season=e.season AND h.episode=e.episode ORDER BY date DESC LIMIT "+str(numPerPage*(p-1))+", "+str(numPerPage))
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
if limit == "0":
|
if limit == "0":
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT h.*, show_name FROM history h, tv_shows s WHERE h.showid=s.indexer_id ORDER BY date DESC")
|
"SELECT h.*, show_name FROM history h, tv_shows s WHERE h.showid=s.indexer_id ORDER BY date DESC")
|
||||||
else:
|
else:
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT h.*, show_name FROM history h, tv_shows s WHERE h.showid=s.indexer_id ORDER BY date DESC LIMIT ?",
|
"SELECT h.*, show_name FROM history h, tv_shows s WHERE h.showid=s.indexer_id ORDER BY date DESC LIMIT ?",
|
||||||
[limit])
|
[limit])
|
||||||
|
|
||||||
history = {'show_id': 0, 'season': 0, 'episode': 0, 'quality': 0,
|
history = {'show_id': 0, 'season': 0, 'episode': 0, 'quality': 0,
|
||||||
'actions': [{'time': '', 'action': '', 'provider': ''}]}
|
'actions': [{'time': '', 'action': '', 'provider': ''}]}
|
||||||
@ -1295,8 +1295,8 @@ class History(MainHandler):
|
|||||||
|
|
||||||
def clearHistory(self, *args, **kwargs):
|
def clearHistory(self, *args, **kwargs):
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.action("DELETE FROM history WHERE 1=1")
|
myDB.action("DELETE FROM history WHERE 1=1")
|
||||||
|
|
||||||
ui.notifications.message('History cleared')
|
ui.notifications.message('History cleared')
|
||||||
return self.redirect("/history/")
|
return self.redirect("/history/")
|
||||||
@ -1304,9 +1304,9 @@ class History(MainHandler):
|
|||||||
|
|
||||||
def trimHistory(self, *args, **kwargs):
|
def trimHistory(self, *args, **kwargs):
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.action("DELETE FROM history WHERE date < " + str(
|
myDB.action("DELETE FROM history WHERE date < " + str(
|
||||||
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(history.dateFormat)))
|
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(history.dateFormat)))
|
||||||
|
|
||||||
ui.notifications.message('Removed history entries greater than 30 days old')
|
ui.notifications.message('Removed history entries greater than 30 days old')
|
||||||
return self.redirect("/history/")
|
return self.redirect("/history/")
|
||||||
@ -2619,56 +2619,56 @@ class NewHomeAddShows(MainHandler):
|
|||||||
|
|
||||||
dir_list = []
|
dir_list = []
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for root_dir in root_dirs:
|
for root_dir in root_dirs:
|
||||||
try:
|
try:
|
||||||
file_list = ek.ek(os.listdir, root_dir)
|
file_list = ek.ek(os.listdir, root_dir)
|
||||||
except:
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for cur_file in file_list:
|
||||||
|
|
||||||
|
cur_path = ek.ek(os.path.normpath, ek.ek(os.path.join, root_dir, cur_file))
|
||||||
|
if not ek.ek(os.path.isdir, cur_path):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for cur_file in file_list:
|
cur_dir = {
|
||||||
|
'dir': cur_path,
|
||||||
|
'display_dir': '<b>' + ek.ek(os.path.dirname, cur_path) + os.sep + '</b>' + ek.ek(
|
||||||
|
os.path.basename,
|
||||||
|
cur_path),
|
||||||
|
}
|
||||||
|
|
||||||
cur_path = ek.ek(os.path.normpath, ek.ek(os.path.join, root_dir, cur_file))
|
# see if the folder is in XBMC already
|
||||||
if not ek.ek(os.path.isdir, cur_path):
|
dirResults = myDB.select("SELECT * FROM tv_shows WHERE location = ?", [cur_path])
|
||||||
continue
|
|
||||||
|
|
||||||
cur_dir = {
|
if dirResults:
|
||||||
'dir': cur_path,
|
cur_dir['added_already'] = True
|
||||||
'display_dir': '<b>' + ek.ek(os.path.dirname, cur_path) + os.sep + '</b>' + ek.ek(
|
else:
|
||||||
os.path.basename,
|
cur_dir['added_already'] = False
|
||||||
cur_path),
|
|
||||||
}
|
|
||||||
|
|
||||||
# see if the folder is in XBMC already
|
dir_list.append(cur_dir)
|
||||||
dirResults = myDB.select("SELECT * FROM tv_shows WHERE location = ?", [cur_path])
|
|
||||||
|
|
||||||
if dirResults:
|
indexer_id = show_name = indexer = None
|
||||||
cur_dir['added_already'] = True
|
for cur_provider in sickbeard.metadata_provider_dict.values():
|
||||||
else:
|
(indexer_id, show_name, indexer) = cur_provider.retrieveShowMetadata(cur_path)
|
||||||
cur_dir['added_already'] = False
|
if show_name: break
|
||||||
|
|
||||||
dir_list.append(cur_dir)
|
# default to TVDB if indexer was not detected
|
||||||
|
if show_name and not (indexer and indexer_id):
|
||||||
|
(sn, idx, id) = helpers.searchIndexerForShowID(show_name, indexer, indexer_id)
|
||||||
|
|
||||||
indexer_id = show_name = indexer = None
|
# set indexer and indexer_id from found info
|
||||||
for cur_provider in sickbeard.metadata_provider_dict.values():
|
if indexer is None and idx:
|
||||||
(indexer_id, show_name, indexer) = cur_provider.retrieveShowMetadata(cur_path)
|
indexer = idx
|
||||||
if show_name: break
|
|
||||||
|
|
||||||
# default to TVDB if indexer was not detected
|
if indexer_id is None and id:
|
||||||
if show_name and not (indexer and indexer_id):
|
indexer_id = id
|
||||||
(sn, idx, id) = helpers.searchIndexerForShowID(show_name, indexer, indexer_id)
|
|
||||||
|
|
||||||
# set indexer and indexer_id from found info
|
cur_dir['existing_info'] = (indexer_id, show_name, indexer)
|
||||||
if indexer is None and idx:
|
|
||||||
indexer = idx
|
|
||||||
|
|
||||||
if indexer_id is None and id:
|
if indexer_id and helpers.findCertainShow(sickbeard.showList, indexer_id):
|
||||||
indexer_id = id
|
cur_dir['added_already'] = True
|
||||||
|
|
||||||
cur_dir['existing_info'] = (indexer_id, show_name, indexer)
|
|
||||||
|
|
||||||
if indexer_id and helpers.findCertainShow(sickbeard.showList, indexer_id):
|
|
||||||
cur_dir['added_already'] = True
|
|
||||||
|
|
||||||
t.dirList = dir_list
|
t.dirList = dir_list
|
||||||
|
|
||||||
@ -3240,8 +3240,8 @@ class Home(MainHandler):
|
|||||||
def loadShowNotifyLists(self, *args, **kwargs):
|
def loadShowNotifyLists(self, *args, **kwargs):
|
||||||
self.set_header('Cache-Control', "max-age=0,no-cache,no-store")
|
self.set_header('Cache-Control', "max-age=0,no-cache,no-store")
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
rows = myDB.select("SELECT show_id, show_name, notify_list FROM tv_shows ORDER BY show_name ASC")
|
rows = myDB.select("SELECT show_id, show_name, notify_list FROM tv_shows ORDER BY show_name ASC")
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
size = 0
|
size = 0
|
||||||
@ -3355,16 +3355,16 @@ class Home(MainHandler):
|
|||||||
if showObj is None:
|
if showObj is None:
|
||||||
return _genericMessage("Error", "Show not in show list")
|
return _genericMessage("Error", "Show not in show list")
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
seasonResults = myDB.select(
|
seasonResults = myDB.select(
|
||||||
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season desc",
|
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season desc",
|
||||||
[showObj.indexerid]
|
[showObj.indexerid]
|
||||||
)
|
)
|
||||||
|
|
||||||
sqlResults = myDB.select(
|
sqlResults = myDB.select(
|
||||||
"SELECT * FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
|
"SELECT * FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
|
||||||
[showObj.indexerid]
|
[showObj.indexerid]
|
||||||
)
|
)
|
||||||
|
|
||||||
t = PageTemplate(file="displayShow.tmpl")
|
t = PageTemplate(file="displayShow.tmpl")
|
||||||
t.submenu = [{'title': 'Edit', 'path': 'home/editShow?show=%d' % showObj.indexerid}]
|
t.submenu = [{'title': 'Edit', 'path': 'home/editShow?show=%d' % showObj.indexerid}]
|
||||||
@ -3476,10 +3476,10 @@ class Home(MainHandler):
|
|||||||
|
|
||||||
|
|
||||||
def plotDetails(self, show, season, episode):
|
def plotDetails(self, show, season, episode):
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
result = myDB.action(
|
result = myDB.action(
|
||||||
"SELECT description FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
"SELECT description FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||||
(int(show), int(season), int(episode))).fetchone()
|
(int(show), int(season), int(episode))).fetchone()
|
||||||
return result['description'] if result else 'Episode not found.'
|
return result['description'] if result else 'Episode not found.'
|
||||||
|
|
||||||
|
|
||||||
@ -3939,8 +3939,8 @@ class Home(MainHandler):
|
|||||||
sql_l.append(epObj.get_sql())
|
sql_l.append(epObj.get_sql())
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
myDB.mass_action(sql_l)
|
myDB.mass_action(sql_l)
|
||||||
|
|
||||||
if int(status) == WANTED:
|
if int(status) == WANTED:
|
||||||
msg = "Backlog was automatically started for the following seasons of <b>" + showObj.name + "</b>:<br />"
|
msg = "Backlog was automatically started for the following seasons of <b>" + showObj.name + "</b>:<br />"
|
||||||
@ -4042,30 +4042,30 @@ class Home(MainHandler):
|
|||||||
if eps is None:
|
if eps is None:
|
||||||
return self.redirect("/home/displayShow?show=" + show)
|
return self.redirect("/home/displayShow?show=" + show)
|
||||||
|
|
||||||
with db.DBConnection() as myDB:
|
myDB = db.DBConnection()
|
||||||
for curEp in eps.split('|'):
|
for curEp in eps.split('|'):
|
||||||
|
|
||||||
epInfo = curEp.split('x')
|
epInfo = curEp.split('x')
|
||||||
|
|
||||||
# this is probably the worst possible way to deal with double eps but I've kinda painted myself into a corner here with this stupid database
|
# this is probably the worst possible way to deal with double eps but I've kinda painted myself into a corner here with this stupid database
|
||||||
ep_result = myDB.select(
|
ep_result = myDB.select(
|
||||||
"SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ? AND 5=5",
|
"SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ? AND 5=5",
|
||||||
[show, epInfo[0], epInfo[1]])
|
[show, epInfo[0], epInfo[1]])
|
||||||
if not ep_result:
|
if not ep_result:
|
||||||
logger.log(u"Unable to find an episode for " + curEp + ", skipping", logger.WARNING)
|
logger.log(u"Unable to find an episode for " + curEp + ", skipping", logger.WARNING)
|
||||||
continue
|
continue
|
||||||
related_eps_result = myDB.select("SELECT * FROM tv_episodes WHERE location = ? AND episode != ?",
|
related_eps_result = myDB.select("SELECT * FROM tv_episodes WHERE location = ? AND episode != ?",
|
||||||
[ep_result[0]["location"], epInfo[1]])
|
[ep_result[0]["location"], epInfo[1]])
|
||||||
|
|
||||||
root_ep_obj = show_obj.getEpisode(int(epInfo[0]), int(epInfo[1]))
|
root_ep_obj = show_obj.getEpisode(int(epInfo[0]), int(epInfo[1]))
|
||||||
root_ep_obj.relatedEps = []
|
root_ep_obj.relatedEps = []
|
||||||
|
|
||||||
for cur_related_ep in related_eps_result:
|
for cur_related_ep in related_eps_result:
|
||||||
related_ep_obj = show_obj.getEpisode(int(cur_related_ep["season"]), int(cur_related_ep["episode"]))
|
related_ep_obj = show_obj.getEpisode(int(cur_related_ep["season"]), int(cur_related_ep["episode"]))
|
||||||
if related_ep_obj not in root_ep_obj.relatedEps:
|
if related_ep_obj not in root_ep_obj.relatedEps:
|
||||||
root_ep_obj.relatedEps.append(related_ep_obj)
|
root_ep_obj.relatedEps.append(related_ep_obj)
|
||||||
|
|
||||||
root_ep_obj.rename()
|
root_ep_obj.rename()
|
||||||
|
|
||||||
return self.redirect("/home/displayShow?show=" + show)
|
return self.redirect("/home/displayShow?show=" + show)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user