def __init__(self): self.omdb = Omdb() self.config = config.Config() self.predb = predb.PreDB() self.searcher = searcher.Searcher() self.sql = sqldb.SQL() self.poster = poster.Poster() self.snatcher = snatcher.Snatcher() self.update = updatestatus.Status()
def html(self, imdbid): omdb = Omdb() trailer = Trailer() data = omdb.movie_info(imdbid) if not data: return self.no_data() data_json = json.dumps(data) title_date = data['title'] + ' ' + data['year'] imdbid = data['imdbid'] youtube_id = trailer.get_trailer(title_date) if youtube_id: trailer_embed = "https://www.youtube.com/embed/{}?&showinfo=0".format(youtube_id) else: trailer_embed = '' if data['poster'] == 'N/A': data['poster'] = core.URL_BASE + '/static/images/missing_poster.jpg' doc = dominate.document() with doc.head: script(type='text/javascript', src=core.URL_BASE + '/static/js/add_movie/movie_info_popup.js?v=12.27') with doc: with div(id='container'): with div(id='title'): with p(): span(title_date, id='title') i(cls='fa fa-plus', id='button_add') i(cls='fa fa-floppy-o', id='button_submit', imdbid=imdbid) with div(id='media'): img(id='poster', src=data['poster']) with div(id='trailer_container'): iframe(id='trailer', width="640", height="360", src=trailer_embed, frameborder="0") # Panel that swaps in with quality adjustments resolutions = ['4K', '1080P', '720P', 'SD'] with ul(id='quality', cls='wide'): # Resolution Block with ul(id='resolution', cls='sortable'): span('Resolutions', cls='sub_cat not_sortable') for res in resolutions: prior = '{}priority'.format(res) with li(cls='rbord', id=prior, sort=core.CONFIG['Quality'][res][1]): i(cls='fa fa-bars') i(id=res, cls='fa fa-square-o checkbox', value=core.CONFIG['Quality'][res][0]) span(res) # Size restriction block with ul(id='resolution_size'): with li('Size Restrictions (MB)', cls='sub_cat'): for res in resolutions: min = '{}min'.format(res) max = '{}max'.format(res) with li(): span(res) input(type='number', id=min, value=core.CONFIG['Quality'][res][2], min='0', style='width: 7.5em') input(type='number', id=max, value=core.CONFIG['Quality'][res][3], min='0', style='width: 7.5em') with ul(id='filters', cls='wide'): with li(cls='bbord'): span('Required words:') input(type='text', id='requiredwords', value=core.CONFIG['Filters']['requiredwords'], style='width: 16em') with li(cls='bbord'): span('Preferred words:') input(type='text', id='preferredwords', value=core.CONFIG['Filters']['preferredwords'], style='width: 16em') with li(): span('Ignored words:') input(type='text', id='ignoredwords', value=core.CONFIG['Filters']['ignoredwords'], style='width: 16em') with div(id='plot'): p(data['plot']) with div(id='additional_info'): with a(href=data['tomatourl'], target='_blank'): p('Rotten Tomatoes Rating: {}'.format(data['tomatorating'])) p('Theatrical Release Date: {}'.format(data['released'])) p('DVD Release Date: {}'.format(data['dvd'])) div(data_json, id='hidden_data') return doc.render()
class Ajax(object): ''' These are all the methods that handle ajax post/get requests from the browser. Except in special circumstances, all should return a string since that is the only datatype sent over http ''' def __init__(self): self.omdb = Omdb() self.config = config.Config() self.predb = predb.PreDB() self.searcher = searcher.Searcher() self.sql = sqldb.SQL() self.poster = poster.Poster() self.snatcher = snatcher.Snatcher() self.update = updatestatus.Status() @cherrypy.expose def search_omdb(self, search_term): ''' Search omdb for movies :param search_term: str title and year of movie (Movie Title 2016) Returns str json-encoded list of dicts that contain omdb's data. ''' results = self.omdb.search(search_term.replace(' ', '+')) if type(results) is str: logging.info('No Results found for {}'.format(search_term)) return None else: for i in results: if i['Poster'] == 'N/A': i['Poster'] = core.URL_BASE + '/static/images/missing_poster.jpg' return json.dumps(results) @cherrypy.expose def movie_info_popup(self, imdbid): ''' Calls movie_info_popup to render html :param imdbid: str imdb identification number (tt123456) Returns str html content. ''' mip = movie_info_popup.MovieInfoPopup() return mip.html(imdbid) @cherrypy.expose def movie_status_popup(self, imdbid): ''' Calls movie_status_popup to render html :param imdbid: str imdb identification number (tt123456) Returns str html content. ''' msp = movie_status_popup.MovieStatusPopup() return msp.html(imdbid) @cherrypy.expose def add_wanted_movie(self, data): ''' Adds movie to Wanted list. :param data: str json.dumps(dict) of info to add to database. Writes data to MOVIES table. If Search on Add enabled, searches for movie immediately in separate thread. If Auto Grab enabled, will snatch movie if found. Returns str json.dumps(dict) of status and message ''' data = json.loads(data) response = {} def thread_search_grab(data): imdbid = data['imdbid'] title = data['title'] self.predb.check_one(data) if core.CONFIG['Search']['searchafteradd'] == 'true': if self.searcher.search(imdbid, title): # if we don't need to wait to grab the movie do it now. if core.CONFIG['Search']['autograb'] == 'true' and \ core.CONFIG['Search']['waitdays'] == '0': self.snatcher.auto_grab(imdbid) TABLE = 'MOVIES' imdbid = data['imdbid'] title = data['title'].replace('_', ' ').encode('ascii', 'ignore') year = data['year'][:4] if self.sql.row_exists(TABLE, imdbid=imdbid): logging.info(u'{} {} already exists as a wanted movie'.format( title, year, imdbid)) response['response'] = 'false' response['message'] = u'{} {} is already wanted, cannot add.' \ .format(title, year, imdbid) return json.dumps(response) else: data['status'] = 'Wanted' data['predb'] = 'None' poster_url = data['poster'] data['poster'] = 'images/poster/{}.jpg'.format(imdbid) DB_STRING = data if self.sql.write(TABLE, DB_STRING): t2 = threading.Thread(target=self.poster.save_poster, args=(imdbid, poster_url)) t2.start() t = threading.Thread(target=thread_search_grab, args=(data, )) t.start() response['response'] = 'true' response['message'] = u'{} {} added to wanted list.' \ .format(title, year) return json.dumps(response) else: response['response'] = 'false' response['message'] = 'Could not write to database. ' \ 'Check logs for more information.' return json.dumps(response) @cherrypy.expose def quick_add(self, imdbid): ''' Method to quckly add movie with just imdbid :param imdbid: str imdb identification number (tt123456) Submits movie with base quality options Gets info from omdb and sends to self.add_wanted_movie Returns dict of success/fail with message. Returns str json.dumps(dict) ''' response = {} movie_info = self.omdb.movie_info(imdbid) if not movie_info: response['status'] = 'failed' response['message'] = '{} not found on omdb.'.format(imdbid) return response quality = {} quality['Quality'] = core.CONFIG['Quality'] quality['Filters'] = core.CONFIG['Filters'] movie_info['quality'] = json.dumps(quality) return self.add_wanted_movie(json.dumps(movie_info)) @cherrypy.expose def save_settings(self, data): ''' Saves settings to config file :param data: dict of Section with nested dict of keys and values: {'Section': {'key': 'val', 'key2': 'val2'}, 'Section2': {'key': 'val'}} Returns str 'failed' or 'success' ''' logging.info('Saving settings.') data = json.loads(data) try: self.config.write_dict(data) return 'success' except (SystemExit, KeyboardInterrupt): raise except Exception, e: # noqa logging.exception('Writing config.') return 'failed'
def __init__(self): self.config = config.Config() self.omdb = Omdb() self.sql = sqldb.SQL() self.ajax = ajax.Ajax() return