when item download fails, trigger item_error event
This commit is contained in:
parent
86da6c2b06
commit
44226c9a04
4 changed files with 21 additions and 7 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import asyncio
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
|
|
@ -54,7 +55,7 @@ class DataStore:
|
|||
if (key and self.dict[i].info._id == key) or (url and self.dict[i].info.url == url):
|
||||
return self.dict[i]
|
||||
|
||||
msg = f"{key=} or {url=} not found."
|
||||
msg: str = f"{key=} or {url=} not found."
|
||||
raise KeyError(msg)
|
||||
|
||||
def get_by_id(self, id: str) -> Download | None:
|
||||
|
|
@ -82,6 +83,11 @@ class DataStore:
|
|||
return items
|
||||
|
||||
def put(self, value: Download) -> Download:
|
||||
if "error" == value.info.status:
|
||||
from app.library.Events import EventBus, Events
|
||||
|
||||
asyncio.create_task(EventBus.get_instance().emit(Events.ITEM_ERROR, value.info), name="emit_item_error")
|
||||
|
||||
self.dict.update({value.info._id: value})
|
||||
self._update_store_item(self.type, value.info)
|
||||
|
||||
|
|
@ -121,7 +127,7 @@ class DataStore:
|
|||
ON CONFLICT DO UPDATE SET "type" = ?, "url" = ?, "data" = ?, created_at = ?
|
||||
"""
|
||||
|
||||
stored = copy.deepcopy(item)
|
||||
stored: ItemDTO = copy.deepcopy(item)
|
||||
|
||||
if hasattr(stored, "datetime"):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from datetime import UTC, datetime, timedelta
|
|||
from email.utils import formatdate
|
||||
from pathlib import Path
|
||||
from sqlite3 import Connection
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import yt_dlp
|
||||
from aiohttp import web
|
||||
|
|
@ -38,6 +39,9 @@ from .Utils import (
|
|||
)
|
||||
from .YTDLPOpts import YTDLPOpts
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.library.Presets import Preset
|
||||
|
||||
LOG = logging.getLogger("DownloadQueue")
|
||||
|
||||
|
||||
|
|
@ -490,7 +494,7 @@ class DownloadQueue(metaclass=Singleton):
|
|||
{ "status": "text" }
|
||||
|
||||
"""
|
||||
_preset = Presets.get_instance().get(item.preset)
|
||||
_preset: Preset | None = Presets.get_instance().get(item.preset)
|
||||
|
||||
if item.has_cli():
|
||||
try:
|
||||
|
|
@ -520,9 +524,9 @@ class DownloadQueue(metaclass=Singleton):
|
|||
already.add(item.url)
|
||||
|
||||
try:
|
||||
logs = []
|
||||
logs: list = []
|
||||
|
||||
yt_conf = {
|
||||
yt_conf: dict = {
|
||||
"callback": {
|
||||
"func": lambda _, msg: logs.append(msg),
|
||||
"level": logging.WARNING,
|
||||
|
|
@ -542,7 +546,7 @@ class DownloadQueue(metaclass=Singleton):
|
|||
await self._notify.emit(Events.LOG_WARNING, data=event_warning(message))
|
||||
return {"status": "error", "msg": message}
|
||||
|
||||
started = time.perf_counter()
|
||||
started: float = time.perf_counter()
|
||||
|
||||
if item.cookies:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ class Events:
|
|||
INITIAL_DATA = "initial_data"
|
||||
ITEM_DELETE = "item_delete"
|
||||
ITEM_CANCEL = "item_cancel"
|
||||
ITEM_ERROR = "item_error"
|
||||
STATUS = "status"
|
||||
CLI_CLOSE = "cli_close"
|
||||
CLI_OUTPUT = "cli_output"
|
||||
|
|
|
|||
|
|
@ -235,6 +235,9 @@ class ItemDTO:
|
|||
def get_id(self) -> str:
|
||||
return self._id
|
||||
|
||||
def name(self) -> str:
|
||||
return f'id="{self.id}", title="{self.title}"'
|
||||
|
||||
@staticmethod
|
||||
def removed_fields() -> tuple:
|
||||
"""Fields that once existed but are no longer used."""
|
||||
|
|
@ -247,5 +250,5 @@ class ItemDTO:
|
|||
"output_template",
|
||||
"output_template_chapter",
|
||||
"config",
|
||||
"temp_path"
|
||||
"temp_path",
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue