def reg_twitter(self, token_key=None, token_secret=None, token_pin=None): import autosubliminal.notifiers.twitter as twitter_notifier if not token_key and not token_secret: # Getting request token oauth_client = OAuth1Session( client_key=twitter_notifier.CONSUMER_KEY, client_secret=twitter_notifier.CONSUMER_SECRET) try: response = oauth_client.fetch_request_token( twitter_notifier.REQUEST_TOKEN_URL) except Exception as e: message = 'Something went wrong.../n' + e.message return PageTemplate( filename='/general/message.mako').render( message=message) # Authorize url = oauth_client.authorization_url( twitter_notifier.AUTHORIZATION_URL) token_key = response.get('oauth_token') token_secret = response.get('oauth_token_secret') return PageTemplate( filename='/config/config-regtwitter.mako').render( url=url, token_key=token_key, token_secret=token_secret) if token_key and token_secret and token_pin: # Getting access token oauth_client = OAuth1Session( client_key=twitter_notifier.CONSUMER_KEY, client_secret=twitter_notifier.CONSUMER_SECRET, resource_owner_key=token_key, resource_owner_secret=token_secret, verifier=token_pin) try: response = oauth_client.fetch_access_token( twitter_notifier.ACCESS_TOKEN_URL) except Exception as e: message = 'Something went wrong.../n' + e.message return PageTemplate( filename='/general/message.mako').render( message=message) # Store access token autosubliminal.TWITTERKEY = response.get('oauth_token') autosubliminal.TWITTERSECRET = response.get( 'oauth_token_secret') # Render template message = 'Twitter is now set up, remember to save your config and remember to test twitter!' \ '<br><a href="' + autosubliminal.WEBROOT + '/config/notification">Return</a>' return PageTemplate(filename='/general/message.mako').render( message=message)
def search_subtitle(self, wanted_item_index, lang): # Search subtitle subs, errormessage = subchecker.search_subtitle( wanted_item_index, lang) # Send response in html (store subs under subs key) return PageTemplate(filename='/home/home-manualsearch.mako').render( subs=subs, infomessage=None, errormessage=errormessage)
def error_page(status, message, traceback, version): # Parse status code (example status: '404 Not Found') match = re.search(r'^(\d{3}).*$', status) # Render template status_code = int(match.group(1)) if match else 500 return PageTemplate(filename='/general/error.mako').render( status_code=status_code, status=status, message=message, traceback=traceback)
def clear_log(self): # Clear log file (open it in write mode and pass) with open(autosubliminal.LOGFILE, 'w'): pass # Remove possible backup log files for f in [ f for f in os.listdir('.') if os.path.isfile(f) and re.match(autosubliminal.LOGFILE + '.', f) ]: os.remove(f) # Return to default log view content = utils.display_logfile() return PageTemplate(filename=self.template_file).render( loglevel='all', lognum=None, content=content)
def delete_video(self, wanted_item_index, confirmed=False, cleanup=False): if not confirmed: wanted_item = autosubliminal.WANTEDQUEUE[int(wanted_item_index)] video = wanted_item.videopath return PageTemplate('/home/home-deletevideo.mako').render( wanted_item_index=wanted_item_index, video=video) else: # Delete video deleted = subchecker.delete_video(wanted_item_index, cleanup) if deleted: send_websocket_notification('Video deleted from filesystem.') else: send_websocket_notification( 'Video could not be deleted! Please check the log file!', type='error') redirect('/home')
def skip_show(self, wanted_item_index, title, season=None): if not season: return PageTemplate('/home/home-skipshow.mako').render( wanted_item_index=wanted_item_index, title=title) else: if not wanted_item_index: raise cherrypy.HTTPError(400, 'No wanted_item index supplied') if not title: raise cherrypy.HTTPError(400, 'No show supplied') # Check if season is a number to be sure if not season == '00': season = text_type(int(season)) config_season = season # Check if already skipped title_sanitized = sanitize(title) for x in autosubliminal.SKIPSHOW: if title_sanitized == sanitize(x): for s in autosubliminal.SKIPSHOW[x].split(','): if s == season or s == '00': send_websocket_notification( 'Already skipped show %s season %s.' % (title, season)) redirect('/home') # Not skipped yet, skip all or append season the seasons to skip if season == '00': config_season = '00' else: seasons = autosubliminal.SKIPSHOW[x].split(',') seasons.append(season) config_season = ','.join(sorted(seasons)) # Skip show if subchecker.skip_show(wanted_item_index, season): config.write_config_property('skipshow', title, config_season) config.apply_skipshow() if season == '00': send_websocket_notification( 'Skipped show %s all seasons.' % title) else: send_websocket_notification('Skipped show %s season %s.' % (title, season)) else: send_websocket_notification( 'Could not skip show! Please check the log file!', type='error') redirect('/home')
def error_page(status, message, traceback, version): """ Custom error page. :param status: the http error status :param message: the error message :param traceback: the error traceback :param version: the server version :return: the error page or json error """ # Do not show error page for json errors, show json error response instead content_type = cherrypy.response.headers['Content-Type'] if content_type and 'application/json' in content_type.lower(): return json.dumps({'status': status, 'error': message}) # Parse status code (example status: '404 Not Found') match = re.search(r'^(\d{3}).*$', status) # Render template status_code = int(match.group(1)) if match else 500 return PageTemplate('/general/error.mako').render(status_code=status_code, status=status, message=message, traceback=traceback)
def index(self): return PageTemplate(self.template_file).render()
def view_log(self, loglevel='all', lognum=None): content = display_logfile(loglevel, lognum) return PageTemplate(self.template_file).render(loglevel=loglevel, lognum=lognum, content=content)
def update_version(self): autosubliminal.CHECKVERSION.process.update() runner.restart_app(exit=True) message = 'Auto-Subliminal is restarting...' return PageTemplate(filename='/system/system-restart.mako').render( message=message)
def status(self): return PageTemplate(filename='/system/system-status.mako').render()
def info(self): return PageTemplate(filename='/system/system-info.mako').render()
def shutdown(self): runner.shutdown_app() message = 'Auto-Subliminal is shutting down...' return PageTemplate(filename='/general/message.mako').render( message=message)
def restart(self): runner.restart_app() message = 'Auto-Subliminal is restarting...' return PageTemplate(filename='/system/system-restart.mako').render( message=message)
def index(self): return PageTemplate(filename='/home/home.mako').render()