mirror of
https://github.com/moparisthebest/SickRage
synced 2025-01-07 11:58:01 -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
@ -82,7 +82,7 @@ def loadShowsFromDB():
|
||||
Populates the showList with shows from the database
|
||||
"""
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select("SELECT * FROM tv_shows")
|
||||
|
||||
for sqlShow in sqlResults:
|
||||
@ -310,7 +310,8 @@ def main():
|
||||
|
||||
sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
|
||||
CUR_DB_VERSION = myDB.checkDBVersion()
|
||||
|
||||
if CUR_DB_VERSION > 0:
|
||||
|
@ -907,19 +907,19 @@ def initialize(consoleLogging=True):
|
||||
logger.sb_log_instance.initLogging(consoleLogging=consoleLogging)
|
||||
|
||||
# initialize the main SB database
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
db.upgradeDatabase(myDB, mainDB.InitialSchema)
|
||||
|
||||
# initialize the cache database
|
||||
with db.DBConnection('cache.db') as myDB:
|
||||
myDB = db.DBConnection('cache.db')
|
||||
db.upgradeDatabase(myDB, cache_db.InitialSchema)
|
||||
|
||||
# initialize the failed downloads database
|
||||
with db.DBConnection('failed.db') as myDB:
|
||||
myDB = db.DBConnection('failed.db')
|
||||
db.upgradeDatabase(myDB, failed_db.InitialSchema)
|
||||
|
||||
# fix up any db problems
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
db.sanityCheckDatabase(myDB, mainDB.MainSanityCheck)
|
||||
|
||||
# migrate the config if it needs it
|
||||
@ -1820,7 +1820,7 @@ def getEpList(epIDs, showid=None):
|
||||
query += " AND showid = ?"
|
||||
params.append(showid)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(query, params)
|
||||
|
||||
epList = []
|
||||
|
@ -96,9 +96,10 @@ class BlackAndWhiteList(object):
|
||||
return "Blacklist: " + blackResult + ", Whitelist: " + whiteResult
|
||||
|
||||
def _add_keywords(self, table, range, values):
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
for value in values:
|
||||
myDB.action("INSERT INTO " + table + " (show_id, range , keyword) VALUES (?,?,?)", [self.show_id, range, value])
|
||||
|
||||
self.refresh()
|
||||
|
||||
def _del_all_black_keywords(self):
|
||||
@ -115,18 +116,18 @@ class BlackAndWhiteList(object):
|
||||
|
||||
def _del_all_keywords(self, table):
|
||||
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])
|
||||
self.refresh()
|
||||
|
||||
def _del_all_keywords_for(self, table, range):
|
||||
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])
|
||||
self.refresh()
|
||||
|
||||
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])
|
||||
if not sqlResults or not len(sqlResults):
|
||||
return ([], {})
|
||||
|
@ -456,7 +456,7 @@ class ConfigMigrator():
|
||||
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
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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
|
||||
|
@ -43,7 +43,7 @@ class DailySearcher():
|
||||
fromDate = datetime.date.today() - datetime.timedelta(weeks=1)
|
||||
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 <= ?",
|
||||
[common.UNAIRED, common.WANTED, fromDate.toordinal(), curDate.toordinal()])
|
||||
|
||||
@ -80,7 +80,7 @@ class DailySearcher():
|
||||
sql_l.append(ep.get_sql())
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
if len(todaysEps):
|
||||
|
@ -50,13 +50,58 @@ class DBConnection(object):
|
||||
def __init__(self, filename="sickbeard.db", suffix=None, row_type=None):
|
||||
|
||||
self.filename = filename
|
||||
self.connection = sqlite3.connect(dbFilename(filename, suffix), 20)
|
||||
if row_type == "dict":
|
||||
self.suffix = suffix
|
||||
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
|
||||
else:
|
||||
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):
|
||||
|
||||
result = None
|
||||
|
||||
try:
|
||||
@ -83,8 +128,7 @@ class DBConnection(object):
|
||||
attempt = 0
|
||||
|
||||
# Transaction
|
||||
self.connection.isolation_level = None
|
||||
self.connection.execute('BEGIN')
|
||||
#self.execute('BEGIN')
|
||||
|
||||
while attempt < 5:
|
||||
try:
|
||||
@ -93,13 +137,11 @@ class DBConnection(object):
|
||||
if len(qu) == 1:
|
||||
if logTransaction:
|
||||
logger.log(qu[0], logger.DEBUG)
|
||||
sqlResult.append(self.connection.execute(qu[0]))
|
||||
sqlResult.append(self.execute(qu[0]))
|
||||
elif len(qu) > 1:
|
||||
if logTransaction:
|
||||
logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG)
|
||||
sqlResult.append(self.connection.execute(qu[0], qu[1]))
|
||||
|
||||
self.connection.commit()
|
||||
sqlResult.append(self.execute(qu[0], qu[1]))
|
||||
|
||||
logger.log(u"Transaction with " + str(len(querylist)) + u" queries executed", logger.DEBUG)
|
||||
return sqlResult
|
||||
@ -123,7 +165,7 @@ class DBConnection(object):
|
||||
|
||||
return sqlResult
|
||||
|
||||
def action(self, query, args=None):
|
||||
def action(self, query, args=None, fetchall=False):
|
||||
|
||||
with db_lock:
|
||||
|
||||
@ -137,11 +179,11 @@ class DBConnection(object):
|
||||
try:
|
||||
if args == None:
|
||||
logger.log(self.filename + ": " + query, logger.DB)
|
||||
sqlResult = self.connection.execute(query)
|
||||
else:
|
||||
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
|
||||
break
|
||||
except sqlite3.OperationalError, e:
|
||||
@ -158,10 +200,9 @@ class DBConnection(object):
|
||||
|
||||
return sqlResult
|
||||
|
||||
|
||||
def select(self, query, args=None):
|
||||
|
||||
sqlResults = self.action(query, args).fetchall()
|
||||
sqlResults = self.action(query, args, fetchall=True)
|
||||
|
||||
if sqlResults == None:
|
||||
return []
|
||||
@ -185,10 +226,11 @@ class DBConnection(object):
|
||||
self.action(query, valueDict.values() + keyDict.values())
|
||||
|
||||
def tableInfo(self, tableName):
|
||||
|
||||
# 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 = {}
|
||||
for column in cursor:
|
||||
for column in sqlResult:
|
||||
columns[column['name']] = {'type': column['type']}
|
||||
return columns
|
||||
|
||||
@ -200,16 +242,13 @@ class DBConnection(object):
|
||||
return d
|
||||
|
||||
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):
|
||||
"""Close database connection"""
|
||||
if getattr(self, "connection", None) is not None:
|
||||
self.connection.close()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.close()
|
||||
self.connection = None
|
||||
|
||||
def sanityCheckDatabase(connection, sanity_check):
|
||||
sanity_check(connection).check()
|
||||
@ -235,14 +274,16 @@ def upgradeDatabase(connection, schema):
|
||||
def prettyName(class_name):
|
||||
return ' '.join([x.group() for x in re.finditer("([A-Z])([a-z0-9]+)", class_name)])
|
||||
|
||||
|
||||
def restoreDatabase(version):
|
||||
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")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def _processUpgrade(connection, upgradeClass):
|
||||
instance = upgradeClass(connection)
|
||||
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")
|
||||
if result:
|
||||
version = int(result[0]["db_version"])
|
||||
connection.close()
|
||||
if restoreDatabase(version):
|
||||
# initialize the main SB database
|
||||
upgradeDatabase(DBConnection(), sickbeard.mainDB.InitialSchema)
|
||||
@ -282,7 +322,7 @@ class SchemaUpgrade(object):
|
||||
self.connection = connection
|
||||
|
||||
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):
|
||||
return column in self.connection.tableInfo(tableName)
|
||||
|
@ -50,7 +50,7 @@ def logFailed(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])
|
||||
|
||||
if len(sql_results) == 0:
|
||||
@ -78,7 +78,7 @@ def logFailed(release):
|
||||
provider = sql_results[0]["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])
|
||||
|
||||
deleteLoggedSnatch(release, size, provider)
|
||||
@ -89,7 +89,7 @@ def logFailed(release):
|
||||
def logSuccess(release):
|
||||
release = prepareFailedName(release)
|
||||
|
||||
with db.DBConnection('failed.db') as myDB:
|
||||
myDB = db.DBConnection('failed.db')
|
||||
myDB.action("DELETE FROM history WHERE release=?", [release])
|
||||
|
||||
|
||||
@ -104,7 +104,7 @@ def hasFailed(release, size, provider="%"):
|
||||
|
||||
release = prepareFailedName(release)
|
||||
|
||||
with db.DBConnection('failed.db') as myDB:
|
||||
myDB = db.DBConnection('failed.db')
|
||||
sql_results = myDB.select(
|
||||
"SELECT * FROM failed WHERE release=? AND size=? AND provider LIKE ?",
|
||||
[release, size, provider])
|
||||
@ -114,7 +114,7 @@ def hasFailed(release, size, provider="%"):
|
||||
|
||||
def revertEpisode(epObj):
|
||||
"""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=?",
|
||||
[epObj.show.indexerid, epObj.season])
|
||||
|
||||
@ -164,7 +164,7 @@ def logSnatch(searchResult):
|
||||
|
||||
show_obj = searchResult.episodes[0].show
|
||||
|
||||
with db.DBConnection('failed.db') as myDB:
|
||||
myDB = db.DBConnection('failed.db')
|
||||
for episode in searchResult.episodes:
|
||||
myDB.action(
|
||||
"INSERT INTO history (date, size, release, provider, showid, season, episode, old_status)"
|
||||
@ -176,13 +176,13 @@ def logSnatch(searchResult):
|
||||
def deleteLoggedSnatch(release, size, provider):
|
||||
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=?",
|
||||
[release, size, provider])
|
||||
|
||||
|
||||
def trimHistory():
|
||||
with db.DBConnection('failed.db') as myDB:
|
||||
myDB = db.DBConnection('failed.db')
|
||||
myDB.action("DELETE FROM history WHERE date < " + str(
|
||||
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(dateFormat)))
|
||||
|
||||
@ -198,7 +198,7 @@ def findRelease(epObj):
|
||||
|
||||
|
||||
# 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(
|
||||
epObj.season) + " AND episode=" + str(
|
||||
epObj.episode) + " AND date < (SELECT max(date) FROM history WHERE showid=" + str(
|
||||
|
@ -291,7 +291,7 @@ def searchDBForShow(regShowName, log=False):
|
||||
|
||||
yearRegex = "([^()]+?)\s*(\()?(\d{4})(?(2)\))$"
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
for showName in showNames:
|
||||
|
||||
sqlResults = myDB.select("SELECT * FROM tv_shows WHERE show_name LIKE ?",
|
||||
@ -682,7 +682,7 @@ def update_anime_support():
|
||||
|
||||
|
||||
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 = ?"
|
||||
sqlResults = myDB.select(sql, [show.indexerid, season, episode])
|
||||
|
||||
|
@ -31,7 +31,7 @@ def _logHistoryItem(action, showid, season, episode, quality, resource, provider
|
||||
if not isinstance(resource, unicode):
|
||||
resource = unicode(resource, 'utf-8')
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.action(
|
||||
"INSERT INTO history (action, date, showid, season, episode, quality, resource, provider) VALUES (?,?,?,?,?,?,?,?)",
|
||||
[action, logDate, showid, season, episode, quality, resource, provider])
|
||||
|
@ -32,7 +32,7 @@ def addNameToCache(name, indexer_id=0):
|
||||
|
||||
# standardize the name we're using to account for small differences in providers
|
||||
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])
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ def retrieveNameFromCache(name):
|
||||
# standardize the name we're using to account for small differences in providers
|
||||
name = sanitizeSceneName(name)
|
||||
|
||||
with db.DBConnection('cache.db') as myDB:
|
||||
myDB = db.DBConnection('cache.db')
|
||||
if myDB.hasTable('scene_names'):
|
||||
cache_results = myDB.select("SELECT * FROM scene_names WHERE name = ?", [name])
|
||||
|
||||
@ -67,7 +67,7 @@ def clearCache(show=None, season=-1, indexer_id=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:
|
||||
showNames = sickbeard.show_name_helpers.allPossibleShowNames(show, season=season)
|
||||
for showName in showNames:
|
||||
|
@ -164,7 +164,7 @@ def update_network_dict():
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
|
||||
with db.DBConnection('cache.db') as myDB:
|
||||
myDB = db.DBConnection('cache.db')
|
||||
# load current network timezones
|
||||
old_d = dict(myDB.select("SELECT * FROM network_timezones"))
|
||||
|
||||
@ -195,7 +195,7 @@ def update_network_dict():
|
||||
def load_network_dict():
|
||||
d = {}
|
||||
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()
|
||||
|
@ -151,7 +151,7 @@ class EmailNotifier:
|
||||
addrs.append(addr)
|
||||
|
||||
# Grab the recipients for the show
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
for s in show:
|
||||
for subs in myDB.select("SELECT notify_list FROM tv_shows WHERE show_name = ?", (s,)):
|
||||
if subs['notify_list']:
|
||||
|
@ -406,7 +406,7 @@ class PostProcessor(object):
|
||||
names.append(self.folder_name)
|
||||
|
||||
# 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:
|
||||
search_name = re.sub("[\.\-\ ]", "_", curName)
|
||||
sql_results = myDB.select("SELECT * FROM history WHERE resource LIKE ?", [search_name])
|
||||
@ -621,7 +621,7 @@ 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",
|
||||
logger.DEBUG)
|
||||
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 = ?",
|
||||
[show.indexerid, show.indexer, airdate])
|
||||
|
||||
@ -637,7 +637,7 @@ class PostProcessor(object):
|
||||
|
||||
# if there's no season then we can hopefully just use 1 automatically
|
||||
elif season == None and show:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
numseasonsSQlResult = myDB.select(
|
||||
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and indexer = ? and season != 0",
|
||||
[show.indexerid, show.indexer])
|
||||
@ -963,7 +963,7 @@ class PostProcessor(object):
|
||||
self._log(u"Couldn't find release in snatch history", logger.WARNING)
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# find the destination folder
|
||||
@ -1040,7 +1040,7 @@ class PostProcessor(object):
|
||||
sql_l.append(ep_obj.get_sql())
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# log it to history
|
||||
|
@ -242,7 +242,7 @@ def validateDir(path, dirName, nzbNameOriginal, failed):
|
||||
return False
|
||||
|
||||
# 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")
|
||||
|
||||
for sqlShow in sqlResults:
|
||||
@ -345,7 +345,7 @@ def already_postprocessed(dirName, videofile, force):
|
||||
dirName = unicode(dirName, 'utf_8')
|
||||
|
||||
# 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])
|
||||
if sqlResult:
|
||||
returnStr += logHelper(u"You're trying to post process a dir that's already been processed, skipping",
|
||||
|
@ -166,7 +166,7 @@ class ProperFinder():
|
||||
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
||||
logger.DEBUG)
|
||||
airdate = curProper.episode.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 = ?",
|
||||
[curProper.indexerid, curProper.indexer, airdate])
|
||||
@ -180,7 +180,7 @@ class ProperFinder():
|
||||
continue
|
||||
|
||||
# check if we actually want this proper (if it's the right quality)
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
"SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||
[curProper.indexerid, curProper.season, curProper.episode])
|
||||
@ -209,7 +209,7 @@ class ProperFinder():
|
||||
historyLimit = datetime.datetime.today() - datetime.timedelta(days=30)
|
||||
|
||||
# make sure the episode has been downloaded before
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
historyResults = myDB.select(
|
||||
"SELECT resource FROM history "
|
||||
"WHERE showid = ? AND season = ? AND episode = ? AND quality = ? AND date >= ? "
|
||||
@ -260,7 +260,7 @@ class ProperFinder():
|
||||
|
||||
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")
|
||||
|
||||
if len(sqlResults) == 0:
|
||||
@ -271,7 +271,7 @@ class ProperFinder():
|
||||
|
||||
def _get_lastProperSearch(self):
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select("SELECT * FROM info")
|
||||
|
||||
try:
|
||||
|
@ -321,7 +321,7 @@ class GenericProvider:
|
||||
logger.DEBUG)
|
||||
continue
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sql_results = myDB.select(
|
||||
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
|
||||
[show.indexerid,
|
||||
|
@ -314,7 +314,7 @@ class HDTorrentsProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -257,7 +257,7 @@ class IPTorrentsProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -393,7 +393,7 @@ class KATProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -305,7 +305,7 @@ class NextGenProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -277,7 +277,7 @@ class PublicHDProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -299,7 +299,7 @@ class SCCProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -239,7 +239,7 @@ class SpeedCDProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -371,7 +371,7 @@ class ThePirateBayProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -263,7 +263,7 @@ class TorrentDayProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -258,7 +258,7 @@ class TorrentLeechProvider(generic.TorrentProvider):
|
||||
|
||||
results = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select(
|
||||
'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)' +
|
||||
|
@ -41,7 +41,7 @@ def get_scene_exceptions(indexer_id, season=-1):
|
||||
global exceptionCache
|
||||
|
||||
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 = ?",
|
||||
[indexer_id, season])
|
||||
exceptionsList = list(set([cur_exception["show_name"] for cur_exception in exceptions]))
|
||||
@ -60,7 +60,7 @@ def get_scene_exceptions(indexer_id, season=-1):
|
||||
return exceptionsList
|
||||
|
||||
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])
|
||||
exceptionsList = {}
|
||||
[cur_exception["show_name"] for cur_exception in exceptions]
|
||||
@ -77,7 +77,7 @@ def get_scene_seasons(indexer_id):
|
||||
"""
|
||||
global 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 = ?",
|
||||
[indexer_id])
|
||||
exceptionSeasonCache[indexer_id] = [int(x["season"]) for x in sqlResults]
|
||||
@ -96,7 +96,7 @@ def get_scene_exception_by_name_multiple(show_name):
|
||||
"""
|
||||
|
||||
# try the obvious case first
|
||||
with db.DBConnection('cache.db') as myDB:
|
||||
myDB = db.DBConnection('cache.db')
|
||||
exception_result = myDB.select(
|
||||
"SELECT indexer_id, season FROM scene_exceptions WHERE LOWER(show_name) = ? ORDER BY season ASC",
|
||||
[show_name.lower()])
|
||||
@ -183,7 +183,7 @@ def retrieve_exceptions():
|
||||
changed_exceptions = False
|
||||
|
||||
# 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:
|
||||
|
||||
# get a list of the existing exceptions for this ID
|
||||
@ -216,7 +216,7 @@ def update_scene_exceptions(indexer_id, scene_exceptions):
|
||||
|
||||
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])
|
||||
|
||||
logger.log(u"Updating internal scene name cache", logger.MESSAGE)
|
||||
@ -235,7 +235,7 @@ def _retrieve_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 = ?",
|
||||
['anidb'])
|
||||
if rows:
|
||||
@ -268,7 +268,7 @@ def _xem_excpetions_fetcher(indexer):
|
||||
|
||||
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 = ?",
|
||||
['xem'])
|
||||
if rows:
|
||||
@ -299,7 +299,7 @@ def _xem_excpetions_fetcher(indexer):
|
||||
def getSceneSeasons(indexer_id):
|
||||
"""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])
|
||||
return [cur_exception["season"] for cur_exception in seasons]
|
||||
|
||||
|
@ -82,7 +82,7 @@ def find_scene_numbering(indexer_id, indexer, season, episode):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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",
|
||||
[indexer, indexer_id, season, episode])
|
||||
@ -134,7 +134,7 @@ def find_scene_absolute_numbering(indexer_id, indexer, absolute_number):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
"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])
|
||||
@ -154,7 +154,7 @@ def get_indexer_numbering(indexer_id, indexer, sceneSeason, sceneEpisode, fallba
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
"SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ?",
|
||||
[indexer, indexer_id, sceneSeason, sceneEpisode])
|
||||
@ -178,7 +178,7 @@ def get_indexer_absolute_numbering(indexer_id, indexer, sceneAbsoluteNumber, fal
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
"SELECT absolute_number FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_absolute_number = ?",
|
||||
[indexer, indexer_id, sceneAbsoluteNumber])
|
||||
@ -203,7 +203,7 @@ def set_scene_numbering(indexer_id, indexer, season=None, episode=None, absolute
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
if season and episode:
|
||||
myDB.action(
|
||||
"INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, season, episode) VALUES (?,?,?,?)",
|
||||
@ -240,7 +240,7 @@ def find_xem_numbering(indexer_id, indexer, season, episode):
|
||||
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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",
|
||||
[indexer, indexer_id, season, episode])
|
||||
@ -266,7 +266,7 @@ def find_xem_absolute_numbering(indexer_id, indexer, absolute_number):
|
||||
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
"SELECT scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and absolute_number = ? and scene_absolute_number != 0",
|
||||
[indexer, indexer_id, absolute_number])
|
||||
@ -292,7 +292,7 @@ def get_indexer_numbering_for_xem(indexer_id, indexer, sceneSeason, sceneEpisode
|
||||
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
"SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ?",
|
||||
[indexer, indexer_id, sceneSeason, sceneEpisode])
|
||||
@ -319,7 +319,7 @@ def get_indexer_absolute_numbering_for_xem(indexer_id, indexer, sceneAbsoluteNum
|
||||
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
"SELECT absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and scene_absolute_number = ?",
|
||||
[indexer, indexer_id, sceneAbsoluteNumber])
|
||||
@ -342,7 +342,7 @@ def get_scene_numbering_for_show(indexer_id, indexer):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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',
|
||||
[indexer, indexer_id])
|
||||
@ -373,7 +373,7 @@ def get_xem_numbering_for_show(indexer_id, indexer):
|
||||
|
||||
xem_refresh(indexer_id, indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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',
|
||||
[indexer, indexer_id])
|
||||
@ -402,7 +402,7 @@ def get_scene_absolute_numbering_for_show(indexer_id, indexer):
|
||||
indexer_id = int(indexer_id)
|
||||
indexer = int(indexer)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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',
|
||||
[indexer, indexer_id])
|
||||
@ -433,7 +433,7 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer):
|
||||
|
||||
|
||||
result = {}
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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',
|
||||
[indexer, indexer_id])
|
||||
@ -458,7 +458,7 @@ def xem_refresh(indexer_id, indexer, force=False):
|
||||
indexer_id = int(indexer_id)
|
||||
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 = ?",
|
||||
[indexer, indexer_id])
|
||||
|
||||
@ -526,7 +526,7 @@ def xem_refresh(indexer_id, indexer, force=False):
|
||||
return None
|
||||
|
||||
if ql:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(ql)
|
||||
|
||||
# fix xem scene numbering issues
|
||||
@ -585,7 +585,7 @@ def fix_xem_numbering(indexer_id, indexer):
|
||||
# # Get query results
|
||||
# tmp = get_from_api(url, params=params)['result']
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
'SELECT season, episode, absolute_number, scene_season, scene_episode, scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ?',
|
||||
[indexer, indexer_id])
|
||||
@ -693,5 +693,5 @@ def fix_xem_numbering(indexer_id, indexer):
|
||||
update_scene_absolute_number = False
|
||||
|
||||
if ql:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(ql)
|
@ -173,7 +173,7 @@ def snatchEpisode(result, endStatus=SNATCHED):
|
||||
notifiers.notify_snatch(curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN'))
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
return True
|
||||
@ -509,7 +509,7 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
||||
u"The quality of the season " + bestSeasonNZB.provider.providerType + " is " + Quality.qualityStrings[
|
||||
seasonQual], logger.DEBUG)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
allEps = [int(x["episode"]) for x in
|
||||
myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND season = ?",
|
||||
[show.indexerid, season])]
|
||||
|
@ -117,7 +117,7 @@ class BacklogSearcher:
|
||||
|
||||
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")
|
||||
|
||||
if len(sqlResults) == 0:
|
||||
@ -137,7 +137,7 @@ class BacklogSearcher:
|
||||
|
||||
logger.log(u"Seeing if we need anything from " + show.name)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
if show.air_by_date:
|
||||
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",
|
||||
@ -175,7 +175,7 @@ class BacklogSearcher:
|
||||
|
||||
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")
|
||||
|
||||
if len(sqlResults) == 0:
|
||||
|
@ -73,7 +73,7 @@ class ShowUpdater():
|
||||
stale_update_date = (update_date - datetime.timedelta(days=90)).toordinal()
|
||||
|
||||
# last_update_date <= 90 days, sorted ASC because dates are ordinal
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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;",
|
||||
[stale_update_date])
|
||||
|
@ -143,7 +143,7 @@ def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None):
|
||||
seasonStrings.append("%d" % ab_number)
|
||||
|
||||
else:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
numseasonsSQlResult = myDB.select(
|
||||
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and season != 0",
|
||||
[show.indexerid])
|
||||
@ -177,7 +177,7 @@ def makeSceneSeasonSearchString(show, ep_obj, extraSearchType=None):
|
||||
|
||||
|
||||
def makeSceneSearchString(show, ep_obj):
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
numseasonsSQlResult = myDB.select(
|
||||
"SELECT COUNT(DISTINCT season) as numseasons FROM tv_episodes WHERE showid = ? and season != 0",
|
||||
[show.indexerid])
|
||||
|
@ -370,7 +370,7 @@ class QueueItemAdd(ShowQueueItem):
|
||||
# if they gave a custom status then change all the eps to it
|
||||
if self.default_status != SKIPPED:
|
||||
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",
|
||||
[self.default_status, SKIPPED, self.show.indexerid])
|
||||
|
||||
|
@ -107,7 +107,7 @@ class SubtitlesFinder():
|
||||
today = datetime.date.today().toordinal()
|
||||
|
||||
# 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])
|
||||
if len(sqlResults) == 0:
|
||||
logger.log('No subtitles to download', logger.MESSAGE)
|
||||
|
@ -169,7 +169,7 @@ class TVShow(object):
|
||||
# need ORDER episode ASC to rename multi-episodes in order S01E01-02
|
||||
sql_selection = sql_selection + " ORDER BY season ASC, episode ASC"
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
results = myDB.select(sql_selection)
|
||||
|
||||
ep_list = []
|
||||
@ -201,7 +201,7 @@ class TVShow(object):
|
||||
|
||||
# if we get an anime get the real season and 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"
|
||||
sqlResults = myDB.select(sql, [self.indexerid, absolute_number])
|
||||
|
||||
@ -266,7 +266,7 @@ class TVShow(object):
|
||||
last_airdate = datetime.date.fromordinal(1)
|
||||
|
||||
# get latest aired episode to compare against today - graceperiod and today + graceperiod
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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",
|
||||
[cur_indexerid])
|
||||
@ -330,7 +330,7 @@ class TVShow(object):
|
||||
|
||||
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])
|
||||
|
||||
for epResult in sqlResults:
|
||||
@ -421,14 +421,14 @@ class TVShow(object):
|
||||
sql_l.append(curEpisode.get_sql())
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
def loadEpisodesFromDB(self):
|
||||
|
||||
logger.log(u"Loading all episodes from the DB")
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sql = "SELECT * FROM tv_episodes WHERE showid = ?"
|
||||
sqlResults = myDB.select(sql, [self.indexerid])
|
||||
|
||||
@ -542,7 +542,7 @@ class TVShow(object):
|
||||
scannedEps[season][episode] = True
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# Done updating save last update date
|
||||
@ -602,7 +602,7 @@ class TVShow(object):
|
||||
u"Looks like this is an air-by-date or sports show, attempting to convert the date to season/episode",
|
||||
logger.DEBUG)
|
||||
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(
|
||||
"SELECT season, episode FROM tv_episodes WHERE showid = ? and indexer = ? and airdate = ?",
|
||||
[self.indexerid, self.indexer, airdate])
|
||||
@ -712,7 +712,7 @@ class TVShow(object):
|
||||
sql_l.append(curEp.get_sql())
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# creating metafiles on the root should be good enough
|
||||
@ -726,7 +726,7 @@ class TVShow(object):
|
||||
|
||||
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])
|
||||
|
||||
if len(sqlResults) > 1:
|
||||
@ -806,7 +806,7 @@ class TVShow(object):
|
||||
self.imdbid = sqlResults[0]["imdb_id"]
|
||||
|
||||
# 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])
|
||||
|
||||
if len(sqlResults) == 0:
|
||||
@ -936,7 +936,7 @@ class TVShow(object):
|
||||
def nextEpisode(self):
|
||||
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"
|
||||
innerParams = [self.indexerid, datetime.date.today().toordinal(), UNAIRED, WANTED]
|
||||
query = "SELECT * FROM tv_episodes WHERE showid = ? AND airdate >= ? AND airdate <= (" + innerQuery + ") and status in (?,?)"
|
||||
@ -964,7 +964,7 @@ class TVShow(object):
|
||||
["DELETE FROM xem_refresh 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)
|
||||
|
||||
# remove self from show list
|
||||
@ -994,7 +994,7 @@ class TVShow(object):
|
||||
# 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")
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND location != ''", [self.indexerid])
|
||||
|
||||
sql_l = []
|
||||
@ -1038,7 +1038,7 @@ class TVShow(object):
|
||||
self.airdateModifyStamp(curEp)
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
def airdateModifyStamp(self, ep_obj):
|
||||
@ -1088,7 +1088,7 @@ class TVShow(object):
|
||||
logger.log(str(self.indexerid) + ": Downloading subtitles", logger.DEBUG)
|
||||
|
||||
try:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
episodes = myDB.select(
|
||||
"SELECT location FROM tv_episodes WHERE showid = ? AND location NOT LIKE '' ORDER BY season DESC, episode DESC",
|
||||
[self.indexerid])
|
||||
@ -1132,7 +1132,7 @@ class TVShow(object):
|
||||
"rls_require_words": self.rls_require_words
|
||||
}
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.upsert("tv_shows", newValueDict, controlValueDict)
|
||||
|
||||
helpers.update_anime_support()
|
||||
@ -1141,7 +1141,7 @@ class TVShow(object):
|
||||
controlValueDict = {"indexer_id": self.indexerid}
|
||||
newValueDict = self.imdb_info
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.upsert("imdb_info", newValueDict, controlValueDict)
|
||||
|
||||
def __str__(self):
|
||||
@ -1182,7 +1182,7 @@ class TVShow(object):
|
||||
logger.log(u"Don't want this quality, ignoring found episode", logger.DEBUG)
|
||||
return False
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||
[self.indexerid, season, episode])
|
||||
|
||||
@ -1474,7 +1474,7 @@ class TVEpisode(object):
|
||||
str(self.show.indexerid) + u": Loading episode details from DB for episode " + str(season) + "x" + str(
|
||||
episode), logger.DEBUG)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||
[self.show.indexerid, season, episode])
|
||||
|
||||
@ -1827,7 +1827,7 @@ class TVEpisode(object):
|
||||
|
||||
# delete myself from the DB
|
||||
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(
|
||||
self.season) + " AND episode=" + str(self.episode)
|
||||
myDB.action(sql)
|
||||
@ -1846,7 +1846,7 @@ class TVEpisode(object):
|
||||
logger.log(str(self.show.indexerid) + u": Not creating SQL queue - record is not dirty", logger.DEBUG)
|
||||
return
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
rows = myDB.select(
|
||||
'SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?',
|
||||
[self.show.indexerid, self.season, self.episode])
|
||||
@ -1917,7 +1917,7 @@ class TVEpisode(object):
|
||||
"episode": self.episode}
|
||||
|
||||
# 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)
|
||||
|
||||
def fullPath(self):
|
||||
@ -2382,5 +2382,5 @@ class TVEpisode(object):
|
||||
sql_l.append(relEp.get_sql())
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
@ -83,7 +83,7 @@ class TVCache():
|
||||
|
||||
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()))])
|
||||
|
||||
def _getRSSData(self):
|
||||
@ -125,7 +125,7 @@ class TVCache():
|
||||
cl.append(ci)
|
||||
|
||||
if cl:
|
||||
with self._getDB() as myDB:
|
||||
myDB = self._getDB()
|
||||
myDB.mass_action(cl)
|
||||
|
||||
else:
|
||||
@ -192,7 +192,7 @@ class TVCache():
|
||||
|
||||
|
||||
def _getLastUpdate(self):
|
||||
with self._getDB() as myDB:
|
||||
myDB = self._getDB()
|
||||
sqlResults = myDB.select("SELECT time FROM lastUpdate WHERE provider = ?", [self.providerID])
|
||||
|
||||
if sqlResults:
|
||||
@ -205,7 +205,7 @@ class TVCache():
|
||||
return datetime.datetime.fromtimestamp(lastTime)
|
||||
|
||||
def _getLastSearch(self):
|
||||
with self._getDB() as myDB:
|
||||
myDB = self._getDB()
|
||||
sqlResults = myDB.select("SELECT time FROM lastSearch WHERE provider = ?", [self.providerID])
|
||||
|
||||
if sqlResults:
|
||||
@ -222,7 +222,7 @@ class TVCache():
|
||||
if not toDate:
|
||||
toDate = datetime.datetime.today()
|
||||
|
||||
with self._getDB() as myDB:
|
||||
myDB = self._getDB()
|
||||
myDB.upsert("lastUpdate",
|
||||
{'time': int(time.mktime(toDate.timetuple()))},
|
||||
{'provider': self.providerID})
|
||||
@ -231,7 +231,7 @@ class TVCache():
|
||||
if not toDate:
|
||||
toDate = datetime.datetime.today()
|
||||
|
||||
with self._getDB() as myDB:
|
||||
myDB = self._getDB()
|
||||
myDB.upsert("lastSearch",
|
||||
{'time': int(time.mktime(toDate.timetuple()))},
|
||||
{'provider': self.providerID})
|
||||
@ -277,7 +277,7 @@ class TVCache():
|
||||
if parse_result.air_by_date or parse_result.sports:
|
||||
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(
|
||||
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND indexer = ? AND airdate = ?",
|
||||
[parse_result.show.indexerid, parse_result.show.indexer, airdate])
|
||||
@ -314,7 +314,7 @@ class TVCache():
|
||||
return neededEps
|
||||
|
||||
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.%'"
|
||||
|
||||
if date != None:
|
||||
@ -327,7 +327,7 @@ class TVCache():
|
||||
neededEps = {}
|
||||
|
||||
for epObj in episodes:
|
||||
with self._getDB() as myDB:
|
||||
myDB = self._getDB()
|
||||
sqlResults = myDB.select(
|
||||
"SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?",
|
||||
[epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"])
|
||||
|
@ -138,7 +138,7 @@ class Api(webserve.MainHandler):
|
||||
seasonSQLResults = {}
|
||||
episodeSQLResults = {}
|
||||
|
||||
with db.DBConnection(row_type="dict") as myDB:
|
||||
myDB = db.DBConnection(row_type="dict")
|
||||
for curShow in t.sortedShowList:
|
||||
seasonSQLResults[curShow.indexerid] = myDB.select(
|
||||
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season DESC", [curShow.indexerid])
|
||||
@ -805,7 +805,7 @@ class CMD_ComingEpisodes(ApiCall):
|
||||
finalEpResults[status] = []
|
||||
|
||||
finalEpResults[status].append(ep)
|
||||
myDB.connection.close()
|
||||
|
||||
return _responds(RESULT_SUCCESS, finalEpResults)
|
||||
|
||||
|
||||
@ -866,7 +866,6 @@ class CMD_Episode(ApiCall):
|
||||
episode["quality"] = _get_quality_string(quality)
|
||||
episode["file_size_human"] = _sizeof_fmt(episode["file_size"])
|
||||
|
||||
myDB.connection.close()
|
||||
return _responds(RESULT_SUCCESS, episode)
|
||||
|
||||
|
||||
@ -1113,7 +1112,6 @@ class CMD_Exceptions(ApiCall):
|
||||
for row in sqlResults:
|
||||
scene_exceptions.append(row["show_name"])
|
||||
|
||||
myDB.connection.close()
|
||||
return _responds(RESULT_SUCCESS, scene_exceptions)
|
||||
|
||||
|
||||
@ -1174,7 +1172,6 @@ class CMD_History(ApiCall):
|
||||
row['tvdbid'] = row['indexerid']
|
||||
results.append(row)
|
||||
|
||||
myDB.connection.close()
|
||||
return _responds(RESULT_SUCCESS, results)
|
||||
|
||||
|
||||
@ -1193,7 +1190,6 @@ class CMD_HistoryClear(ApiCall):
|
||||
myDB = db.DBConnection()
|
||||
myDB.action("DELETE FROM history WHERE 1=1")
|
||||
|
||||
myDB.connection.close()
|
||||
return _responds(RESULT_SUCCESS, msg="History cleared")
|
||||
|
||||
|
||||
@ -1213,7 +1209,7 @@ class CMD_HistoryTrim(ApiCall):
|
||||
myDB.action("DELETE FROM history WHERE date < " + str(
|
||||
(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")
|
||||
|
||||
|
||||
@ -1370,7 +1366,7 @@ class CMD_SickBeardCheckScheduler(ApiCall):
|
||||
backlogRunning = sickbeard.searchQueueScheduler.action.is_backlog_in_progress() #@UndefinedVariable
|
||||
nextBacklog = sickbeard.backlogSearchScheduler.nextRun().strftime(dateFormat).decode(sickbeard.SYS_ENCODING)
|
||||
|
||||
myDB.connection.close()
|
||||
|
||||
data = {"backlog_is_paused": int(backlogPaused), "backlog_is_running": int(backlogRunning),
|
||||
"last_backlog": _ordinal_to_dateForm(sqlResults[0]["last_backlog"]),
|
||||
"next_backlog": nextBacklog}
|
||||
@ -2221,7 +2217,7 @@ class CMD_ShowSeasonList(ApiCall):
|
||||
for row in sqlResults:
|
||||
seasonList.append(int(row["season"]))
|
||||
|
||||
myDB.connection.close()
|
||||
|
||||
return _responds(RESULT_SUCCESS, seasonList)
|
||||
|
||||
|
||||
@ -2284,7 +2280,7 @@ class CMD_ShowSeasons(ApiCall):
|
||||
seasons[curEpisode] = {}
|
||||
seasons[curEpisode] = row
|
||||
|
||||
myDB.connection.close()
|
||||
|
||||
return _responds(RESULT_SUCCESS, seasons)
|
||||
|
||||
|
||||
@ -2453,7 +2449,7 @@ class CMD_ShowStats(ApiCall):
|
||||
")", "")
|
||||
episodes_stats[statusString] = episode_status_counts_total[statusCode]
|
||||
|
||||
myDB.connection.close()
|
||||
|
||||
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(
|
||||
[str(show) for show in (Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_PROPER) + [
|
||||
ARCHIVED]]) + ")) AND airdate <= " + today + " AND status != " + str(IGNORED) + "")[0][0]
|
||||
myDB.connection.close()
|
||||
|
||||
return _responds(RESULT_SUCCESS, stats)
|
||||
|
||||
# WARNING: never define a cmd call string that contains a "_" (underscore)
|
||||
|
@ -213,11 +213,11 @@ class MainHandler(RequestHandler):
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
response = self._dispatch()
|
||||
self.write(response)
|
||||
self.finish(response)
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
response = self._dispatch()
|
||||
self.write(response)
|
||||
self.finish(response)
|
||||
|
||||
def robots_txt(self, *args, **kwargs):
|
||||
""" Keep web crawlers out """
|
||||
@ -309,7 +309,7 @@ class MainHandler(RequestHandler):
|
||||
done_show_list = []
|
||||
qualList = Quality.DOWNLOADED + Quality.SNATCHED + [ARCHIVED, IGNORED]
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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(
|
||||
['?'] * len(qualList)) + ")", [today, next_week] + qualList)
|
||||
@ -404,7 +404,7 @@ class MainHandler(RequestHandler):
|
||||
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)
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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'")
|
||||
for show in calendar_shows:
|
||||
@ -626,7 +626,7 @@ class Manage(MainHandler):
|
||||
if status_list[0] == SNATCHED:
|
||||
status_list = Quality.SNATCHED + Quality.SNATCHED_PROPER
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
cur_show_results = myDB.select(
|
||||
"SELECT season, episode, name FROM tv_episodes WHERE showid = ? AND season != 0 AND status IN (" + ','.join(
|
||||
['?'] * len(status_list)) + ")", [int(indexer_id)] + status_list)
|
||||
@ -662,7 +662,7 @@ class Manage(MainHandler):
|
||||
if not status_list:
|
||||
return _munge(t)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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(
|
||||
['?'] * len(
|
||||
@ -710,7 +710,7 @@ class Manage(MainHandler):
|
||||
|
||||
to_change[indexer_id].append(what)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
for cur_indexer_id in to_change:
|
||||
|
||||
# get a list of all the eps we want to change if they just said "all"
|
||||
@ -729,7 +729,7 @@ class Manage(MainHandler):
|
||||
|
||||
|
||||
def showSubtitleMissed(self, indexer_id, whichSubs):
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
cur_show_results = myDB.select(
|
||||
"SELECT season, episode, name, subtitles FROM tv_episodes WHERE showid = ? AND season != 0 AND status LIKE '%4'",
|
||||
[int(indexer_id)])
|
||||
@ -770,7 +770,7 @@ class Manage(MainHandler):
|
||||
if not whichSubs:
|
||||
return _munge(t)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
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")
|
||||
|
||||
@ -821,7 +821,7 @@ class Manage(MainHandler):
|
||||
for cur_indexer_id in to_download:
|
||||
# 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]:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
all_eps_results = myDB.select(
|
||||
"SELECT season, episode FROM tv_episodes WHERE status LIKE '%4' AND season != 0 AND showid = ?",
|
||||
[cur_indexer_id])
|
||||
@ -855,7 +855,7 @@ class Manage(MainHandler):
|
||||
showCats = {}
|
||||
showSQLResults = {}
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
for curShow in sickbeard.showList:
|
||||
|
||||
epCounts = {}
|
||||
@ -1198,7 +1198,7 @@ class Manage(MainHandler):
|
||||
|
||||
def failedDownloads(self, limit=100, toRemove=None):
|
||||
|
||||
with db.DBConnection('failed.db') as myDB:
|
||||
myDB = db.DBConnection('failed.db')
|
||||
|
||||
if limit == "0":
|
||||
sqlResults = myDB.select("SELECT * FROM failed")
|
||||
@ -1225,7 +1225,7 @@ class History(MainHandler):
|
||||
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))
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
if limit == "0":
|
||||
sqlResults = myDB.select(
|
||||
"SELECT h.*, show_name FROM history h, tv_shows s WHERE h.showid=s.indexer_id ORDER BY date DESC")
|
||||
@ -1295,7 +1295,7 @@ class History(MainHandler):
|
||||
|
||||
def clearHistory(self, *args, **kwargs):
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.action("DELETE FROM history WHERE 1=1")
|
||||
|
||||
ui.notifications.message('History cleared')
|
||||
@ -1304,7 +1304,7 @@ class History(MainHandler):
|
||||
|
||||
def trimHistory(self, *args, **kwargs):
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.action("DELETE FROM history WHERE date < " + str(
|
||||
(datetime.datetime.today() - datetime.timedelta(days=30)).strftime(history.dateFormat)))
|
||||
|
||||
@ -2619,7 +2619,7 @@ class NewHomeAddShows(MainHandler):
|
||||
|
||||
dir_list = []
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
for root_dir in root_dirs:
|
||||
try:
|
||||
file_list = ek.ek(os.listdir, root_dir)
|
||||
@ -3240,7 +3240,7 @@ class Home(MainHandler):
|
||||
def loadShowNotifyLists(self, *args, **kwargs):
|
||||
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")
|
||||
|
||||
data = {}
|
||||
@ -3355,7 +3355,7 @@ class Home(MainHandler):
|
||||
if showObj is None:
|
||||
return _genericMessage("Error", "Show not in show list")
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
seasonResults = myDB.select(
|
||||
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season desc",
|
||||
[showObj.indexerid]
|
||||
@ -3476,7 +3476,7 @@ class Home(MainHandler):
|
||||
|
||||
|
||||
def plotDetails(self, show, season, episode):
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
result = myDB.action(
|
||||
"SELECT description FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
|
||||
(int(show), int(season), int(episode))).fetchone()
|
||||
@ -3939,7 +3939,7 @@ class Home(MainHandler):
|
||||
sql_l.append(epObj.get_sql())
|
||||
|
||||
if sql_l:
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
if int(status) == WANTED:
|
||||
@ -4042,7 +4042,7 @@ class Home(MainHandler):
|
||||
if eps is None:
|
||||
return self.redirect("/home/displayShow?show=" + show)
|
||||
|
||||
with db.DBConnection() as myDB:
|
||||
myDB = db.DBConnection()
|
||||
for curEp in eps.split('|'):
|
||||
|
||||
epInfo = curEp.split('x')
|
||||
|
Loading…
Reference in New Issue
Block a user