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): file = unquote(query['File'][0]) tsn = query['tsn'][0] path = self.get_local_path(handler, query) file_path = path + file file_info = VideoDetails() file_info['valid'] = transcode.supported_format(file_path) if file_info['valid']: file_info.update(self.__metadata_full(file_path, tsn)) import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('tivo.com',123)) ip = s.getsockname()[0] container = quote(query['Container'][0].split('/')[0]) port = config.getPort() url = 'http://%s:%s/%s%s' % (ip, port, container, quote(file)) print 'tsn', tsn print 'url', url print query username = config.getTivoUsername() password = config.getTivoPassword() if not username or not password: raise Exception("tivo_username and tivo_password required") try: m = mind.Mind(username, password, True) m.pushVideo( tsn = tsn, url = url, description = file_info['description'], duration = file_info['duration'] / 1000, size = file_info['size'], title = file_info['title'], subtitle = file_info['name']) except Exception, e: import traceback handler.send_response(500) handler.end_headers() handler.wfile.write('%s\n\n%s' % (e, traceback.format_exc() )) raise
def Push(self, handler, query): file = unquote(query['File'][0]) tsn = query['tsn'][0] path = self.get_local_path(handler, query) file_path = path + file file_info = VideoDetails() file_info['valid'] = transcode.supported_format(file_path) if file_info['valid']: file_info.update(self.__metadata_full(file_path, tsn)) import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('tivo.com', 123)) ip = s.getsockname()[0] container = quote(query['Container'][0].split('/')[0]) port = config.getPort() url = 'http://%s:%s/%s%s' % (ip, port, container, quote(file)) print 'tsn', tsn print 'url', url print query username = config.getTivoUsername() password = config.getTivoPassword() if not username or not password: raise Exception("tivo_username and tivo_password required") try: m = mind.Mind(username, password, True) m.pushVideo(tsn=tsn, url=url, description=file_info['description'], duration=file_info['duration'] / 1000, size=file_info['size'], title=file_info['title'], subtitle=file_info['name']) except Exception, e: import traceback handler.send_response(500) handler.end_headers() handler.wfile.write('%s\n\n%s' % (e, traceback.format_exc())) raise
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 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 push_one_file(self, f): file_info = VideoDetails() file_info['valid'] = transcode.supported_format(f['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']) if new_path: mime = 'video/mp4' f['name'] = new_path 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_one_file(self, f): file_info = VideoDetails() file_info["valid"] = transcode.supported_format(f["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"]) if new_path: mime = "video/mp4" f["name"] = new_path 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_one_file(self, f): file_info = VideoDetails() file_info['valid'] = transcode.supported_format(f['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']) if new_path: mime = 'video/mp4' f['name'] = new_path 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): 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')
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))