def test_client(self, mock_get): from ms_client.client import MediaServerClient msc = MediaServerClient(local_conf=CONFIG) response = msc.api('/') self.assertTrue(isinstance(response, dict)) self.assertEqual(response['mediaserver'], '10.0.0') self.assertEqual(len(mock_get.call_args_list), 1)
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)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' Example script that mass moves media into a channel based on a criteria (e.g. here a specific external_ref prefix) ''' import os import sys 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) # ping print(msc.api('/')) more = True start = '' index = 0 external_ref_prefix = 'examplevalue' target_channel_oid = 'c12345678910' while more: print('//// Making request on latest (start=%s)' % start) response = msc.api('latest/', params={ 'start': start, 'content': 'v',
parser.add_argument('--channel', dest='channel_oid', help='Channel oid to check.', required=True, type=str) parser.add_argument('--delete', action='store_true', default=False, dest='enable_delete', help='Delete media in MediaServer.') args = parser.parse_args() print('Configuration path: %s' % args.configuration) print('Parent channel oid: %s' % args.channel_oid) print('Enable delete: %s' % args.enable_delete) # Check if configuration file exists if not args.configuration.startswith('unix:') and not os.path.exists( args.configuration): print('Invalid path for configuration file.') sys.exit(1) msc = MediaServerClient(args.configuration) msc.check_server() rc = find_duplicate(msc, args.channel_oid, args.enable_delete) sys.exit(rc)
parser.add_argument('--validate-subs', action='store_true', help='If unvalidated subs are found, validate them') languages = [ 'de-DE', 'en-GB', 'en-US', 'es-ES', 'fr-FR', 'it-IT', 'ja-JP', 'nl-NL', 'pt-PT', 'ru-RU', 'ar-AR', 'zh-CN', ] parser.add_argument( '--language', choices=languages, required=True, ) args = parser.parse_args() global msc msc = MediaServerClient(args.conf) msc.check_server() subtitle_all_videos(args)
if m: try: from_date = datetime.date(year=m.groups()[0], month=m.groups()[1], day=m.groups()[2]) to_date = datetime.date(year=m.groups()[3], month=m.groups()[4], day=m.groups()[5]) except ValueError: print('Incorrect date format, should be "YYYY-MM-DD".') sys.exit(1) else: print('Incorrect period value.') sys.exit(1) msc = MediaServerClient('unix:%s' % args.user) msc.check_server() verbose = args.verbose or args.output if args.output: with open(args.output, 'w') as fout: rc = get_files_to_backup(msc, user=args.user, from_date=from_date, to_date=to_date, fout=fout, verbose=verbose) else: rc = get_files_to_backup(msc, user=args.user, from_date=from_date,
#!/usr/bin/env python3 ''' Script to ping a MediaServer. ''' import os import sys 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) # ping annotations = msc.api('/annotations/list/', params={'oid': 'v125f52117974vspq8g1'}) type_id = None annotation_type_name = 'comment' for key, val in annotations['types'].items(): if val['slug'] == annotation_type_name: type_id = val['id'] if type_id is None: print(f'Annotation type {annotation_type_name} not found') exit(1) for annotation in annotations['annotations']: # comment if annotation['type_id'] == type_id: s = '{poster} ({popularity} votes): {content}\n'.format(
help='Delete media in MediaServer once successfully backuped.') args = parser.parse_args() print('Configuration path: %s' % args.configuration_path) print('Date limit: %s' % args.limit_date) print('Backups directory: %s' % args.dir_path) print('Enable delete: %s' % args.enable_delete) # Check if file exists if not os.path.exists(args.configuration_path): print('Invalid path for configuration file.') sys.exit(1) # Check date format try: limit_date = datetime.datetime.strptime(str(args.limit_date), '%Y-%m-%d').date() except ValueError: print('Incorrect data format, should be "YYYY-MM-DD".') sys.exit(1) msc = MediaServerClient(args.configuration_path) msc.check_server() # Increase default timeout because backups can be very disk intensive and slow the server msc.conf['TIMEOUT'] = max(60, msc.conf['TIMEOUT']) rc = make_backup(msc, args.dir_path, limit_date, args.use_add_date, args.enable_delete) sys.exit(rc)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' Script to ping a MediaServer. ''' import os import sys 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) # ping print(msc.api('/'))
parser.add_argument( '--title', type=str, required=False, help='Media title', ) args = parser.parse_args() # get ms client sys.path.append(os.path.dirname(os.path.dirname( os.path.abspath(__file__)))) from ms_client.client import MediaServerClient def print_progress(progress): print(f'Uploading: {progress * 100:.1f}%') msc = MediaServerClient(args.config) msc.check_server() resp = msc.add_media( file_path=args.input, title=args.title, channel=args.channel, speaker_email=args.speaker_email, progress_callback=print_progress, ) if resp['success']: print(f'File {args.input} upload finished, object id is {resp["oid"]}') else: print(f'Upload of {args.input} failed: {resp}')
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
default='path', dest='path', help='Directory in which media should be restored.', type=str) parser.add_argument( '--channel', dest='channel', help= 'Path to an existing channel in which all restored media should be added. The path should be splitted by slashes and can contain slug or title. Example: "Channel A/Channel B". If no value is given, media will be restored in their original channel.', required=False, type=str) args = parser.parse_args() print('Configuration path: %s' % args.configuration_path) print('Path: %s' % args.path) print('Channel: %s' % args.channel) # Check if file exists if not os.path.exists(args.configuration_path): print('Invalid path for configuration file.') sys.exit(1) msc = MediaServerClient(args.configuration_path) msc.get_server_version() msc.conf[ 'TIMEOUT'] = 60 # Increase timeout because backups can be very disk intensive and slow the server rc = restore_path(msc, args.path, args.channel) sys.exit(rc)