mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 11:32:20 -05:00
Added thread locking for queues.
Fixed imdbinfo issues.
This commit is contained in:
parent
cfcc35ebcc
commit
2c0f3a3dc3
@ -61,48 +61,47 @@ class GenericQueue(object):
|
|||||||
|
|
||||||
# only start a new task if one isn't already going
|
# only start a new task if one isn't already going
|
||||||
if self.thread == None or self.thread.isAlive() == False:
|
if self.thread == None or self.thread.isAlive() == False:
|
||||||
|
with self.lock:
|
||||||
|
# if the thread is dead then the current item should be finished
|
||||||
|
if self.currentItem != None:
|
||||||
|
self.currentItem.finish()
|
||||||
|
self.currentItem = None
|
||||||
|
|
||||||
# if the thread is dead then the current item should be finished
|
# if there's something in the queue then run it in a thread and take it out of the queue
|
||||||
if self.currentItem != None:
|
if len(self.queue) > 0:
|
||||||
self.currentItem.finish()
|
|
||||||
self.currentItem = None
|
|
||||||
|
|
||||||
# if there's something in the queue then run it in a thread and take it out of the queue
|
# sort by priority
|
||||||
if len(self.queue) > 0:
|
def sorter(x,y):
|
||||||
|
"""
|
||||||
|
Sorts by priority descending then time ascending
|
||||||
|
"""
|
||||||
|
if x.priority == y.priority:
|
||||||
|
if y.added == x.added:
|
||||||
|
return 0
|
||||||
|
elif y.added < x.added:
|
||||||
|
return 1
|
||||||
|
elif y.added > x.added:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return y.priority-x.priority
|
||||||
|
|
||||||
# sort by priority
|
|
||||||
def sorter(x,y):
|
|
||||||
"""
|
|
||||||
Sorts by priority descending then time ascending
|
|
||||||
"""
|
|
||||||
if x.priority == y.priority:
|
|
||||||
if y.added == x.added:
|
|
||||||
return 0
|
|
||||||
elif y.added < x.added:
|
|
||||||
return 1
|
|
||||||
elif y.added > x.added:
|
|
||||||
return -1
|
|
||||||
else:
|
|
||||||
return y.priority-x.priority
|
|
||||||
|
|
||||||
with self.lock:
|
|
||||||
self.queue.sort(cmp=sorter)
|
self.queue.sort(cmp=sorter)
|
||||||
|
|
||||||
queueItem = self.queue[0]
|
queueItem = self.queue[0]
|
||||||
|
|
||||||
if queueItem.priority < self.min_priority:
|
if queueItem.priority < self.min_priority:
|
||||||
return
|
return
|
||||||
|
|
||||||
# launch the queue item in a thread
|
# launch the queue item in a thread
|
||||||
# TODO: improve thread name
|
# TODO: improve thread name
|
||||||
threadName = self.queue_name + '-' + queueItem.get_thread_name()
|
threadName = self.queue_name + '-' + queueItem.get_thread_name()
|
||||||
self.thread = threading.Thread(None, queueItem.execute, threadName)
|
self.thread = threading.Thread(None, queueItem.execute, threadName)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
self.currentItem = queueItem
|
self.currentItem = queueItem
|
||||||
|
|
||||||
# take it out of the queue
|
# take it out of the queue
|
||||||
del self.queue[0]
|
del self.queue[0]
|
||||||
|
|
||||||
class QueueItem:
|
class QueueItem:
|
||||||
def __init__(self, name, action_id = 0):
|
def __init__(self, name, action_id = 0):
|
||||||
|
@ -892,11 +892,21 @@ class TVShow(object):
|
|||||||
imdb_info[key] = imdbTv.get(key.replace('_', ' '))
|
imdb_info[key] = imdbTv.get(key.replace('_', ' '))
|
||||||
|
|
||||||
# Filter only the value
|
# Filter only the value
|
||||||
imdb_info['runtimes'] = re.search('\d+', imdb_info['runtimes']).group(0) or self.runtime
|
if imdb_info['runtimes']:
|
||||||
imdb_info['akas'] = '|'.join(imdb_info['akas']) or ''
|
imdb_info['runtimes'] = re.search('\d+', imdb_info['runtimes']).group(0)
|
||||||
|
else:
|
||||||
|
imdb_info['runtimes'] = self.runtime
|
||||||
|
|
||||||
|
if imdb_info['akas']:
|
||||||
|
imdb_info['akas'] = '|'.join(imdb_info['akas'])
|
||||||
|
else:
|
||||||
|
imdb_info['akas'] = ''
|
||||||
|
|
||||||
# Join all genres in a string
|
# Join all genres in a string
|
||||||
imdb_info['genres'] = '|'.join(imdb_info['genres']) or ''
|
if imdb_info['genres']:
|
||||||
|
imdb_info['genres'] = '|'.join(imdb_info['genres'])
|
||||||
|
else:
|
||||||
|
imdb_info['genres'] = ''
|
||||||
|
|
||||||
# Get only the production country certificate if any
|
# Get only the production country certificate if any
|
||||||
if imdb_info['certificates'] and imdb_info['countries']:
|
if imdb_info['certificates'] and imdb_info['countries']:
|
||||||
@ -912,7 +922,11 @@ class TVShow(object):
|
|||||||
else:
|
else:
|
||||||
imdb_info['certificates'] = ''
|
imdb_info['certificates'] = ''
|
||||||
|
|
||||||
imdb_info['country_codes'] = '|'.join(imdb_info['country_codes']) or ''
|
if imdb_info['country_codes']:
|
||||||
|
imdb_info['country_codes'] = '|'.join(imdb_info['country_codes'])
|
||||||
|
else:
|
||||||
|
imdb_info['country_codes'] = ''
|
||||||
|
|
||||||
imdb_info['last_update'] = datetime.date.today().toordinal()
|
imdb_info['last_update'] = datetime.date.today().toordinal()
|
||||||
|
|
||||||
# Rename dict keys without spaces for DB upsert
|
# Rename dict keys without spaces for DB upsert
|
||||||
@ -1499,14 +1513,20 @@ class TVEpisode(object):
|
|||||||
self.indexer = int(sqlResults[0]["indexer"])
|
self.indexer = int(sqlResults[0]["indexer"])
|
||||||
|
|
||||||
# does one now a better way to test for NULL in the db field ?
|
# does one now a better way to test for NULL in the db field ?
|
||||||
if sqlResults[0]["scene_season"]:
|
try:
|
||||||
self.scene_season = int(sqlResults[0]["scene_season"] or 0)
|
self.scene_season = int(sqlResults[0]["scene_season"])
|
||||||
|
except:
|
||||||
|
self.scene_season = 0
|
||||||
|
|
||||||
if sqlResults[0]["scene_episode"]:
|
try:
|
||||||
self.scene_episode = int(sqlResults[0]["scene_episode"] or 0)
|
self.scene_episode = int(sqlResults[0]["scene_episode"])
|
||||||
|
except:
|
||||||
|
self.scene_episode = 0
|
||||||
|
|
||||||
if sqlResults[0]["scene_absolute_number"]:
|
try:
|
||||||
self.scene_absolute_number = int(sqlResults[0]["scene_absolute_number"] or 0)
|
self.scene_absolute_number = int(sqlResults[0]["scene_absolute_number"])
|
||||||
|
except:
|
||||||
|
self.scene_absolute_number = 0
|
||||||
|
|
||||||
if sqlResults[0]["release_name"] is not None:
|
if sqlResults[0]["release_name"] is not None:
|
||||||
self.release_name = sqlResults[0]["release_name"]
|
self.release_name = sqlResults[0]["release_name"]
|
||||||
@ -2355,8 +2375,7 @@ class TVEpisode(object):
|
|||||||
for curEp in [self] + self.relatedEps:
|
for curEp in [self] + self.relatedEps:
|
||||||
curEp.checkForMetaFiles()
|
curEp.checkForMetaFiles()
|
||||||
|
|
||||||
# save any changes to the database
|
# save any changes to the databas
|
||||||
|
|
||||||
sql_l = []
|
sql_l = []
|
||||||
with self.lock:
|
with self.lock:
|
||||||
sql_l.append(self.get_sql())
|
sql_l.append(self.get_sql())
|
||||||
|
@ -3577,9 +3577,9 @@ class Home:
|
|||||||
# mass add to database
|
# mass add to database
|
||||||
sql_l.append(epObj.get_sql())
|
sql_l.append(epObj.get_sql())
|
||||||
|
|
||||||
if sql_l:
|
if sql_l:
|
||||||
myDB = db.DBConnection()
|
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 />"
|
||||||
|
Loading…
Reference in New Issue
Block a user