mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Fixed issues with scene numbering being overwritten by ep objects.
Converted more object saves to database to use transactionals, better performance.
This commit is contained in:
parent
05cca0dfe0
commit
70e7f1bfce
10 changed files with 93 additions and 44 deletions
|
@ -47,6 +47,7 @@ class DailySearcher():
|
|||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE status in (?,?) AND airdate >= ? AND airdate <= ?",
|
||||
[common.UNAIRED, common.WANTED, fromDate.toordinal(), curDate.toordinal()])
|
||||
|
||||
sql_l = []
|
||||
todaysEps = {}
|
||||
for sqlEp in sqlResults:
|
||||
|
||||
|
@ -70,7 +71,7 @@ class DailySearcher():
|
|||
logger.log(u"New episode " + ep.prettyName() + " airs today, setting status to WANTED")
|
||||
ep.status = common.WANTED
|
||||
|
||||
ep.saveToDB()
|
||||
sql_l.append(ep.get_sql())
|
||||
|
||||
if ep.status == common.WANTED:
|
||||
if show not in todaysEps:
|
||||
|
@ -78,6 +79,12 @@ class DailySearcher():
|
|||
else:
|
||||
todaysEps[show].append(ep)
|
||||
|
||||
sql_l.append(ep.get_sql())
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
if len(todaysEps):
|
||||
for show in todaysEps:
|
||||
segment = todaysEps[show]
|
||||
|
|
|
@ -129,7 +129,6 @@ def revertEpisode(epObj):
|
|||
logger.log(u"WARNING: Episode not found in history. Setting it back to WANTED",
|
||||
logger.WARNING)
|
||||
epObj.status = WANTED
|
||||
|
||||
epObj.saveToDB()
|
||||
|
||||
except EpisodeNotFoundException, e:
|
||||
|
|
|
@ -63,9 +63,9 @@ class TVEpisode(tv.TVEpisode):
|
|||
self._season = season
|
||||
self._episode = episode
|
||||
self._absolute_number = absolute_number
|
||||
self._scene_season = season
|
||||
self._scene_episode = episode
|
||||
self._scene_absolute_number = absolute_number
|
||||
self.scene_season = season
|
||||
self.scene_episode = episode
|
||||
self.scene_absolute_number = absolute_number
|
||||
self._airdate = datetime.date(2010, 3, 9)
|
||||
self.show = TVShow()
|
||||
self._status = Quality.compositeStatus(common.DOWNLOADED, common.Quality.SDTV)
|
||||
|
|
|
@ -915,6 +915,7 @@ class PostProcessor(object):
|
|||
ep_obj.show.writeMetadata(True)
|
||||
|
||||
# update the ep info before we rename so the quality & release name go into the name properly
|
||||
sql_l = []
|
||||
for cur_ep in [ep_obj] + ep_obj.relatedEps:
|
||||
with cur_ep.lock:
|
||||
cur_release_name = None
|
||||
|
@ -951,7 +952,7 @@ class PostProcessor(object):
|
|||
|
||||
cur_ep.is_proper = self.is_proper
|
||||
|
||||
cur_ep.saveToDB()
|
||||
sql_l.append(cur_ep.get_sql())
|
||||
|
||||
# Just want to keep this consistent for failed handling right now
|
||||
releaseName = show_name_helpers.determineReleaseName(self.folder_path, self.nzb_name)
|
||||
|
@ -960,10 +961,13 @@ class PostProcessor(object):
|
|||
else:
|
||||
self._log(u"Couldn't find release in snatch history", logger.WARNING)
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# find the destination folder
|
||||
try:
|
||||
proper_path = ep_obj.proper_path()
|
||||
test = proper_path
|
||||
proper_absolute_path = ek.ek(os.path.join, ep_obj.show.location, proper_path)
|
||||
|
||||
dest_path = ek.ek(os.path.dirname, proper_absolute_path)
|
||||
|
@ -1019,24 +1023,31 @@ class PostProcessor(object):
|
|||
cur_ep.downloadSubtitles(force=True)
|
||||
|
||||
# put the new location in the database
|
||||
sql_l = []
|
||||
for cur_ep in [ep_obj] + ep_obj.relatedEps:
|
||||
with cur_ep.lock:
|
||||
cur_ep.location = ek.ek(os.path.join, dest_path, new_file_name)
|
||||
cur_ep.saveToDB()
|
||||
|
||||
sql_l.append(cur_ep.get_sql())
|
||||
|
||||
# set file modify stamp to show airdate
|
||||
if sickbeard.AIRDATE_EPISODES:
|
||||
ep_obj.show.airdateModifyStamp(cur_ep)
|
||||
|
||||
# generate nfo/tbn
|
||||
ep_obj.createMetaFiles()
|
||||
sql_l.append(ep_obj.get_sql())
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# log it to history
|
||||
history.logDownload(ep_obj, self.file_path, new_ep_quality, self.release_group)
|
||||
|
||||
# send notifications
|
||||
notifiers.notify_download(ep_obj._format_pattern('%SN - %Sx%0E - %EN - %QN'))
|
||||
|
||||
# generate nfo/tbn
|
||||
ep_obj.createMetaFiles()
|
||||
ep_obj.saveToDB()
|
||||
|
||||
# do the library update for XBMC
|
||||
notifiers.xbmc_notifier.update_library(ep_obj.show.name)
|
||||
|
||||
|
|
|
@ -161,17 +161,23 @@ def snatchEpisode(result, endStatus=SNATCHED):
|
|||
history.logSnatch(result)
|
||||
|
||||
# don't notify when we re-download an episode
|
||||
sql_l = []
|
||||
for curEpObj in result.episodes:
|
||||
with curEpObj.lock:
|
||||
if isFirstBestMatch(result):
|
||||
curEpObj.status = Quality.compositeStatus(SNATCHED_BEST, result.quality)
|
||||
else:
|
||||
curEpObj.status = Quality.compositeStatus(endStatus, result.quality)
|
||||
curEpObj.saveToDB()
|
||||
|
||||
sql_l.append(curEpObj.get_sql())
|
||||
|
||||
if curEpObj.status not in Quality.DOWNLOADED:
|
||||
notifiers.notify_snatch(curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN'))
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ class QueueItemAdd(ShowQueueItem):
|
|||
self.show.subtitles = self.subtitles if self.subtitles != None else sickbeard.SUBTITLES_DEFAULT
|
||||
self.show.quality = self.quality if self.quality else sickbeard.QUALITY_DEFAULT
|
||||
self.show.flatten_folders = self.flatten_folders if self.flatten_folders != None else sickbeard.FLATTEN_FOLDERS_DEFAULT
|
||||
#self.show.anime = self.anime if self.anime != None else sickbeard.ANIME_DEFAULT
|
||||
self.show.anime = self.anime if self.anime != None else sickbeard.ANIME_DEFAULT
|
||||
self.show.paused = False
|
||||
|
||||
# be smartish about this
|
||||
|
@ -294,10 +294,8 @@ class QueueItemAdd(ShowQueueItem):
|
|||
self.show.air_by_date = 0
|
||||
if self.show.classification and "sports" in self.show.classification.lower():
|
||||
self.show.sports = 1
|
||||
if self.show.genre and "animation" in self.show.genre.lower():
|
||||
self.show.anime = 1
|
||||
if sickbeard.scene_numbering.get_xem_numbering_for_show(self.show.indexerid, self.show.indexer):
|
||||
self.show.scene = 1
|
||||
#if self.show.genre and "animation" in self.show.genre.lower():
|
||||
# self.show.anime = 1
|
||||
|
||||
except sickbeard.indexer_exception, e:
|
||||
logger.log(
|
||||
|
@ -386,6 +384,10 @@ class QueueItemAdd(ShowQueueItem):
|
|||
# Load XEM data to DB for show
|
||||
sickbeard.scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer, force=True)
|
||||
|
||||
# check if show has XEM mapping so we can determin if searches should go by scene numbering or indexer numbering.
|
||||
if sickbeard.scene_numbering.get_xem_numbering_for_show(self.show.indexerid, self.show.indexer):
|
||||
self.show.scene = 1
|
||||
|
||||
self.finish()
|
||||
|
||||
def _finishEarly(self):
|
||||
|
|
|
@ -23,6 +23,7 @@ from sickbeard import encodingKludge as ek
|
|||
from sickbeard import logger
|
||||
from sickbeard import helpers
|
||||
from sickbeard import search_queue
|
||||
from sickbeard import db
|
||||
from sickbeard.common import SNATCHED, SNATCHED_PROPER, DOWNLOADED, SKIPPED, UNAIRED, IGNORED, ARCHIVED, WANTED, UNKNOWN
|
||||
from lib.trakt import *
|
||||
|
||||
|
@ -125,6 +126,7 @@ class TraktChecker():
|
|||
|
||||
epObj.status = WANTED
|
||||
epObj.saveToDB()
|
||||
|
||||
backlog = (show, ep_segment)
|
||||
if self.todoBacklog.count(backlog) == 0:
|
||||
self.todoBacklog.append(backlog)
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import with_statement
|
||||
import json
|
||||
|
||||
import os.path
|
||||
import datetime
|
||||
|
@ -25,7 +24,6 @@ import threading
|
|||
import re
|
||||
import glob
|
||||
import traceback
|
||||
import requests
|
||||
|
||||
import sickbeard
|
||||
|
||||
|
@ -378,6 +376,7 @@ class TVShow(object):
|
|||
mediaFiles = helpers.listMediaFiles(self._location)
|
||||
|
||||
# create TVEpisodes from each media file (if possible)
|
||||
sql_l = []
|
||||
for mediaFile in mediaFiles:
|
||||
parse_result = None
|
||||
curEpisode = None
|
||||
|
@ -419,7 +418,12 @@ class TVShow(object):
|
|||
except:
|
||||
logger.log(str(self.indexerid) + ": Could not refresh subtitles", logger.ERROR)
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
curEpisode.saveToDB()
|
||||
|
||||
sql_l.append(curEpisode.get_sql())
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
def loadEpisodesFromDB(self):
|
||||
|
||||
|
@ -533,8 +537,8 @@ class TVShow(object):
|
|||
logger.log(str(self.indexerid) + u": Loading info from " + sickbeard.indexerApi(
|
||||
self.indexer).name + " for episode " + str(season) + "x" + str(episode), logger.DEBUG)
|
||||
ep.loadFromIndexer(season, episode, tvapi=t)
|
||||
if ep.dirty:
|
||||
sql_l.append(ep.get_sql())
|
||||
|
||||
sql_l.append(ep.get_sql())
|
||||
|
||||
scannedEps[season][episode] = True
|
||||
|
||||
|
@ -612,6 +616,7 @@ class TVShow(object):
|
|||
parse_result.air_date) + " for show " + self.name + ", skipping", logger.WARNING)
|
||||
return None
|
||||
|
||||
sql_l = []
|
||||
for curEpNum in episodes:
|
||||
|
||||
episode = int(curEpNum)
|
||||
|
@ -705,7 +710,11 @@ class TVShow(object):
|
|||
curEp.status = Quality.compositeStatus(newStatus, newQuality)
|
||||
|
||||
with curEp.lock:
|
||||
curEp.saveToDB()
|
||||
sql_l.append(curEp.get_sql())
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# creating metafiles on the root should be good enough
|
||||
if sickbeard.USE_FAILED_DOWNLOADS and rootEp is not None:
|
||||
|
@ -990,6 +999,7 @@ class TVShow(object):
|
|||
myDB = db.DBConnection()
|
||||
sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND location != ''", [self.indexerid])
|
||||
|
||||
sql_l = []
|
||||
for ep in sqlResults:
|
||||
curLoc = os.path.normpath(ep["location"])
|
||||
season = int(ep["season"])
|
||||
|
@ -1022,12 +1032,17 @@ class TVShow(object):
|
|||
curEp.hasnfo = False
|
||||
curEp.hastbn = False
|
||||
curEp.release_name = ''
|
||||
curEp.saveToDB()
|
||||
|
||||
sql_l.append(curEp.get_sql())
|
||||
else:
|
||||
# the file exists, set its modify file stamp
|
||||
if sickbeard.AIRDATE_EPISODES:
|
||||
self.airdateModifyStamp(curEp)
|
||||
|
||||
if len(sql_l):
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
def airdateModifyStamp(self, ep_obj):
|
||||
"""
|
||||
Make the modify date and time of a file reflect the show air date and time.
|
||||
|
@ -1261,9 +1276,6 @@ class TVEpisode(object):
|
|||
self._season = season
|
||||
self._episode = episode
|
||||
self._absolute_number = 0
|
||||
self._scene_season = 0
|
||||
self._scene_episode = 0
|
||||
self._scene_absolute_number = 0
|
||||
self._description = ""
|
||||
self._subtitles = list()
|
||||
self._subtitles_searchcount = 0
|
||||
|
@ -1282,6 +1294,10 @@ class TVEpisode(object):
|
|||
|
||||
self.show = show
|
||||
|
||||
self.scene_season = 0
|
||||
self.scene_episode = 0
|
||||
self.scene_absolute_number = 0
|
||||
|
||||
self._location = file
|
||||
|
||||
self._indexer = int(self.show.indexer)
|
||||
|
@ -1298,9 +1314,6 @@ class TVEpisode(object):
|
|||
season = property(lambda self: self._season, dirty_setter("_season"))
|
||||
episode = property(lambda self: self._episode, dirty_setter("_episode"))
|
||||
absolute_number = property(lambda self: self._absolute_number, dirty_setter("_absolute_number"))
|
||||
scene_season = property(lambda self: self._scene_season, dirty_setter("_scene_season"))
|
||||
scene_episode = property(lambda self: self._scene_episode, dirty_setter("_scene_episode"))
|
||||
scene_absolute_number = property(lambda self: self._scene_absolute_number, dirty_setter("_scene_absolute_number"))
|
||||
description = property(lambda self: self._description, dirty_setter("_description"))
|
||||
subtitles = property(lambda self: self._subtitles, dirty_setter("_subtitles"))
|
||||
subtitles_searchcount = property(lambda self: self._subtitles_searchcount, dirty_setter("_subtitles_searchcount"))
|
||||
|
@ -1827,13 +1840,12 @@ class TVEpisode(object):
|
|||
|
||||
# use a custom update/insert method to get the data into the DB
|
||||
return [
|
||||
"INSERT OR REPLACE INTO tv_episodes (episode_id, indexerid, indexer, name, description, subtitles, subtitles_searchcount, subtitles_lastsearch, airdate, hasnfo, hastbn, status, location, file_size, release_name, is_proper, showid, season, episode, scene_season, scene_episode, absolute_number, scene_absolute_number) VALUES "
|
||||
"((SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
|
||||
"INSERT OR REPLACE INTO tv_episodes (episode_id, indexerid, indexer, name, description, subtitles, subtitles_searchcount, subtitles_lastsearch, airdate, hasnfo, hastbn, status, location, file_size, release_name, is_proper, showid, season, episode, absolute_number) VALUES "
|
||||
"((SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
|
||||
[self.show.indexerid, self.season, self.episode, self.indexerid, self.indexer, self.name, self.description,
|
||||
",".join([sub for sub in self.subtitles]), self.subtitles_searchcount, self.subtitles_lastsearch,
|
||||
self.airdate.toordinal(), self.hasnfo, self.hastbn, self.status, self.location, self.file_size,
|
||||
self.release_name, self.is_proper, self.show.indexerid, self.season, self.episode, self.scene_season,
|
||||
self.scene_episode, self.absolute_number, self.scene_absolute_number]]
|
||||
self.release_name, self.is_proper, self.show.indexerid, self.season, self.episode, self.absolute_number]]
|
||||
|
||||
def saveToDB(self, forceSave=False):
|
||||
"""
|
||||
|
@ -1868,10 +1880,7 @@ class TVEpisode(object):
|
|||
"file_size": self.file_size,
|
||||
"release_name": self.release_name,
|
||||
"is_proper": self.is_proper,
|
||||
"scene_season": self.scene_season,
|
||||
"scene_episode": self.scene_episode,
|
||||
"absolute_number": self.absolute_number,
|
||||
"scene_absolute_number": self.scene_absolute_number
|
||||
"absolute_number": self.absolute_number
|
||||
}
|
||||
controlValueDict = {"showid": self.show.indexerid,
|
||||
"season": self.season,
|
||||
|
@ -2277,6 +2286,7 @@ class TVEpisode(object):
|
|||
logger.log(str(self.indexerid) + u": Unable to rename file " + cur_related_file, logger.ERROR)
|
||||
|
||||
for cur_related_sub in related_subs:
|
||||
absolute_proper_subs_path = ek.ek(os.path.join, sickbeard.SUBTITLES_DIR, self.formatted_filename())
|
||||
cur_result = helpers.rename_ep_file(cur_related_sub, absolute_proper_subs_path,
|
||||
absolute_current_path_no_ext_length)
|
||||
if not cur_result:
|
||||
|
@ -2294,7 +2304,14 @@ class TVEpisode(object):
|
|||
curEp.checkForMetaFiles()
|
||||
|
||||
# save any changes to the database
|
||||
|
||||
sql_l = []
|
||||
with self.lock:
|
||||
self.saveToDB()
|
||||
sql_l.append(self.get_sql())
|
||||
|
||||
for relEp in self.relatedEps:
|
||||
relEp.saveToDB()
|
||||
sql_l.append(relEp.get_sql())
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
|
|
@ -978,6 +978,8 @@ class CMD_EpisodeSetStatus(ApiCall):
|
|||
failure = False
|
||||
start_backlog = False
|
||||
ep_segment = None
|
||||
|
||||
sql_l = []
|
||||
for epObj in ep_list:
|
||||
if ep_segment == None and self.status == WANTED:
|
||||
# figure out what segment the episode is in and remember it so we can backlog it
|
||||
|
@ -1003,12 +1005,16 @@ class CMD_EpisodeSetStatus(ApiCall):
|
|||
continue
|
||||
|
||||
epObj.status = self.status
|
||||
epObj.saveToDB()
|
||||
sql_l.append(epObj.get_sql())
|
||||
|
||||
if self.status == WANTED:
|
||||
start_backlog = True
|
||||
ep_results.append(_epResult(RESULT_SUCCESS, epObj))
|
||||
|
||||
if len(sql_l):
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
extra_msg = ""
|
||||
if start_backlog:
|
||||
cur_backlog_queue_item = search_queue.BacklogQueueItem(showObj, ep_segment)
|
||||
|
|
|
@ -3526,8 +3526,7 @@ class Home:
|
|||
epObj.status = int(status)
|
||||
|
||||
# mass add to database
|
||||
if epObj.dirty:
|
||||
sql_l.append(epObj.get_sql())
|
||||
sql_l.append(epObj.get_sql())
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
|
|
Loading…
Reference in a new issue