Added "getMediaFilesNames" action (#247)

This commit is contained in:
Konstantin Sukovatij 2021-04-12 07:26:03 +03:00 committed by GitHub
parent 2081330c35
commit 929716c7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -93,6 +93,29 @@
}
```
* **getMediaFilesNames**
Gets the names of media files matched the pattern. Returning all names by default.
*Sample request*:
```json
{
"action": "getMediaFilesNames",
"version": 6,
"params": {
"pattern": "_hell*.txt"
}
}
```
*Sample result*:
```json
{
"result": ["_hello.txt"],
"error": null
}
```
* **deleteMediaFile**
Deletes the specified file inside the media folder.

View File

@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
import glob
import hashlib
import inspect
import json
@ -549,6 +550,12 @@ class AnkiConnect:
return False
@util.api()
def getMediaFilesNames(self, pattern='*'):
path = os.path.join(self.media().dir(), pattern)
return [os.path.basename(p) for p in glob.glob(path)]
@util.api()
def deleteMediaFile(self, filename):
try:

View File

@ -16,6 +16,9 @@ class TestMedia(unittest.TestCase):
media = util.invoke('retrieveMediaFile', filename=filename)
self.assertEqual(media, data)
names = util.invoke('getMediaFilesNames', pattern='_tes*.txt')
self.assertEqual(names, [filename])
# deleteMediaFile
util.invoke('deleteMediaFile', filename=filename)