2014-04-22 08:02:43 +00:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
|
|
|
# Created on Sep 20, 2012
|
|
|
|
# @author: Dermot Buckley <dermot@buckley.ie>
|
|
|
|
# @copyright: Dermot Buckley
|
|
|
|
#
|
|
|
|
|
2014-07-27 10:59:21 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
import time
|
2014-07-27 10:59:21 +00:00
|
|
|
import datetime
|
2014-03-10 05:18:05 +00:00
|
|
|
import traceback
|
2014-05-28 21:13:29 +00:00
|
|
|
import sickbeard
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard import db
|
|
|
|
from sickbeard.exceptions import ex
|
2018-09-07 16:23:19 +00:00
|
|
|
from sickbeard.helpers import tryInt
|
2015-12-06 11:36:45 +00:00
|
|
|
from sickbeard.scene_exceptions import xem_ids_list
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
def get_scene_numbering(indexer_id, indexer, season, episode, fallback_to_xem=True):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
|
|
|
Returns a tuple, (season, episode), with the scene numbering (if there is one),
|
2015-12-06 11:36:45 +00:00
|
|
|
otherwise returns the xem numbering (if fallback_to_xem is set), otherwise
|
2018-09-07 16:23:19 +00:00
|
|
|
returns the TVDB numbering.
|
2014-03-10 05:18:05 +00:00
|
|
|
(so the return values will always be set)
|
2015-12-06 11:36:45 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
@param indexer_id: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param indexer: int
|
2014-03-10 05:18:05 +00:00
|
|
|
@param season: int
|
|
|
|
@param episode: int
|
|
|
|
@param fallback_to_xem: bool If set (the default), check xem for matches if there is no local scene numbering
|
2015-12-06 11:36:45 +00:00
|
|
|
@return: (int, int) a tuple with (season, episode)
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2015-07-25 09:19:46 +00:00
|
|
|
if None is indexer_id or None is season or None is episode:
|
|
|
|
return season, episode
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
show_obj = sickbeard.helpers.findCertainShow(sickbeard.showList, int(indexer_id))
|
|
|
|
if show_obj and not show_obj.is_scene:
|
|
|
|
return season, episode
|
2014-05-03 09:58:04 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
result = find_scene_numbering(int(indexer_id), int(indexer), season, episode)
|
2014-03-10 05:18:05 +00:00
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
if fallback_to_xem:
|
2014-05-30 05:48:02 +00:00
|
|
|
xem_result = find_xem_numbering(int(indexer_id), int(indexer), season, episode)
|
2014-03-10 05:18:05 +00:00
|
|
|
if xem_result:
|
|
|
|
return xem_result
|
2015-07-25 09:19:46 +00:00
|
|
|
return season, episode
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
def find_scene_numbering(indexer_id, indexer, season, episode):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
|
|
|
Same as get_scene_numbering(), but returns None if scene numbering is not set
|
|
|
|
"""
|
2015-07-25 09:19:46 +00:00
|
|
|
if None is indexer_id or None is season or None is episode:
|
2018-09-07 16:23:19 +00:00
|
|
|
return
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT scene_season, scene_episode'
|
|
|
|
' FROM scene_numbering'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND season = ? AND episode = ? AND (scene_season OR scene_episode) != 0',
|
2014-06-21 22:46:59 +00:00
|
|
|
[indexer, indexer_id, season, episode])
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['scene_season']), int(rows[0]['scene_episode'])
|
2014-03-21 08:34:00 +00:00
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2018-09-05 14:15:08 +00:00
|
|
|
def get_scene_absolute_numbering(indexer_id, indexer, absolute_number, season, episode, fallback_to_xem=True):
|
2014-05-30 05:48:02 +00:00
|
|
|
"""
|
|
|
|
Returns a tuple, (season, episode), with the scene numbering (if there is one),
|
|
|
|
otherwise returns the xem numbering (if fallback_to_xem is set), otherwise
|
2018-09-07 16:23:19 +00:00
|
|
|
returns the TVDB numbering.
|
2014-05-30 05:48:02 +00:00
|
|
|
(so the return values will always be set)
|
|
|
|
|
|
|
|
@param indexer_id: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param indexer: int
|
2014-06-07 12:36:50 +00:00
|
|
|
@param absolute_number: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param season: int
|
|
|
|
@param episode: int
|
2014-05-30 05:48:02 +00:00
|
|
|
@param fallback_to_xem: bool If set (the default), check xem for matches if there is no local scene numbering
|
|
|
|
@return: (int, int) a tuple with (season, episode)
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
has_sxe = None is not season and None is not episode
|
|
|
|
if None is indexer_id or (None is absolute_number and not has_sxe):
|
2014-05-30 05:48:02 +00:00
|
|
|
return absolute_number
|
|
|
|
|
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
show_obj = sickbeard.helpers.findCertainShow(sickbeard.showList, indexer_id)
|
2018-09-07 16:23:19 +00:00
|
|
|
if show_obj and not show_obj.is_scene and not has_sxe:
|
2014-05-30 05:48:02 +00:00
|
|
|
return absolute_number
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
result = find_scene_absolute_numbering(indexer_id, indexer, absolute_number, season, episode)
|
2014-05-30 05:48:02 +00:00
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
if fallback_to_xem:
|
2018-09-05 14:15:08 +00:00
|
|
|
xem_result = find_xem_absolute_numbering(indexer_id, indexer, absolute_number, season, episode)
|
2014-05-30 05:48:02 +00:00
|
|
|
if xem_result:
|
|
|
|
return xem_result
|
|
|
|
return absolute_number
|
|
|
|
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def find_scene_absolute_numbering(indexer_id, indexer, absolute_number, season=None, episode=None):
|
2014-05-30 05:48:02 +00:00
|
|
|
"""
|
|
|
|
Same as get_scene_numbering(), but returns None if scene numbering is not set
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
has_sxe = None is not season and None is not episode
|
|
|
|
if None is indexer_id or (None is absolute_number and not has_sxe):
|
|
|
|
return
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
2018-09-07 16:23:19 +00:00
|
|
|
sql_vars, cond = (([absolute_number], 'and absolute_number = ?'),
|
|
|
|
([season, episode], 'and season = ? AND episode = ?'))[has_sxe]
|
2015-07-25 09:19:46 +00:00
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT scene_absolute_number'
|
|
|
|
' FROM scene_numbering'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? %s AND scene_absolute_number != 0' % cond,
|
|
|
|
[indexer, indexer_id] + sql_vars)
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['scene_absolute_number'])
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def get_indexer_numbering(indexer_id, indexer, scene_season, scene_episode, fallback_to_xem=True):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
Returns a tuple, (season, episode) with the TVDB numbering for (sceneSeason, sceneEpisode)
|
2014-03-10 05:18:05 +00:00
|
|
|
(this works like the reverse of get_scene_numbering)
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
if None is indexer_id or None is scene_season or None is scene_episode:
|
|
|
|
return scene_season, scene_episode
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT season, episode'
|
|
|
|
' FROM scene_numbering'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND scene_season = ? AND scene_episode = ?',
|
|
|
|
[indexer, indexer_id, scene_season, scene_episode])
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['season']), int(rows[0]['episode'])
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
|
|
|
if fallback_to_xem:
|
2018-09-07 16:23:19 +00:00
|
|
|
return get_indexer_numbering_for_xem(indexer_id, indexer, scene_season, scene_episode)
|
|
|
|
return scene_season, scene_episode
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def get_indexer_absolute_numbering(indexer_id, indexer, scene_absolute_number, fallback_to_xem=True, scene_season=None):
|
2014-05-28 21:13:29 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
Returns a tuple, (season, episode, absolute_number) with the TVDB numbering for (sceneAbsoluteNumber)
|
2014-05-28 21:13:29 +00:00
|
|
|
(this works like the reverse of get_absolute_numbering)
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
if None is indexer_id or None is scene_absolute_number:
|
|
|
|
return scene_absolute_number
|
2014-05-28 21:13:29 +00:00
|
|
|
|
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
if None is scene_season:
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT absolute_number'
|
|
|
|
' FROM scene_numbering'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND scene_absolute_number = ?',
|
|
|
|
[indexer, indexer_id, scene_absolute_number])
|
2014-07-03 16:15:03 +00:00
|
|
|
else:
|
2015-07-25 09:19:46 +00:00
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT absolute_number'
|
|
|
|
' FROM scene_numbering'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND scene_absolute_number = ? AND scene_season = ?',
|
|
|
|
[indexer, indexer_id, scene_absolute_number, scene_season])
|
2014-05-28 21:13:29 +00:00
|
|
|
|
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['absolute_number'])
|
2014-05-28 21:13:29 +00:00
|
|
|
else:
|
|
|
|
if fallback_to_xem:
|
2018-09-07 16:23:19 +00:00
|
|
|
return get_indexer_absolute_numbering_for_xem(indexer_id, indexer, scene_absolute_number, scene_season)
|
|
|
|
return scene_absolute_number
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def set_scene_numbering(indexer_id, indexer, season=None, episode=None, absolute_number=None, scene_season=None,
|
|
|
|
scene_episode=None, scene_absolute=None, anime=False):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2014-05-30 05:48:02 +00:00
|
|
|
Set scene numbering for a season/episode.
|
|
|
|
To clear the scene numbering, leave both sceneSeason and sceneEpisode as None.
|
2015-12-06 11:36:45 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2015-07-25 09:19:46 +00:00
|
|
|
if None is indexer_id:
|
2014-05-30 05:48:02 +00:00
|
|
|
return
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
2016-02-01 19:37:32 +00:00
|
|
|
if None is not season and None is not episode:
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db.action(
|
|
|
|
'INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, season, episode) VALUES (?,?,?,?)',
|
2014-06-21 22:46:59 +00:00
|
|
|
[indexer, indexer_id, season, episode])
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
# sxe replaced abs_num as key, migrate data with only abs
|
|
|
|
_, _, ep_absolute_number = _get_sea(indexer, indexer_id, season, episode)
|
|
|
|
rows = my_db.select(
|
|
|
|
'SELECT scene_season, scene_episode, scene_absolute_number'
|
|
|
|
' FROM scene_numbering'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND season IS NULL AND episode IS NULL AND absolute_number = ?',
|
|
|
|
[indexer, indexer_id, ep_absolute_number])
|
|
|
|
|
|
|
|
if not len(rows):
|
|
|
|
update, values = (('scene_absolute_number = ?', [scene_absolute]),
|
|
|
|
('scene_season = ?, scene_episode = ?', [scene_season, scene_episode]))[not anime]
|
|
|
|
else:
|
|
|
|
for row in rows:
|
|
|
|
scene_season = scene_season or row['scene_season']
|
|
|
|
scene_episode = scene_episode or row['scene_episode']
|
|
|
|
scene_absolute = scene_absolute or row['scene_absolute_number']
|
|
|
|
|
|
|
|
update, values = ('scene_season = ?, scene_episode = ?, scene_absolute_number = ?',
|
|
|
|
[scene_season, scene_episode, scene_absolute])
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db.action(
|
2018-09-07 16:23:19 +00:00
|
|
|
'UPDATE scene_numbering'
|
|
|
|
' SET %s' % update +
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND season = ? AND episode = ?',
|
|
|
|
values + [indexer, indexer_id, season, episode])
|
|
|
|
|
|
|
|
my_db.action(
|
|
|
|
'DELETE'
|
|
|
|
' FROM scene_numbering'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND'
|
|
|
|
' ((absolute_number = ? OR (season = ? AND episode = ?))'
|
|
|
|
' AND scene_season IS NULL AND scene_episode IS NULL AND scene_absolute_number IS NULL)',
|
|
|
|
[indexer, indexer_id, ep_absolute_number, season, episode])
|
|
|
|
|
2014-06-21 22:46:59 +00:00
|
|
|
elif absolute_number:
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db.action(
|
|
|
|
'INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, absolute_number) VALUES (?,?,?)',
|
2014-06-21 22:46:59 +00:00
|
|
|
[indexer, indexer_id, absolute_number])
|
2014-05-26 06:29:22 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db.action(
|
2018-09-07 16:23:19 +00:00
|
|
|
'UPDATE scene_numbering'
|
|
|
|
' SET scene_absolute_number = ?'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ? AND absolute_number = ?',
|
|
|
|
[scene_absolute, indexer, indexer_id, absolute_number])
|
2014-03-25 05:57:24 +00:00
|
|
|
|
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
def find_xem_numbering(indexer_id, indexer, season, episode):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2014-05-30 05:48:02 +00:00
|
|
|
Returns the scene numbering, as retrieved from xem.
|
|
|
|
Refreshes/Loads as needed.
|
2015-12-06 11:36:45 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
@param indexer_id: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param indexer: int
|
2014-05-30 05:48:02 +00:00
|
|
|
@param season: int
|
|
|
|
@param episode: int
|
|
|
|
@return: (int, int) a tuple of scene_season, scene_episode, or None if there is no special mapping.
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2015-07-25 09:19:46 +00:00
|
|
|
if None is indexer_id or None is season or None is episode:
|
|
|
|
return season, episode
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2014-05-30 06:49:47 +00:00
|
|
|
xem_refresh(indexer_id, indexer)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT scene_season, scene_episode'
|
|
|
|
' FROM tv_episodes'
|
|
|
|
' WHERE indexer = ? AND showid = ? AND season = ? AND episode = ? AND (scene_season OR scene_episode) != 0',
|
2014-06-21 22:46:59 +00:00
|
|
|
[indexer, indexer_id, season, episode])
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['scene_season']), int(rows[0]['scene_episode'])
|
2014-03-25 05:57:24 +00:00
|
|
|
|
|
|
|
|
2018-09-05 14:15:08 +00:00
|
|
|
def find_xem_absolute_numbering(indexer_id, indexer, absolute_number, season, episode):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
|
|
|
Returns the scene numbering, as retrieved from xem.
|
|
|
|
Refreshes/Loads as needed.
|
2014-05-30 05:48:02 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
@param indexer_id: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param indexer: int
|
2014-06-07 12:36:50 +00:00
|
|
|
@param absolute_number: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param season: int
|
|
|
|
@param episode: int
|
2014-06-07 12:36:50 +00:00
|
|
|
@return: int
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2015-07-25 09:19:46 +00:00
|
|
|
if None is indexer_id or None is absolute_number:
|
2014-05-30 05:48:02 +00:00
|
|
|
return absolute_number
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2014-05-30 06:49:47 +00:00
|
|
|
xem_refresh(indexer_id, indexer)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT scene_absolute_number'
|
|
|
|
' FROM tv_episodes'
|
|
|
|
' WHERE indexer = ? AND showid = ? AND season = ? AND episode = ? AND scene_absolute_number != 0',
|
2018-09-05 14:15:08 +00:00
|
|
|
[indexer, indexer_id, season, episode])
|
2014-05-11 22:24:02 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['scene_absolute_number'])
|
2014-05-30 05:48:02 +00:00
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def get_indexer_numbering_for_xem(indexer_id, indexer, scene_season, scene_episode):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
|
|
|
Reverse of find_xem_numbering: lookup a tvdb season and episode using scene numbering
|
2015-12-06 11:36:45 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
@param indexer_id: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param indexer: int
|
|
|
|
@param scene_season: int
|
|
|
|
@param scene_episode: int
|
2015-12-06 11:36:45 +00:00
|
|
|
@return: (int, int) a tuple of (season, episode)
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
if None is indexer_id or None is scene_season or None is scene_episode:
|
|
|
|
return scene_season, scene_episode
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2014-05-30 06:49:47 +00:00
|
|
|
xem_refresh(indexer_id, indexer)
|
2014-05-28 21:13:29 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT season, episode'
|
|
|
|
' FROM tv_episodes'
|
|
|
|
' WHERE indexer = ? AND showid = ? AND scene_season = ? AND scene_episode = ?',
|
|
|
|
[indexer, indexer_id, scene_season, scene_episode])
|
2014-05-28 21:13:29 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['season']), int(rows[0]['episode'])
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
return scene_season, scene_episode
|
2014-05-28 21:13:29 +00:00
|
|
|
|
2014-05-30 05:48:02 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def get_indexer_absolute_numbering_for_xem(indexer_id, indexer, scene_absolute_number, scene_season=None):
|
2014-05-28 21:13:29 +00:00
|
|
|
"""
|
|
|
|
Reverse of find_xem_numbering: lookup a tvdb season and episode using scene numbering
|
|
|
|
|
|
|
|
@param indexer_id: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param indexer: int
|
|
|
|
@param scene_absolute_number: int
|
|
|
|
@param scene_season: int/None
|
2014-06-07 12:36:50 +00:00
|
|
|
@return: int
|
2014-05-28 21:13:29 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
if None is indexer_id or None is scene_absolute_number:
|
|
|
|
return scene_absolute_number
|
2014-05-28 21:13:29 +00:00
|
|
|
|
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2014-05-30 06:49:47 +00:00
|
|
|
xem_refresh(indexer_id, indexer)
|
2014-05-28 21:13:29 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
if None is scene_season:
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT absolute_number'
|
|
|
|
' FROM tv_episodes'
|
|
|
|
' WHERE indexer = ? AND showid = ? AND scene_absolute_number = ?',
|
|
|
|
[indexer, indexer_id, scene_absolute_number])
|
2014-07-03 16:15:03 +00:00
|
|
|
else:
|
2015-07-25 09:19:46 +00:00
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT absolute_number'
|
|
|
|
' FROM tv_episodes'
|
|
|
|
' WHERE indexer = ? AND showid = ? AND scene_absolute_number = ? AND scene_season = ?',
|
|
|
|
[indexer, indexer_id, scene_absolute_number, scene_season])
|
2014-05-28 21:13:29 +00:00
|
|
|
|
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
return int(rows[0]['absolute_number'])
|
2014-05-30 05:48:02 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
return scene_absolute_number
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_scene_numbering_for_show(indexer_id, indexer):
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
Returns a dict of (season, episode) : (scene_season, scene_episode) mappings
|
2014-05-30 05:48:02 +00:00
|
|
|
for an entire show. Both the keys and values of the dict are tuples.
|
2018-09-07 16:23:19 +00:00
|
|
|
Will be empty if no scene numbers are set
|
2014-05-30 05:48:02 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
return _get_numbering_for_show('scene_numbering', indexer, indexer_id)
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_xem_numbering_for_show(indexer_id, indexer):
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
Returns a dict of (season, episode) : (scene_season, scene_episode) mappings
|
2014-05-30 05:48:02 +00:00
|
|
|
for an entire show. Both the keys and values of the dict are tuples.
|
2018-09-07 16:23:19 +00:00
|
|
|
Will be empty if no scene numbers are set in xem
|
2014-05-30 05:48:02 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
return _get_numbering_for_show('tv_episodes', indexer, indexer_id)
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def _get_numbering_for_show(tbl, indexer, indexer_id):
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
if None is not indexer_id:
|
|
|
|
if 'tv_episodes' == tbl:
|
|
|
|
xem_refresh(indexer_id, indexer)
|
|
|
|
|
|
|
|
my_db = db.DBConnection()
|
|
|
|
# noinspection SqlResolve
|
|
|
|
rows = my_db.select(
|
|
|
|
'SELECT season, episode, scene_season, scene_episode'
|
|
|
|
' FROM %s' % tbl +
|
|
|
|
' WHERE indexer = ? AND %s = ?' % ('indexer_id', 'showid')['tv_episodes' == tbl] +
|
|
|
|
' AND (scene_season OR scene_episode) != 0'
|
|
|
|
' ORDER BY season, episode',
|
|
|
|
[int(indexer), int(indexer_id)])
|
|
|
|
|
|
|
|
for row in rows:
|
|
|
|
season, episode = tryInt(row['season'], None), tryInt(row['episode'], None)
|
|
|
|
if None is not season and None is not episode:
|
|
|
|
scene_season, scene_episode = tryInt(row['scene_season'], None), tryInt(row['scene_episode'], None)
|
|
|
|
if None is not scene_season and None is not scene_episode:
|
|
|
|
result[(season, episode)] = (scene_season, scene_episode)
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def get_scene_absolute_numbering_for_show(indexer_id, indexer):
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
Returns a dict of (season, episode) : scene_absolute_number mappings for an entire show.
|
|
|
|
Will be empty if no scene numbers are set
|
2014-05-30 05:48:02 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
return _get_absolute_numbering_for_show('scene_numbering', indexer, indexer_id)
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_xem_absolute_numbering_for_show(indexer_id, indexer):
|
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
Returns a dict of (season, episode) : scene_absolute_number mappings for an entire show.
|
|
|
|
Will be empty if no scene numbers are set in xem
|
2014-05-30 05:48:02 +00:00
|
|
|
"""
|
2018-09-07 16:23:19 +00:00
|
|
|
return _get_absolute_numbering_for_show('tv_episodes', indexer, indexer_id)
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def _get_absolute_numbering_for_show(tbl, indexer, indexer_id):
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
if None is not indexer_id:
|
|
|
|
if 'tv_episodes' == tbl:
|
|
|
|
xem_refresh(indexer_id, indexer)
|
2014-05-30 05:48:02 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
# noinspection SqlResolve
|
|
|
|
rows = my_db.select(
|
|
|
|
'SELECT season, episode, absolute_number, scene_absolute_number'
|
|
|
|
' FROM %s' % tbl +
|
|
|
|
' WHERE indexer = ? AND %s = ?' % ('indexer_id', 'showid')['tv_episodes' == tbl] +
|
|
|
|
' AND scene_absolute_number != 0'
|
|
|
|
' ORDER BY season, episode',
|
|
|
|
[int(indexer), int(indexer_id)])
|
|
|
|
|
|
|
|
for row in rows:
|
|
|
|
season, episode, abs_num = map(lambda x: tryInt(row[x], None), ('season', 'episode', 'absolute_number'))
|
|
|
|
if None is season and None is episode and None is not abs_num:
|
|
|
|
season, episode, _ = _get_sea(indexer, indexer_id, absolute_number=abs_num)
|
|
|
|
|
|
|
|
if None is not season and None is not episode:
|
|
|
|
scene_absolute_number = tryInt(row['scene_absolute_number'], None)
|
|
|
|
if None is not scene_absolute_number:
|
|
|
|
result[(season, episode)] = scene_absolute_number
|
2014-05-30 05:48:02 +00:00
|
|
|
|
|
|
|
return result
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-07-27 10:59:21 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def _get_sea(indexer, indexer_id, season=None, episode=None, absolute_number=None):
|
|
|
|
show_obj = sickbeard.helpers.find_show_by_id(sickbeard.showList, {indexer: indexer_id},
|
|
|
|
no_mapped_ids=True)
|
|
|
|
if show_obj:
|
|
|
|
ep_obj = None
|
|
|
|
if None is not absolute_number:
|
|
|
|
ep_obj = show_obj.getEpisode(absolute_number=absolute_number)
|
|
|
|
elif None is not season and None is not episode:
|
|
|
|
ep_obj = show_obj.getEpisode(season, episode)
|
|
|
|
if None is not ep_obj:
|
|
|
|
season, episode, absolute_number = ep_obj.season, ep_obj.episode, ep_obj.absolute_number
|
|
|
|
return season, episode, absolute_number
|
|
|
|
|
|
|
|
|
2014-05-30 06:49:47 +00:00
|
|
|
def xem_refresh(indexer_id, indexer, force=False):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2014-05-30 06:49:47 +00:00
|
|
|
Refresh data from xem for a tv show
|
2015-12-06 11:36:45 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
@param indexer_id: int
|
2018-09-07 16:23:19 +00:00
|
|
|
@param indexer: int
|
|
|
|
@param force: bool
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2015-07-25 09:19:46 +00:00
|
|
|
if None is indexer_id:
|
2014-05-30 06:49:47 +00:00
|
|
|
return
|
2014-03-20 05:33:34 +00:00
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2017-05-17 15:55:59 +00:00
|
|
|
if 'xem_origin' not in sickbeard.indexerApi(indexer).config or indexer_id not in xem_ids_list.get(indexer, []):
|
2015-08-10 14:16:22 +00:00
|
|
|
return
|
|
|
|
|
2014-07-27 10:59:21 +00:00
|
|
|
# XEM API URL
|
2015-07-25 09:19:46 +00:00
|
|
|
url = 'http://thexem.de/map/all?id=%s&origin=%s&destination=scene' % (
|
|
|
|
indexer_id, sickbeard.indexerApi(indexer).config['xem_origin'])
|
2014-07-27 10:59:21 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
max_refresh_age_secs = 86400 # 1 day
|
2014-07-27 10:59:21 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
2018-09-07 16:23:19 +00:00
|
|
|
rows = my_db.select(
|
|
|
|
'SELECT last_refreshed'
|
|
|
|
' FROM xem_refresh'
|
|
|
|
' WHERE indexer = ? AND indexer_id = ?',
|
|
|
|
[indexer, indexer_id])
|
2014-03-10 05:18:05 +00:00
|
|
|
if rows:
|
2015-07-25 09:19:46 +00:00
|
|
|
last_refresh = int(rows[0]['last_refreshed'])
|
|
|
|
refresh = int(time.mktime(datetime.datetime.today().timetuple())) > last_refresh + max_refresh_age_secs
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
2014-05-30 06:49:47 +00:00
|
|
|
refresh = True
|
|
|
|
|
|
|
|
if refresh or force:
|
2014-07-27 10:59:21 +00:00
|
|
|
logger.log(
|
2015-07-25 09:19:46 +00:00
|
|
|
u'Looking up XEM scene mapping for show %s on %s' % (indexer_id, sickbeard.indexerApi(indexer).name),
|
2014-07-27 10:59:21 +00:00
|
|
|
logger.DEBUG)
|
|
|
|
|
|
|
|
# mark refreshed
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db.upsert('xem_refresh',
|
|
|
|
{'indexer': indexer, 'last_refreshed': int(time.mktime(datetime.datetime.today().timetuple()))},
|
|
|
|
{'indexer_id': indexer_id})
|
2014-07-27 10:59:21 +00:00
|
|
|
|
2014-05-30 06:49:47 +00:00
|
|
|
try:
|
2015-07-25 09:19:46 +00:00
|
|
|
parsed_json = sickbeard.helpers.getURL(url, json=True, timeout=90)
|
|
|
|
if not parsed_json or '' == parsed_json:
|
2018-09-07 16:23:19 +00:00
|
|
|
logger.log(u'No XEM data for show %s on %s' % (
|
|
|
|
indexer_id, sickbeard.indexerApi(indexer).name), logger.MESSAGE)
|
2014-07-27 10:59:21 +00:00
|
|
|
return
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
if 'success' in parsed_json['result']:
|
2014-07-27 10:59:21 +00:00
|
|
|
cl = []
|
2015-07-25 09:19:46 +00:00
|
|
|
for entry in parsed_json['data']:
|
2018-09-07 16:23:19 +00:00
|
|
|
# use scene2 for doubles
|
|
|
|
scene = 'scene%s' % ('', '_2')['scene_2' in entry]
|
|
|
|
cl.append([
|
|
|
|
'UPDATE tv_episodes'
|
|
|
|
' SET scene_season = ?, scene_episode = ?, scene_absolute_number = ?'
|
|
|
|
' WHERE showid = ? AND season = ? AND episode = ?',
|
|
|
|
[entry[scene]['season'], entry[scene]['episode'], entry[scene]['absolute'],
|
|
|
|
indexer_id,
|
|
|
|
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['season'],
|
|
|
|
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']
|
|
|
|
]])
|
2014-07-27 10:59:21 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
if 0 < len(cl):
|
|
|
|
my_db = db.DBConnection()
|
|
|
|
my_db.mass_action(cl)
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
2015-07-25 09:19:46 +00:00
|
|
|
logger.log(u'Empty lookup result - no XEM data for show %s on %s' % (
|
|
|
|
indexer_id, sickbeard.indexerApi(indexer).name), logger.DEBUG)
|
2015-06-08 12:47:01 +00:00
|
|
|
except Exception as e:
|
2014-07-27 10:59:21 +00:00
|
|
|
logger.log(
|
2015-07-25 09:19:46 +00:00
|
|
|
u'Exception while refreshing XEM data for show ' + str(indexer_id) + ' on ' + sickbeard.indexerApi(
|
|
|
|
indexer).name + ': ' + ex(e), logger.WARNING)
|
2017-06-04 16:19:22 +00:00
|
|
|
logger.log(traceback.format_exc(), logger.ERROR)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
|
2014-05-28 21:13:29 +00:00
|
|
|
def fix_xem_numbering(indexer_id, indexer):
|
2018-09-07 16:23:19 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
if None is indexer_id:
|
2014-03-10 05:18:05 +00:00
|
|
|
return {}
|
|
|
|
|
2014-05-03 09:58:04 +00:00
|
|
|
indexer_id = int(indexer_id)
|
|
|
|
indexer = int(indexer)
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db = db.DBConnection()
|
|
|
|
rows = my_db.select(
|
2018-09-07 16:23:19 +00:00
|
|
|
'SELECT season, episode, absolute_number, scene_season, scene_episode, scene_absolute_number'
|
|
|
|
' FROM tv_episodes'
|
|
|
|
' WHERE indexer = ? AND showid = ?',
|
2014-06-21 22:46:59 +00:00
|
|
|
[indexer, indexer_id])
|
2014-05-03 22:29:00 +00:00
|
|
|
|
2014-05-28 21:13:29 +00:00
|
|
|
last_absolute_number = None
|
|
|
|
last_scene_season = None
|
|
|
|
last_scene_episode = None
|
|
|
|
last_scene_absolute_number = None
|
2014-05-03 22:29:00 +00:00
|
|
|
|
2014-05-28 21:13:29 +00:00
|
|
|
update_absolute_number = False
|
|
|
|
update_scene_season = False
|
|
|
|
update_scene_episode = False
|
|
|
|
update_scene_absolute_number = False
|
2014-05-03 22:29:00 +00:00
|
|
|
|
2014-05-28 21:13:29 +00:00
|
|
|
logger.log(
|
2015-07-25 09:19:46 +00:00
|
|
|
u'Fixing any XEM scene mapping issues for show %s on %s' % (indexer_id, sickbeard.indexerApi(indexer).name),
|
2014-05-28 21:13:29 +00:00
|
|
|
logger.DEBUG)
|
2014-05-03 22:29:00 +00:00
|
|
|
|
2014-07-15 02:00:53 +00:00
|
|
|
cl = []
|
2014-05-28 21:13:29 +00:00
|
|
|
for row in rows:
|
|
|
|
season = int(row['season'])
|
|
|
|
episode = int(row['episode'])
|
2014-05-03 22:29:00 +00:00
|
|
|
|
2014-05-28 21:13:29 +00:00
|
|
|
if not int(row['scene_season']) and last_scene_season:
|
|
|
|
scene_season = last_scene_season + 1
|
|
|
|
update_scene_season = True
|
|
|
|
else:
|
|
|
|
scene_season = int(row['scene_season'])
|
|
|
|
if last_scene_season and scene_season < last_scene_season:
|
|
|
|
scene_season = last_scene_season + 1
|
|
|
|
update_scene_season = True
|
|
|
|
|
|
|
|
if not int(row['scene_episode']) and last_scene_episode:
|
|
|
|
scene_episode = last_scene_episode + 1
|
|
|
|
update_scene_episode = True
|
|
|
|
else:
|
|
|
|
scene_episode = int(row['scene_episode'])
|
|
|
|
if last_scene_episode and scene_episode < last_scene_episode:
|
|
|
|
scene_episode = last_scene_episode + 1
|
|
|
|
update_scene_episode = True
|
|
|
|
|
|
|
|
# check for unset values and correct them
|
|
|
|
if not int(row['absolute_number']) and last_absolute_number:
|
|
|
|
absolute_number = last_absolute_number + 1
|
|
|
|
update_absolute_number = True
|
|
|
|
else:
|
|
|
|
absolute_number = int(row['absolute_number'])
|
|
|
|
if last_absolute_number and absolute_number < last_absolute_number:
|
|
|
|
absolute_number = last_absolute_number + 1
|
|
|
|
update_absolute_number = True
|
|
|
|
|
|
|
|
if not int(row['scene_absolute_number']) and last_scene_absolute_number:
|
|
|
|
scene_absolute_number = last_scene_absolute_number + 1
|
|
|
|
update_scene_absolute_number = True
|
|
|
|
else:
|
|
|
|
scene_absolute_number = int(row['scene_absolute_number'])
|
|
|
|
if last_scene_absolute_number and scene_absolute_number < last_scene_absolute_number:
|
|
|
|
scene_absolute_number = last_scene_absolute_number + 1
|
|
|
|
update_scene_absolute_number = True
|
|
|
|
|
|
|
|
# store values for lookup on next iteration
|
|
|
|
last_absolute_number = absolute_number
|
|
|
|
last_scene_season = scene_season
|
|
|
|
last_scene_episode = scene_episode
|
|
|
|
last_scene_absolute_number = scene_absolute_number
|
|
|
|
|
|
|
|
if update_absolute_number:
|
2014-07-15 02:00:53 +00:00
|
|
|
cl.append([
|
2018-09-07 16:23:19 +00:00
|
|
|
'UPDATE tv_episodes'
|
|
|
|
' SET absolute_number = ?'
|
|
|
|
' WHERE showid = ? AND season = ? AND episode = ?',
|
2014-05-28 21:13:29 +00:00
|
|
|
[absolute_number,
|
|
|
|
indexer_id,
|
|
|
|
season,
|
|
|
|
episode
|
2015-07-25 09:19:46 +00:00
|
|
|
]])
|
2014-05-28 21:13:29 +00:00
|
|
|
update_absolute_number = False
|
|
|
|
|
|
|
|
if update_scene_season:
|
2014-07-15 02:00:53 +00:00
|
|
|
cl.append([
|
2018-09-07 16:23:19 +00:00
|
|
|
'UPDATE tv_episodes'
|
|
|
|
' SET scene_season = ?'
|
|
|
|
' WHERE showid = ? AND season = ? AND episode = ?',
|
2014-05-28 21:13:29 +00:00
|
|
|
[scene_season,
|
|
|
|
indexer_id,
|
|
|
|
season,
|
|
|
|
episode
|
2015-07-25 09:19:46 +00:00
|
|
|
]])
|
2014-05-28 21:13:29 +00:00
|
|
|
update_scene_season = False
|
|
|
|
|
|
|
|
if update_scene_episode:
|
2014-07-15 02:00:53 +00:00
|
|
|
cl.append([
|
2018-09-07 16:23:19 +00:00
|
|
|
'UPDATE tv_episodes'
|
|
|
|
' SET scene_episode = ?'
|
|
|
|
' WHERE showid = ? AND season = ? AND episode = ?',
|
2014-05-28 21:13:29 +00:00
|
|
|
[scene_episode,
|
|
|
|
indexer_id,
|
|
|
|
season,
|
|
|
|
episode
|
2015-07-25 09:19:46 +00:00
|
|
|
]])
|
2014-05-28 21:13:29 +00:00
|
|
|
update_scene_episode = False
|
|
|
|
|
|
|
|
if update_scene_absolute_number:
|
2014-07-15 02:00:53 +00:00
|
|
|
cl.append([
|
2018-09-07 16:23:19 +00:00
|
|
|
'UPDATE tv_episodes'
|
|
|
|
' SET scene_absolute_number = ?'
|
|
|
|
' WHERE showid = ? AND season = ? AND episode = ?',
|
2014-05-28 21:13:29 +00:00
|
|
|
[scene_absolute_number,
|
|
|
|
indexer_id,
|
|
|
|
season,
|
|
|
|
episode
|
2015-07-25 09:19:46 +00:00
|
|
|
]])
|
2014-05-28 21:13:29 +00:00
|
|
|
update_scene_absolute_number = False
|
2014-05-03 22:29:00 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
if 0 < len(cl):
|
|
|
|
my_db = db.DBConnection()
|
|
|
|
my_db.mass_action(cl)
|
2016-08-24 19:02:12 +00:00
|
|
|
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
def set_scene_numbering_helper(indexerid, indexer, for_season=None, for_episode=None, for_absolute=None,
|
|
|
|
scene_season=None, scene_episode=None, scene_absolute=None):
|
2016-08-24 19:02:12 +00:00
|
|
|
# sanitize:
|
|
|
|
indexerid = None if indexerid in [None, 'null', ''] else int(indexerid)
|
|
|
|
indexer = None if indexer in [None, 'null', ''] else int(indexer)
|
|
|
|
|
|
|
|
show_obj = sickbeard.helpers.find_show_by_id(sickbeard.showList, {indexer: indexerid}, no_mapped_ids=True)
|
|
|
|
if not show_obj:
|
2018-09-07 16:23:19 +00:00
|
|
|
return {'success': False}
|
2016-08-24 19:02:12 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
for_season = None if for_season in [None, 'null', ''] else int(for_season)
|
|
|
|
for_episode = None if for_episode in [None, 'null', ''] else int(for_episode)
|
|
|
|
ep_args = {'show': indexerid, 'season': for_season, 'episode': for_episode}
|
|
|
|
scene_args = {'indexer': indexer, 'indexer_id': indexerid, 'season': for_season, 'episode': for_episode}
|
2016-08-24 19:02:12 +00:00
|
|
|
if not show_obj.is_anime:
|
2018-09-07 16:23:19 +00:00
|
|
|
scene_season = None if scene_season in [None, 'null', ''] else int(scene_season)
|
|
|
|
scene_episode = None if scene_episode in [None, 'null', ''] else int(scene_episode)
|
2016-08-24 19:02:12 +00:00
|
|
|
action_log = u'Set episode scene numbering to %sx%s for episode %sx%s of "%s"' \
|
|
|
|
% (scene_season, scene_episode, for_season, for_episode, show_obj.name)
|
2018-09-07 16:23:19 +00:00
|
|
|
scene_args.update({'scene_season': scene_season, 'scene_episode': scene_episode})
|
2016-08-24 19:02:12 +00:00
|
|
|
result = {'forSeason': for_season, 'forEpisode': for_episode, 'sceneSeason': None, 'sceneEpisode': None}
|
|
|
|
else:
|
2018-09-07 16:23:19 +00:00
|
|
|
for_absolute = None if for_absolute in [None, 'null', ''] else int(for_absolute)
|
|
|
|
scene_absolute = None if scene_absolute in [None, 'null', ''] else int(scene_absolute)
|
|
|
|
action_log = u'Set absolute scene numbering to %s for episode %sx%s of "%s"' \
|
|
|
|
% (scene_absolute, for_season, for_episode, show_obj.name)
|
|
|
|
ep_args.update({'absolute': for_absolute})
|
|
|
|
scene_args.update({'absolute_number': for_absolute, 'scene_absolute': scene_absolute, 'anime': True})
|
2016-08-24 19:02:12 +00:00
|
|
|
result = {'forAbsolute': for_absolute, 'sceneAbsolute': None}
|
|
|
|
|
|
|
|
if ep_args.get('absolute'):
|
|
|
|
ep_obj = show_obj.getEpisode(absolute_number=int(ep_args['absolute']))
|
|
|
|
elif None is not ep_args['season'] and None is not ep_args['episode']:
|
|
|
|
ep_obj = show_obj.getEpisode(int(ep_args['season']), int(ep_args['episode']))
|
|
|
|
else:
|
2018-09-07 16:23:19 +00:00
|
|
|
ep_obj = 'Invalid parameters'
|
2016-08-24 19:02:12 +00:00
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
result['success'] = None is not ep_obj and not isinstance(ep_obj, str)
|
2016-08-24 19:02:12 +00:00
|
|
|
if result['success']:
|
|
|
|
logger.log(action_log, logger.DEBUG)
|
|
|
|
set_scene_numbering(**scene_args)
|
|
|
|
show_obj.flushEpisodes()
|
|
|
|
else:
|
2018-09-07 16:23:19 +00:00
|
|
|
result['errorMessage'] = "Episode couldn't be retrieved, invalid parameters"
|
2016-08-24 19:02:12 +00:00
|
|
|
|
|
|
|
if not show_obj.is_anime:
|
|
|
|
scene_numbering = get_scene_numbering(indexerid, indexer, for_season, for_episode)
|
|
|
|
if scene_numbering:
|
|
|
|
(result['sceneSeason'], result['sceneEpisode']) = scene_numbering
|
|
|
|
else:
|
2018-09-05 14:15:08 +00:00
|
|
|
scene_numbering = get_scene_absolute_numbering(indexerid, indexer, for_absolute, for_season, for_episode)
|
2016-08-24 19:02:12 +00:00
|
|
|
if scene_numbering:
|
|
|
|
result['sceneAbsolute'] = scene_numbering
|
|
|
|
|
2018-09-07 16:23:19 +00:00
|
|
|
return result
|