def push_one_file(self, f): file_info = VideoDetails() file_info['valid'] = transcode.supported_format(f['path']) temp_share = config.get_server('temp_share', '') temp_share_path = '' if temp_share: for name, data in config.getShares(): if temp_share == name: temp_share_path = data.get('path') mime = 'video/mpeg' if config.isHDtivo(f['tsn']): for m in ['video/mp4', 'video/bif']: if transcode.tivo_compatible(f['path'], f['tsn'], m)[0]: mime = m break if (mime == 'video/mpeg' and transcode.mp4_remuxable(f['path'], f['tsn'])): new_path = transcode.mp4_remux(f['path'], f['name'], f['tsn'], temp_share_path) if new_path: mime = 'video/mp4' f['name'] = new_path if temp_share_path: ip = config.get_ip() port = config.getPort() container = quote(temp_share) + '/' f['url'] = 'http://%s:%s/%s' % (ip, port, container) if file_info['valid']: file_info.update(self.metadata_full(f['path'], f['tsn'], mime)) url = f['url'] + quote(f['name']) title = file_info['seriesTitle'] if not title: title = file_info['title'] source = file_info['seriesId'] if not source: source = title subtitle = file_info['episodeTitle'] try: m = mind.getMind(f['tsn']) m.pushVideo( tsn = f['tsn'], url = url, description = file_info['description'], duration = file_info['duration'] / 1000, size = file_info['size'], title = title, subtitle = subtitle, source = source, mime = mime, tvrating = file_info['tvRating']) except Exception, msg: logger.error(msg)
def Push(self, handler, query): try: tsn = query['tsn'][0] except: logger.error('Push requires a TiVo Service Number') handler.send_error(404) return if not tsn in config.tivos: for key, value in config.tivos.items(): if value.get('name') == tsn: tsn = key break try: tivo_name = config.tivos[tsn]['name'] except: tivo_name = tsn container = quote(query['Container'][0].split('/')[0]) ip = config.get_ip(tsn) port = config.getPort() baseurl = 'http://%s:%s/%s' % (ip, port, container) if config.getIsExternal(tsn): exturl = config.get_server('externalurl') if exturl: if not exturl.endswith('/'): exturl += '/' baseurl = exturl + container else: ip = self.readip() baseurl = 'http://%s:%s/%s' % (ip, port, container) path = self.get_local_base_path(handler, query) files = query.get('File', []) for f in files: file_path = os.path.normpath(path + '/' + f) queue.append({ 'path': file_path, 'name': f, 'tsn': tsn, 'url': baseurl }) if len(queue) == 1: thread.start_new_thread(Video.process_queue, (self, )) logger.info('[%s] Queued "%s" for Push to %s' % (time.strftime('%d/%b/%Y %H:%M:%S'), unicode(file_path, 'utf-8'), tivo_name)) files = [unicode(f, 'utf-8') for f in files] handler.redir(PUSHED % (tivo_name, '<br>'.join(files)), 5)
def processDlRequest(self): while True: data = self.work_queue.get() for share_name, settings in config.getShares(): if settings['type'] == 'webvideo': break self.__logger.debug('Processing request: %s' % data) path = settings['path'] file_name = os.path.join(path, '%s-%s' % (data['bodyOfferId'].replace(':', '-'), data['url'].split('/')[-1])) status = self.downloadFile(data['url'], file_name) mime = 'video/mpeg' if status: tsn = data['bodyId'][4:] file_info = VideoDetails() if config.isHDtivo(tsn): for m in ['video/mp4', 'video/bif']: if tivo_compatible(file_name, tsn, m)[0]: mime = m break file_info.update(self.metadata_full(file_name, tsn, mime)) ip = config.get_ip() port = config.getPort() data['url'] = ('http://%s:%s' % (ip, port) + urllib.quote('/%s/%s' % (share_name, os.path.basename(file_name)))) data['duration'] = file_info['duration'] / 1000 data['size'] = file_info['size'] self.__logger.debug('Complete request: %s' % data) m = mind.getMind() m.completeDownloadRequest(data, status, mime) self.in_progress_lock.acquire() try: del self.in_progress[data['bodyOfferId']] finally: self.in_progress_lock.release()
def Push(self, handler, query): try: tsn = query['tsn'][0] except: logger.error('Push requires a TiVo Service Number') handler.send_error(404) return if not tsn in config.tivos: for key, value in config.tivos.items(): if value.get('name') == tsn: tsn = key break try: tivo_name = config.tivos[tsn]['name'] except: tivo_name = tsn container = quote(query['Container'][0].split('/')[0]) ip = config.get_ip(tsn) port = config.getPort() baseurl = 'http://%s:%s/%s' % (ip, port, container) if config.getIsExternal(tsn): exturl = config.get_server('externalurl') if exturl: if not exturl.endswith('/'): exturl += '/' baseurl = exturl + container else: ip = self.readip() baseurl = 'http://%s:%s/%s' % (ip, port, container) path = self.get_local_base_path(handler, query) files = query.get('File', []) for f in files: file_path = os.path.normpath(path + '/' + f) queue.append({'path': file_path, 'name': f, 'tsn': tsn, 'url': baseurl}) if len(queue) == 1: thread.start_new_thread(Video.process_queue, (self,)) logger.info('[%s] Queued "%s" for Push to %s' % (time.strftime('%d/%b/%Y %H:%M:%S'), unicode(file_path, 'utf-8'), tivo_name)) files = [unicode(f, 'utf-8') for f in files] handler.redir(PUSHED % (tivo_name, '<br>'.join(files)), 5)
async def fetch(session, url): try: if config.proxy_on: global proxy_num,myip,proxy if proxy_num %15==0: myip = config.get_ip(config.proxy_url) proxy = 'http://'+myip proxy_num += 1 async with session.get(url,headers=headers,timeout=10,proxy=proxy) as response: return await response.text() else: async with session.get(url,headers=headers,timeout=10) as response: return await response.text() except: return None
def Push(self, handler, query): tsn = query['tsn'][0] for key in config.tivo_names: if config.tivo_names[key] == tsn: tsn = key break tivo_name = config.tivo_names.get(tsn, tsn) container = quote(query['Container'][0].split('/')[0]) ip = config.get_ip(tsn) port = config.getPort() baseurl = 'http://%s:%s/%s' % (ip, port, container) if config.getIsExternal(tsn): exturl = config.get_server('externalurl') if exturl: baseurl = exturl else: ip = self.readip() baseurl = 'http://%s:%s/%s' % (ip, port, container) path = self.get_local_base_path(handler, query) files = query.get('File', []) for f in files: file_path = path + os.path.normpath(f) queue.append({ 'path': file_path, 'name': f, 'tsn': tsn, 'url': baseurl }) if len(queue) == 1: thread.start_new_thread(Video.process_queue, (self, )) logger.info('[%s] Queued "%s" for Push to %s' % (time.strftime('%d/%b/%Y %H:%M:%S'), unicode(file_path, 'utf-8'), tivo_name)) files = [unicode(f, 'utf-8') for f in files] handler.redir(PUSHED % (tivo_name, '<br>'.join(files)), 5)
def Push(self, handler, query): tsn = query['tsn'][0] for key in config.tivo_names: if config.tivo_names[key] == tsn: tsn = key break tivo_name = config.tivo_names.get(tsn, tsn) container = quote(query['Container'][0].split('/')[0]) ip = config.get_ip(tsn) port = config.getPort() baseurl = 'http://%s:%s/%s' % (ip, port, container) if config.getIsExternal(tsn): exturl = config.get_server('externalurl') if exturl: if not exturl.endswith('/'): exturl += '/' baseurl = exturl + container else: ip = self.readip() baseurl = 'http://%s:%s/%s' % (ip, port, container) path = self.get_local_base_path(handler, query) files = query.get('File', []) for f in files: file_path = path + os.path.normpath(f) queue.append({'path': file_path, 'name': f, 'tsn': tsn, 'url': baseurl}) if len(queue) == 1: thread.start_new_thread(Video.process_queue, (self,)) logger.info('[%s] Queued "%s" for Push to %s' % (time.strftime('%d/%b/%Y %H:%M:%S'), unicode(file_path, 'utf-8'), tivo_name)) files = [unicode(f, 'utf-8') for f in files] handler.redir(PUSHED % (tivo_name, '<br>'.join(files)), 5)
def Push(self, handler, query): tsn = query["tsn"][0] for key in config.tivo_names: if config.tivo_names[key] == tsn: tsn = key break tivo_name = config.tivo_names.get(tsn, tsn) container = quote(query["Container"][0].split("/")[0]) ip = config.get_ip(tsn) port = config.getPort() baseurl = "http://%s:%s/%s" % (ip, port, container) if config.getIsExternal(tsn): exturl = config.get_server("externalurl") if exturl: if not exturl.endswith("/"): exturl += "/" baseurl = exturl + container else: ip = self.readip() baseurl = "http://%s:%s/%s" % (ip, port, container) path = self.get_local_base_path(handler, query) files = query.get("File", []) for f in files: file_path = path + os.path.normpath(f) queue.append({"path": file_path, "name": f, "tsn": tsn, "url": baseurl}) if len(queue) == 1: thread.start_new_thread(Video.process_queue, (self,)) logger.info( '[%s] Queued "%s" for Push to %s' % (time.strftime("%d/%b/%Y %H:%M:%S"), unicode(file_path, "utf-8"), tivo_name) ) files = [unicode(f, "utf-8") for f in files] handler.redir(PUSHED % (tivo_name, "<br>".join(files)), 5)
def push_one_file(self, f): file_info = VideoDetails() file_info['valid'] = transcode.supported_format(f['path']) temp_share = config.get_server('temp_share', '') temp_share_path = '' remux_path = os.path.dirname(f['path']) if temp_share: for name, data in config.getShares(): if temp_share == name: temp_share_path = data.get('path') remux_path = temp_share_path mime = 'video/mpeg' if config.isHDtivo(f['tsn']): for m in ['video/mp4', 'video/bif']: if transcode.tivo_compatible(f['path'], f['tsn'], m)[0]: mime = m break if (mime == 'video/mpeg' and transcode.mp4_remuxable(f['path'], f['tsn'])): if config.get_freeSpace(remux_path, f['path']): new_path = transcode.mp4_remux(f['path'], f['name'], f['tsn'], temp_share_path) if new_path: mime = 'video/mp4' f['name'] = new_path if temp_share_path: ip = config.get_ip() port = config.getPort() container = quote(temp_share) + '/' f['url'] = 'http://%s:%s/%s' % (ip, port, container) else: logger.warning('Not enough disk space to perform remux, ' + 'transcoding instead.') if file_info['valid']: file_info.update(self.metadata_full(f['path'], f['tsn'], mime)) url = f['url'] + quote(f['name']) title = file_info['seriesTitle'] if not title: title = file_info['title'] source = file_info['seriesId'] if not source: source = title subtitle = file_info['episodeTitle'] try: m = mind.getMind(f['tsn']) m.pushVideo( tsn = f['tsn'], url = url, description = file_info['description'], duration = file_info['duration'] / 1000, size = file_info['size'], title = title, subtitle = subtitle, source = source, mime = mime, tvrating = file_info['tvRating']) except ValueError, msg: if 'usernamePasswordError' in msg: if f['name'].endswith('.pyTivo-temp'): fname = os.path.join(remux_path, os.path.basename(f['name'])) fname = unicode(fname, 'utf-8') os.remove(fname) logger.debug(fname + ' has been removed')
#!/usr/bin/env python import socket, config, time import sender, receiver, log from message import MessageTransporter if __name__ == '__main__': port = config.get_available_port() config.insert_proc_on_group (port) proc_id = config.get_uuid() ip = config.get_ip() transporter = MessageTransporter(ip, port) log.log('process {proc_id} waiting for start at {ip}:{port}'.format(ip = ip, port=port, proc_id = proc_id)) start_message = transporter.receive() log.log('{proc_id} received start message:[{msg}]'.format(proc_id = proc_id, msg = start_message)) group = [proc for proc in config.get_group() if proc['port'] != port] send_msgs_count = int(start_message['start']) time.sleep(3) #starting receiver thread received_msgs_count = (len(group) + 1) * send_msgs_count receiver = receiver.Receiver(proc_id, group, received_msgs_count, transporter) receiver.start() #starting sender thread sender = sender.Sender(proc_id, group, send_msgs_count, transporter) sender.start()
# Author: Aniketh S Deshpande # API-name: Student-API # Flask-Server # Database: MongoDB from flask import Flask, request, jsonify from flask_restful import Resource, Api from flask_pymongo import PyMongo from flask_cors import CORS from random import randint from hashlib import sha1 from config import get_ip ip_address = get_ip() app = Flask(__name__) CORS(app) app.config["MONGO_URI"] = "mongodb://localhost:27017/quiz" api = Api(app) mongo = PyMongo(app) #StudentSignUp class StudentSignUp(Resource): # checkAvailability is a function that checks if the email_id # can be used to create a new account def checkAvailability(self, obj): mongo_obj = list( mongo.db.student_details.find({'email_id': obj['email_id']})) if len(mongo_obj) > 0: return False
def get_stock_url(env): ip = get_ip(env) mfc_code = get_mfc_code(env) return f"http://{ip}:8090/api/stock/details?mfc-code={mfc_code}"
def Push(self, handler, query): tsn = query['tsn'][0] for key in config.tivo_names: if config.tivo_names[key] == tsn: tsn = key break tivo_name = config.tivo_names.get(tsn, tsn) container = quote(query['Container'][0].split('/')[0]) ip = config.get_ip() port = config.getPort() baseurl = 'http://%s:%s' % (ip, port) if config.getIsExternal(tsn): exturl = config.get_server('externalurl') if exturl: baseurl = exturl else: ip = self.readip() baseurl = 'http://%s:%s' % (ip, port) path = self.get_local_base_path(handler, query) files = query.get('File', []) for f in files: file_path = path + os.path.normpath(f) file_info = VideoDetails() file_info['valid'] = transcode.supported_format(file_path) mime = 'video/mpeg' if config.isHDtivo(tsn): for m in ['video/mp4', 'video/bif']: if transcode.tivo_compatible(file_path, tsn, m)[0]: mime = m break if file_info['valid']: file_info.update(self.metadata_full(file_path, tsn, mime)) url = baseurl + '/%s%s' % (container, quote(f)) title = file_info['seriesTitle'] if not title: title = file_info['title'] source = file_info['seriesId'] if not source: source = title subtitle = file_info['episodeTitle'] try: m = mind.getMind(tsn) m.pushVideo( tsn = tsn, url = url, description = file_info['description'], duration = file_info['duration'] / 1000, size = file_info['size'], title = title, subtitle = subtitle, source = source, mime = mime, tvrating = file_info['tvRating']) except Exception, e: handler.send_response(500) handler.end_headers() handler.wfile.write('%s\n\n%s' % (e, traceback.format_exc() )) raise logger.info('[%s] Queued "%s" for Push to %s' % (time.strftime('%d/%b/%Y %H:%M:%S'), unicode(file_path, 'utf-8'), tivo_name))
os.environ["EXPORT_FILE"] = export_file log_file_extension = (config.current_timestamp + ".log") log_file1 = (report_title + "_" + log_file_extension) os.environ["LOG_FILE_EXTENSION"] = log_file_extension os.environ["LOG_FILE1"] = log_file1 log_file_list = [log_file1] log_file_list_len = len(log_file_list) else: logger.error('Wrong or none-existing report number, exiting') exit(1) config.isOFFICEnetwork(config.default_local_ip) if verbose == True: logger.debug('current timestamp is: ' + config.blue + config.current_timestamp) logger.debug('my default ip is: ' + config.blue + config.get_ip()) if config.office == 1: if verbose == True: logger.debug(config.blue + 'office_network is present') office_ip = config.default_local_ip os.environ["OFFICE_IP"] = office_ip elif config.vpn == 1: if verbose == True: logger.debug(config.blue + 'vpn is present') vpn_ip = config.default_local_ip os.environ["VPN_IP"] = vpn_ip else: if verbose == True: logger.debug(config.blue + 'not connected to the office') #running appropriate BTEQ script