Beispiel #1
0
 def __init__(self, something):
     super(UnicodeTests, self).__init__(something)
     self.setUp()
     self.show = TVShow(1, 1, 'en')
     self.show.name = "The Big Bang Theory"
     self.show.saveToDB()
     self.show.loadFromDB(skipNFO=True)
    def _test_allPossibleShowNames(self, name, indexerid=0, expected=[]):
        s = TVShow(1, indexerid)
        s.name = name
        s.saveToDB()
        s.loadFromDB(skipNFO=True)

        result = show_names.allPossibleShowNames(s)
        self.assertTrue(
            len(set(expected).intersection(set(result))) == len(expected))
Beispiel #3
0
    def test_process(self):
        show = TVShow(1, 3)
        show.name = SHOWNAME
        show.location = SHOWDIR
        show.saveToDB()
        show.loadFromDB(skipNFO=True)
        sickrage.srCore.SHOWLIST = [show]
        ep = TVEpisode(show, SEASON, EPISODE)
        ep.name = "some ep name"
        ep.saveToDB()

        sickrage.srCore.NAMECACHE.addNameToCache('show name', 3)
        self.pp = PostProcessor(FILEPATH, process_method='move')
        self.assertTrue(self.pp.process)
Beispiel #4
0
    def loadFromDB(self):
        """
        Populates the showList with shows from the database
        """

        sqlResults = main_db.MainDB().select("SELECT * FROM tv_shows")

        for sqlShow in sqlResults:
            try:
                curShow = TVShow(int(sqlShow[b"indexer"]),
                                 int(sqlShow[b"indexer_id"]))
                curShow.saveToDB()
                curShow.loadFromDB(skipNFO=True)
                sickrage.srCore.SHOWLIST.append(curShow)
            except Exception as e:
                print "There was an error creating the show"
Beispiel #5
0
    def load_shows(self):
        """
        Populates the showlist with shows from the database
        """

        for sqlShow in main_db.MainDB().select("SELECT * FROM tv_shows"):
            try:
                curshow = TVShow(int(sqlShow[b"indexer"]), int(sqlShow[b"indexer_id"]))
                sickrage.srLogger.debug("Loading data for show: [{}]".format(curshow.name))
                self.NAMECACHE.buildNameCache(curshow)
                curshow.nextEpisode()
                self.SHOWLIST += [curshow]
            except Exception as e:
                sickrage.srLogger.error(
                    "There was an error creating the show in {}: {}".format(sqlShow[b"location"], e.message))
                sickrage.srLogger.debug(traceback.format_exc())
                continue
    def test_isGoodName(self):
        listOfcases = [
            ('Show.Name.S01E02.Test-Test', 'Show/Name'),
            ('Show.Name.S01E02.Test-Test', 'Show. Name'),
            ('Show.Name.S01E02.Test-Test', 'Show- Name'),
            ('Show.Name.Part.IV.Test-Test', 'Show Name'),
            ('Show.Name.S01.Test-Test', 'Show Name'),
            ('Show.Name.E02.Test-Test', 'Show: Name'),
            ('Show Name Season 2 Test', 'Show: Name'),
        ]

        for testCase in listOfcases:
            scene_name, show_name = testCase
            s = TVShow(1, 0)
            s.name = show_name
            s.saveToDB()
            s.loadFromDB(skipNFO=True)
            self._test_isGoodName(scene_name, s)
            del s
Beispiel #7
0
    def test(self):
        global searchItems
        searchItems = curData[b"i"]
        show = TVShow(1, tvdbdid)
        show.name = show_name
        show.quality = curData[b"q"]
        show.saveToDB()
        show.loadFromDB(skipNFO=True)
        sickrage.srCore.SHOWLIST.append(show)
        episode = None

        for epNumber in curData[b"e"]:
            episode = TVEpisode(show, curData[b"s"], epNumber)
            episode.status = WANTED
            episode.saveToDB()

        bestResult = searchProviders(show, episode.episode, forceSearch)
        if not bestResult:
            self.assertEqual(curData[b"b"], bestResult)
        self.assertEqual(
            curData[b"b"],
            bestResult.name)  # first is expected, second is choosen one
Beispiel #8
0
    def run(self):
        ShowQueueItem.run(self)

        sickrage.srLogger.info("Started adding show {}".format(self.showDir))

        index_name = sickrage.srCore.INDEXER_API(self.indexer).name

        # update internal name cache
        sickrage.srCore.NAMECACHE.buildNameCache()

        # make sure the Indexer IDs are valid
        try:

            lINDEXER_API_PARMS = sickrage.srCore.INDEXER_API(self.indexer).api_params.copy()
            if self.lang:
                lINDEXER_API_PARMS[b'language'] = self.lang

            sickrage.srLogger.info("{}: {}".format(index_name, repr(lINDEXER_API_PARMS)))

            t = sickrage.srCore.INDEXER_API(self.indexer).indexer(**lINDEXER_API_PARMS)
            s = t[self.indexer_id]

            # 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:
                sickrage.srLogger.error(
                    "Show in {} has no name on {}, probably the wrong language used to search with".format(self.showDir,
                                                                                                           index_name))
                notifications.error("Unable to add show",
                                    "Show in {} has no name on {}, probably the wrong language. Delete .nfo and add manually in the correct language".format(
                                        self.showDir, index_name))
                return self._finishEarly()

            # if the show has no episodes/seasons
            if not s:
                sickrage.srLogger.error("Show " + str(s[b'seriesname']) + " is on " + str(
                    sickrage.srCore.INDEXER_API(self.indexer).name) + " but contains no season/episode data.")
                notifications.error("Unable to add show",
                                    "Show " + str(s[b'seriesname']) + " is on " + str(sickrage.srCore.INDEXER_API(
                                        self.indexer).name) + " but contains no season/episode data.")
                return self._finishEarly()
        except Exception as e:
            sickrage.srLogger.error(
                "{}: Error while loading information from indexer {}. Error: {}".format(self.indexer_id, index_name,
                                                                                        e.message))

            notifications.error(
                "Unable to add show",
                "Unable to look up the show in {} on {} using ID {}, not using the NFO. Delete .nfo and try adding manually again.".format(
                    self.showDir, index_name, self.indexer_id)
            )

            if sickrage.srConfig.USE_TRAKT:

                trakt_id = sickrage.srCore.INDEXER_API(self.indexer).config[b'trakt_id']
                trakt_api = TraktAPI(sickrage.srConfig.SSL_VERIFY, sickrage.srConfig.TRAKT_TIMEOUT)

                title = self.showDir.split("/")[-1]
                data = {
                    'shows': [
                        {
                            'title': title,
                            'ids': {}
                        }
                    ]
                }
                if trakt_id == 'tvdb_id':
                    data[b'shows'][0][b'ids'][b'tvdb'] = self.indexer_id
                else:
                    data[b'shows'][0][b'ids'][b'tvrage'] = self.indexer_id

                trakt_api.traktRequest("sync/watchlist/remove", data, method='POST')

            return self._finishEarly()

        try:
            self.show = TVShow(self.indexer, self.indexer_id, self.lang)
            self.show.loadFromIndexer()

            # set up initial values
            self.show.location = self.showDir
            self.show.subtitles = self.subtitles or sickrage.srConfig.SUBTITLES_DEFAULT
            self.show.quality = self.quality or sickrage.srConfig.QUALITY_DEFAULT
            self.show.flatten_folders = self.flatten_folders or sickrage.srConfig.FLATTEN_FOLDERS_DEFAULT
            self.show.anime = self.anime or sickrage.srConfig.ANIME_DEFAULT
            self.show.scene = self.scene or sickrage.srConfig.SCENE_DEFAULT
            self.show.archive_firstmatch = self.archive or sickrage.srConfig.ARCHIVE_DEFAULT
            self.show.paused = self.paused or False

            # set up default new/missing episode status
            sickrage.srLogger.info(
                "Setting all current episodes to the specified default status: " + str(self.default_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 smartish 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 indexer_exception as e:
            sickrage.srLogger.error(
                "Unable to add show due to an error with " + sickrage.srCore.INDEXER_API(
                    self.indexer).name + ": {}".format(e.message))
            if self.show:
                notifications.error(
                    "Unable to add " + str(self.show.name) + " due to an error with " + sickrage.srCore.INDEXER_API(
                        self.indexer).name + "")
            else:
                notifications.error(
                    "Unable to add show due to an error with " + sickrage.srCore.INDEXER_API(self.indexer).name + "")
            return self._finishEarly()

        except MultipleShowObjectsException:
            sickrage.srLogger.warning("The show in " + self.showDir + " is already in your show list, skipping")
            notifications.error('Show skipped', "The show in " + self.showDir + " is already in your show list")
            return self._finishEarly()

        except Exception as e:
            sickrage.srLogger.error("Error trying to add show: {}".format(e.message))
            sickrage.srLogger.debug(traceback.format_exc())
            raise self._finishEarly()

        sickrage.srLogger.debug("Retrieving show info from TMDb")
        try:
            self.show.loadTMDbInfo()
        except Exception as e:
            sickrage.srLogger.error("Error loading TMDb info: {}".format(e.message))
            try:
                sickrage.srLogger.debug("Attempting to retrieve show info from IMDb")
                self.show.loadIMDbInfo()
            except Exception as e:
                sickrage.srLogger.error("Error loading IMDb info: {}".format(e.message))

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

        # check if show has XEM mapping so we can determin if searches should go by scene numbering or indexer numbering.
        if not self.scene and get_xem_numbering_for_show(self.show.indexerid, self.show.indexer):
            self.show.scene = 1

        try:
            self.show.saveToDB()
        except Exception as e:
            sickrage.srLogger.error("Error saving the show to the database: {}".format(e.message))
            sickrage.srLogger.debug(traceback.format_exc())
            raise self._finishEarly()

        # add it to the show list
        sickrage.srCore.SHOWLIST.append(self.show)

        try:
            self.show.loadEpisodesFromIndexer()
        except Exception as e:
            sickrage.srLogger.error(
                "Error with " + sickrage.srCore.INDEXER_API(
                    self.show.indexer).name + ", not creating episode list: {}".format(e.message))
            sickrage.srLogger.debug(traceback.format_exc())

        try:
            self.show.loadEpisodesFromDir()
        except Exception as e:
            sickrage.srLogger.error("Error searching dir for episodes: {}".format(e.message))
            sickrage.srLogger.debug(traceback.format_exc())

        # if they set default ep status to WANTED then run the backlog to search for episodes
        if self.show.default_ep_status == WANTED:
            sickrage.srLogger.info("Launching backlog for this show since its episodes are WANTED")
            sickrage.srCore.BACKLOGSEARCHER.searchBacklog([self.show])

        self.show.writeMetadata()
        self.show.updateMetadata()
        self.show.populateCache()

        if sickrage.srConfig.USE_TRAKT:
            # if there are specific episodes that need to be added by trakt
            sickrage.srCore.TRAKTSEARCHER.manageNewShow(self.show)

            # add show to trakt.tv library
            if sickrage.srConfig.TRAKT_SYNC:
                sickrage.srCore.TRAKTSEARCHER.addShowToTraktLibrary(self.show)

            if sickrage.srConfig.TRAKT_SYNC_WATCHLIST:
                sickrage.srLogger.info("update watchlist")
                sickrage.srCore.NOTIFIERS.trakt_notifier.update_watchlist(show_obj=self.show)

        # After initial add, set to default_status_after.
        sickrage.srLogger.info(
            "Setting all future episodes to the specified default status: " + str(self.default_status_after))
        self.show.default_ep_status = self.default_status_after

        self.show.saveToDB()

        sickrage.srLogger.info("Finished adding show {}".format(self.showDir))
Beispiel #9
0
    def test(self):
        show = TVShow(1, int(curData[b"tvdbid"]))
        show.name = name
        show.quality = ANY | Quality.UNKNOWN | Quality.RAWHDTV
        show.saveToDB()
        show.loadFromDB(skipNFO=True)

        sickrage.srCore.SHOWLIST.append(show)

        for epNumber in curData[b"e"]:
            episode = TVEpisode(show, curData[b"s"], epNumber)
            episode.status = WANTED

            # We arent updating scene numbers, so fake it here
            episode.scene_season = curData[b"s"]
            episode.scene_episode = epNumber

            episode.saveToDB()

            provider.show = show
            season_strings = provider._get_season_search_strings(episode)
            episode_strings = provider._get_episode_search_strings(episode)

            fail = False
            for cur_string in season_strings, episode_strings:
                if not all([isinstance(cur_string, list), isinstance(cur_string[0], dict)]):
                    print(" %s is using a wrong string format!" % provider.name)
                    print(cur_string)
                    fail = True
                    continue

            if fail:
                continue

            try:
                assert (season_strings == curData[b"s_strings"])
                assert (episode_strings == curData[b"e_strings"])
            except AssertionError:
                continue

            search_strings = episode_strings[0]
            # search_strings.update(season_strings[0])
            # search_strings.update({"RSS":['']})

            # print search_strings

            if not provider.public:
                continue

            items = provider._doSearch(search_strings)
            if not items:
                print("No results from provider?")
                continue

            title, url = provider._get_title_and_url(items[0])
            for word in show.name.split(" "):
                if not word.lower() in title.lower():
                    print("Show name not in title: %s. URL: %s" % (title, url))
                    continue

            if not url:
                print("url is empty")
                continue

            quality = provider.getQuality(items[0])
            size = provider._get_size(items[0])
            if not show.quality & quality:
                print("Quality not in ANY, %r" % quality)
                continue
Beispiel #10
0
 def __init__(self, something):
     super(BasicTests, self).__init__(something)
     super(BasicTests, self).setUp()
     self.show = TVShow(1, 1, 'en')
     self.show.saveToDB()