def run(self): QueueItem.run(self) try: sickrage.srLogger.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.srLogger.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.srConfig.CPU_PRESET]) else: notifications.message('No downloads were found', "Couldn't find a download for <i>%s</i>" % self.segment.prettyName()) sickrage.srLogger.info("Unable to find a download for: [" + self.segment.prettyName() + "]") except Exception: sickrage.srLogger.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()
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.srConfig.VERSION_NOTIFY and not sickrage.srConfig.AUTO_UPDATE and not force): sickrage.srLogger.info("Version checking is disabled, not checking for the newest version") return False # checking for updates if force or not sickrage.srConfig.AUTO_UPDATE: sickrage.srLogger.info("Checking for updates using " + self.updater.type.upper()) if self.updater.need_update(): self.updater.set_newest_text() if sickrage.srConfig.AUTO_UPDATE: sickrage.srLogger.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.srLogger.info("No update needed")
def _runbackup(self): # Do a system backup before update sickrage.srLogger.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.srLogger.info("Config backup successful, updating...") notifications.message('Backup', 'Config backup successful, updating...') return True else: sickrage.srLogger.error( "Config backup failed, aborting update") notifications.message('Backup', 'Config backup failed, aborting update') return False except Exception as e: sickrage.srLogger.error('Update: Config backup failed. Error: %s' % e) notifications.message('Backup', 'Config backup failed, aborting update') return False
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 core.ui import notifications if self.update(): sickrage.srLogger.info("Update was successful!") notifications.message('Update was successful') sickrage.srCore.WEBSERVER.server_restart() else: sickrage.srLogger.info("Update failed!") notifications.message('Update failed!') self.check_for_new_news(force) finally: self.amActive = False
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 core.ui import notifications if self.update(): sickrage.srLogger.info("Update was successful!") notifications.message('Update was successful') sickrage.srCore.WEBSERVER.server_restart() else: sickrage.srLogger.info("Update failed!") notifications.message('Update failed!') self.check_for_new_news(force) finally: self.amActive = False
def run(self): QueueItem.run(self) try: sickrage.srLogger.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.srLogger.info("Downloading " + searchResult[0].name + " from " + searchResult[0].provider.name) self.success = snatchEpisode(searchResult[0]) # give the CPU a break time.sleep(cpu_presets[sickrage.srConfig.CPU_PRESET]) else: notifications.message( 'No downloads were found', "Couldn't find a download for <i>%s</i>" % self.segment.prettyName()) sickrage.srLogger.info("Unable to find a download for: [" + self.segment.prettyName() + "]") except Exception: sickrage.srLogger.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
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.srConfig.VERSION_NOTIFY and not sickrage.srConfig.AUTO_UPDATE and not force): sickrage.srLogger.info( "Version checking is disabled, not checking for the newest version" ) return False # checking for updates if force or not sickrage.srConfig.AUTO_UPDATE: sickrage.srLogger.info("Checking for updates using " + self.updater.type.upper()) if self.updater.need_update(): self.updater.set_newest_text() if sickrage.srConfig.AUTO_UPDATE: sickrage.srLogger.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.srLogger.info("No update needed")
def _runbackup(self): # Do a system backup before update sickrage.srLogger.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.srLogger.info("Config backup successful, updating...") notifications.message('Backup', 'Config backup successful, updating...') return True else: sickrage.srLogger.error("Config backup failed, aborting update") notifications.message('Backup', 'Config backup failed, aborting update') return False except Exception as e: sickrage.srLogger.error('Update: Config backup failed. Error: %s' % e) notifications.message('Backup', 'Config backup failed, aborting update') return False
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.srConfig.ALLOW_HIGH_PRIORITY: # if it aired recently make it high priority for curEp in result.episodes: if date.today() - curEp.airdate <= 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.srConfig.NZB_METHOD == "blackhole": dlResult = _downloadResult(result) elif sickrage.srConfig.NZB_METHOD == "sabnzbd": dlResult = SabNZBd.sendNZB(result) elif sickrage.srConfig.NZB_METHOD == "nzbget": is_proper = True if endStatus == SNATCHED_PROPER else False dlResult = NZBGet.sendNZB(result, is_proper) else: sickrage.srLogger.error("Unknown NZB action specified in config: " + sickrage.srConfig.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.srConfig.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.srConfig.TORRENT_METHOD)() dlResult = client.sendTORRENT(result) else: sickrage.srLogger.warning("Torrent file content is empty") dlResult = False else: sickrage.srLogger.error("Unknown result type, unable to download it (%r)" % result.resultType) dlResult = False if not dlResult: return False if sickrage.srConfig.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_q = curEpObj.saveToDB(False) if sql_q: sql_l.append(sql_q) del sql_q # cleanup if curEpObj.status not in Quality.DOWNLOADED: try: srNotifiers.notify_snatch( curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN') + " from " + result.provider.name) except: sickrage.srLogger.debug("Failed to send snatch notification") trakt_data.append((curEpObj.season, curEpObj.episode)) data = sickrage.srCore.NOTIFIERS.trakt_notifier.trakt_episode_data_generate(trakt_data) if sickrage.srConfig.USE_TRAKT and sickrage.srConfig.TRAKT_SYNC_WATCHLIST: sickrage.srLogger.debug("Add episodes, showid: indexerid " + str(result.show.indexerid) + ", Title " + str( result.show.name) + " to Traktv Watchlist") if data: sickrage.srCore.NOTIFIERS.trakt_notifier.update_watchlist(result.show, data_episode=data, update="add") if len(sql_l) > 0: main_db.MainDB().mass_upsert(sql_l) del sql_l # cleanup return True