mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-01-20 00:20:46 -08:00
feat(download screen):implement download capabilities
This commit is contained in:
@@ -47,6 +47,8 @@
|
||||
on_press: root.next_episode()
|
||||
MDIconButton:
|
||||
icon:"download"
|
||||
on_press:
|
||||
if root.current_link: app.download_anime_video(root.current_link,(root.current_title[0],root.current_episode))
|
||||
MDButton:
|
||||
on_press:
|
||||
if root.current_link: app.play_on_mpv(root.current_link)
|
||||
|
||||
@@ -18,11 +18,6 @@
|
||||
|
||||
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:"download"
|
||||
text:"{} Episode: {}".format(root.file[0],root.file[1])
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from kivy.properties import StringProperty
|
||||
from kivy.properties import StringProperty, ListProperty
|
||||
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()
|
||||
file = ListProperty(("", ""))
|
||||
eta = StringProperty()
|
||||
|
||||
def __init__(self, anime_title: str, episodes: str, *args, **kwargs):
|
||||
def __init__(self, file: str, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.anime_task_name = f"{anime_title}"
|
||||
self.episodes_to_download = f"Episodes: {episodes}"
|
||||
self.file = file
|
||||
# self.eta = eta
|
||||
#
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
shorten:False
|
||||
markup:True
|
||||
font_style: "Label"
|
||||
role: "large"
|
||||
role: "small"
|
||||
bold:True
|
||||
<DownloadsScreenView>
|
||||
md_bg_color: self.theme_cls.backgroundColor
|
||||
@@ -46,12 +46,12 @@
|
||||
md_bg_color:self.theme_cls.secondaryContainerColor
|
||||
DownloadsScreenLabel:
|
||||
id:download_progress_label
|
||||
size_hint_x: .6
|
||||
size_hint_x: .8
|
||||
text:"Try Downloading sth :)"
|
||||
pos_hint: {'center_y': .5}
|
||||
MDLinearProgressIndicator:
|
||||
id: progress_bar
|
||||
size_hint_x: .4
|
||||
size_hint_x: .2
|
||||
size_hint_y:None
|
||||
height:"10dp"
|
||||
type: "determinate"
|
||||
|
||||
@@ -11,21 +11,31 @@ class DownloadsScreenView(BaseScreenView):
|
||||
progress_bar = ObjectProperty()
|
||||
download_progress_label = ObjectProperty()
|
||||
|
||||
def on_new_download_task(self, anime_title: str, episodes: str | None):
|
||||
if not episodes:
|
||||
episodes = "All"
|
||||
def new_download_task(self, filename):
|
||||
Clock.schedule_once(
|
||||
lambda _: self.main_container.add_widget(TaskCard(anime_title, episodes))
|
||||
lambda _: self.main_container.add_widget(TaskCard(filename))
|
||||
)
|
||||
|
||||
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 on_episode_download_progress(self, data):
|
||||
percentage_completion = round(
|
||||
(data.get("downloaded_bytes", 0) / data.get("total_bytes", 0)) * 100
|
||||
)
|
||||
speed = format_bytes_to_human(data.get("speed", 0)) if data.get("speed") else 0
|
||||
progress_text = f"Downloading: {data.get('filename', 'unknown')} ({format_bytes_to_human(data.get('downloaded_bytes',0)) if data.get('downloaded_bytes') else 0}/{format_bytes_to_human(data.get('total_bytes',0)) if data.get('total_bytes') else 0})\n Elapsed: {round(data.get('elapsed',0)) if data.get('elapsed') else 0}s ETA: {data.get('eta',0) if data.get('eta') else 0}s Speed: {speed}/s"
|
||||
|
||||
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)
|
||||
|
||||
#
|
||||
# d["filename"],
|
||||
# d["downloaded_bytes"],
|
||||
# d["total_bytes"],
|
||||
# d.get("total_bytes"),
|
||||
# d["elapsed"],
|
||||
# d["eta"],
|
||||
# d["speed"],
|
||||
# d.get("percent"),
|
||||
# )
|
||||
|
||||
Reference in New Issue
Block a user