Created
October 5, 2018 19:32
-
-
Save isaac-ped/41e4c791b7cf3f2fb1d64a243209d7ce to your computer and use it in GitHub Desktop.
Download streams of .ts files
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
import re | |
import argparse | |
import os | |
import time | |
import subprocess | |
from subprocess import Popen | |
parser = argparse.ArgumentParser(description='get panopto files') | |
parser.add_argument('curl', type=str) | |
parser.add_argument('out', type=str) | |
parser.add_argument('--start', type=int, required=False, default=0) | |
parser.add_argument('--end', type=int, required=False, default=600) | |
parser.add_argument('--concurrency', type=int, required=False, default=50) | |
args = parser.parse_args() | |
cmd = re.sub(r'\d\d\d.ts', '{:03d}.ts', args.curl) | |
try: | |
os.mkdir(args.out + "_files") | |
except: | |
pass | |
popens = [] | |
for i in range(args.start, args.end): | |
print("Starting {}".format(i)) | |
popens.append(Popen(cmd.format(i), | |
shell=True, | |
stdout=open('{}_files/{:03d}.ts'.format(args.out, i), 'w'), | |
stderr=open(os.devnull))) | |
if i > args.concurrency: | |
print("Waiting on {}".format(i - args.concurrency)) | |
popens[i - args.concurrency].wait() | |
for i in range(args.end - args.concurrency, args.end): | |
print("Waiting on {}".format(i)) | |
popens[i].wait() | |
print("Concatenating") | |
subprocess.call('cat {0}_files/*.ts > {0}.ts'.format(args.out), shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment