Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Download params #712

Merged
merged 8 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: typing
  • Loading branch information
Quentame committed Oct 28, 2024
commit 3fb9f62fd30b583f1a421a8cd96a2a0dbe6b12a7
4 changes: 2 additions & 2 deletions src/freebox_api/access.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hmac
import json
import logging
from typing import Any
from typing import Any, Mapping
from typing import Dict
from typing import Optional
from urllib.parse import urljoin
Expand Down Expand Up @@ -138,7 +138,7 @@ async def get(
return await self._perform_request(self.session.get, end_url)

async def post(
self, end_url: str, payload: Optional[Dict[str, Any]] = None
self, end_url: str, payload: Optional[Mapping[str, Any]] = None
) -> Dict[str, Any]:
"""
Send post request and return results
Expand Down
44 changes: 31 additions & 13 deletions src/freebox_api/api/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"""

import base64
from typing import Any, TypedDict
from typing import Any, Required, TypedDict
from typing import Dict
from typing import Optional

from freebox_api.access import Access


class DownloadAddURL(TypedDict):
class _DownloadAddURL(TypedDict, total=False):
"""
Add download by URL parameters data structure.

Expand All @@ -30,17 +30,27 @@ class DownloadAddURL(TypedDict):
cookies : `str` – The http cookies (to be able to pass session cookies along with url)
"""

download_url: str
download_url_list: str
download_dir: Optional[str]
download_dir: str
recursive: bool
username: Optional[str]
password: Optional[str]
username: str
password: str
archive_password: str
cookies: str


class DownloadAddFile(TypedDict):
class DownloadAddURL(_DownloadAddURL):
"""Add download by URL parameters data structure."""

download_url: Required[str]


class DownloadAddURLList(_DownloadAddURL):
"""Add download by URL list parameters data structure."""

download_url_list: Required[str]


class DownloadAddFile(TypedDict, total=False):
"""
Add download by file upload parameters data structure.

Expand All @@ -53,8 +63,8 @@ class DownloadAddFile(TypedDict):
(only relevant for nzb)
"""

download_file: str
download_dir: Optional[str]
download_file: Required[str]
download_dir: str
archive_password: str


Expand All @@ -66,8 +76,14 @@ class Download:
def __init__(self, access: Access) -> None:
self._access = access

download_url_schema = {
download_url_schema: DownloadAddURL = {
"download_url": "",
"username": "",
"password": "",
"recursive": False,
"download_dir": "",
}
download_url_list_schema: DownloadAddURLList = {
"download_url_list": "", # items separated by /n
"username": "",
"password": "",
Expand Down Expand Up @@ -169,8 +185,9 @@ async def add_download_task_from_url(
"""
download_params: DownloadAddURL = {
"download_url": download_url,
"download_dir": download_dir,
}
if download_dir:
download_params["download_dir"] = download_dir
return await self.add_download_task(download_params)

async def add_download_task_from_file(
Expand All @@ -183,8 +200,9 @@ async def add_download_task_from_file(
"""
download_params: DownloadAddFile = {
"download_file": download_file,
"download_dir": download_dir,
}
if download_dir:
download_params["download_dir"] = download_dir
return await self.add_download_task(download_params)

# Download Stats
Expand Down
Loading