Exemple #1
0
    def get_show(self, name, tryIndexers=False):
        if not sickrage.srCore.SHOWLIST:
            return

        showObj = None
        fromCache = False

        if not name:
            return showObj

        try:
            # check cache for show
            cache = sickrage.srCore.NAMECACHE.retrieveNameFromCache(name)
            if cache:
                fromCache = True
                showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(cache))

            # try indexers
            if not showObj and tryIndexers:
                showObj = findCertainShow(sickrage.srCore.SHOWLIST,
                                          searchIndexerForShowID(full_sanitizeSceneName(name), ui=ShowListUI)[2])

            # try scene exceptions
            if not showObj:
                ShowID = get_scene_exception_by_name(name)[0]
                if ShowID:
                    showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(ShowID))

            # add show to cache
            if showObj and not fromCache:
                sickrage.srCore.NAMECACHE.addNameToCache(name, showObj.indexerid)
        except Exception as e:
            sickrage.srLogger.debug("Error when attempting to find show: %s in SiCKRAGE. Error: %r " % (name, repr(e)))

        return showObj
Exemple #2
0
    def findPropers(self, search_date=datetime.today()):

        results = []

        sqlResults = main_db.MainDB().select(
            "SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e"
            + " INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)"
            + " WHERE e.airdate >= "
            + str(search_date.toordinal())
            + " AND e.status IN ("
            + ",".join([str(x) for x in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST])
            + ")"
        )

        for sqlshow in sqlResults or []:
            show = findCertainShow(sickrage.srCore.SHOWLIST, int(sqlshow[b"showid"]))
            if show:
                curEp = show.getEpisode(int(sqlshow[b"season"]), int(sqlshow[b"episode"]))
                for term in self.proper_strings:
                    searchString = self._get_episode_search_strings(curEp, add_string=term)

                    for item in self._doSearch(searchString[0]):
                        title, url = self._get_title_and_url(item)
                        results.append(Proper(title, url, datetime.today(), show))

        return results
Exemple #3
0
    def findPropers(self, search_date=datetime.today()):
        results = []

        sqlResults = main_db.MainDB().select(
            "SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e"
            + " INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)"
            + " WHERE e.airdate >= "
            + str(search_date.toordinal())
            + " AND (e.status IN ("
            + ",".join([str(x) for x in Quality.DOWNLOADED])
            + ")"
            + " OR (e.status IN ("
            + ",".join([str(x) for x in Quality.SNATCHED])
            + ")))"
        )

        if not sqlResults:
            return []

        for sqlshow in sqlResults:
            self.show = findCertainShow(sickrage.srCore.SHOWLIST, int(sqlshow[b"showid"]))
            if self.show:
                curEp = self.show.getEpisode(int(sqlshow[b"season"]), int(sqlshow[b"episode"]))
                searchStrings = self._get_episode_search_strings(curEp, add_string="PROPER|REPACK")
                for searchString in searchStrings:
                    for item in self._doSearch(searchString):
                        title, url = self._get_title_and_url(item)
                        if re.match(r".*(REPACK|PROPER).*", title, re.I):
                            results.append(Proper(title, url, datetime.today(), self.show))

        return results
Exemple #4
0
    def addDefaultShow(indexer, indexer_id, name, status):
        """
        Adds a new show with the default settings
        """
        if not findCertainShow(sickrage.srCore.SHOWLIST, int(indexer_id)):
            sickrage.srLogger.info("Adding show " + str(indexer_id))
            root_dirs = sickrage.srConfig.ROOT_DIRS.split('|')

            try:
                location = root_dirs[int(root_dirs[0]) + 1]
            except Exception:
                location = None

            if location:
                showPath = os.path.join(location, sanitizeFileName(name))
                dir_exists = makeDir(showPath)

                if not dir_exists:
                    sickrage.srLogger.warning("Unable to create the folder %s , can't add the show" % showPath)
                    return
                else:
                    chmodAsParent(showPath)

                sickrage.srCore.SHOWQUEUE.addShow(int(indexer), int(indexer_id), showPath,
                                              default_status=status,
                                              quality=int(sickrage.srConfig.QUALITY_DEFAULT),
                                              flatten_folders=int(sickrage.srConfig.FLATTEN_FOLDERS_DEFAULT),
                                              paused=sickrage.srConfig.TRAKT_START_PAUSED,
                                              default_status_after=status,
                                              archive=sickrage.srConfig.ARCHIVE_DEFAULT)
            else:
                sickrage.srLogger.warning("There was an error creating the show, no root directory setting found")
                return
Exemple #5
0
def get_scene_numbering(indexer_id,
                        indexer,
                        season,
                        episode,
                        fallback_to_xem=True):
    """
    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
    returns the TVDB numbering.
    (so the return values will always be set)

    :param indexer_id: int
    :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
    :return: (int, int) a tuple with (season, episode)
    """
    if indexer_id is None or season is None or episode is None:
        return season, episode

    showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(indexer_id))
    if showObj and not showObj.is_scene:
        return season, episode

    result = find_scene_numbering(int(indexer_id), int(indexer), season,
                                  episode)
    if result:
        return result
    else:
        if fallback_to_xem:
            xem_result = find_xem_numbering(int(indexer_id), int(indexer),
                                            season, episode)
            if xem_result:
                return xem_result
        return season, episode
Exemple #6
0
    def updateShows(self):
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::START - Trakt Show Watchlist")

        if not len(self.ShowWatchlist):
            sickrage.srLogger.debug("No shows found in your watchlist, aborting watchlist update")
            return

        indexer = int(sickrage.srConfig.TRAKT_DEFAULT_INDEXER)
        trakt_id = sickrage.srCore.INDEXER_API(indexer).config[b'trakt_id']

        for show_el in self.ShowWatchlist[trakt_id]:
            indexer_id = int(str(show_el))
            show = self.ShowWatchlist[trakt_id][show_el]

            # LOGGER.debug(u"Checking Show: %s %s %s" % (trakt_id, indexer_id, show[b'title']))
            if int(sickrage.srConfig.TRAKT_METHOD_ADD) != 2:
                self.addDefaultShow(indexer, indexer_id, show[b'title'], SKIPPED)
            else:
                self.addDefaultShow(indexer, indexer_id, show[b'title'], WANTED)

            if int(sickrage.srConfig.TRAKT_METHOD_ADD) == 1:
                newShow = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)

                if newShow is not None:
                    setEpisodeToWanted(newShow, 1, 1)
                else:
                    self.todoWanted.append((indexer_id, 1, 1))
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::FINISH - Trakt Show Watchlist")
Exemple #7
0
    def addDefaultShow(indexer, indexer_id, name, status):
        """
        Adds a new show with the default settings
        """
        if not findCertainShow(sickrage.srCore.SHOWLIST, int(indexer_id)):
            sickrage.srLogger.info("Adding show " + str(indexer_id))
            root_dirs = sickrage.srConfig.ROOT_DIRS.split('|')

            try:
                location = root_dirs[int(root_dirs[0]) + 1]
            except Exception:
                location = None

            if location:
                showPath = os.path.join(location, sanitizeFileName(name))
                dir_exists = makeDir(showPath)

                if not dir_exists:
                    sickrage.srLogger.warning("Unable to create the folder %s , can't add the show" % showPath)
                    return
                else:
                    chmodAsParent(showPath)

                sickrage.srCore.SHOWQUEUE.addShow(int(indexer), int(indexer_id), showPath,
                                              default_status=status,
                                              quality=int(sickrage.srConfig.QUALITY_DEFAULT),
                                              flatten_folders=int(sickrage.srConfig.FLATTEN_FOLDERS_DEFAULT),
                                              paused=sickrage.srConfig.TRAKT_START_PAUSED,
                                              default_status_after=status,
                                              archive=sickrage.srConfig.ARCHIVE_DEFAULT)
            else:
                sickrage.srLogger.warning("There was an error creating the show, no root directory setting found")
                return
Exemple #8
0
    def updateShows(self):
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::START - Trakt Show Watchlist")

        if not len(self.ShowWatchlist):
            sickrage.srLogger.debug("No shows found in your watchlist, aborting watchlist update")
            return

        indexer = int(sickrage.srConfig.TRAKT_DEFAULT_INDEXER)
        trakt_id = sickrage.srCore.INDEXER_API(indexer).config[b'trakt_id']

        for show_el in self.ShowWatchlist[trakt_id]:
            indexer_id = int(str(show_el))
            show = self.ShowWatchlist[trakt_id][show_el]

            # LOGGER.debug(u"Checking Show: %s %s %s" % (trakt_id, indexer_id, show[b'title']))
            if int(sickrage.srConfig.TRAKT_METHOD_ADD) != 2:
                self.addDefaultShow(indexer, indexer_id, show[b'title'], SKIPPED)
            else:
                self.addDefaultShow(indexer, indexer_id, show[b'title'], WANTED)

            if int(sickrage.srConfig.TRAKT_METHOD_ADD) == 1:
                newShow = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)

                if newShow is not None:
                    setEpisodeToWanted(newShow, 1, 1)
                else:
                    self.todoWanted.append((indexer_id, 1, 1))
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::FINISH - Trakt Show Watchlist")
Exemple #9
0
def get_scene_absolute_numbering(indexer_id, indexer, absolute_number, fallback_to_xem=True):
    """
    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
    returns the TVDB numbering.
    (so the return values will always be set)

    :param indexer_id: int
    ;param absolute_number: int
    :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)
    """
    if indexer_id is None or absolute_number is None:
        return absolute_number

    indexer_id = int(indexer_id)
    indexer = int(indexer)

    showObj = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)
    if showObj and not showObj.is_scene:
        return absolute_number

    result = find_scene_absolute_numbering(indexer_id, indexer, absolute_number)
    if result:
        return result
    else:
        if fallback_to_xem:
            xem_result = find_xem_absolute_numbering(indexer_id, indexer, absolute_number)
            if xem_result:
                return xem_result
        return absolute_number
Exemple #10
0
def set_scene_numbering(indexer_id, indexer, season=None, episode=None, absolute_number=None, sceneSeason=None,
                        sceneEpisode=None, sceneAbsolute=None):
    """
    Set scene numbering for a season/episode.
    To clear the scene numbering, leave both sceneSeason and sceneEpisode as None.
    """
    if indexer_id is None:
        return

    indexer_id = int(indexer_id)
    indexer = int(indexer)

    if season and episode:
        main_db.MainDB().action(
            "INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, season, episode) VALUES (?,?,?,?)",
            [indexer, indexer_id, season, episode])

        main_db.MainDB().action(
            "UPDATE scene_numbering SET scene_season = ?, scene_episode = ? WHERE indexer = ? AND indexer_id = ? AND season = ? AND episode = ?",
            [sceneSeason, sceneEpisode, indexer, indexer_id, season, episode])
    elif absolute_number:
        main_db.MainDB().action(
            "INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, absolute_number) VALUES (?,?,?)",
            [indexer, indexer_id, absolute_number])

        main_db.MainDB().action(
            "UPDATE scene_numbering SET scene_absolute_number = ? WHERE indexer = ? AND indexer_id = ? AND absolute_number = ?",
            [sceneAbsolute, indexer, indexer_id, absolute_number])

    # Reload data from DB so that cache and db are in sync
    show = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)
    show.flushEpisodes()
Exemple #11
0
    def get_show(self):
        """
        :return: The show object associated with ``self.indexer_id`` or ``None``
        """

        try:
            return findCertainShow(sickrage.srCore.SHOWLIST, self.indexer_id)
        except MultipleShowObjectsException:
            return None
Exemple #12
0
    def _addCacheEntry(self, name, url, parse_result=None, indexer_id=0):

        # check if we passed in a parsed result or should we try and create one
        if not parse_result:

            # create showObj from indexer_id if available
            showObj = None
            if indexer_id:
                showObj = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)

            try:
                myParser = NameParser(showObj=showObj)
                parse_result = myParser.parse(name)
            except InvalidNameException:
                sickrage.srLogger.debug("Unable to parse the filename " +
                                        name + " into a valid episode")
                return None
            except InvalidShowException:
                sickrage.srLogger.debug("Unable to parse the filename " +
                                        name + " into a valid show")
                return None

            if not parse_result or not parse_result.series_name:
                return None

        # if we made it this far then lets add the parsed result to cache for usager later on
        season = parse_result.season_number if parse_result.season_number else 1
        episodes = parse_result.episode_numbers

        if season and episodes:
            # store episodes as a seperated string
            episodeText = "|" + "|".join(map(str, episodes)) + "|"

            # get the current timestamp
            curTimestamp = int(time.mktime(datetime.today().timetuple()))

            # get quality of release
            quality = parse_result.quality

            # get release group
            release_group = parse_result.release_group

            # get version
            version = parse_result.version

            sickrage.srLogger.debug("Added RSS item: [" + name +
                                    "] to cache: [" + self.providerID + "]")

            return [
                "INSERT OR IGNORE INTO [" + self.providerID +
                "] (name, season, episodes, indexerid, url, time, quality, release_group, version) VALUES (?,?,?,?,?,?,?,?,?)",
                [
                    name, season, episodeText, parse_result.show.indexerid,
                    url, curTimestamp, quality, release_group, version
                ]
            ]
Exemple #13
0
    def _addCacheEntry(self, name, url, parse_result=None, indexer_id=0):

        # check if we passed in a parsed result or should we try and create one
        if not parse_result:

            # create showObj from indexer_id if available
            showObj = None
            if indexer_id:
                showObj = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)

            try:
                myParser = NameParser(showObj=showObj)
                parse_result = myParser.parse(name)
            except InvalidNameException:
                sickrage.srLogger.debug("Unable to parse the filename " + name + " into a valid episode")
                return None
            except InvalidShowException:
                sickrage.srLogger.debug("Unable to parse the filename " + name + " into a valid show")
                return None

            if not parse_result or not parse_result.series_name:
                return None

        # if we made it this far then lets add the parsed result to cache for usager later on
        season = parse_result.season_number if parse_result.season_number else 1
        episodes = parse_result.episode_numbers

        if season and episodes:
            # store episodes as a seperated string
            episodeText = "|" + "|".join(map(str, episodes)) + "|"

            # get the current timestamp
            curTimestamp = int(time.mktime(datetime.today().timetuple()))

            # get quality of release
            quality = parse_result.quality

            # get release group
            release_group = parse_result.release_group

            # get version
            version = parse_result.version

            sickrage.srLogger.debug("Added RSS item: [" + name + "] to cache: [" + self.providerID + "]")

            return [
                "INSERT OR IGNORE INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality, release_group, version) VALUES (?,?,?,?,?,?,?,?,?)",
                [name, season, episodeText, parse_result.show.indexerid, url, curTimestamp, quality, release_group,
                 version]]
Exemple #14
0
    def updateEpisodes(self):
        """
        Sets episodes to wanted that are in trakt watchlist
        """
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::START - Trakt Episode Watchlist")

        if not len(self.EpisodeWatchlist):
            sickrage.srLogger.debug("No episode found in your watchlist, aborting episode update")
            return

        managed_show = []

        indexer = int(sickrage.srConfig.TRAKT_DEFAULT_INDEXER)
        trakt_id = sickrage.srCore.INDEXER_API(indexer).config[b'trakt_id']

        for show_el in self.EpisodeWatchlist[trakt_id]:
            indexer_id = int(show_el)
            show = self.EpisodeWatchlist[trakt_id][show_el]

            newShow = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)

            try:
                if newShow is None:
                    if indexer_id not in managed_show:
                        self.addDefaultShow(indexer, indexer_id, show[b'title'], SKIPPED)
                        managed_show.append(indexer_id)

                        for season_el in show[b'seasons']:
                            season = int(season_el)

                            for episode_el in show[b'seasons'][season_el][b'episodes']:
                                self.todoWanted.append((indexer_id, season, int(episode_el)))
                else:
                    if newShow.indexer == indexer:
                        for season_el in show[b'seasons']:
                            season = int(season_el)

                            for episode_el in show[b'seasons'][season_el][b'episodes']:
                                setEpisodeToWanted(newShow, season, int(episode_el))
            except TypeError:
                sickrage.srLogger.debug("Could not parse the output from trakt for %s " % show[b"title"])
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::FINISH - Trakt Episode Watchlist")
Exemple #15
0
    def updateEpisodes(self):
        """
        Sets episodes to wanted that are in trakt watchlist
        """
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::START - Trakt Episode Watchlist")

        if not len(self.EpisodeWatchlist):
            sickrage.srLogger.debug("No episode found in your watchlist, aborting episode update")
            return

        managed_show = []

        indexer = int(sickrage.srConfig.TRAKT_DEFAULT_INDEXER)
        trakt_id = sickrage.srCore.INDEXER_API(indexer).config[b'trakt_id']

        for show_el in self.EpisodeWatchlist[trakt_id]:
            indexer_id = int(show_el)
            show = self.EpisodeWatchlist[trakt_id][show_el]

            newShow = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)

            try:
                if newShow is None:
                    if indexer_id not in managed_show:
                        self.addDefaultShow(indexer, indexer_id, show[b'title'], SKIPPED)
                        managed_show.append(indexer_id)

                        for season_el in show[b'seasons']:
                            season = int(season_el)

                            for episode_el in show[b'seasons'][season_el][b'episodes']:
                                self.todoWanted.append((indexer_id, season, int(episode_el)))
                else:
                    if newShow.indexer == indexer:
                        for season_el in show[b'seasons']:
                            season = int(season_el)

                            for episode_el in show[b'seasons'][season_el][b'episodes']:
                                setEpisodeToWanted(newShow, season, int(episode_el))
            except TypeError:
                sickrage.srLogger.debug("Could not parse the output from trakt for %s " % show[b"title"])
        sickrage.srLogger.debug("SHOW_WATCHLIST::CHECK::FINISH - Trakt Episode Watchlist")
Exemple #16
0
def set_scene_numbering(indexer_id,
                        indexer,
                        season=None,
                        episode=None,
                        absolute_number=None,
                        sceneSeason=None,
                        sceneEpisode=None,
                        sceneAbsolute=None):
    """
    Set scene numbering for a season/episode.
    To clear the scene numbering, leave both sceneSeason and sceneEpisode as None.
    """
    if indexer_id is None:
        return

    indexer_id = int(indexer_id)
    indexer = int(indexer)

    if season and episode:
        main_db.MainDB().action(
            "INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, season, episode) VALUES (?,?,?,?)",
            [indexer, indexer_id, season, episode])

        main_db.MainDB().action(
            "UPDATE scene_numbering SET scene_season = ?, scene_episode = ? WHERE indexer = ? AND indexer_id = ? AND season = ? AND episode = ?",
            [sceneSeason, sceneEpisode, indexer, indexer_id, season, episode])
    elif absolute_number:
        main_db.MainDB().action(
            "INSERT OR IGNORE INTO scene_numbering (indexer, indexer_id, absolute_number) VALUES (?,?,?)",
            [indexer, indexer_id, absolute_number])

        main_db.MainDB().action(
            "UPDATE scene_numbering SET scene_absolute_number = ? WHERE indexer = ? AND indexer_id = ? AND absolute_number = ?",
            [sceneAbsolute, indexer, indexer_id, absolute_number])

    # Reload data from DB so that cache and db are in sync
    show = findCertainShow(sickrage.srCore.SHOWLIST, indexer_id)
    show.flushEpisodes()
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

        if len(getEnabledServiceList()) < 1:
            sickrage.srLogger.warning(
                'Not enough services selected. At least 1 service is required to search subtitles in the background'
            )
            return

        sickrage.srLogger.info('Checking for subtitles')

        # get episodes on which we want subtitles
        # criteria is:
        #  - show subtitles = 1
        #  - episode subtitles != config wanted languages or 'und' (depends on config multi)
        #  - search count < 2 and diff(airdate, now) > 1 week : now -> 1d
        #  - search count < 7 and diff(airdate, now) <= 1 week : now -> 4h -> 8h -> 16h -> 1d -> 1d -> 1d

        today = date.today().toordinal()

        # you have 5 minutes to understand that one. Good luck

        sqlResults = main_db.MainDB().select(
            'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.subtitles, '
            +
            'e.subtitles_searchcount AS searchcount, e.subtitles_lastsearch AS lastsearch, e.location, (? - e.airdate) AS airdate_daydiff '
            +
            'FROM tv_episodes AS e INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id) '
            + 'WHERE s.subtitles = 1 AND e.subtitles NOT LIKE (?) ' +
            'AND (e.subtitles_searchcount <= 2 OR (e.subtitles_searchcount <= 7 AND airdate_daydiff <= 7)) '
            + 'AND e.location != ""', [today, wantedLanguages(True)])

        if len(sqlResults) == 0:
            sickrage.srLogger.info('No subtitles to download')
            return

        rules = self._getRules()
        now = datetime.now()
        for epToSub in sqlResults:

            if not os.path.isfile(epToSub[b'location']):
                sickrage.srLogger.debug(
                    'Episode file does not exist, cannot download subtitles for episode %dx%d of show %s'
                    % (epToSub[b'season'], epToSub[b'episode'],
                       epToSub[b'show_name']))
                continue

            # http://bugs.python.org/issue7980#msg221094
            # I dont think this needs done here, but keeping to be safe
            datetime.strptime('20110101', '%Y%m%d')
            if ((epToSub[b'airdate_daydiff'] > 7
                 and epToSub[b'searchcount'] < 2 and now -
                 datetime.strptime(epToSub[b'lastsearch'], dateTimeFormat) >
                 timedelta(hours=rules['old'][epToSub[b'searchcount']])) or
                (epToSub[b'airdate_daydiff'] <= 7
                 and epToSub[b'searchcount'] < 7 and now -
                 datetime.strptime(epToSub[b'lastsearch'], dateTimeFormat) >
                 timedelta(hours=rules[b'new'][epToSub[b'searchcount']]))):

                sickrage.srLogger.debug(
                    'Downloading subtitles for episode %dx%d of show %s' %
                    (epToSub[b'season'], epToSub[b'episode'],
                     epToSub[b'show_name']))

                showObj = findCertainShow(sickrage.srCore.SHOWLIST,
                                          int(epToSub[b'showid']))
                if not showObj:
                    sickrage.srLogger.debug('Show not found')
                    return

                epObj = showObj.getEpisode(int(epToSub[b"season"]),
                                           int(epToSub[b"episode"]))
                if isinstance(epObj, str):
                    sickrage.srLogger.debug('Episode not found')
                    return

                existing_subtitles = epObj.subtitles

                try:
                    epObj.downloadSubtitles()
                except Exception as e:
                    sickrage.srLogger.debug('Unable to find subtitles')
                    sickrage.srLogger.debug(str(e))
                    return

                newSubtitles = frozenset(
                    epObj.subtitles).difference(existing_subtitles)
                if newSubtitles:
                    sickrage.srLogger.info(
                        'Downloaded subtitles for S%02dE%02d in %s' %
                        (epToSub[b"season"], epToSub[b"episode"],
                         ', '.join(newSubtitles)))

        self.amActive = False
Exemple #18
0
    def findNeededEpisodes(self,
                           episode,
                           manualSearch=False,
                           downCurQuality=False):
        sqlResults = []
        neededEps = {}
        cl = []

        if not episode:
            sqlResults = self._getDB().select("SELECT * FROM [" +
                                              self.providerID + "]")
        elif type(episode) != list:
            sqlResults = self._getDB().select(
                "SELECT * FROM [" + self.providerID +
                "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?", [
                    episode.show.indexerid, episode.season,
                    "%|" + str(episode.episode) + "|%"
                ])
        else:
            for epObj in episode:
                cl.append([
                    "SELECT * FROM [" + self.providerID +
                    "] WHERE indexerid = ? AND season = ? AND episodes LIKE ? AND quality IN ("
                    + ",".join([str(x) for x in epObj.wantedQuality]) + ")",
                    [
                        epObj.show.indexerid, epObj.season,
                        "%|" + str(epObj.episode) + "|%"
                    ]
                ])

            if len(cl) > 0:
                sqlResults = list(
                    itertools.chain(*self._getDB().mass_action(cl)))
                del cl  # cleanup

        # for each cache entry
        for curResult in sqlResults:
            # ignored/required words, and non-tv junk
            if not show_names.filterBadReleases(curResult[b"name"]):
                continue

            # get the show object, or if it's not one of our shows then ignore it
            showObj = findCertainShow(sickrage.srCore.SHOWLIST,
                                      int(curResult[b"indexerid"]))
            if not showObj:
                continue

            # skip if provider is anime only and show is not anime
            if self.provider.anime_only and not showObj.is_anime:
                sickrage.srLogger.debug("" + str(showObj.name) +
                                        " is not an anime, skiping")
                continue

            # get season and ep data (ignoring multi-eps for now)
            curSeason = int(curResult[b"season"])
            if curSeason == -1:
                continue

            curEp = curResult[b"episodes"].split("|")[1]
            if not curEp:
                continue

            curEp = int(curEp)

            curQuality = int(curResult[b"quality"])
            curReleaseGroup = curResult[b"release_group"]
            curVersion = curResult[b"version"]

            # if the show says we want that episode then add it to the list
            if not showObj.wantEpisode(curSeason, curEp, curQuality,
                                       manualSearch, downCurQuality):
                sickrage.srLogger.info(
                    "Skipping " + curResult[b"name"] +
                    " because we don't want an episode that's " +
                    Quality.qualityStrings[curQuality])
                continue

            epObj = showObj.getEpisode(curSeason, curEp)

            # build a result object
            title = curResult[b"name"]
            url = curResult[b"url"]

            sickrage.srLogger.info("Found result " + title + " at " + url)

            result = self.provider.getResult([epObj])
            result.show = showObj
            result.url = url
            result.name = title
            result.quality = curQuality
            result.release_group = curReleaseGroup
            result.version = curVersion
            result.content = None

            # add it to the list
            if epObj not in neededEps:
                neededEps[epObj] = [result]
            else:
                neededEps[epObj].append(result)

        # datetime stamp this search so cache gets cleared
        self.setLastSearch()

        return neededEps
Exemple #19
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive:
            return

        self.amActive = True

        # trim failed download history
        if sickrage.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        sickrage.srLogger.info("Searching for new released episodes ...")

        if tz_updater.load_network_dict():
            curDate = (date.today() + timedelta(days=1)).toordinal()
        else:
            curDate = (date.today() + timedelta(days=2)).toordinal()

        curTime = datetime.now(tz_updater.sr_timezone)

        sqlResults = main_db.MainDB().select(
                "SELECT * FROM tv_episodes WHERE status = ? AND season > 0 AND (airdate <= ? AND airdate > 1)",
                [UNAIRED, curDate])

        sql_l = []
        show = None

        for sqlEp in sqlResults:
            try:
                if not show or int(sqlEp[b"showid"]) != show.indexerid:
                    show = findCertainShow(sickrage.srCore.SHOWLIST, int(sqlEp[b"showid"]))

                # for when there is orphaned series in the database but not loaded into our showlist
                if not show or show.paused:
                    continue

            except MultipleShowObjectsException:
                sickrage.srLogger.info("ERROR: expected to find a single show matching " + str(sqlEp[b'showid']))
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(sqlEp[b'airdate'], show.airs, show.network).astimezone(
                        tz_updater.sr_timezone)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime:
                    continue

            ep = show.getEpisode(int(sqlEp[b"season"]), int(sqlEp[b"episode"]))
            with ep.lock:
                if ep.season == 0:
                    sickrage.srLogger.info(
                            "New episode " + ep.prettyName() + " airs today, setting status to SKIPPED because is a special season")
                    ep.status = SKIPPED
                else:
                    sickrage.srLogger.info("New episode %s airs today, setting to default episode status for this show: %s" % (
                        ep.prettyName(), statusStrings[ep.show.default_ep_status]))
                    ep.status = ep.show.default_ep_status

                sql_q = ep.saveToDB(False)
                if sql_q:
                    sql_l.append(sql_q)
                    del sql_q

        if len(sql_l) > 0:
            main_db.MainDB().mass_upsert(sql_l)
            del sql_l
        else:
            sickrage.srLogger.info("No new released episodes found ...")

        # queue episode for daily search
        sickrage.srCore.SEARCHQUEUE.add_item(DailySearchQueueItem())

        self.amActive = False
Exemple #20
0
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

        if len(getEnabledServiceList()) < 1:
            sickrage.srLogger.warning(
                    'Not enough services selected. At least 1 service is required to search subtitles in the background'
            )
            return

        sickrage.srLogger.info('Checking for subtitles')

        # get episodes on which we want subtitles
        # criteria is:
        #  - show subtitles = 1
        #  - episode subtitles != config wanted languages or 'und' (depends on config multi)
        #  - search count < 2 and diff(airdate, now) > 1 week : now -> 1d
        #  - search count < 7 and diff(airdate, now) <= 1 week : now -> 4h -> 8h -> 16h -> 1d -> 1d -> 1d

        today = date.today().toordinal()

        # you have 5 minutes to understand that one. Good luck


        sqlResults = main_db.MainDB().select(
                'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.subtitles, ' +
                'e.subtitles_searchcount AS searchcount, e.subtitles_lastsearch AS lastsearch, e.location, (? - e.airdate) AS airdate_daydiff ' +
                'FROM tv_episodes AS e INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id) ' +
                'WHERE s.subtitles = 1 AND e.subtitles NOT LIKE (?) ' +
                'AND (e.subtitles_searchcount <= 2 OR (e.subtitles_searchcount <= 7 AND airdate_daydiff <= 7)) ' +
                'AND e.location != ""', [today, wantedLanguages(True)])

        if len(sqlResults) == 0:
            sickrage.srLogger.info('No subtitles to download')
            return

        rules = self._getRules()
        now = datetime.now()
        for epToSub in sqlResults:

            if not os.path.isfile(epToSub[b'location']):
                sickrage.srLogger.debug('Episode file does not exist, cannot download subtitles for episode %dx%d of show %s' % (
                    epToSub[b'season'], epToSub[b'episode'], epToSub[b'show_name']))
                continue

            # http://bugs.python.org/issue7980#msg221094
            # I dont think this needs done here, but keeping to be safe
            datetime.strptime('20110101', '%Y%m%d')
            if (
                        (epToSub[b'airdate_daydiff'] > 7 and epToSub[
                            b'searchcount'] < 2 and now - datetime.strptime(
                                epToSub[b'lastsearch'], dateTimeFormat) > timedelta(
                                hours=rules['old'][epToSub[b'searchcount']])) or
                        (
                                            epToSub[b'airdate_daydiff'] <= 7 and
                                            epToSub[b'searchcount'] < 7 and
                                            now - datetime.strptime(
                                                epToSub[b'lastsearch'], dateTimeFormat) > timedelta
                                    (
                                            hours=rules[b'new'][epToSub[b'searchcount']]
                                    )
                        )
            ):

                sickrage.srLogger.debug('Downloading subtitles for episode %dx%d of show %s' % (
                    epToSub[b'season'], epToSub[b'episode'], epToSub[b'show_name']))

                showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(epToSub[b'showid']))
                if not showObj:
                    sickrage.srLogger.debug('Show not found')
                    return

                epObj = showObj.getEpisode(int(epToSub[b"season"]), int(epToSub[b"episode"]))
                if isinstance(epObj, str):
                    sickrage.srLogger.debug('Episode not found')
                    return

                existing_subtitles = epObj.subtitles

                try:
                    epObj.downloadSubtitles()
                except Exception as e:
                    sickrage.srLogger.debug('Unable to find subtitles')
                    sickrage.srLogger.debug(str(e))
                    return

                newSubtitles = frozenset(epObj.subtitles).difference(existing_subtitles)
                if newSubtitles:
                    sickrage.srLogger.info('Downloaded subtitles for S%02dE%02d in %s' % (
                        epToSub[b"season"], epToSub[b"episode"], ', '.join(newSubtitles)))

        self.amActive = False
Exemple #21
0
    def findNeededEpisodes(self, episode, manualSearch=False, downCurQuality=False):
        sqlResults = []
        neededEps = {}
        cl = []

        if not episode:
            sqlResults = self._getDB().select("SELECT * FROM [" + self.providerID + "]")
        elif type(episode) != list:
            sqlResults = self._getDB().select(
                    "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?",
                    [episode.show.indexerid, episode.season, "%|" + str(episode.episode) + "|%"])
        else:
            for epObj in episode:
                cl.append([
                    "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ? AND quality IN (" + ",".join(
                            [str(x) for x in epObj.wantedQuality]) + ")",
                    [epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"]])

            if len(cl) > 0:
                sqlResults = list(itertools.chain(*self._getDB().mass_action(cl)))

        # for each cache entry
        for curResult in sqlResults:
            # ignored/required words, and non-tv junk
            if not show_names.filterBadReleases(curResult[b"name"]):
                continue

            # get the show object, or if it's not one of our shows then ignore it
            showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(curResult[b"indexerid"]))
            if not showObj:
                continue

            # skip if provider is anime only and show is not anime
            if self.provider.anime_only and not showObj.is_anime:
                sickrage.srLogger.debug("" + str(showObj.name) + " is not an anime, skiping")
                continue

            # get season and ep data (ignoring multi-eps for now)
            curSeason = int(curResult[b"season"])
            if curSeason == -1:
                continue

            curEp = curResult[b"episodes"].split("|")[1]
            if not curEp:
                continue

            curEp = int(curEp)

            curQuality = int(curResult[b"quality"])
            curReleaseGroup = curResult[b"release_group"]
            curVersion = curResult[b"version"]

            # if the show says we want that episode then add it to the list
            if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch, downCurQuality):
                sickrage.srLogger.info("Skipping " + curResult[b"name"] + " because we don't want an episode that's " +
                                        Quality.qualityStrings[curQuality])
                continue

            epObj = showObj.getEpisode(curSeason, curEp)

            # build a result object
            title = curResult[b"name"]
            url = curResult[b"url"]

            sickrage.srLogger.info("Found result " + title + " at " + url)

            result = self.provider.getResult([epObj])
            result.show = showObj
            result.url = url
            result.name = title
            result.quality = curQuality
            result.release_group = curReleaseGroup
            result.version = curVersion
            result.content = None

            # add it to the list
            if epObj not in neededEps:
                neededEps[epObj] = [result]
            else:
                neededEps[epObj].append(result)

        # datetime stamp this search so cache gets cleared
        self.setLastSearch()

        return neededEps