def run_cmd_async(self, body): try: self.stdin.write(body) except: request_info = request_info_serialize(video_id=self.video_id, status='failed', bitrate=str(self.bitrate)) res = http_callback(self.config['url']['update_video_status'], request_info) self.log(res, self.video_id, 'update_video_status', 'stdin.write error line 61') return 1 running = self.running() while running: line = self.stdout.read(-1) #segment:'/tmp/a_sd_000030.flv' count:30 endedp=24 drop=0 if line is None: break line = line.decode() ts_re = re.search("segment:\'(.*?)\'\s+count:(\d+).*", line) if ts_re: ts_file = ts_re.group(1) ts_file_index = ts_re.group(2) ts_filename = ts_file.split('/')[-1] (target_file, storage_path) = get_target_file( self.config['storage']['release_dir'], ts_filename, 'ts') retcode = flv2ts(ts_file, target_file) if retcode != 0: self.logger.error("flv2ts flvfile: %s tsfile: %s failed", ts_file, target_file) continue request_info = self.segment_request_info( target_file, storage_path, ts_file_index) add_video_segment_url = self.config['url']['add_video_segment'] res = http_callback(add_video_segment_url, request_info) self.log(res, self.video_id, 'add_video_segment', storage_path) snap_re = re.search("snap:\'(.*?)\'\s+count:(\d+).*", line) if snap_re: snap_img_file = snap_re.group(1) snap_index = snap_re.group(2) snap_filename = snap_img_file.split('/')[-1] (target_file, storage_path) = get_target_file( self.config['storage']['release_dir'], snap_filename, 'snap') shutil.move(snap_img_file, target_file) info = request_info_serialize(video_id=self.video_id, snap_image_count=snap_index) res = http_callback( self.config['url']['update_video_snap_image_count'], info) self.log(res, self.video_id, 'update_video_snap_image_count', storage_path)
def run_cmd_async(self, body): try: self.stdin.write(body) except: request_info = request_info_serialize(video_id=self.video_id, status='failed', bitrate=str(self.bitrate)) res = http_callback(self.config['url']['update_video_status'], request_info) self.log(res, self.video_id, 'update_video_status', 'stdin.write error line 61') return 1 running = self.running() while running: line = self.stdout.read(-1) #segment:'/tmp/a_sd_000030.flv' count:30 endedp=24 drop=0 if line is None: break line = line.decode() ts_re = re.search("segment:\'(.*?)\'\s+count:(\d+).*", line) if ts_re: ts_file = ts_re.group(1) ts_file_index = ts_re.group(2) ts_filename = ts_file.split('/')[-1] (target_file, storage_path) = get_target_file(self.config['storage']['release_dir'], ts_filename, 'ts') retcode = flv2ts(ts_file, target_file) if retcode != 0: self.logger.error("flv2ts flvfile: %s tsfile: %s failed", ts_file, target_file) continue request_info = self.segment_request_info(target_file, storage_path, ts_file_index) add_video_segment_url = self.config['url']['add_video_segment'] res = http_callback( add_video_segment_url, request_info) self.log(res, self.video_id, 'add_video_segment', storage_path) snap_re = re.search("snap:\'(.*?)\'\s+count:(\d+).*", line) if snap_re: snap_img_file = snap_re.group(1) snap_index = snap_re.group(2) snap_filename = snap_img_file.split('/')[-1] (target_file, storage_path) = get_target_file(self.config['storage']['release_dir'], snap_filename, 'snap') shutil.move(snap_img_file, target_file) info = request_info_serialize(video_id=self.video_id, snap_image_count=snap_index) res = http_callback(self.config['url']['update_video_snap_image_count'], info) self.log(res, self.video_id, 'update_video_snap_image_count', storage_path)
def __del__(self): request_info = request_info_serialize(video_id=self.video_id, status='success', bitrate=str(self.bitrate)) res = http_callback(self.config['url']['update_video_status'], request_info) self.log(res, self.video_id, 'update_video_status', None)
def upload_process(self, key, line): if key == b'video_id': video_id = line.decode().rstrip() self.video_id = video_id self.init_popen_handler() request_info = request_info_serialize(video_id=self.video_id, status='proceed', bitrate=str(self.bitrate)) res = http_callback(self.config['url']['update_video_status'], request_info) self.log(res, self.video_id, 'update_video_status', None) elif key == b'upload': self.run_cmd_async(line) self.write_original_file(line)