def run(self): with wyvern.LOCK: if wyvern.SB_URL is None or wyvern.SHOW_INSTANCES is None or wyvern.TORRENT_BLACKHOLE is None: return logger.info("Checking on downloads") for show in wyvern.SHOW_INSTANCES: if wyvern.STOP_EVENT.isSet(): return logger.debug("Checking on show: " + show.ShowName) if show.feed is None: logger.warning("Show {0} has no download feed".format(show.ShowName)) continue feed = feedparser.parse(show.feed) for e in feed['entries']: filename = e['title'] file_info = show.parse_filename(filename) if file_info is None: continue sb_url = "{0}/?cmd=episode&tvdbid={1}&season={2}&episode={3}&full_path=1" \ .format(wyvern.SB_URL, show.TheTvDbId, file_info.Season, file_info.Episode) show_json = requests.get(sb_url).json() if 'result' not in show_json or show_json['result'] <> 'success': if int(file_info.Season) >= 0 and int(file_info.Episode) >= 0: logger.warning( "Could not poll sickbeard for show {0}({1}) - S{2:02d}E{3:02d}" .format(show.ShowName, show.TheTvDbId, int(file_info.Season), int(file_info.Episode))) continue show_data = show_json['data'] status = show_data['status'] airdate = show_data['airdate'] if not (status.upper() == 'WANTED' or (status.upper() == 'UNAIRED' and time.strptime(airdate, "%Y-%m-%d") <= datetime.datetime.now( ).timetuple())): continue torrent_link = e['link'] logger.debug("from " + torrent_link) logger.info("Downloading Torrent for show {0} - S{1:02d}E{2:02d}" .format(show.ShowName, int(file_info.Season), int(file_info.Episode))) r = requests.get(torrent_link) if not r.status_code == requests.codes.ok: logger.warning( "Could not update sickbeard for show {0} - S{1:02d}E{2:02d}" .format(show.ShowName, int(file_info.Season), int(file_info.Episode))) continue f = open(os.path.join(wyvern.TORRENT_BLACKHOLE, filename.replace(' ', '_') + ".torrent"), 'w') f.write(r.content) f.close() sb_url = "{0}/?cmd=episode.setstatus&tvdbid={1}&season={2}&episode={3}&status=skipped".format( wyvern.SB_URL, show.TheTvDbId, file_info.Season, file_info.Episode) logger.debug("Updating sickbeard with URL " + sb_url) result_json = requests.get(sb_url).json() logger.debug("Result: " + result_json['result'])
def join(self, timeout=None): logger.info("Exiting Thread")
def sig_handler(signum=None, frame=None): if type(signum) != type(None): logger.info(u"Signal %i caught, saving and exiting..." % int(signum)) save_and_exit()