def prepare(self, **kwargs): self.browser = StatefulBrowser() self._mediatypes = kwargs.get("mediatypes") self._qualities = kwargs.get("qualities") self._templates = kwargs.get("templates") auth_package = kwargs.get("auth") if auth_package[0] == types.AuthType.COOKIES: jar = requests.cookies.RequestsCookieJar() session_values = auth_package[1]["session"] jar.set( "session", session_values["value"], domain=".cloud.blender.org", path="/", ) self.browser.session.cookies = jar self.browser.open("https://cloud.blender.org/settings/profile" ).status_code == 200 profile_page = self.browser.get_current_page() try: assert profile_page.find(class_="py-1") is not None except AssertionError: echo.error_msg("Authentication was not successfull") exit(1) echo.debug_msg("Authentication successfull")
def download(ctx, **kwargs): package = validation.validate(**kwargs) plugin = package["plugin"]() plugin.prepare(**package) files = plugin.collect(part_id=kwargs.get("part_id")) with click.progressbar( files, length=len(files), label="Downloaded files", show_pos=True, item_show_func=cli_utils.current_item_name, ) as files_progress: for f in files_progress: if not ctx.obj.get("SIMULATION"): f.prepare_file_path(kwargs.get("download_path")) if not kwargs.get("replace"): if f.absolute_file_path.exists(): echo.debug_msg("Skip existing file") continue plugin.download(f) else: sleep(0.5) continue # SIMULATE DOWNLOAD echo.debug_msg("Download complete")
def _create_video_file(self, url): self.browser.open(url + "/view") page = self.browser.get_current_page() title = page.find("h4").string.replace("", "") duration = page.find("li", title="Duration").string author = page.find(title="Author").get_text().strip() project_name = self._project_name group_title = self.browser.open( url + "/breadcrumbs").json()["breadcrumbs"][0]["name"] links = page.find("li", class_="download").find_all("a") video_quality = self._qualities[types.MediaType.VIDEO] dl_urls = [] for link in links: if (link.find(class_="size") is not None and link.find(class_="size").string == video_quality): dl_urls.append(link) file_format = dl_urls[0].find(class_="format").string video_template = Template(self._templates[types.MediaType.VIDEO]) file = File( url=dl_urls[0].get("href"), file_path_string=video_template.render( title=title, duration=duration, author=author, project_name=project_name, group_title=group_title, file_format=file_format, ), ) echo.debug_msg( video_template.render( title=title, duration=duration, author=author, project_name=project_name, group_title=group_title, file_format=file_format, )) return file
def validate(**kwargs): plugin = cli_utils.get_all_plugins().get(kwargs.get("plugin")) auth_package = auth_validation( plugin, kwargs.get("username"), kwargs.get("password"), kwargs.get("cookies"), kwargs.get("token"), ) mediatypes = mediatype_validation(plugin, kwargs.get("mediatype")) qualities = quality_validation(plugin, kwargs.get("quality", [])) templates = template_validation(plugin, kwargs.get("template", [])) return_value = { "plugin": plugin, "auth": auth_package, "mediatypes": mediatypes, "qualities": qualities, "templates": templates, } echo.debug_msg(f"Validated args: {return_value}") return return_value
def set_debug(debug_state): ctx = click.get_current_context() ctx.obj["DEBUG"] = debug_state echo.debug_msg("Debug mode is active")