Skip to content

Commit

Permalink
Add an option to disable media download
Browse files Browse the repository at this point in the history
  • Loading branch information
abdnh committed Jul 23, 2024
1 parent 0b66018 commit dea00ce
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"token": ""
}
},
"report_errors": true
"report_errors": true,
"download_media": true
}
1 change: 1 addition & 0 deletions src/config.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## General

- `download_media`: Download media files.
- `report_errors`: Report add-on errors automatically.

## AnkiApp
Expand Down
3 changes: 3 additions & 0 deletions src/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"properties": {
"download_media": {
"type": "boolean"
},
"importer_options": {
"properties": {
"ankiapp": {
Expand Down
3 changes: 3 additions & 0 deletions src/importers/ankiapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from anki.models import NotetypeId
from aqt.main import AnkiQt

from ..config import config
from ..log import logger
from .errors import CopycatImporterCanceled
from .httpclient import HttpClient
Expand Down Expand Up @@ -236,6 +237,8 @@ def _api_get(self, path: str) -> requests.Response:
return response

def _get_media(self, blob_id: str) -> AnkiAppMedia | None:
if not config["download_media"]:
return None
try:
response = self._get_request(f"https://blobs.ankiapp.com/{blob_id}")
data = response.content
Expand Down
3 changes: 3 additions & 0 deletions src/importers/ankipro.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
if TYPE_CHECKING:
from aqt.main import AnkiQt

from ..config import config
from ..log import logger
from .httpclient import HttpClient
from .importer import CopycatImporter
Expand Down Expand Up @@ -92,6 +93,8 @@ def _api_get(self, path: str, *args: Any, **kwrags: Any) -> requests.Response:
)

def _get_media(self, url: str) -> Optional[tuple[str, bytes]]:
if not config["download_media"]:
return None
res = self._get(url)
mime = res.headers.get("content-type", None)
if not mime:
Expand Down

0 comments on commit dea00ce

Please sign in to comment.