-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
56 lines (44 loc) · 1.53 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from reecho import Multimedia
from reecho import HomeParse
import requests
import argparse
import json
#Multimedia._merge('.tmp/s0q0.m4s', '.tmp/s1q1.m4s', "SPCE0005 20/03/2020")
#exit(0)
parser = argparse.ArgumentParser(description='Download lecture streams from echo360. Only tested on UCL Moodle so far.')
parser.add_argument('curl_file', type=str, nargs=1, help="Curl requests from the echo360 home.")
args = parser.parse_args()
file = args.curl_file[0]
try:
Multimedia.clean()
except FileNotFoundError:
pass
class ExtendAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
items = getattr(namespace, self.dest) or []
items.extend(values)
setattr(namespace, self.dest, items)
# read in curl contents
with open(file, 'r') as f:
contents = f.read().split("\n")[0]
contents = contents.split('-H')
home_url = contents[0].split(' ')[1].replace('\'', '')
print(f"Using HOME url: '{home_url}'")
headers = ""
for i in contents[1:]:
i = i.replace('--compressed', '')
i = i.replace('\'', '"').replace(': ', '":"')
headers += i.strip() + ", "
headers = headers.strip()[:-1]
headers = json.loads("{" + headers + "}")
for k in headers:
print(f"HEADER loaded: {k}")
# setup requests sesssion
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(pool_connections=10, pool_maxsize=10, max_retries=10)
session.mount('https://', adapter)
session.mount('http://', adapter)
hp = HomeParse(session, home_url, headers)
hp.full_parse()
hp.select_lesson()
hp.download()