Skip to content

Commit 31aae77

Browse files
committed
fixed moodle
1 parent 42921e5 commit 31aae77

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

sites/moodle/parser.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ async def parse_sections(session,
6868
index=None,
6969
keep_section_order=False,
7070
keep_file_order=False):
71-
if "aria-labelledby" in section.attrs:
72-
section_title_id = str(section["aria-labelledby"])
73-
section_name = str(section.find("h3", id=section_title_id).string).strip()
74-
else:
75-
section_name = str(section["aria-label"]).strip()
71+
72+
title = section.find("h3", id=re.compile("sectionid-([0-9]+)-title"), recursive=True)
73+
section_name = str(title.text).strip()
7674

7775
if keep_section_order:
7876
section_name = f"[{index + 1:02}] {section_name}"
@@ -175,28 +173,23 @@ async def parse_module(session,
175173
process_external_links,
176174
keep_file_order,
177175
password_mapper):
178-
mtype = module["class"][1]
176+
mtype = module["class"][2]
179177
module_id = int(re.search("module-([0-9]+)", module["id"])[1])
180178
if mtype == MTYPE_FILE:
181-
instance = module.find("div", class_="activityinstance")
179+
link = module.find("a")
182180
try:
183-
file_name = str(instance.a.span.contents[0])
181+
file_name = str(link.span.contents[0])
184182
except AttributeError:
185183
return
186184
last_updated = last_updated_dict[module_id]
187185

188-
with_extension = False
189-
if "pdf-24" in instance.a.img["src"]:
190-
file_name += ".pdf"
191-
with_extension = True
192-
193186
if keep_file_order:
194187
file_name = f"[{module_idx + 1:02}] {file_name}"
195188

196-
url = instance.a["href"] + "&redirect=1"
189+
url = link["href"] + "&redirect=1"
197190
await queue.put({"path": safe_path_join(base_path, file_name),
198191
"url": url,
199-
"with_extension": with_extension,
192+
"with_extension": False,
200193
"checksum": last_updated})
201194

202195
elif mtype == MTYPE_DIRECTORY:
@@ -207,9 +200,9 @@ async def parse_module(session,
207200
if not process_external_links:
208201
return
209202

210-
instance = module.find("div", class_="activityinstance")
211-
url = instance.a["href"] + "&redirect=1"
212-
name = str(instance.a.span.contents[0])
203+
link = module.find("a")
204+
url = link["href"] + "&redirect=1"
205+
name = str(link.span.contents[0])
213206

214207
if keep_file_order:
215208
name = f"[{module_idx + 1:02}] {name}"
@@ -226,13 +219,12 @@ async def parse_module(session,
226219
password_mapper=password_mapper)
227220

228221
elif mtype == MTYPE_ASSIGN:
229-
instance = module.find("div", class_="activityinstance")
230-
link = instance.a
222+
link = module.find("a")
231223
if link is None:
232224
return
233-
href = instance.a["href"]
225+
href = link["href"]
234226
last_updated = last_updated_dict[module_id]
235-
name = str(instance.a.span.contents[0])
227+
name = str(link.span.contents[0])
236228

237229
assign_file_tree_soup_soup = await call_function_or_cache(get_assign_files_tree,
238230
last_updated,
@@ -291,11 +283,11 @@ async def parse_folder(session, queue, download_settings, module, base_path, las
291283
await parse_folder_tree(queue, folder_tree.ul, base_path, last_updated)
292284
return
293285

294-
instance = module.find("div", class_="activityinstance")
295-
folder_name = str(instance.a.span.contents[0])
286+
link = module.find("a")
287+
folder_name = str(link.span.contents[0])
296288
folder_path = safe_path_join(base_path, folder_name)
297289

298-
href = instance.a["href"]
290+
href = link["href"]
299291

300292
folder_soup = await call_function_or_cache(get_filemanager, last_updated, session, href)
301293

sites/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ async def process_single_file_url(session, queue, base_path, download_settings,
2323
password=password)
2424

2525
elif "zoom.us/rec/play" in url or "zoom.us/rec/share" in url:
26+
# TODO: fix zoom
27+
return
2628
allowed_extensions = []
2729
if download_settings.allowed_extensions:
2830
allowed_extensions += download_settings.allowed_extensions

0 commit comments

Comments
 (0)