diff --git a/src/cc2olx/main.py b/src/cc2olx/main.py index 524a7ab3..8f1f1ba2 100644 --- a/src/cc2olx/main.py +++ b/src/cc2olx/main.py @@ -35,6 +35,7 @@ def convert_one_file(input_file, workspace, link_file=None, passport_file=None): (str(olx_filename), "course.xml"), (str(policy_filename), "policies/course/policy.json"), (str(cartridge.directory / "web_resources"), "/{}/".format(OLX_STATIC_DIR)), + (str(cartridge.directory / "resources"), "/{}/".format(OLX_STATIC_DIR)), ] # Add static files that are outside of web_resources directory diff --git a/src/cc2olx/models.py b/src/cc2olx/models.py index c8510d0a..a63df98c 100644 --- a/src/cc2olx/models.py +++ b/src/cc2olx/models.py @@ -330,7 +330,17 @@ def get_resource_content(self, identifier): res_type = res["type"] - if res_type == "webcontent": + is_html_resource = False + try: + if re.match(r".*/imscc_xmlv\d+p\d+/learning-application-resource$", res_type): + res_relative_path = res["children"][0].href + res_filename = self._res_filename(res_relative_path) + if res_filename.suffix == ".html": + is_html_resource = True + except IndexError: + logger.info("Content is not html for Resource type: %s ", res_type) + + if res_type == "webcontent" or is_html_resource: res_relative_path = res["children"][0].href res_filename = self._res_filename(res_relative_path) if res_filename.suffix == ".html": @@ -354,12 +364,21 @@ def get_resource_content(self, identifier): # So we need to manually copy it to OLX_STATIC_DIR self.extra_static_files.append(res_relative_path) olx_static_path = "/{}/{}".format(OLX_STATIC_DIR, res_relative_path) - html = ( - '' - '

{}

'.format( - olx_static_path, res_relative_path, res_relative_path + + if imghdr.what(str(res_filename)): + html = ( + '' + '

{}

'.format( + olx_static_path, res_relative_path + ) + ) + else: + html = ( + '' + '

{}

'.format( + olx_static_path, res_relative_path, res_relative_path + ) ) - ) return "html", {"html": html} else: logger.info("Skipping webcontent: %s", res_filename) @@ -791,8 +810,14 @@ def _parse_discussion(self, res, res_type): tree = filesystem.get_xml_tree(self._res_filename(child.href)) root = tree.getroot() ns = {"dt": namespaces[res_type]} - data["title"] = root.find("dt:title", ns).text - data["text"] = root.find("dt:text", ns).text + try: + data["title"] = root.find("dt:title", ns).text + except AttributeError: + data["title"] = '' + try: + data["text"] = root.find("dt:text", ns).text + except AttributeError: + data["text"] = '' elif isinstance(child, ResourceDependency): data["dependencies"].append(self.get_resource_content(child.identifierref)) return data diff --git a/src/cc2olx/olx.py b/src/cc2olx/olx.py index 9f8c8af5..c0048a6a 100644 --- a/src/cc2olx/olx.py +++ b/src/cc2olx/olx.py @@ -231,7 +231,9 @@ def process_ims_cc_filebase(item, html): """ Replace $IMS-CC-FILEBASE$ with /static """ - new_item = urllib.parse.unquote(item).replace("$IMS-CC-FILEBASE$", "/static") + + new_item = urllib.parse.unquote(item).replace("$IMS-CC-FILEBASE$../resources", "/static") + new_item = urllib.parse.unquote(new_item).replace("$IMS-CC-FILEBASE$", "/static") # skip query parameters for static files new_item = new_item.split("?")[0] # & is not valid in an URL. But some file seem to have it when it should be & diff --git a/src/cc2olx/qti.py b/src/cc2olx/qti.py index 71d40acf..48d5bb32 100644 --- a/src/cc2olx/qti.py +++ b/src/cc2olx/qti.py @@ -334,7 +334,7 @@ def parse_qti(self): # when we're getting malformed course (due to a weird Canvas behaviour) # with equal identifiers. LMS doesn't support blocks with the same identifiers. data["ident"] = attributes["ident"] + str(i) - data["title"] = attributes["title"] + data["title"] = attributes.get("title", "") cc_profile = self._parse_problem_profile(problem) data["cc_profile"] = cc_profile diff --git a/tests/fixtures_data/imscc_file/CREADOR.png b/tests/fixtures_data/imscc_file/CREADOR.png new file mode 100644 index 00000000..2215e969 Binary files /dev/null and b/tests/fixtures_data/imscc_file/CREADOR.png differ diff --git a/tests/fixtures_data/imscc_file/iframe3.html b/tests/fixtures_data/imscc_file/iframe3.html new file mode 100644 index 00000000..b6617b1c --- /dev/null +++ b/tests/fixtures_data/imscc_file/iframe3.html @@ -0,0 +1 @@ +

\ No newline at end of file diff --git a/tests/fixtures_data/imscc_file/imsmanifest.xml b/tests/fixtures_data/imscc_file/imsmanifest.xml index 4a03a111..fd594217 100644 --- a/tests/fixtures_data/imscc_file/imsmanifest.xml +++ b/tests/fixtures_data/imscc_file/imsmanifest.xml @@ -170,5 +170,13 @@ + + + + + + diff --git a/tests/test_models.py b/tests/test_models.py index 0b26b07d..15abf858 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -37,7 +37,7 @@ def test_load_manifest_extracted(imscc_file, settings, temp_workspace_dir): "version": cartridge_version, } - assert len(cartridge.resources) == 18 + assert len(cartridge.resources) == 20 assert len(cartridge.resources[0]["children"]) == 6 assert isinstance(cartridge.resources[0]["children"][0], ResourceFile) @@ -382,3 +382,19 @@ def test_cartridge_get_resource_content(cartridge): "\n\n\n" }, ) + + assert cartridge.get_resource_content("resource_10_video") == ( + "html", + { + "html": '

' + }, + ) + + assert cartridge.get_resource_content("resource_6_image_file") == ( + "html", + { + "html": '' + '

CREADOR.png

' + }, + ) diff --git a/tests/test_video_download_tool.py b/tests/test_video_download_tool.py index 1dc3683f..deb205bf 100644 --- a/tests/test_video_download_tool.py +++ b/tests/test_video_download_tool.py @@ -36,6 +36,7 @@ def test_find_all_video_urls_in_cc(imscc_file): expected = [ "https://cdnapisec.kaltura.com/p/2019031/sp/201903100/playManifest/entryId/1_zeqnrfgw/format/url/protocol/https", # noqa: E501 "https://cdnapisec.kaltura.com/p/2019031/sp/201903100/playManifest/entryId/1_zeqnrfgw/format/url/protocol/https", # noqa: E501 + "https://www.youtube.com/watch?v=zE-a5eqvlv8", ] assert urls == expected