Merge pull request #275 from JackDandy/feature/FixSetWantedOnAdd

Fix to correctly use wanted_begin and wanted_latest when adding shows.
This commit is contained in:
JackDandy 2015-03-16 12:03:01 +00:00
commit dfa28d31fb
5 changed files with 44 additions and 32 deletions

View file

@ -51,7 +51,7 @@
* Fix being able to actually turn IMDb off when it has been turned on * Fix being able to actually turn IMDb off when it has been turned on
* Remove IMDb option from General Settings * Remove IMDb option from General Settings
* Change IMDb option to enable by default now the slow operation has been eliminated from process flows * Change IMDb option to enable by default now the slow operation has been eliminated from process flows
* Fix to correctly use wanted_begin and wanted_latest when adding shows
### 0.7.2 (2015-03-10 17:05:00 UTC) ### 0.7.2 (2015-03-10 17:05:00 UTC)

View file

@ -31,15 +31,15 @@
<div class="field-pair alt"> <div class="field-pair alt">
<span class="component-title">From season 1 forward, set</span> <span class="component-title">From season 1 forward, set</span>
<span class="component-desc"> <span class="component-desc">
<label for="wanted-begin" style="padding-bottom:10px"> <label for="wanted_begin" style="padding-bottom:10px">
<input type="number" name="wanted-begin" id="wanted-begin" value="$sickbeard.WANTED_BEGIN_DEFAULT" class="form-control input-sm input75"> <input type="number" name="wanted_begin" id="wanted_begin" value="$sickbeard.WANTED_BEGIN_DEFAULT" class="form-control input-sm input75">
<span>episodes as wanted (10 ... 0, and where -1 is whole first season)</span> <span>episodes as wanted (10 ... 0, and where -1 is whole first season)</span>
</label> </label>
</span> </span>
<span class="component-title">From latest going back, set</span> <span class="component-title">From latest going back, set</span>
<span class="component-desc"> <span class="component-desc">
<label for="wanted-latest"> <label for="wanted_latest">
<input type="number" name="wanted-latest" id="wanted-latest" value="$sickbeard.WANTED_LATEST_DEFAULT" class="form-control input-sm input75"> <input type="number" name="wanted_latest" id="wanted_latest" value="$sickbeard.WANTED_LATEST_DEFAULT" class="form-control input-sm input75">
<span>episodes as wanted (10 ... 0, and where -1 is whole latest season)</span> <span>episodes as wanted (10 ... 0, and where -1 is whole latest season)</span>
</label> </label>
</span> </span>

View file

@ -14,8 +14,8 @@ $(document).ready(function(){
default_status: $('#statusSelect').val(), default_status: $('#statusSelect').val(),
any_qualities: anyQualArray.join(','), any_qualities: anyQualArray.join(','),
best_qualities: bestQualArray.join(','), best_qualities: bestQualArray.join(','),
default_wanted_begin: $('#wanted-begin').val(), default_wanted_begin: $('#wanted_begin').val(),
default_wanted_latest: $('#wanted-latest').val(), default_wanted_latest: $('#wanted_latest').val(),
default_flatten_folders: $('#flatten_folders').prop('checked'), default_flatten_folders: $('#flatten_folders').prop('checked'),
default_scene: $('#scene').prop('checked'), default_scene: $('#scene').prop('checked'),
default_subtitles: $('#subtitles').prop('checked'), default_subtitles: $('#subtitles').prop('checked'),
@ -31,7 +31,7 @@ $(document).ready(function(){
$(this).attr('disabled', true); $(this).attr('disabled', true);
}); });
$('#statusSelect, #qualityPreset, #anyQualities, #bestQualities, #wanted-begin, #wanted-latest,' $('#statusSelect, #qualityPreset, #anyQualities, #bestQualities, #wanted_begin, #wanted_latest,'
+ ' #flatten_folders, #scene, #subtitles, #anime').change(function() { + ' #flatten_folders, #scene, #subtitles, #anime').change(function() {
$('#saveDefaultsButton').attr('disabled', false); $('#saveDefaultsButton').attr('disabled', false);
}); });

View file

@ -22,7 +22,7 @@ import traceback
import sickbeard import sickbeard
from sickbeard.common import SKIPPED, WANTED from sickbeard.common import SKIPPED, WANTED, UNAIRED
from sickbeard.tv import TVShow from sickbeard.tv import TVShow
from sickbeard import exceptions, logger, ui, db from sickbeard import exceptions, logger, ui, db
from sickbeard import generic_queue from sickbeard import generic_queue
@ -133,10 +133,10 @@ class ShowQueue(generic_queue.GenericQueue):
def addShow(self, indexer, indexer_id, showDir, default_status=None, quality=None, flatten_folders=None, def addShow(self, indexer, indexer_id, showDir, default_status=None, quality=None, flatten_folders=None,
lang="en", subtitles=None, anime=None, scene=None, paused=None, blacklist=None, whitelist=None, lang="en", subtitles=None, anime=None, scene=None, paused=None, blacklist=None, whitelist=None,
default_wanted_begin=None, default_wanted_latest=None): wanted_begin=None, wanted_latest=None):
queueItemObj = QueueItemAdd(indexer, indexer_id, showDir, default_status, quality, flatten_folders, lang, queueItemObj = QueueItemAdd(indexer, indexer_id, showDir, default_status, quality, flatten_folders, lang,
subtitles, anime, scene, paused, blacklist, whitelist, subtitles, anime, scene, paused, blacklist, whitelist,
default_wanted_begin, default_wanted_latest) wanted_begin, wanted_latest)
self.add_item(queueItemObj) self.add_item(queueItemObj)
@ -370,33 +370,47 @@ class QueueItemAdd(ShowQueueItem):
logger.log(traceback.format_exc(), logger.DEBUG) logger.log(traceback.format_exc(), logger.DEBUG)
# if they gave a custom status then change all the eps to it # if they gave a custom status then change all the eps to it
my_db = db.DBConnection()
if self.default_status != SKIPPED: if self.default_status != SKIPPED:
logger.log(u"Setting all episodes to the specified default status: " + str(self.default_status)) logger.log(u"Setting all episodes to the specified default status: " + str(self.default_status))
myDB = db.DBConnection() my_db.action("UPDATE tv_episodes SET status = ? WHERE status = ? AND showid = ? AND season != 0",
myDB.action("UPDATE tv_episodes SET status = ? WHERE status = ? AND showid = ? AND season != 0",
[self.default_status, SKIPPED, self.show.indexerid]) [self.default_status, SKIPPED, self.show.indexerid])
# if they gave a number to start or number to end as wanted, then change those eps to it # if they gave a number to start or number to end as wanted, then change those eps to it
def get_wanted_sql(wanted_max, sql_vars): def get_wanted(db_obj, wanted_max, latest):
actual = 0 actual = 0
if wanted_max: if wanted_max:
my_db = db.DBConnection() select_id = 'FROM [tv_episodes] t5 JOIN (SELECT t3.indexerid, t3.status, t3.season*1000000+t3.episode AS t3_se, t2.start_season FROM [tv_episodes] t3'\
sql = "UPDATE `tv_episodes` SET status=%s" % WANTED\ + ' JOIN (SELECT t1.showid, M%s(t1.season) AS start_season' % ('IN', 'AX')[latest]\
+ " WHERE indexerid IN "\ + ', MAX(t1.airdate) AS airdate, t1.episode, t1.season*1000000+t1.episode AS se FROM [tv_episodes] t1'\
+ "(SELECT t1.indexerid FROM `tv_episodes` t1 JOIN "\ + ' WHERE %s=t1.showid' % self.show.indexerid\
+ "(SELECT %s(season),showid,season FROM `tv_episodes` WHERE '%s'=showid" % (sql_vars[0], self.show.indexerid)\ + ' AND 0<t1.season AND t1.status NOT IN (%s)) AS t2' % UNAIRED\
+ " AND '0'<season ORDER BY season,episode) AS t2 ON t2.showid=t1.showid AND t2.season = t1.season"\ + ' ON t2.showid=t3.showid AND 0<t3.season AND t2.se>=t3_se ORDER BY t3_se %sSC' % ('A', 'DE')[latest]\
+ " ORDER BY episode %s%s)" % (sql_vars[1], (' LIMIT %s' % wanted_max, '')[-1 == wanted_max])\ + ' %s) as t4' % (' LIMIT %s' % wanted_max, '')[-1 == wanted_max]\
+ ' AND status NOT IN (%s)' % ','.join([str(x) for x in sickbeard.common.Quality.DOWNLOADED + [sickbeard.common.UNAIRED]]) + ' ON t4.indexerid=t5.indexerid'\
my_db.action(sql) + '%s' % ('', ' AND t4.start_season=t5.season')[-1 == wanted_max]\
result = my_db.select("SELECT changes() as last FROM `tv_episodes`") + ' AND t4.status NOT IN (%s)' % ','.join([str(x) for x in sickbeard.common.Quality.DOWNLOADED + [WANTED]])
select = 'SELECT t5.indexerid as indexerid, t5.season as season, t5.episode as episode, t5.status as status ' + select_id
update = 'UPDATE [tv_episodes] SET status=%s WHERE indexerid IN (SELECT t5.indexerid %s)' % (WANTED, select_id)
wanted_updates = db_obj.select(select)
db_obj.action(update)
result = db_obj.select("SELECT changes() as last FROM [tv_episodes]")
for cur_result in result: for cur_result in result:
actual = cur_result['last'] actual = cur_result['last']
break break
action_log = 'didn\'t find any episodes that need to be set wanted'
if actual:
action_log = ('updated %s %s episodes > %s'
% ((((('%s of %s' % (actual, wanted_max)), ('%s of max %s limited' % (actual, wanted_max)))[10 == wanted_max]), ('max %s available' % actual))[-1 == wanted_max],
('first season', 'latest')[latest],
','.join([('S%02dE%02d=%d' % (a['season'], a['episode'], a['status'])) for a in wanted_updates])))
logger.log('Get wanted ' + action_log)
return actual return actual
items_wanted = get_wanted_sql(self.default_wanted_begin, ['MIN', 'ASC']) items_wanted = get_wanted(my_db, self.default_wanted_begin, latest=False)
items_wanted += get_wanted_sql(self.default_wanted_latest, ['MAX', 'DESC']) items_wanted += get_wanted(my_db, self.default_wanted_latest, latest=True)
msg = ' the specified show into ' + self.showDir msg = ' the specified show into ' + self.showDir
# if started with WANTED eps then run the backlog # if started with WANTED eps then run the backlog

View file

@ -2254,7 +2254,7 @@ class NewHomeAddShows(Home):
def addNewShow(self, whichSeries=None, indexerLang='en', rootDir=None, defaultStatus=None, def addNewShow(self, whichSeries=None, indexerLang='en', rootDir=None, defaultStatus=None,
anyQualities=None, bestQualities=None, flatten_folders=None, subtitles=None, anyQualities=None, bestQualities=None, flatten_folders=None, subtitles=None,
fullShowPath=None, other_shows=None, skipShow=None, providedIndexer=None, anime=None, fullShowPath=None, other_shows=None, skipShow=None, providedIndexer=None, anime=None,
scene=None, blacklist=None, whitelist=None, default_wanted_begin=None, default_wanted_latest=None): scene=None, blacklist=None, whitelist=None, wanted_begin=None, wanted_latest=None):
""" """
Receive tvdb id, dir, and other options and create a show from them. If extra show dirs are Receive tvdb id, dir, and other options and create a show from them. If extra show dirs are
provided then it forwards back to newShow, if not it goes to /home. provided then it forwards back to newShow, if not it goes to /home.
@ -2353,14 +2353,14 @@ class NewHomeAddShows(Home):
bestQualities = [bestQualities] bestQualities = [bestQualities]
newQuality = Quality.combineQualities(map(int, anyQualities), map(int, bestQualities)) newQuality = Quality.combineQualities(map(int, anyQualities), map(int, bestQualities))
default_wanted_begin = config.minimax(default_wanted_begin, 0, -1, 10) wanted_begin = config.minimax(wanted_begin, 0, -1, 10)
default_wanted_latest = config.minimax(default_wanted_latest, 0, -1, 10) wanted_latest = config.minimax(wanted_latest, 0, -1, 10)
# add the show # add the show
sickbeard.showQueueScheduler.action.addShow(indexer, indexer_id, show_dir, int(defaultStatus), newQuality, sickbeard.showQueueScheduler.action.addShow(indexer, indexer_id, show_dir, int(defaultStatus), newQuality,
flatten_folders, indexerLang, subtitles, anime, flatten_folders, indexerLang, subtitles, anime,
scene, None, blacklist, whitelist, scene, None, blacklist, whitelist,
default_wanted_begin, default_wanted_latest) # @UndefinedVariable wanted_begin, wanted_latest) # @UndefinedVariable
# ui.notifications.message('Show added', 'Adding the specified show into ' + show_dir) # ui.notifications.message('Show added', 'Adding the specified show into ' + show_dir)
return finishAddShow() return finishAddShow()
@ -2428,8 +2428,6 @@ class NewHomeAddShows(Home):
# add the show # add the show
sickbeard.showQueueScheduler.action.addShow(indexer, indexer_id, show_dir, sickbeard.showQueueScheduler.action.addShow(indexer, indexer_id, show_dir,
default_status=sickbeard.STATUS_DEFAULT, default_status=sickbeard.STATUS_DEFAULT,
default_wanted_begin=sickbeard.WANTED_BEGIN_DEFAULT,
default_wanted_latest=sickbeard.WANTED_LATEST_DEFAULT,
quality=sickbeard.QUALITY_DEFAULT, quality=sickbeard.QUALITY_DEFAULT,
flatten_folders=sickbeard.FLATTEN_FOLDERS_DEFAULT, flatten_folders=sickbeard.FLATTEN_FOLDERS_DEFAULT,
subtitles=sickbeard.SUBTITLES_DEFAULT, subtitles=sickbeard.SUBTITLES_DEFAULT,