Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mass upload script #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}')
Loading