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
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()