mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-05 20:40:09 -08:00
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from kivy.clock import Clock
|
|
from kivy.properties import ObjectProperty
|
|
from kivy.logger import Logger
|
|
from kivy.utils import format_bytes_to_human
|
|
|
|
from anixstream.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"
|
|
Clock.schedule_once(
|
|
lambda _: self.main_container.add_widget(TaskCard(anime_title, episodes))
|
|
)
|
|
|
|
def on_episode_download_progress(
|
|
self, current_bytes_downloaded, total_bytes, episode_info
|
|
):
|
|
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
|
|
|
|
def update_layout(self, widget):
|
|
self.user_anime_list_container.add_widget(widget)
|