Ejemplo n.º 1
0
    def check_for_new_version(self, force=False):
        """
        Checks the internet for a newer version.

        returns: bool, True for new version or False for no new version.
        :param force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced
        """

        if not self.updater or (not sickrage.VERSION_NOTIFY and not sickrage.AUTO_UPDATE and not force):
            sickrage.LOGGER.info("Version checking is disabled, not checking for the newest version")
            return False

        # checking for updates
        if force or not sickrage.AUTO_UPDATE:
            sickrage.LOGGER.info("Checking for updates using " + self.updater.type.upper())

        if self.updater.need_update():
            self.updater.set_newest_text()

            if sickrage.AUTO_UPDATE:
                sickrage.LOGGER.info("New update found for SiCKRAGE, starting auto-updater ...")
                notifications.message('New update found for SiCKRAGE, starting auto-updater')

            return True

        # no updates needed if we made it here
        if force:
            notifications.message('No update needed')
            sickrage.LOGGER.info("No update needed")
Ejemplo n.º 2
0
    def run(self):
        QueueItem.run(self)

        try:
            sickrage.LOGGER.info("Beginning manual search for: [" + self.segment.prettyName() + "]")
            self.started = True

            searchResult = searchProviders(self.show, [self.segment], True, self.downCurQuality)

            if searchResult:
                # just use the first result for now
                sickrage.LOGGER.info("Downloading " + searchResult[0].name + " from " + searchResult[0].provider.name)
                self.success = snatchEpisode(searchResult[0])

                # give the CPU a break
                gen.sleep(cpu_presets[sickrage.CPU_PRESET])

            else:
                notifications.message('No downloads were found',
                                      "Couldn't find a download for <i>%s</i>" % self.segment.prettyName())

                sickrage.LOGGER.info("Unable to find a download for: [" + self.segment.prettyName() + "]")

        except Exception:
            sickrage.LOGGER.debug(traceback.format_exc())

        ### Keep a list with the 100 last executed searches
        fifo(MANUAL_SEARCH_HISTORY, self, MANUAL_SEARCH_HISTORY_SIZE)

        if self.success is None:
            self.success = False

        self.finish()
Ejemplo n.º 3
0
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

        try:
            if self.updater:
                if self.check_for_new_version(force):
                    if self.run_backup_if_safe() is True:
                        from sickrage.core.ui import notifications
                        if self.update():
                            sickrage.LOGGER.info("Update was successful!")
                            notifications.message('Update was successful')
                            sickrage.WEB_SERVER.server_restart()
                        else:
                            sickrage.LOGGER.info("Update failed!")
                            notifications.message('Update failed!')

                self.check_for_new_news(force)
        finally:self.amActive = False
Ejemplo n.º 4
0
    def run(self):
        QueueItem.run(self)

        try:
            sickrage.LOGGER.info("Beginning manual search for: [" +
                                 self.segment.prettyName() + "]")
            self.started = True

            searchResult = searchProviders(self.show, [self.segment], True,
                                           self.downCurQuality)

            if searchResult:
                # just use the first result for now
                sickrage.LOGGER.info("Downloading " + searchResult[0].name +
                                     " from " + searchResult[0].provider.name)
                self.success = snatchEpisode(searchResult[0])

                # give the CPU a break
                gen.sleep(cpu_presets[sickrage.CPU_PRESET])

            else:
                notifications.message(
                    'No downloads were found',
                    "Couldn't find a download for <i>%s</i>" %
                    self.segment.prettyName())

                sickrage.LOGGER.info("Unable to find a download for: [" +
                                     self.segment.prettyName() + "]")

        except Exception:
            sickrage.LOGGER.debug(traceback.format_exc())

        ### Keep a list with the 100 last executed searches
        fifo(MANUAL_SEARCH_HISTORY, self, MANUAL_SEARCH_HISTORY_SIZE)

        if self.success is None:
            self.success = False

        self.finish()
Ejemplo n.º 5
0
    def _runbackup(self):
        # Do a system backup before update
        sickrage.LOGGER.info("Config backup in progress...")
        notifications.message('Backup', 'Config backup in progress...')
        try:
            backupDir = os.path.join(sickrage.DATA_DIR, 'backup')
            if not os.path.isdir(backupDir):
                os.mkdir(backupDir)

            if self._keeplatestbackup(backupDir) and backupAll(backupDir):
                sickrage.LOGGER.info("Config backup successful, updating...")
                notifications.message('Backup', 'Config backup successful, updating...')
                return True
            else:
                sickrage.LOGGER.error("Config backup failed, aborting update")
                notifications.message('Backup', 'Config backup failed, aborting update')
                return False
        except Exception as e:
            sickrage.LOGGER.error('Update: Config backup failed. Error: %s' % e)
            notifications.message('Backup', 'Config backup failed, aborting update')
            return False
Ejemplo n.º 6
0
def snatchEpisode(result, endStatus=SNATCHED):
    """
    Contains the internal logic necessary to actually "snatch" a result that
    has been found.

    :param result: SearchResult instance to be snatched.
    :param endStatus: the episode status that should be used for the episode object once it's snatched.
    :return: boolean, True on success
    """

    if result is None:
        return False

    result.priority = 0  # -1 = low, 0 = normal, 1 = high
    if sickrage.ALLOW_HIGH_PRIORITY:
        # if it aired recently make it high priority
        for curEp in result.episodes:
            if datetime.date.today() - curEp.airdate <= datetime.timedelta(
                    days=7):
                result.priority = 1
    if re.search(r'(^|[\. _-])(proper|repack)([\. _-]|$)', result.name,
                 re.I) is not None:
        endStatus = SNATCHED_PROPER

    if result.url.startswith('magnet') or result.url.endswith('torrent'):
        result.resultType = 'torrent'

    # NZBs can be sent straight to SAB or saved to disk
    if result.resultType in ("nzb", "nzbdata"):
        if sickrage.NZB_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        elif sickrage.NZB_METHOD == "sabnzbd":
            dlResult = SabNZBd.sendNZB(result)
        elif sickrage.NZB_METHOD == "nzbget":
            is_proper = True if endStatus == SNATCHED_PROPER else False
            dlResult = NZBGet.sendNZB(result, is_proper)
        else:
            sickrage.LOGGER.error("Unknown NZB action specified in config: " +
                                  sickrage.NZB_METHOD)
            dlResult = False

    # TORRENTs can be sent to clients or saved to disk
    elif result.resultType == "torrent":
        # torrents are saved to disk when blackhole mode
        if sickrage.TORRENT_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        else:
            if not result.content and not result.url.startswith('magnet'):
                result.content = result.provider.getURL(result.url,
                                                        needBytes=True)

            if result.content or result.url.startswith('magnet'):
                client = getClientIstance(sickrage.TORRENT_METHOD)()
                dlResult = client.sendTORRENT(result)
            else:
                sickrage.LOGGER.warning("Torrent file content is empty")
                dlResult = False
    else:
        sickrage.LOGGER.error(
            "Unknown result type, unable to download it (%r)" %
            result.resultType)
        dlResult = False

    if not dlResult:
        return False

    if sickrage.USE_FAILED_DOWNLOADS:
        FailedHistory.logSnatch(result)

    notifications.message('Episode snatched', result.name)

    History.logSnatch(result)

    # don't notify when we re-download an episode
    sql_l = []
    trakt_data = []
    for curEpObj in result.episodes:
        with curEpObj.lock:
            if isFirstBestMatch(result):
                curEpObj.status = Quality.compositeStatus(
                    SNATCHED_BEST, result.quality)
            else:
                curEpObj.status = Quality.compositeStatus(
                    endStatus, result.quality)

            sql_l.append(curEpObj.get_sql())

        if curEpObj.status not in Quality.DOWNLOADED:
            try:
                notify_snatch(
                    curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN') +
                    " from " + result.provider.name)
            except:
                sickrage.LOGGER.debug("Failed to send snatch notification")

            trakt_data.append((curEpObj.season, curEpObj.episode))

    data = sickrage.NOTIFIERS.trakt_notifier.trakt_episode_data_generate(
        trakt_data)

    if sickrage.USE_TRAKT and sickrage.TRAKT_SYNC_WATCHLIST:
        sickrage.LOGGER.debug("Add episodes, showid: indexerid " +
                              str(result.show.indexerid) + ", Title " +
                              str(result.show.name) + " to Traktv Watchlist")
        if data:
            sickrage.NOTIFIERS.trakt_notifier.update_watchlist(
                result.show, data_episode=data, update="add")

    if len(sql_l) > 0:
        main_db.MainDB().mass_action(sql_l)

    return True
Ejemplo n.º 7
0
def snatchEpisode(result, endStatus=SNATCHED):
    """
    Contains the internal logic necessary to actually "snatch" a result that
    has been found.

    :param result: SearchResult instance to be snatched.
    :param endStatus: the episode status that should be used for the episode object once it's snatched.
    :return: boolean, True on success
    """

    if result is None:
        return False

    result.priority = 0  # -1 = low, 0 = normal, 1 = high
    if sickrage.ALLOW_HIGH_PRIORITY:
        # if it aired recently make it high priority
        for curEp in result.episodes:
            if datetime.date.today() - curEp.airdate <= datetime.timedelta(days=7):
                result.priority = 1
    if re.search(r"(^|[\. _-])(proper|repack)([\. _-]|$)", result.name, re.I) is not None:
        endStatus = SNATCHED_PROPER

    if result.url.startswith("magnet") or result.url.endswith("torrent"):
        result.resultType = "torrent"

    # NZBs can be sent straight to SAB or saved to disk
    if result.resultType in ("nzb", "nzbdata"):
        if sickrage.NZB_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        elif sickrage.NZB_METHOD == "sabnzbd":
            dlResult = SabNZBd.sendNZB(result)
        elif sickrage.NZB_METHOD == "nzbget":
            is_proper = True if endStatus == SNATCHED_PROPER else False
            dlResult = NZBGet.sendNZB(result, is_proper)
        else:
            sickrage.LOGGER.error("Unknown NZB action specified in config: " + sickrage.NZB_METHOD)
            dlResult = False

    # TORRENTs can be sent to clients or saved to disk
    elif result.resultType == "torrent":
        # torrents are saved to disk when blackhole mode
        if sickrage.TORRENT_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        else:
            if not result.content and not result.url.startswith("magnet"):
                result.content = result.provider.getURL(result.url, needBytes=True)

            if result.content or result.url.startswith("magnet"):
                client = getClientIstance(sickrage.TORRENT_METHOD)()
                dlResult = client.sendTORRENT(result)
            else:
                sickrage.LOGGER.warning("Torrent file content is empty")
                dlResult = False
    else:
        sickrage.LOGGER.error("Unknown result type, unable to download it (%r)" % result.resultType)
        dlResult = False

    if not dlResult:
        return False

    if sickrage.USE_FAILED_DOWNLOADS:
        FailedHistory.logSnatch(result)

    notifications.message("Episode snatched", result.name)

    History.logSnatch(result)

    # don't notify when we re-download an episode
    sql_l = []
    trakt_data = []
    for curEpObj in result.episodes:
        with curEpObj.lock:
            if isFirstBestMatch(result):
                curEpObj.status = Quality.compositeStatus(SNATCHED_BEST, result.quality)
            else:
                curEpObj.status = Quality.compositeStatus(endStatus, result.quality)

            sql_l.append(curEpObj.get_sql())

        if curEpObj.status not in Quality.DOWNLOADED:
            try:
                notify_snatch(curEpObj._format_pattern("%SN - %Sx%0E - %EN - %QN") + " from " + result.provider.name)
            except:
                sickrage.LOGGER.debug("Failed to send snatch notification")

            trakt_data.append((curEpObj.season, curEpObj.episode))

    data = sickrage.NOTIFIERS.trakt_notifier.trakt_episode_data_generate(trakt_data)

    if sickrage.USE_TRAKT and sickrage.TRAKT_SYNC_WATCHLIST:
        sickrage.LOGGER.debug(
            "Add episodes, showid: indexerid "
            + str(result.show.indexerid)
            + ", Title "
            + str(result.show.name)
            + " to Traktv Watchlist"
        )
        if data:
            sickrage.NOTIFIERS.trakt_notifier.update_watchlist(result.show, data_episode=data, update="add")

    if len(sql_l) > 0:
        main_db.MainDB().mass_action(sql_l)

    return True