From f3906858db8453dba50dbfa4ff22776c170900cc Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Thu, 16 Apr 2020 21:53:49 -0500 Subject: [PATCH] Implement multi-stream endpoints --- hls_watch/__main__.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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() -- 2.30.2