diff --git a/sickbeard/processTV.py b/sickbeard/processTV.py
index fa3894dc..69840830 100644
--- a/sickbeard/processTV.py
+++ b/sickbeard/processTV.py
@@ -104,7 +104,7 @@ def processDir(dirName, nzbName=None, process_method=None, force=False, is_prior
#Don't Link media when the media is extracted from a rar in the same path
if process_method in ('hardlink', 'symlink') and videoInRar:
process_media(path, videoInRar, nzbName, 'move', force, is_priority, indexer)
- delete_files(path, rarContent)
+ delete_files(path, rarContent)
for video in set(videoFiles) - set(videoInRar):
process_media(path, [video], nzbName, process_method, force, is_priority, indexer)
else:
@@ -129,21 +129,21 @@ def processDir(dirName, nzbName=None, process_method=None, force=False, is_prior
if process_method in ('hardlink', 'symlink') and videoInRar:
process_media(processPath, videoInRar, nzbName, 'move', force, is_priority, indexer)
process_media(processPath, set(videoFiles) - set(videoInRar), nzbName, process_method, force, is_priority, indexer)
- delete_files(processPath, rarContent)
+ delete_files(processPath, rarContent)
else:
process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, indexer)
#Delete all file not needed
if process_method != "move" or not process_result \
- or type=="manual": #Avoid to delete files if is Manual PostProcessing
+ or type=="manual": #Avoid to delete files if is Manual PostProcessing
continue
-
+
delete_files(processPath, notwantedFiles)
-
+
if process_method == "move" and \
ek.ek(os.path.normpath, processPath) != ek.ek(os.path.normpath, sickbeard.TV_DOWNLOAD_DIR):
delete_dir(processPath)
-
+
return returnStr
def validateDir(path, dirName, nzbNameOriginal, failed):
@@ -182,7 +182,7 @@ def validateDir(path, dirName, nzbNameOriginal, failed):
videoFiles = filter(helpers.isMediaFile, allFiles)
allDirs.append(dirName)
-
+
#check if the dir have at least one tv video file
for video in videoFiles:
try:
@@ -237,8 +237,8 @@ def unRAR(path, rarFiles, force):
break
if skip_file:
- continue
-
+ continue
+
rar_handle.extract(path = path, withSubpath = False, overwrite = False)
unpacked_files += [os.path.basename(x.filename) for x in rar_handle.infolist() if not x.isdir]
del rar_handle
diff --git a/sickbeard/providers/kat.py b/sickbeard/providers/kat.py
index f2532384..3365b34c 100644
--- a/sickbeard/providers/kat.py
+++ b/sickbeard/providers/kat.py
@@ -21,7 +21,7 @@ from __future__ import with_statement
import sys
import os
import traceback
-import urllib, urllib2
+import urllib
import re
import datetime
import urlparse
@@ -202,6 +202,7 @@ class KATProvider(generic.TorrentProvider):
else:
for show_name in set(allPossibleShowNames(ep_obj.show)):
ep_string = sanitizeSceneName(show_name) +' '+'season:'+str(ep_obj.season)+' episode:'+str(ep_obj.episode)
+
search_string['Episode'].append(re.sub('\s+', ' ', ep_string))
return [search_string]
diff --git a/sickbeard/tv.py b/sickbeard/tv.py
index 972699dd..059700e4 100644
--- a/sickbeard/tv.py
+++ b/sickbeard/tv.py
@@ -419,6 +419,7 @@ class TVShow(object):
scannedEps = {}
+ sql_l = []
for season in showObj:
scannedEps[season] = {}
for episode in showObj[season]:
@@ -442,10 +443,14 @@ class TVShow(object):
logger.log(str(self.indexerid) + u": Loading info from " + self.indexer + " for episode " + str(season) + "x" + str(episode), logger.DEBUG)
ep.loadFromIndexer(season, episode, tvapi=t)
if ep.dirty:
- ep.saveToDB()
+ sql_l.append(ep.get_sql())
scannedEps[season][episode] = True
+ if len(sql_l) > 0:
+ myDB = db.DBConnection()
+ myDB.mass_action(sql_l)
+
# Done updating save last update date
self.last_update_indexer = datetime.date.today().toordinal()
self.saveToDB()
@@ -826,9 +831,12 @@ class TVShow(object):
def deleteShow(self):
myDB = db.DBConnection()
- myDB.action("DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid])
- myDB.action("DELETE FROM tv_shows WHERE indexer_id = ?", [self.indexerid])
- myDB.action("DELETE FROM imdb_info WHERE indexer_id = ?", [self.indexerid])
+
+ sql_l = [["DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid]],
+ ["DELETE FROM tv_shows WHERE indexer_id = ?", [self.indexerid]],
+ ["DELETE FROM imdb_info WHERE indexer_id = ?", [self.indexerid]]]
+
+ myDB.mass_action(sql_l)
# remove self from show list
sickbeard.showList = [x for x in sickbeard.showList if x.indexerid != self.indexerid]
@@ -1238,10 +1246,6 @@ class TVEpisode(object):
if result == False:
raise exceptions.EpisodeNotFoundException("Couldn't find episode " + str(season) + "x" + str(episode))
- # don't update if not needed
- if self.dirty:
- self.saveToDB()
-
def loadFromDB(self, season, episode):
logger.log(str(self.show.indexerid) + u": Loading episode details from DB for episode " + str(season) + "x" + str(episode), logger.DEBUG)
@@ -1546,6 +1550,22 @@ class TVEpisode(object):
raise exceptions.EpisodeDeletedException()
+ def get_sql(self, forceSave=False):
+ """
+ Creates SQL queue for this episode if any of its data has been changed since the last save.
+
+ forceSave: If True it will create SQL queue even if no data has been changed since the
+ last save (aka if the record is not dirty).
+ """
+
+ if not self.dirty and not forceSave:
+ logger.log(str(self.show.indexeridid) + u": Not creating SQL queue - record is not dirty", logger.DEBUG)
+ return
+
+ # 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) VALUES ((SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
+ [self.show.tvdbid, 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]]
+
def saveToDB(self, forceSave=False):
"""
Saves this episode to the database if any of its data has been changed since the last save.
diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py
index 001c108c..36af98e7 100644
--- a/sickbeard/webserve.py
+++ b/sickbeard/webserve.py
@@ -3080,6 +3080,7 @@ class Home:
if eps != None:
+ sql_l = []
for curEp in eps.split('|'):
logger.log(u"Attempting to set status on episode " + curEp + " to " + status, logger.DEBUG)
@@ -3116,8 +3117,12 @@ class Home:
continue
epObj.status = int(status)
- epObj.saveToDB()
-
+ sql_l.append(epObj.get_sql())
+
+ if len(sql_l) > 0:
+ myDB = db.DBConnection()
+ myDB.mass_action(sql_l)
+
if int(status) == WANTED:
msg = "Backlog was automatically started for the following seasons of " + showObj.name + ":