Browse Source

Added Transaction for add/update/delete episodes and change episode status

tags/release_0.1.0
echel0n 11 years ago
parent
commit
972833a7f6
  1. 3
      sickbeard/providers/kat.py
  2. 36
      sickbeard/tv.py
  3. 7
      sickbeard/webserve.py

3
sickbeard/providers/kat.py

@ -21,7 +21,7 @@ from __future__ import with_statement
import sys import sys
import os import os
import traceback import traceback
import urllib, urllib2 import urllib
import re import re
import datetime import datetime
import urlparse import urlparse
@ -202,6 +202,7 @@ class KATProvider(generic.TorrentProvider):
else: else:
for show_name in set(allPossibleShowNames(ep_obj.show)): for show_name in set(allPossibleShowNames(ep_obj.show)):
ep_string = sanitizeSceneName(show_name) +' '+'season:'+str(ep_obj.season)+' episode:'+str(ep_obj.episode) ep_string = sanitizeSceneName(show_name) +' '+'season:'+str(ep_obj.season)+' episode:'+str(ep_obj.episode)
search_string['Episode'].append(re.sub('\s+', ' ', ep_string)) search_string['Episode'].append(re.sub('\s+', ' ', ep_string))
return [search_string] return [search_string]

36
sickbeard/tv.py

@ -419,6 +419,7 @@ class TVShow(object):
scannedEps = {} scannedEps = {}
sql_l = []
for season in showObj: for season in showObj:
scannedEps[season] = {} scannedEps[season] = {}
for episode in showObj[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) 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) ep.loadFromIndexer(season, episode, tvapi=t)
if ep.dirty: if ep.dirty:
ep.saveToDB() sql_l.append(ep.get_sql())
scannedEps[season][episode] = True scannedEps[season][episode] = True
if len(sql_l) > 0:
myDB = db.DBConnection()
myDB.mass_action(sql_l)
# Done updating save last update date # Done updating save last update date
self.last_update_indexer = datetime.date.today().toordinal() self.last_update_indexer = datetime.date.today().toordinal()
self.saveToDB() self.saveToDB()
@ -826,9 +831,12 @@ class TVShow(object):
def deleteShow(self): def deleteShow(self):
myDB = db.DBConnection() myDB = db.DBConnection()
myDB.action("DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid])
myDB.action("DELETE FROM tv_shows WHERE indexer_id = ?", [self.indexerid]) sql_l = [["DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid]],
myDB.action("DELETE FROM imdb_info WHERE indexer_id = ?", [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 # remove self from show list
sickbeard.showList = [x for x in sickbeard.showList if x.indexerid != self.indexerid] sickbeard.showList = [x for x in sickbeard.showList if x.indexerid != self.indexerid]
@ -1238,10 +1246,6 @@ class TVEpisode(object):
if result == False: if result == False:
raise exceptions.EpisodeNotFoundException("Couldn't find episode " + str(season) + "x" + str(episode)) 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): 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) 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() 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): def saveToDB(self, forceSave=False):
""" """
Saves this episode to the database if any of its data has been changed since the last save. Saves this episode to the database if any of its data has been changed since the last save.

7
sickbeard/webserve.py

@ -3080,6 +3080,7 @@ class Home:
if eps != None: if eps != None:
sql_l = []
for curEp in eps.split('|'): for curEp in eps.split('|'):
logger.log(u"Attempting to set status on episode " + curEp + " to " + status, logger.DEBUG) logger.log(u"Attempting to set status on episode " + curEp + " to " + status, logger.DEBUG)
@ -3116,7 +3117,11 @@ class Home:
continue continue
epObj.status = int(status) 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: if int(status) == WANTED:
msg = "Backlog was automatically started for the following seasons of <b>" + showObj.name + "</b>:<br /><ul>" msg = "Backlog was automatically started for the following seasons of <b>" + showObj.name + "</b>:<br /><ul>"

Loading…
Cancel
Save