def revertEpisode(epObj):
 failed_db_con = db.DBConnection('failed.db')
 sql_results = failed_db_con.select('SELECT episode, old_status FROM history WHERE showid=? AND season=?', [epObj.show.indexerid, epObj.season])
 history_eps = {res['episode']: res for res in sql_results}
 try:
  logger.log(u'Reverting episode ({0}, {1}): {2}'.format(epObj.season, epObj.episode, epObj.name))
  with epObj.lock:
   if (epObj.episode in history_eps):
    logger.log(u'Found in history')
    epObj.status = history_eps[epObj.episode]['old_status']
   else:
    logger.log(u"Episode don't have a previous snatched status to revert. Setting it back to WANTED", logger.DEBUG)
    epObj.status = WANTED
    epObj.saveToDB()
 except EpisodeNotFoundException as e:
  logger.log((u'Unable to create episode, please set its status manually: ' + ex(e)), logger.WARNING)

def revertEpisode ( epObj ) : failed_db_con = db . DBConnection ( 'failed.db' ) sql_results = failed_db_con . select ( 'SELECT episode, old_status FROM history WHERE showid=? AND season=?' , [ epObj . show . indexerid , epObj . season ] ) history_eps = { res [ 'episode' ] : res for res in sql_results } try : logger . log ( u'Reverting episode ({0}, {1}): {2}' . format ( epObj . season , epObj . episode , epObj . name ) ) with epObj . lock : if ( epObj . episode in history_eps ) : logger . log ( u'Found in history' ) epObj . status = history_eps [ epObj . episode ] [ 'old_status' ] else : logger . log ( u"Episode don't have a previous snatched status to revert. Setting it back to WANTED" , logger . DEBUG ) epObj . status = WANTED epObj . saveToDB ( ) except EpisodeNotFoundException as e : logger . log ( ( u'Unable to create episode, please set its status manually: ' + ex ( e ) ) , logger . WARNING )
restore the episodes of a failed download to their original state .