-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/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, or just a title string).', | ||
) | ||
|
||
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}%') | ||
|
||
success = list() | ||
failed = list() | ||
|
||
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}') |