From 1e9e9d71a19e4a80b1a7fb09a1a4cb13b57e7bf2 Mon Sep 17 00:00:00 2001 From: Benedict Xavier Wanyonyi Date: Tue, 28 May 2024 14:02:18 +0300 Subject: [PATCH] feat:added download task card to download screen which marks the end of it --- .../DownloadsScreen/components/task_card.kv | 28 +++++++++++++++++++ .../DownloadsScreen/components/task_card.py | 12 ++++++++ app/View/DownloadsScreen/download_screen.kv | 18 ++++++++---- app/View/DownloadsScreen/download_screen.py | 19 ++++++++++--- app/View/components/general.kv | 6 ++-- app/main.py | 7 +++-- .../Episode 5/Bleach | 0 7 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 app/View/DownloadsScreen/components/task_card.kv create mode 100644 app/View/DownloadsScreen/components/task_card.py create mode 100644 app/vids/Bleach sennen kessen-hen - ketsubetsu-tan/Episode 5/Bleach diff --git a/app/View/DownloadsScreen/components/task_card.kv b/app/View/DownloadsScreen/components/task_card.kv new file mode 100644 index 0000000..e3a090b --- /dev/null +++ b/app/View/DownloadsScreen/components/task_card.kv @@ -0,0 +1,28 @@ +#:import color_text Utility.kivy_markup_helper.color_text + +: + adaptive_height:True + max_lines:0 + shorten:False + markup:True + font_style: "Label" + role: "large" + bold:True + + +: + adaptive_height:True + radius:8 + padding:"20dp" + md_bg_color:self.theme_cls.surfaceContainerHighColor + + TaskText: + size_hint_x:.8 + text:color_text(root.anime_task_name,root.theme_cls.primaryColor) + TaskText: + size_hint_x:.2 + # color:self.theme_cls.surfaceDimColor + theme_text_color:"Secondary" + text:color_text(root.episodes_to_download,root.theme_cls.secondaryColor) + MDIcon: + icon:"check-bold" diff --git a/app/View/DownloadsScreen/components/task_card.py b/app/View/DownloadsScreen/components/task_card.py new file mode 100644 index 0000000..726cd89 --- /dev/null +++ b/app/View/DownloadsScreen/components/task_card.py @@ -0,0 +1,12 @@ +from kivy.properties import StringProperty + +from kivymd.uix.boxlayout import MDBoxLayout + +# TODO: add a progress bar to show the individual progress of each task +class TaskCard(MDBoxLayout): + anime_task_name = StringProperty() + episodes_to_download = StringProperty() + def __init__(self, anime_title:str, episodes:str, *args, **kwargs): + super().__init__(*args, **kwargs) + self.anime_task_name = f"{anime_title}" + self.episodes_to_download = f"Episodes: {episodes}" \ No newline at end of file diff --git a/app/View/DownloadsScreen/download_screen.kv b/app/View/DownloadsScreen/download_screen.kv index 5ed5d81..7092a86 100644 --- a/app/View/DownloadsScreen/download_screen.kv +++ b/app/View/DownloadsScreen/download_screen.kv @@ -24,12 +24,20 @@ SearchBar: MDScrollView: size_hint:.95,1 - MDGridLayout: - padding: "75dp","50dp","10dp","100dp" - spacing:"40dp" + MDBoxLayout: id:main_container - cols:5 + orientation:"vertical" + padding:"40dp" + pos_hint:{"center_x":.5} + spacing:"10dp" adaptive_height:True + HeaderLabel: + text:"Download Tasks" + halign:"left" + MDIcon: + padding:"10dp" + pos_hint:{"center_y":.5} + icon:"clock" MDBoxLayout: size_hint_y:None height:"40dp" @@ -39,7 +47,7 @@ DownloadsScreenLabel: id:download_progress_label size_hint_x: .6 - text:"current episode" + text:"Try Downloading sth :)" pos_hint: {'center_y': .5} MDLinearProgressIndicator: id: progress_bar diff --git a/app/View/DownloadsScreen/download_screen.py b/app/View/DownloadsScreen/download_screen.py index d4908b7..a435c21 100644 --- a/app/View/DownloadsScreen/download_screen.py +++ b/app/View/DownloadsScreen/download_screen.py @@ -1,18 +1,29 @@ from kivy.clock import Clock from kivy.properties import ObjectProperty +from kivy.logger import Logger from kivy.utils import format_bytes_to_human from View.base_screen import BaseScreenView - +from .components.task_card import TaskCard class DownloadsScreenView(BaseScreenView): main_container = ObjectProperty() progress_bar = ObjectProperty() download_progress_label = ObjectProperty() + + def on_new_download_task(self,anime_title:str,episodes:str|None): + if not episodes: + episodes = "All" + self.main_container.add_widget(TaskCard(anime_title,episodes)) + def on_episode_download_progress(self,current_bytes_downloaded,total_bytes,episode_info): - percentage_completion = (current_bytes_downloaded/total_bytes)*100 - self.progress_bar.value= max(min(percentage_completion,100),0) - self.download_progress_label.text = f"Downloading: {episode_info['anime_title']} - {episode_info['episode']} ({format_bytes_to_human(current_bytes_downloaded)}/{format_bytes_to_human(total_bytes)})" + percentage_completion = round((current_bytes_downloaded/total_bytes)*100) + progress_text = f"Downloading: {episode_info['anime_title']} - {episode_info['episode']} ({format_bytes_to_human(current_bytes_downloaded)}/{format_bytes_to_human(total_bytes)})" + if (percentage_completion%5)==0: + self.progress_bar.value= max(min(percentage_completion,100),0) + self.download_progress_label.text = progress_text + Logger.info(f"Downloader: {progress_text}") + # def on_enter(self): # Clock.schedule_once(lambda _:self.controller.requested_update_my_list_screen()) diff --git a/app/View/components/general.kv b/app/View/components/general.kv index 31019bc..444dc32 100644 --- a/app/View/components/general.kv +++ b/app/View/components/general.kv @@ -1,3 +1,3 @@ -: - allow_copy:True - allow_selection:True \ No newline at end of file +# : +# allow_copy:True +# allow_selection:True \ No newline at end of file diff --git a/app/main.py b/app/main.py index 40eb2e8..a45f24a 100644 --- a/app/main.py +++ b/app/main.py @@ -139,6 +139,7 @@ class AniXStreamApp(MDApp): self.theme_cls.theme_style = value def on_stop(self): + del self.downloads_worker_thread if self.animdl_streaming_subprocess: self.animdl_streaming_subprocess.terminate() Logger.info("Animdl:Successfully terminated existing animdl subprocess") @@ -185,7 +186,6 @@ class AniXStreamApp(MDApp): "New Download Task Queued", f"{default_cmds.get('title')} has been queued for downloading", ) - self.add_anime_to_user_downloads_list(anime_id) # TODO:Add custom download cmds functionality @@ -193,6 +193,7 @@ class AniXStreamApp(MDApp): *args ) output_path = self.config.get("Preferences", "downloads_dir") # type: ignore + self.download_screen.on_new_download_task(default_cmds["title"],default_cmds.get("episodes_range")) if episodes_range := default_cmds.get("episodes_range"): download_task = lambda: AnimdlApi.download_anime_by_title( default_cmds["title"], @@ -213,7 +214,9 @@ class AniXStreamApp(MDApp): output_path, ) # ,default_cmds.get("quality") self.downloads_queue.put(download_task) - + Logger.info( + f"Downloader:Successfully Queued {default_cmds['title']} for downloading" + ) def watch_on_allanime(self, title_): """ Opens the given anime in your default browser on allanimes site diff --git a/app/vids/Bleach sennen kessen-hen - ketsubetsu-tan/Episode 5/Bleach b/app/vids/Bleach sennen kessen-hen - ketsubetsu-tan/Episode 5/Bleach new file mode 100644 index 0000000..e69de29