Skip to content

Commit

Permalink
add mass upload script
Browse files Browse the repository at this point in the history
  • Loading branch information
fthiery committed Jun 3, 2024
1 parent 068ef94 commit 86f0412
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions examples/mass_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Script to upload videos
./examples/mass_upload.py
--config beta.json --input myfolder --channel "mscpath-A/B/C"
'''
from pathlib import Path

import argparse
import logging
import os
import sys

logger = logging.getLogger('upload_speed_test')


if __name__ == '__main__':
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)

parser.add_argument(
'--folder',
type=str,
required=True,
help='Path to folder to upload (not recursive)',
)

parser.add_argument(
'--config', type=str, required=True, help='Path to config file.'
)

parser.add_argument(
'--channel',
type=str,
required=True,
help='Channel to publish all files into (can be mscspeaker, mscpath-A/B/C, mscid-1234, ...)',
)

parser.add_argument(
'--speaker-email',
type=str,
required=False,
help='Speaker email; should be set if channel is "mscspeaker".',
)

args = parser.parse_args()

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)
folder = Path(args.folder)
for node in folder.glob("*.*"):
if node.is_file():
resp = msc.add_media(
file_path=str(node),
channel=args.channel,
speaker_email=args.speaker_email,
progress_callback=print_progress,
)
if resp['success']:
print(f'File {node} upload finished, object id is {resp["oid"]}')
else:
print(f'Upload of {node} failed: {resp}')

0 comments on commit 86f0412

Please sign in to comment.