From 58283bdeb50de0b690269214e6d2234b7cc24c20 Mon Sep 17 00:00:00 2001 From: Ren Tatsumoto Date: Tue, 21 Mar 2023 19:46:55 +0300 Subject: [PATCH 1/2] add a new action: getMediaDirPath --- README.md | 26 ++++++++++++++++++++++++++ plugin/__init__.py | 3 +++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 6ad756b..a9d139e 100644 --- a/README.md +++ b/README.md @@ -1759,6 +1759,32 @@ corresponding to when the API was available for use. ``` +#### `getMediaDirPath` + +* Gets the full path to the `collection.media` folder of the currently opened profile. + +
+ Sample request: + + ```json + { + "action": "getMediaDirPath", + "version": 6 + } + ``` +
+ +
+ Sample result: + + ```json + { + "result": "/home/user/.local/share/Anki2/Main/collection.media", + "error": null + } + ``` +
+ #### `deleteMediaFile` * Deletes the specified file inside the media folder. diff --git a/plugin/__init__.py b/plugin/__init__.py index e9c7b75..c578ee4 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -722,6 +722,9 @@ class AnkiConnect: except AttributeError: self.media().trash_files([filename]) + @util.api() + def getMediaDirPath(self): + return os.path.abspath(self.media().dir()) @util.api() def addNote(self, note): From 8d16822cb502b1fcdd217980cedeca9724b19c19 Mon Sep 17 00:00:00 2001 From: Ren Tatsumoto Date: Thu, 23 Mar 2023 06:06:44 +0300 Subject: [PATCH 2/2] add a test for getMediaDirPath() --- tests/test_media.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_media.py b/tests/test_media.py index b667c8e..fde46e8 100755 --- a/tests/test_media.py +++ b/tests/test_media.py @@ -1,4 +1,5 @@ import base64 +import os.path from conftest import ac @@ -49,3 +50,7 @@ def test_deleteMediaFile(session_with_profile_loaded): ac.deleteMediaFile(filename=filename_1) assert ac.retrieveMediaFile(filename=filename_1) is False assert ac.getMediaFilesNames(pattern="_tes*.txt") == [filename_2] + + +def test_getMediaDirPath(session_with_profile_loaded): + assert os.path.isdir(ac.getMediaDirPath())