index += 1 data = msc.api('medias/get/', method='get', params={ 'oid': oid, 'full': 'yes', }, timeout=300)['info'] if data.get('external_ref'): line = f'{data["external_ref"]},{oid}' print(line) f.write(line + '\n') redir_count += 1 start = response['max_date'] more = response['more'] print(f'Wrote {redir_count} redirections') if __name__ == '__main__': sys.path.append(os.path.dirname(os.path.dirname( os.path.abspath(__file__)))) from ms_client.client import MediaServerClient local_conf = sys.argv[1] if len(sys.argv) > 1 else None msc = MediaServerClient(local_conf) msc.check_server() transcode_all_videos(msc)
def run_test(args): # Get ms client start = time.time() sys.path.append(os.path.dirname(os.path.dirname( os.path.abspath(__file__)))) from ms_client.client import MediaServerClient msc = MediaServerClient(args.conf, setup_logging=False) if args.chunk: msc.conf['UPLOAD_CHUNK_SIZE'] = args.chunk * 1000 msc.check_server() # Generate test files tmp_path = '/tmp/ms-test-upload-file' logger.info(f'Generating {args.size} kB of test content in "{tmp_path}".') # Get text pattern of 1000 bytes text = 10 * (string.ascii_letters + string.digits + ' ' + ''.join([c for c in reversed(string.digits)]) + ''.join([c for c in reversed(string.ascii_lowercase)]) + '\n') assert len( text) == 1000 # Check that the text size is exactly of 1000 bytes with open(tmp_path + '.m3u8', 'w') as fo: for i in range(args.size): fo.write(text) if os.path.isdir(tmp_path): shutil.rmtree(tmp_path) os.makedirs(tmp_path) files_list = [] if args.count > 1: logger.info(f'Copying file {args.count - 1} times in "{tmp_path}".') for i in range(1, args.count): shutil.copy(tmp_path + '.m3u8', tmp_path + '/files-' + str(i)) files_list.append(tmp_path + '/files-' + str(i)) files_list.append(tmp_path + '.m3u8') # Prepare arguments if args.m3u8: up_fct = upload_hls_files else: up_fct = upload_chunked_files args_list = [] for i in range(1, args.processes + 1): if args.m3u8: args_list.append((msc, i, tmp_path)) else: args_list.append((msc, i, files_list, args.md5)) end = time.time() duration = end - start duration = round(duration, 2) logger.info(f'Initialisation done in {duration} s.') # Upload files start = time.time() try: if args.processes > 1: pool = multiprocessing.Pool(processes=args.processes) pool.starmap(up_fct, args_list) pool.close() pool.join() else: up_fct(*args_list[0]) except Exception: logger.info(f'Test:\033[91m failed \033[0m\n{traceback.format_exc()}') return except KeyboardInterrupt: logger.info('Test:\033[93m canceled \033[0m') return else: end = time.time() duration = end - start logger.info('Test:\033[92m done \033[0m') finally: os.remove(tmp_path + '.m3u8') shutil.rmtree(tmp_path) total_files = args.count * args.processes total_size = round(args.count * args.processes * args.size / 1000, 2) avg_speed = round(args.count * args.processes * args.size / duration, 2) duration = round(duration, 2) logger.info(f'Number of files uploaded: {total_files}.') logger.info(f'Total size: {total_size} MB.') logger.info(f'Average speed: {avg_speed} kB/s.') logger.info(f'Upload duration: {duration} s.') return total_files, total_size, avg_speed, duration