Skip to content

Commit

Permalink
Moved scene exceptions to be a TVShows table column in database.
Browse files Browse the repository at this point in the history
Added SR API endpoints for scene exception retrieval.
Added scene_exceptions and last_scene_exceptions_refresh properties to TVShow class.
Added retrieval of scene exceptions method to TVShow class.
Added get_scene_exception_by_name to TVShow class.
Added get_scene_exception_by_season to TVShow class.
Added update_scene_exceptions to TVShow class.
Fixed charmap issue with AniDB.
  • Loading branch information
echel0n committed Mar 23, 2020
1 parent abc38a3 commit 104163b
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 378 deletions.
10 changes: 4 additions & 6 deletions sickrage/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
from sickrage.core.queues.postprocessor import PostProcessorQueue
from sickrage.core.queues.search import SearchQueue
from sickrage.core.queues.show import ShowQueue
from sickrage.core.scene_exceptions import load_scene_exceptions, retrieve_scene_exceptions
from sickrage.core.searchers.backlog_searcher import BacklogSearcher
from sickrage.core.searchers.daily_searcher import DailySearcher
from sickrage.core.searchers.failed_snatch_searcher import FailedSnatchSearcher
Expand Down Expand Up @@ -297,9 +296,6 @@ def start(self):
# set torrent client web url
torrent_webui_url(True)

# load scene exceptions
load_scene_exceptions()

# load quicksearch cache
self.quicksearch_cache.load()

Expand Down Expand Up @@ -496,7 +492,7 @@ def start(self):

# add scene exceptions update job
self.scheduler.add_job(
retrieve_scene_exceptions,
lambda: [x.retrieve_scene_exceptions() for x in self.shows],
IntervalTrigger(
days=1,
timezone='utc'
Expand Down Expand Up @@ -564,7 +560,9 @@ def load_shows(self):
for query in session.query(MainDB.TVShow).with_entities(MainDB.TVShow.indexer_id, MainDB.TVShow.indexer, MainDB.TVShow.name):
try:
self.log.info('Loading show {} and building caches'.format(query.name))
self.shows.update({(query.indexer_id, query.indexer): TVShow(query.indexer_id, query.indexer)})
show = TVShow(query.indexer_id, query.indexer)
show.retrieve_scene_exceptions()
self.shows.update({(query.indexer_id, query.indexer): show})
self.quicksearch_cache.add_show(query.indexer_id)
except Exception as e:
self.log.debug('There was an error loading show: {}'.format(query.name))
Expand Down
21 changes: 18 additions & 3 deletions sickrage/core/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def torrent_cache(self):
def provider_cache(self):
return self.ProviderCacheAPI(self)

@property
def scene_exceptions(self):
return self.SceneExceptions(self)

@property
def session(self):
extra = {
Expand Down Expand Up @@ -132,7 +136,6 @@ def exchange_token(self, token, scope='offline_access'):
exchange = {'scope': scope, 'subject_token': token['access_token']}
self.token = sickrage.app.oidc_client.token_exchange(**exchange)


def allowed_usernames(self):
return self.request('GET', 'allowed-usernames')

Expand Down Expand Up @@ -276,8 +279,8 @@ def search_by_imdb_title(self, title):
query = 'imdb/search-by-title/{}'.format(title)
return self.api.request('GET', query)

def search_by_imdb_id(self, id):
query = 'imdb/search-by-id/{}'.format(id)
def search_by_imdb_id(self, imdb_id):
query = 'imdb/search-by-id/{}'.format(imdb_id)
return self.api.request('GET', query)

class GoogleDriveAPI:
Expand Down Expand Up @@ -311,3 +314,15 @@ def list_files(self, id):
def clear_folder(self, id):
query = 'google-drive/clear-folder/{id}'.format(id=id)
return self.api.request('GET', query)

class SceneExceptions:
def __init__(self, api):
self.api = api

def get(self):
query = 'scene-exceptions'
return self.api.request('GET', query)

def search_by_id(self, indexer_id):
query = 'scene-exceptions/search-by-id/{}'.format(indexer_id)
return self.api.request('GET', query)
4 changes: 1 addition & 3 deletions sickrage/core/caches/name_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

import sickrage
from sickrage.core.databases.cache import CacheDB
from sickrage.core.helpers import full_sanitize_scene_name, strip_accents
from sickrage.core.scene_exceptions import retrieve_scene_exceptions, get_scene_seasons, get_scene_exceptions
from sickrage.core.tv.show.helpers import get_show_list
from sickrage.core.helpers import full_sanitize_scene_name


class NameCache(object):
Expand Down
8 changes: 5 additions & 3 deletions sickrage/core/databases/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MainDBBase(SRDatabaseBase):

class MainDB(SRDatabase):
def __init__(self, db_type, db_prefix, db_host, db_port, db_username, db_password):
super(MainDB, self).__init__('main', 10, db_type, db_prefix, db_host, db_port, db_username, db_password)
super(MainDB, self).__init__('main', 11, db_type, db_prefix, db_host, db_port, db_username, db_password)
MainDBBase.metadata.create_all(self.engine)
for model in MainDBBase._decl_class_registry.values():
if hasattr(model, '__tablename__'):
Expand Down Expand Up @@ -70,10 +70,12 @@ class TVShow(MainDBBase):
sub_use_sr_metadata = Column(Boolean, default=0)
notify_list = Column(Text, default='')
search_delay = Column(Integer, default=0)
scene_exceptions = Column(Text, default='')
last_scene_exceptions_refresh = Column(Integer, default=0)
last_update = Column(Integer, default=datetime.datetime.now().toordinal())
last_refresh = Column(Integer, default=datetime.datetime.now().toordinal())
last_backlog_search = Column(Integer, default=datetime.datetime.now().toordinal())
last_proper_search = Column(Integer, default=datetime.datetime.now().toordinal())
last_backlog_search = Column(Integer, default=0)
last_proper_search = Column(Integer, default=0)

episodes = relationship('TVEpisode', uselist=True, backref='tv_shows', lazy='dynamic')
imdb_info = relationship('IMDbInfo', uselist=False, backref='tv_shows')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sqlalchemy import *


def upgrade(migrate_engine):
meta = MetaData(bind=migrate_engine)
tv_shows = Table('tv_shows', meta, autoload=True)
if not hasattr(tv_shows.c, 'scene_exceptions'):
scene_exceptions = Column('scene_exceptions', Text, default='')
scene_exceptions.create(tv_shows)
if not hasattr(tv_shows.c, 'last_scene_exceptions_refresh'):
last_scene_exceptions_refresh = Column('last_scene_exceptions_refresh', Integer, default=0)
last_scene_exceptions_refresh.create(tv_shows)


def downgrade(migrate_engine):
meta = MetaData(bind=migrate_engine)
tv_shows = Table('tv_shows', meta, autoload=True)
if hasattr(tv_shows.c, 'scene_exceptions'):
tv_shows.c.scene_exceptions.drop()
if hasattr(tv_shows.c, 'last_scene_exceptions_refresh'):
tv_shows.c.scene_exceptions.drop()
6 changes: 2 additions & 4 deletions sickrage/core/helpers/show_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,12 @@ def all_possible_show_names(show_id, season=-1):
:rtype: list[unicode]
"""

from sickrage.core.scene_exceptions import get_scene_exceptions

show = find_show(show_id)

show_names = get_scene_exceptions(show_id, season=season)[:]
show_names = show.get_scene_exceptions_by_season(season=season)[:]
if not show_names: # if we dont have any season specific exceptions fallback to generic exceptions
season = -1
show_names = get_scene_exceptions(show_id, season=season)[:]
show_names = show.get_scene_exceptions_by_season(season=season)[:]

if season in [-1, 1]:
show_names.append(show.name)
Expand Down
12 changes: 6 additions & 6 deletions sickrage/core/nameparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
from sqlalchemy import orm

import sickrage
from sickrage.core import scene_exceptions, common
from sickrage.core import common
from sickrage.core.databases.main import MainDB
from sickrage.core.helpers import remove_extension, strip_accents
from sickrage.core.nameparser import regexes
from sickrage.core.scene_numbering import get_absolute_number_from_season_and_episode, get_indexer_absolute_numbering, get_indexer_numbering
from sickrage.core.tv.show.helpers import find_show_by_name, find_show
from sickrage.core.tv.show.helpers import find_show_by_name, find_show, find_show_by_scene_exception
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_episodenotfound, indexer_error

Expand Down Expand Up @@ -70,9 +70,9 @@ def indexer_lookup(term):
return result

def scene_exception_lookup(term):
scene_result = scene_exceptions.get_scene_exception_by_name(term)
if scene_result:
return scene_result[0]
tv_show = find_show_by_scene_exception(term)
if tv_show:
return tv_show.indexer_id

def show_cache_lookup(term):
tv_show = find_show_by_name(term)
Expand Down Expand Up @@ -304,7 +304,7 @@ def _parse_string(self, name, skip_scene_detection=False):
a = epAbsNo

if show_obj.is_scene:
scene_result = scene_exceptions.get_scene_exception_by_name(best_result.series_name)
scene_result = show_obj.get_scene_exception_by_name(best_result.series_name)
if scene_result:
a = get_indexer_absolute_numbering(show_obj.indexer_id,
show_obj.indexer, epAbsNo,
Expand Down
3 changes: 3 additions & 0 deletions sickrage/core/queues/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ def run(self):
sickrage.app.log.info("update watchlist")
sickrage.app.notifier_providers['trakt'].update_watchlist(show_obj)

# Retrieve scene exceptions
show_obj.retrieve_scene_exceptions()

# Load XEM data to DB for show
xem_refresh(show_obj.indexer_id, show_obj.indexer, force=True)

Expand Down
Loading

0 comments on commit 104163b

Please sign in to comment.