def setUp(self): settings.showList = [] setup_test_db() setup_test_episode_file() setup_test_show_dir() setup_test_processing_dir() self.show = TVShow(1, 1, "en") self.show.name = SHOW_NAME self.show.location = FILE_DIR self.show.imdb_info = {"indexer_id": self.show.indexerid, "imdb_id": "tt000000"} self.show.episodes = {} for season in range(1, NUM_SEASONS): self.show.episodes[season] = {} for episode in range(1, EPISODES_PER_SEASON): if season == SEASON and episode == EPISODE: episode = TVEpisode(self.show, season, episode, ep_file=FILE_PATH) else: episode = TVEpisode(self.show, season, episode) self.show.episodes[season][episode] = episode episode.saveToDB() self.show.saveToDB() settings.showList = [self.show]
def setUpClass(cls): cls.shows = [] show = TVShow(1, 121361) show.name = "Italian Works" show.episodes = [] episode = TVEpisode(show, 5, 10) episode.name = "Pines of Rome" episode.scene_season = 5 episode.scene_episode = 10 show.episodes.append(episode) cls.shows.append(show)
def _test_all_possible_show_names(self, name, indexerid=0, expected=None): """ Test all possible show names :param name: :param indexerid: :param expected: :return: """ expected = expected or [] show = Show(1, indexerid) show.name = name result = show_name_helpers.allPossibleShowNames(show) assert len(set(expected).intersection(set(result))) == len(expected)
class SickChillTestPostProcessorCase(unittest.TestCase): """ Superclass for testing the database. Methods: setUp tearDown """ def setUp(self): settings.showList = [] setup_test_db() setup_test_episode_file() setup_test_show_dir() setup_test_processing_dir() self.show = TVShow(1, 1, "en") self.show.name = SHOW_NAME self.show.location = FILE_DIR self.show.imdb_info = { "indexer_id": self.show.indexerid, "imdb_id": "tt000000" } self.show.episodes = {} for season in range(1, NUM_SEASONS): self.show.episodes[season] = {} for episode in range(1, EPISODES_PER_SEASON): if season == SEASON and episode == EPISODE: episode = TVEpisode(self.show, season, episode, ep_file=FILE_PATH) else: episode = TVEpisode(self.show, season, episode) self.show.episodes[season][episode] = episode episode.saveToDB() self.show.saveToDB() settings.showList = [self.show] def tearDown(self): settings.showList = [] self.show.deleteShow(True) teardown_test_db() teardown_test_episode_file() teardown_test_show_dir() teardown_test_processing_dir()
def load_shows_from_db(): """ Populates the showList with shows from the database """ logger.debug("Loading initial show list") main_db_con = db.DBConnection() sql_results = main_db_con.select("SELECT indexer, indexer_id, location FROM tv_shows;") settings.showList = [] for sql_show in sql_results: try: cur_show = TVShow(sql_show["indexer"], sql_show["indexer_id"]) cur_show.nextEpisode() settings.showList.append(cur_show) except Exception as error: logger.exception("There was an error creating the show in {0}: Error {1}".format(sql_show["location"], error)) logger.debug(traceback.format_exc())
def test_init_empty_db(self): """ test init empty db """ show = TVShow(1, 1, "en") episode = TVEpisode(show, 1, 1) episode.name = "asdasdasdajkaj" episode.saveToDB() episode.loadFromDB(1, 1) assert episode.name == "asdasdasdajkaj"
def do_test(): """ Test to perform """ global search_items search_items = cur_data["i"] show = TVShow(1, tvdb_id) show.name = show_name show.quality = cur_data["q"] show.saveToDB() settings.showList.append(show) episode = None for epNumber in cur_data["e"]: episode = TVEpisode(show, cur_data["s"], epNumber) episode.status = common.WANTED episode.saveToDB() best_result = search.searchProviders(show, episode.episode, force_search) if not best_result: assert cur_data["b"] == best_result assert cur_data[ "b"] == best_result.name # first is expected, second is chosen one
def load_from_db(): """ Populates the showList with shows from the database """ test_main_db_con = sickchill.oldbeard.db.DBConnection() sql_results = test_main_db_con.select("SELECT * FROM tv_shows") for sql_show in sql_results: try: cur_show = TVShow(int(sql_show["indexer"]), int(sql_show["indexer_id"])) settings.showList.append(cur_show) except Exception as error: print("There was an error creating the show {0}".format(error))
def load_shows_from_db(): """ Populates the showList with shows from the database """ test_main_db_con = sickchill.oldbeard.db.DBConnection() sql_results = test_main_db_con.select("SELECT * FROM tv_shows") for sql_show in sql_results: try: cur_show = TVShow(int(sql_show["indexer"]), int(sql_show["indexer_id"])) settings.showList.append(cur_show) except Exception: # noqa: S110 pass
def test_process(self): """ Test process """ show = TVShow(1, 3) show.name = test.SHOW_NAME show.location = test.SHOW_DIR show.saveToDB() settings.showList = [show] episode = TVEpisode(show, test.SEASON, test.EPISODE) episode.name = "some episode name" episode.saveToDB() add_name('show name', 3) settings.PROCESS_METHOD = 'move' post_processor = PostProcessor(test.FILE_PATH) self.assertTrue(post_processor.process())
def test_process(self): """ Test process """ show = TVShow(1, 3) show.name = conftest.SHOW_NAME show.location = conftest.SHOW_DIR show.saveToDB() settings.showList = [show] episode = TVEpisode(show, conftest.SEASON, conftest.EPISODE) episode.name = "some episode name" episode.saveToDB() add_name("show name", 3) settings.PROCESS_METHOD = "move" post_processor = PostProcessor(conftest.FILE_PATH) assert post_processor.process()
def setUpClass(cls): num_legacy_shows = 3 num_shows = 3 num_episodes_per_show = 5 cls.mydb = db.DBConnection() cls.legacy_shows = [] cls.shows = [] # Per-show-notifications were originally added for email notifications only. To add # this feature to other notifiers, it was necessary to alter the way text is stored in # one of the DB columns. Therefore, to test properly, we must create some shows that # store emails in the old method (legacy method) and then other shows that will use # the new method. for show_counter in range(100, 100 + num_legacy_shows): show = TVShow(1, show_counter) show.name = "Show " + str(show_counter) show.episodes = [] for episode_counter in range(0, num_episodes_per_show): episode = TVEpisode(show, test.SEASON, episode_counter) episode.name = "Episode " + str(episode_counter + 1) episode.quality = "SDTV" show.episodes.append(episode) show.saveToDB() cls.legacy_shows.append(show) for show_counter in range(200, 200 + num_shows): show = TVShow(1, show_counter) show.name = "Show " + str(show_counter) show.episodes = [] for episode_counter in range(0, num_episodes_per_show): episode = TVEpisode(show, test.SEASON, episode_counter) episode.name = "Episode " + str(episode_counter + 1) episode.quality = "SDTV" show.episodes.append(episode) show.saveToDB() cls.shows.append(show)
def do_test(self): """ Test to perform """ show = TVShow(1, int(cur_data["tvdbid"])) show.name = cur_name show.quality = common.ANY | common.Quality.UNKNOWN | common.Quality.RAWHDTV show.saveToDB() settings.showList.append(show) for ep_number in cur_data["e"]: episode = TVEpisode(show, cur_data["s"], ep_number) episode.status = common.WANTED # We aren't updating scene numbers, so fake it here episode.scene_season = cur_data["s"] episode.scene_episode = ep_number episode.saveToDB() cur_provider.show = show season_strings = cur_provider.get_season_search_strings(episode) episode_strings = cur_provider.get_episode_search_strings(episode) fail = False cur_string = "" for cur_string in season_strings, episode_strings: if not all([ isinstance(cur_string, list), isinstance(cur_string[0], dict) ]): print("{0} is using a wrong string format!".format( cur_provider.name)) print(cur_string) fail = True continue if fail: continue try: assert season_strings == cur_data["s_strings"] assert episode_strings == cur_data["e_strings"] except AssertionError: print("{0} is using a wrong string format!".format( cur_provider.name)) print(cur_string) continue search_strings = episode_strings[0] # search_strings.update(season_strings[0]) # search_strings.update({"RSS":['']}) # print(search_strings) if not cur_provider.public: continue items = cur_provider.search(search_strings) if not items: print("No results from cur_provider?") continue title, url = cur_provider._get_title_and_url(items[0]) for word in show.name.split(" "): if not word.lower() in title.lower(): print("Show cur_name not in title: {0}. URL: {1}".format( title, url)) continue if not url: print("url is empty") continue quality = cur_provider.get_quality(items[0]) size = cur_provider._get_size(items[0]) if not show.quality & quality: print("Quality not in common.ANY, {0!r} {1}".format( quality, size)) continue
def run(self): super(QueueItemAdd, self).run() logger.info(_('Starting to add show {0}').format(_('by ShowDir: {0}').format(self.showDir) if self.showDir else _('by Indexer Id: {0}').format(self.indexer_id))) # make sure the Indexer IDs are valid try: s = sickchill.indexer.series_by_id(indexerid=self.indexer_id, indexer=self.indexer, language=self.lang) if not s: error_string = _('Could not find show with id:{0} on {1}, skipping').format( self.indexer_id, sickchill.indexer.name(self.indexer)) logger.info(error_string) ui.notifications.error(_('Unable to add show'), error_string) self._finish_early() return # Let's try to create the show Dir if it's not provided. This way we force the show dir to build build using the # Indexers provided series name if self.root_dir and not self.showDir: if not s.seriesName: logger.info(_('Unable to get a show {0}, can\'t add the show').format(self.showDir)) self._finish_early() return show_dir = s.seriesName if settings.ADD_SHOWS_WITH_YEAR and s.firstAired: try: year = '({0})'.format(dateutil.parser.parse(s.firstAired).year) if year not in show_dir: show_dir = '{0} {1}'.format(s.seriesName, year) except (TypeError, ValueError): logger.info(_('Could not append the show year folder for the show: {0}').format(show_dir)) self.showDir = os.path.join(self.root_dir, sanitize_filename(show_dir)) if settings.ADD_SHOWS_WO_DIR: logger.info(_("Skipping initial creation of {0} due to config.ini setting").format(self.showDir)) else: dir_exists = makeDir(self.showDir) if not dir_exists: logger.info(_('Unable to create the folder {0}, can\'t add the show').format(self.showDir)) self._finish_early() return chmodAsParent(self.showDir) # this usually only happens if they have an NFO in their show dir which gave us a Indexer ID that has no proper english version of the show if getattr(s, 'seriesName', None) is None: # noinspection PyPep8 error_string = _('Show in {0} has no name on {1}, probably searched with the wrong language. Delete .nfo and add manually in the correct language.').format( self.showDir, sickchill.indexer.name(self.indexer)) logger.warning(error_string) ui.notifications.error(_('Unable to add show'), error_string) self._finish_early() return except Exception as error: error_string = 'Unable to look up the show in {0} on {1} using ID {2}, not using the NFO. Delete .nfo and try adding manually again.'.format( self.showDir, sickchill.indexer.name(self.indexer), self.indexer_id) logger.exception('{0}: {1}'.format(error_string, error)) ui.notifications.error(_('Unable to add show'), error_string) if settings.USE_TRAKT: trakt_api = TraktAPI(settings.SSL_VERIFY, settings.TRAKT_TIMEOUT) title = self.showDir.split('/')[-1] data = { 'shows': [ { 'title': title, 'ids': {sickchill.indexer.slug(self.indexer): self.indexer_id} } ] } trakt_api.traktRequest('sync/watchlist/remove', data, method='POST') self._finish_early() return try: try: newShow = TVShow(self.indexer, self.indexer_id, self.lang) except MultipleShowObjectsException as error: # If we have the show in our list, but the location is wrong, lets fix it and refresh! existing_show = Show.find(settings.showList, self.indexer_id) # noinspection PyProtectedMember if existing_show and not os.path.isdir(existing_show._location): newShow = existing_show else: raise error newShow.loadFromIndexer() self.show = newShow # set up initial values self.show.location = self.showDir self.show.subtitles = self.subtitles if self.subtitles is not None else settings.SUBTITLES_DEFAULT self.show.subtitles_sr_metadata = self.subtitles_sr_metadata self.show.quality = self.quality if self.quality else settings.QUALITY_DEFAULT self.show.season_folders = self.season_folders if self.season_folders is not None else settings.SEASON_FOLDERS_DEFAULT self.show.anime = self.anime if self.anime is not None else settings.ANIME_DEFAULT self.show.scene = self.scene if self.scene is not None else settings.SCENE_DEFAULT self.show.paused = self.paused if self.paused is not None else False # set up default new/missing episode status logger.info(_('Setting all episodes to the specified default status: {0}') .format(self.show.default_ep_status)) self.show.default_ep_status = self.default_status if self.show.anime: self.show.release_groups = BlackAndWhiteList(self.show.indexerid) if self.blacklist: self.show.release_groups.set_black_keywords(self.blacklist) if self.whitelist: self.show.release_groups.set_white_keywords(self.whitelist) # # be smart-ish about this # if self.show.genre and 'talk show' in self.show.genre.lower(): # self.show.air_by_date = 1 # if self.show.genre and 'documentary' in self.show.genre.lower(): # self.show.air_by_date = 0 # if self.show.classification and 'sports' in self.show.classification.lower(): # self.show.sports = 1 except Exception as error: error_string = 'Unable to add {0} due to an error with {1}'.format( self.show.name if self.show else 'show', sickchill.indexer.name(self.indexer)) logger.exception('{0}: {1}'.format(error_string, error)) logger.exception('Error trying to add show: {0}'.format(error)) logger.debug(traceback.format_exc()) ui.notifications.error(_('Unable to add show'), error_string) self._finish_early() return except MultipleShowObjectsException: error_string = _('The show in {0} is already in your show list, skipping').format(self.showDir) logger.warning(error_string) ui.notifications.error(_('Show skipped'), error_string) self._finish_early() return self.show.load_imdb_imfo() try: self.show.saveToDB() except Exception as error: logger.exception('Error saving the show to the database: {0}'.format(error)) logger.debug(traceback.format_exc()) self._finish_early() raise # add it to the show list if not Show.find(settings.showList, self.indexer_id): settings.showList.append(self.show) try: self.show.loadEpisodesFromIndexer() except Exception as error: logger.exception('Error with {0}, not creating episode list: {1}'.format(self.show.idxr.name, error)) logger.debug(traceback.format_exc()) # update internal name cache name_cache.build_name_cache(self.show) try: self.show.loadEpisodesFromDir() except Exception as error: logger.exception('Error searching dir for episodes: {0}'.format(error)) logger.debug(traceback.format_exc()) # if they set default ep status to WANTED then run the backlog to search for episodes # FIXME: This needs to be a backlog queue item!!! if self.show.default_ep_status == WANTED: logger.info('Launching backlog for this show since its episodes are WANTED') settings.backlogSearchScheduler.action.searchBacklog([self.show]) self.show.writeMetadata() self.show.updateMetadata() self.show.populateCache() self.show.flushEpisodes() if settings.USE_TRAKT: # if there are specific episodes that need to be added by trakt settings.traktCheckerScheduler.action.manageNewShow(self.show) # add show to trakt.tv library if settings.TRAKT_SYNC: settings.traktCheckerScheduler.action.addShowToTraktLibrary(self.show) if settings.TRAKT_SYNC_WATCHLIST: logger.info('update watchlist') notifiers.trakt_notifier.update_watchlist(show_obj=self.show) # Load XEM data to DB for show scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer, force=True) # check if show has XEM mapping so we can determine if searches should go by scene numbering or indexer numbering. if not self.scene and scene_numbering.get_xem_numbering_for_show(self.show.indexerid, self.show.indexer): self.show.scene = 1 # After initial add, set to default_status_after. self.show.default_ep_status = self.default_status_after super(QueueItemAdd, self).finish() self.finish()
def test_get_episode(): """ Test get episodes """ show = TVShow(1, 1, "en") show.name = "show name" show.network = "cbs" show.genre = ["crime"] show.runtime = 40 show.status = "Ended" show.default_ep_status = "5" show.airs = "monday" show.startyear = 1987 show.saveToDB() settings.showList = [show]