def view(self): path = getParam('path', '/') home = getUserDir() if not path: path = home try: dirs = self.getDirectories(path=path, show_hidden=getParam( 'show_hidden', True)) except: dirs = [] parent = os.path.dirname(path.rstrip(os.path.sep)) if parent == path.rstrip(os.path.sep): parent = '/' elif parent != '/' and parent[-2:] != ':\\': parent += os.path.sep return jsonified({ 'is_root': path == '/', 'empty': len(dirs) == 0, 'parent': parent, 'home': home + os.path.sep, 'platform': os.name, 'dirs': dirs, })
def view(self): path = getParam('path', '/') home = getUserDir() if not path: path = home try: dirs = self.getDirectories(path = path, show_hidden = getParam('show_hidden', True)) except: dirs = [] parent = os.path.dirname(path.rstrip(os.path.sep)) if parent == path.rstrip(os.path.sep): parent = '/' elif parent != '/' and parent[-2:] != ':\\': parent += os.path.sep return jsonified({ 'is_root': path == '/', 'empty': len(dirs) == 0, 'parent': parent, 'home': home + os.path.sep, 'platform': os.name, 'dirs': dirs, })
def view(self): path = getParam('path', '/') # Set proper home dir for some systems try: import pwd os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir except: pass home = os.path.expanduser('~') if not path: path = home try: dirs = self.getDirectories(path = path, show_hidden = getParam('show_hidden', True)) except: dirs = [] parent = os.path.dirname(path.rstrip(os.path.sep)) if parent == path.rstrip(os.path.sep): parent = '/' elif parent != '/' and parent[-2:] != ':\\': parent += os.path.sep return jsonified({ 'is_root': path == '/', 'empty': len(dirs) == 0, 'parent': parent, 'home': home + os.path.sep, 'platform': os.name, 'dirs': dirs, })
def view(self): try: dirs = self.getDirectories(path = getParam('path', '/'), show_hidden = getParam('show_hidden', True)) except: dirs = [] return jsonified({ 'empty': len(dirs) == 0, 'dirs': dirs, })
def view(self): path = getParam('path', '/') try: dirs = self.getDirectories(path = path, show_hidden = getParam('show_hidden', True)) except: dirs = [] return jsonified({ 'is_root': path == '/' or not path, 'empty': len(dirs) == 0, 'dirs': dirs, })
def add2(self): db = get_session() rand = random.randrange(10000, 90000, 2) lib_id = getParam("lib_id") qua_id = getParam("qua_id") name = getParam("name") identifier = "azerty12345678900" + str(rand) + "00" + lib_id + "00" + qua_id if not lib_id or not qua_id or not name: return jsonified({"success": False}) # Add movie done_status = fireEvent("status.get", "done", single=True) snatched_status = fireEvent("status.get", "snatched", single=True) movie = db.query(Movie).filter_by(library_id=lib_id).first() if not movie: log.debug("Update status to snatched") movie = Movie(library_id=lib_id, profile_id=0, status_id=snatched_status.get("id")) db.add(movie) db.commit() # Add Release rls = db.query(Relea).filter_by(identifier=identifier).first() if not rls: log.debug("Add a %s release for movie %s.", (snatched_status.get("label"), movie.id)) rls = Relea(identifier=identifier, movie=movie, quality_id=qua_id, status_id=snatched_status.get("id")) db.add(rls) db.commit() # Add ReleaseInfo log.debug("Add a %s releaseinfo for movie %s.", (snatched_status.get("label"), movie.id)) infos = { "name": "azerty", "type": "nzb", "size": "700", "description": "", "url": "", "age": "1", "score": "100", } infos["name"] = name for key, value in infos.items(): rls_info = ReleaseInfo(identifier=key, value=toUnicode(value)) rls.info.append(rls_info) db.commit() log.info("New %s release added for movie %s.", (snatched_status.get("label"), movie.id)) return jsonified({"success": True, "identifier": identifier})
def getAuthorizationUrl(self): referer = getParam('host') callback_url = cleanHost(referer) + '%snotify.%s.credentials/' % ( url_for('api.index').lstrip('/'), self.getName().lower()) oauth_consumer = oauth2.Consumer(self.consumer_key, self.consumer_secret) oauth_client = oauth2.Client(oauth_consumer) resp, content = oauth_client.request( self.urls['request'], 'POST', body=tryUrlencode({'oauth_callback': callback_url})) if resp['status'] != '200': log.error( 'Invalid response from Twitter requesting temp token: %s', resp['status']) return jsonified({ 'success': False, }) else: self.request_token = dict(parse_qsl(content)) auth_url = self.urls['authorize'] + ( "?oauth_token=%s" % self.request_token['oauth_token']) log.info('Redirecting to "%s"', auth_url) return jsonified({ 'success': True, 'url': auth_url, })
def getCredentials(self): key = getParam('oauth_verifier') token = oauth2.Token(self.request_token['oauth_token'], self.request_token['oauth_token_secret']) token.set_verifier(key) oauth_consumer = oauth2.Consumer(key=self.consumer_key, secret=self.consumer_secret) oauth_client = oauth2.Client(oauth_consumer, token) resp, content = oauth_client.request(self.urls['access'], method='POST', body='oauth_verifier=%s' % key) access_token = dict(parse_qsl(content)) if resp['status'] != '200': log.error('The request for an access token did not succeed: %s', resp['status']) return 'Twitter auth failed' else: log.debug('Tokens: %s, %s', (access_token['oauth_token'], access_token['oauth_token_secret'])) self.conf('access_token_key', value=access_token['oauth_token']) self.conf('access_token_secret', value=access_token['oauth_token_secret']) self.conf('screen_name', value=access_token['screen_name']) self.request_token = None return redirect(url_for('web.index') + 'settings/notifications/')
def getCredentials(self): key = getParam('oauth_verifier') token = oauth2.Token(self.request_token['oauth_token'], self.request_token['oauth_token_secret']) token.set_verifier(key) oauth_consumer = oauth2.Consumer(key = self.consumer_key, secret = self.consumer_secret) oauth_client = oauth2.Client(oauth_consumer, token) resp, content = oauth_client.request(self.urls['access'], method = 'POST', body = 'oauth_verifier=%s' % key) access_token = dict(parse_qsl(content)) if resp['status'] != '200': log.error('The request for an access token did not succeed: %s' % resp['status']) return 'Twitter auth failed' else: log.debug('Tokens: %s, %s' % (access_token['oauth_token'], access_token['oauth_token_secret'])) self.conf('access_token_key', value = access_token['oauth_token']) self.conf('access_token_secret', value = access_token['oauth_token_secret']) self.conf('screen_name', value = access_token['screen_name']) self.request_token = None return redirect(url_for('web.index') + 'settings/notifications/')
def download(self): db = get_session() id = getParam('id') rel = db.query(Relea).filter_by(id = id).first() if rel: item = {} for info in rel.info: item[info.identifier] = info.value # Get matching provider provider = fireEvent('provider.belongs_to', item['url'], single = True) item['download'] = provider.download fireEvent('searcher.download', data = item, movie = rel.movie.to_dict({ 'profile': {'types': {'quality': {}}}, 'releases': {'status': {}, 'quality': {}}, 'library': {'titles': {}, 'files':{}}, 'files': {} })) return jsonified({ 'success': True }) else: log.error('Couldn\'t find release with id: %s' % id) return jsonified({ 'success': False })
def refresh(self): db = get_session() for id in splitString(getParam('id')): movie = db.query(Movie).filter_by(id=id).first() if movie: # Get current selected title default_title = '' for title in movie.library.titles: if title.default: default_title = title.title fireEvent('notify.frontend', type='movie.busy.%s' % id, data=True, message='Updating "%s"' % default_title) fireEventAsync('library.update', identifier=movie.library.identifier, default_title=default_title, force=True, on_complete=self.createOnComplete(id)) #db.close() return jsonified({ 'success': True, })
def listView(self): db = get_session() limit_offset = getParam('limit_offset', None) q = db.query(Notif) if limit_offset: splt = splitString(limit_offset) limit = splt[0] offset = 0 if len(splt) is 1 else splt[1] q = q.limit(limit).offset(offset) else: q = q.limit(200) results = q.all() notifications = [] for n in results: ndict = n.to_dict() ndict['type'] = 'notification' notifications.append(ndict) return jsonified({ 'success': True, 'empty': len(notifications) == 0, 'notifications': notifications })
def refresh(self): db = get_session() for id in getParam("id").split(","): movie = db.query(Movie).filter_by(id=id).first() if movie: # Get current selected title default_title = "" for title in movie.library.titles: if title.default: default_title = title.title fireEvent( "notify.frontend", type="movie.busy.%s" % id, data=True, message='Updating "%s"' % default_title ) fireEventAsync( "library.update", identifier=movie.library.identifier, default_title=default_title, force=True, on_complete=self.createOnComplete(id), ) # db.close() return jsonified({"success": True})
def listView(self): db = get_session() limit_offset = getParam('limit_offset', None) q = db.query(Notif) if limit_offset: splt = [x.strip() for x in limit_offset.split(',')] limit = splt[0] offset = 0 if len(splt) is 1 else splt[1] q = q.limit(limit).offset(offset) results = q.all() notifications = [] for n in results: ndict = n.to_dict() ndict['type'] = 'notification' notifications.append(ndict) #db.close() return jsonified({ 'success': True, 'empty': len(notifications) == 0, 'notifications': notifications })
def get(self): nr = int(getParam('nr', 0)) current_path = None total = 1 for x in range(0, 50): path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '') # Check see if the log exists if not os.path.isfile(path): total = x - 1 break # Set current path if x is nr: current_path = path log = '' if current_path: f = open(current_path, 'r') log = f.read() return jsonified({ 'success': True, 'log': log, 'total': total, })
def deleteView(self): release_id = getParam('id') return jsonified({ 'success': self.delete(release_id) })
def refresh(self): db = get_session() for id in getParam('id').split(','): fireEvent('notify.frontend', type='movie.busy.%s' % id, data=True) movie = db.query(Movie).filter_by(id=id).first() if movie: # Get current selected title default_title = '' for title in movie.library.titles: if title.default: default_title = title.title fireEventAsync( 'library.update', identifier=movie.library.identifier, default_title=default_title, force=True, on_complete=self.createOnComplete(id)) #db.close() return jsonified({ 'success': True, })
def getAuthorizationUrl(self): referer = getParam('host') callback_url = cleanHost(referer) + '%snotify.%s.credentials/' % (url_for('api.index').lstrip('/'), self.getName().lower()) oauth_consumer = oauth2.Consumer(self.consumer_key, self.consumer_secret) oauth_client = oauth2.Client(oauth_consumer) resp, content = oauth_client.request(self.urls['request'], 'POST', body = tryUrlencode({'oauth_callback': callback_url})) if resp['status'] != '200': log.error('Invalid response from Twitter requesting temp token: %s' % resp['status']) return jsonified({ 'success': False, }) else: self.request_token = dict(parse_qsl(content)) auth_url = self.urls['authorize'] + ("?oauth_token=%s" % self.request_token['oauth_token']) log.info('Redirecting to "%s"' % auth_url) return jsonified({ 'success': True, 'url': auth_url, })
def tryNextReleaseView(self): trynext = self.tryNextRelease(getParam('id')) return jsonified({ 'success': trynext })
def listener(self): messages = [] for message in self.messages: #delete message older then 15s if message['time'] > (time.time() - 15): messages.append(message) # Get unread if getParam('init'): db = get_session() notifications = db.query(Notif) \ .filter(or_(Notif.read == False, Notif.added > (time.time() - 259200))) \ .all() for n in notifications: ndict = n.to_dict() ndict['type'] = 'notification' messages.append(ndict) #db.close() self.messages = [] return jsonified({ 'success': True, 'result': messages, })
def get(self): nr = int(getParam('nr', 0)) current_path = None total = 1 for x in range(0, 50): path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '') # Check see if the log exists if not os.path.isfile(path): total = x - 1 break # Set current path if x is nr: current_path = path log = '' if current_path: f = open(current_path, 'r') log = f.read() return jsonified({ 'success': True, 'log': toUnicode(log), 'total': total, })
def updateLibraryView(self): full = getParam('full', default = 1) fireEventAsync('manage.update', full = True if full == '1' else False) return jsonified({ 'success': True })
def queueSortView(self): full = getParam('mode', default = 1) fireEventAsync('queue.sort', mode = True if mode == '1' else False) return jsonified({ 'success': True })
def bookmark(self): params = { 'includes': fireEvent('userscript.get_includes', merge=True), 'excludes': fireEvent('userscript.get_excludes', merge=True), 'host': getParam('host', None), } return self.renderTemplate(__file__, 'bookmark.js', **params)
def bookmark(self): params = { 'includes': fireEvent('userscript.get_includes', merge = True), 'excludes': fireEvent('userscript.get_excludes', merge = True), 'host': getParam('host', None), } return self.renderTemplate(__file__, 'bookmark.js', **params)
def download(self): db = get_session() id = getParam("id") snatched_status = fireEvent("status.add", "snatched", single=True) done_status = fireEvent("status.get", "done", single=True) rel = db.query(Relea).filter_by(id=id).first() if rel: item = {} for info in rel.info: item[info.identifier] = info.value fireEvent("notify.frontend", type="release.download", data=True, message='Snatching "%s"' % item["name"]) # Get matching provider provider = fireEvent("provider.belongs_to", item["url"], provider=item.get("provider"), single=True) if item["type"] != "torrent_magnet": item["download"] = provider.download success = fireEvent( "searcher.download", data=item, movie=rel.movie.to_dict( { "profile": {"types": {"quality": {}}}, "releases": {"status": {}, "quality": {}}, "library": {"titles": {}, "files": {}}, "files": {}, } ), manual=True, single=True, ) if success: db.expunge_all() rel = db.query(Relea).filter_by(id=id).first() # Get release again if rel.status_id != done_status.get("id"): rel.status_id = snatched_status.get("id") db.commit() fireEvent( "notify.frontend", type="release.download", data=True, message='Successfully snatched "%s"' % item["name"], ) return jsonified({"success": success}) else: log.error("Couldn't find release with id: %s", id) return jsonified({"success": False})
def getView(self): movie_id = getParam('id') movie = self.get(movie_id) if movie_id else None return jsonified({ 'success': movie is not None, 'movie': movie, })
def markAsRead(self): ids = None if getParam("ids"): ids = [x.strip() for x in getParam("ids").split(",")] db = get_session() if ids: q = db.query(Notif).filter(or_(*[Notif.id == tryInt(s) for s in ids])) else: q = db.query(Notif).filter_by(read=False) q.update({Notif.read: True}) db.commit() # db.close() return jsonified({"success": True})
def markAsRead(self): ids = None if getParam('ids'): ids = splitString(getParam('ids')) db = get_session() if ids: q = db.query(Notif).filter( or_(*[Notif.id == tryInt(s) for s in ids])) else: q = db.query(Notif).filter_by(read=False) q.update({Notif.read: True}) db.commit() return jsonified({'success': True})
def getView(self): limit_offset = getParam('limit_offset', None) total_movies, movies = fireEvent('movie.list', status = 'suggest', limit_offset = limit_offset, single = True) return jsonified({ 'success': True, 'empty': len(movies) == 0, 'total': total_movies, 'movies': movies, })
def delete(self): db = get_session() id = getParam('id') rel = db.query(Relea).filter_by(id=id).first() if rel: rel.delete() db.commit() return jsonified({'success': True})
def markAsRead(self): ids = None if getParam('ids'): ids = splitString(getParam('ids')) db = get_session() if ids: q = db.query(Notif).filter(or_(*[Notif.id == tryInt(s) for s in ids])) else: q = db.query(Notif).filter_by(read = False) q.update({Notif.read: True}) db.commit() return jsonified({ 'success': True })
def delete(self): db = get_session() id = getParam('id') rel = db.query(Relea).filter_by(id = id).first() if rel: rel.delete() db.commit() return jsonified({ 'success': True })
def getViaUrl(self): url = getParam('url') params = { 'url': url, 'movie': fireEvent('userscript.get_movie_via_url', url = url, single = True) } if not isDict(params['movie']): log.error('Failed adding movie via url: %s' % url) params['error'] = params['movie'] if params['movie'] else 'Failed getting movie info' return jsonified(params)
def partial(self): log_type = getParam('type', 'all') total_lines = getParam('lines', 30) log_lines = [] for x in range(0, 50): path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '') # Check see if the log exists if not os.path.isfile(path): break reversed_lines = [] f = open(path, 'r') reversed_lines = f.read().split('[0m\n') reversed_lines.reverse() brk = False for line in reversed_lines: #print '%s ' % log_type in line.lower() if log_type == 'all' or '%s ' % log_type.upper() in line: log_lines.append(line) if len(log_lines) >= total_lines: brk = True break if brk: break log_lines.reverse() return jsonified({ 'success': True, 'log': '[0m\n'.join(log_lines), })
def download(self): db = get_session() id = getParam('id') status_snatched = fireEvent('status.add', 'snatched', single=True) rel = db.query(Relea).filter_by(id=id).first() if rel: item = {} for info in rel.info: item[info.identifier] = info.value # Get matching provider provider = fireEvent('provider.belongs_to', item['url'], provider=item.get('provider'), single=True) if item['type'] != 'torrent_magnet': item['download'] = provider.download success = fireEvent('searcher.download', data=item, movie=rel.movie.to_dict({ 'profile': { 'types': { 'quality': {} } }, 'releases': { 'status': {}, 'quality': {} }, 'library': { 'titles': {}, 'files': {} }, 'files': {} }), manual=True, single=True) if success: rel.status_id = status_snatched.get('id') db.commit() return jsonified({'success': success}) else: log.error('Couldn\'t find release with id: %s', id) return jsonified({'success': False})
def partial(self): log_type = getParam('type', 'all') total_lines = tryInt(getParam('lines', 30)) log_lines = [] for x in range(0, 50): path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '') # Check see if the log exists if not os.path.isfile(path): break reversed_lines = [] f = open(path, 'r') reversed_lines = toUnicode(f.read()).split('[0m\n') reversed_lines.reverse() brk = False for line in reversed_lines: if log_type == 'all' or '%s ' % log_type.upper() in line: log_lines.append(line) if len(log_lines) >= total_lines: brk = True break if brk: break log_lines.reverse() return jsonified({ 'success': True, 'log': '[0m\n'.join(log_lines), })
def getView(self): limit_offset = getParam('limit_offset', None) total_movies, movies = fireEvent('movie.list', status='suggest', limit_offset=limit_offset, single=True) return jsonified({ 'success': True, 'empty': len(movies) == 0, 'total': total_movies, 'movies': movies, })
def ignore(self): db = get_session() id = getParam('id') rel = db.query(Relea).filter_by(id = id).first() if rel: ignored_status, available_status = fireEvent('status.get', ['ignored', 'available'], single = True) rel.status_id = available_status.get('id') if rel.status_id is ignored_status.get('id') else ignored_status.get('id') db.commit() return jsonified({ 'success': True })
def markAsRead(self): ids = getParam('ids').split(',') db = get_session() q = db.query(Notif) \ .filter(or_(*[Notif.id == tryInt(s) for s in ids])) q.update({Notif.read: True}) db.commit() return jsonified({ 'success': True })
def search(self): q = getParam("q") cache_key = u"%s/%s" % (__name__, simplifyString(q)) movies = Env.get("cache").get(cache_key) if not movies: if getImdb(q): movies = [fireEvent("movie.info", identifier=q, merge=True)] else: movies = fireEvent("movie.search", q=q, merge=True) Env.get("cache").set(cache_key, movies) return jsonified({"success": True, "empty": len(movies) == 0 if movies else 0, "movies": movies})
def listener(self): messages = [] # Get unread if getParam("init"): db = get_session() notifications = db.query(Notif).filter(or_(Notif.read == False, Notif.added > (time.time() - 259200))).all() for n in notifications: ndict = n.to_dict() ndict["type"] = "notification" messages.append(ndict) return jsonified({"success": True, "result": messages})
def getViaUrl(self): url = getParam('url') params = { 'url': url, 'movie': fireEvent('userscript.get_movie_via_url', url=url, single=True) } if not isDict(params['movie']): log.error('Failed adding movie via url: %s', url) params['error'] = params['movie'] if params[ 'movie'] else 'Failed getting movie info' return jsonified(params)
def download(self): db = get_session() id = getParam('id') snatched_status, done_status = fireEvent('status.get', ['snatched', 'done'], single = True) rel = db.query(Relea).filter_by(id = id).first() if rel: item = {} for info in rel.info: item[info.identifier] = info.value fireEvent('notify.frontend', type = 'release.download', data = True, message = 'Snatching "%s"' % item['name']) # Get matching provider provider = fireEvent('provider.belongs_to', item['url'], provider = item.get('provider'), single = True) if item['type'] != 'torrent_magnet': item['download'] = provider.download success = fireEvent('searcher.download', data = item, movie = rel.movie.to_dict({ 'profile': {'types': {'quality': {}}}, 'releases': {'status': {}, 'quality': {}}, 'library': {'titles': {}, 'files':{}}, 'files': {} }), manual = True, single = True) if success: db.expunge_all() rel = db.query(Relea).filter_by(id = id).first() # Get release again if rel.status_id != done_status.get('id'): rel.status_id = snatched_status.get('id') db.commit() fireEvent('notify.frontend', type = 'release.download', data = True, message = 'Successfully snatched "%s"' % item['name']) return jsonified({ 'success': success }) else: log.error('Couldn\'t find release with id: %s', id) return jsonified({ 'success': False })
def delete(self): id = getParam('id') db = get_session() success = False message = '' try: p = db.query(Profile).filter_by(id=id).first() db.delete(p) db.commit() success = True except Exception, e: message = log.error('Failed deleting Profile: %s', e)
def get(self): nr = int(getParam('nr', 0)) path = '%s%s' % (Env.get('log_path'), '.%s' % nr if nr > 0 else '') # Reverse f = open(path, 'r') lines = [] for line in f.readlines(): lines.insert(0, line) log = '' for line in lines: log += line return jsonified({ 'success': True, 'log': log, })
def search(self): q = getParam('q') cache_key = u'%s/%s' % (__name__, simplifyString(q)) movies = Env.get('cache').get(cache_key) if not movies: if getImdb(q): movies = [fireEvent('movie.info', identifier=q, merge=True)] else: movies = fireEvent('movie.search', q=q, merge=True) Env.get('cache').set(cache_key, movies) return jsonified({ 'success': True, 'empty': len(movies) == 0 if movies else 0, 'movies': movies, })
def listener(self): messages = [] # Get unread if getParam('init'): db = get_session() notifications = db.query(Notif) \ .filter(or_(Notif.read == False, Notif.added > (time.time() - 259200))) \ .all() for n in notifications: ndict = n.to_dict() ndict['type'] = 'notification' messages.append(ndict) return jsonified({ 'success': True, 'result': messages, })
def download(self): db = get_session() id = getParam('id') rel = db.query(Relea).filter_by(id=id).first() if rel: item = {} for info in rel.info: item[info.identifier] = info.value # Get matching provider provider = fireEvent('provider.belongs_to', item['url'], single=True) item['download'] = provider.download fireEvent('searcher.download', data=item, movie=rel.movie.to_dict({ 'profile': { 'types': { 'quality': {} } }, 'releases': { 'status': {}, 'quality': {} }, 'library': { 'titles': {}, 'files': {} }, 'files': {} })) return jsonified({'success': True}) else: log.error('Couldn\'t find release with id: %s' % id) return jsonified({'success': False})