Example #1
0
 def from_module(cls, auth: Dict, module: Module) -> File:
     return File(
         id=module.id,
         name=utils.sanitise_filename(module.code),
         directory=True,
         children=cls.get_children(auth, module.id, allow_upload=False),
         allow_upload=False,
         multimedia=False,
     )
Example #2
0
    def download(self, auth: Dict, path: str, verbose: bool = False):
        """Downloads file to location specified by path, a requests sessions is used 
        as cookies are needed when downloading the mp4"""

        session = requests.Session()
        video_url = self.get_download_url(auth, session)
        destination = os.path.join(path,
                                   utils.sanitise_filename(self.name) + ".mp4")

        if video_url:
            return utils.download_w_session(session, video_url, destination,
                                            False)
Example #3
0
 def parse_child(cls, data: Dict, allow_upload: bool) -> File:
     is_directory = isinstance(data.get("access", None), dict)
     return File(
         id=data["id"],
         name=utils.sanitise_filename("{}{}".format(
             data["creatorName"] + " - " if allow_upload else "",
             data["name"])),
         directory=is_directory,
         children=None if is_directory else
         [],  # NOTE [] indicates that there is no children, None means unknown (lazy)
         allow_upload=data.get("allowUpload", False),
         multimedia=False,
     )
Example #4
0
    def from_lesson(cls, api_data) -> Optional[File]:
        if api_data.get("target", None) is None or api_data["target"].get(
                "isResourceType", True):
            return None

        target = api_data["target"]
        multimedia = "duration" in target
        return File(
            id=target["id"],
            name=utils.sanitise_filename(target["name"]) +
            (".mp4" if multimedia else ""),
            children=[],
            allow_upload=False,
            multimedia=multimedia,
            directory=False,
        )
Example #5
0
    def test_sanitise_filename(self):
        # replaces both nil and / with -
        self.assertEquals(sanitise_filename("asd\0"), "asd-")
        self.assertEquals(sanitise_filename("asd/asd/asd"), "asd-asd-asd")
        self.assertEquals(sanitise_filename("\0asd/asd/asd"), "-asd-asd-asd")

        # works with other replacement
        self.assertEquals(sanitise_filename("asd\0", "+"), "asd+")
        self.assertEquals(sanitise_filename("asd/asd/asd", "+"), "asd+asd+asd")
        self.assertEquals(sanitise_filename("\0asd/asd/asd", "+"),
                          "+asd+asd+asd")