From: Jakob Cornell Date: Fri, 17 Apr 2020 02:53:49 +0000 (-0500) Subject: Implement multi-stream endpoints X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3906858db8453dba50dbfa4ff22776c170900cc;p=hls-watch.git Implement multi-stream endpoints --- diff --git a/hls_watch/__main__.py b/hls_watch/__main__.py index f95f218..b0e1ec6 100644 --- a/hls_watch/__main__.py +++ b/hls_watch/__main__.py @@ -20,12 +20,12 @@ def get_time(resp): if __name__ == '__main__': + from urllib.parse import urlparse, urlunparse + from pathlib import Path, PurePosixPath import argparse import contextlib import os - import pathlib import time - import urllib.parse import urllib.request import toml @@ -36,20 +36,25 @@ if __name__ == '__main__': args = ap.parse_args() - base_path = pathlib.Path(args.base_path) + base_path = Path(args.base_path) assert base_path.is_dir() cfg_path = ( - pathlib.Path( - os.getenv('XDG_CONFIG_HOME', os.getenv('HOME') + '/.config') - ) + Path(os.getenv('XDG_CONFIG_HOME', os.getenv('HOME') + '/.config')) .joinpath('oberlin_webcast2') ) with cfg_path.joinpath('config.toml').open() as f: config = toml.load(f) - endpoint = args.endpoint - url = config['endpoints'][endpoint] + try: + (endpoint, s_num) = args.endpoint.rsplit('_', 1) + except: + raise ValueError("The endpoint arg doesn't look correct") + base_url = urlparse(config['endpoints'][endpoint]) + path_seg = '{}_{}.m3u8'.format(endpoint, s_num) + url = urlunparse(base_url._replace( + path = str(PurePosixPath(base_url.path).joinpath(path_seg)), + )) # Follow redirects but don't throw on 4XX opener = urllib.request.OpenerDirector()