mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Add hooks for filtering media.
This commit is contained in:
parent
20f0c887eb
commit
c2901e4859
7 changed files with 21 additions and 2 deletions
|
@ -68,6 +68,7 @@ Piotr Kubowicz <piotr.kubowicz@gmail.com>
|
||||||
RumovZ <gp5glkw78@relay.firefox.com>
|
RumovZ <gp5glkw78@relay.firefox.com>
|
||||||
Cecini <github.com/cecini>
|
Cecini <github.com/cecini>
|
||||||
Krish Shah <github.com/k12ish>
|
Krish Shah <github.com/k12ish>
|
||||||
|
ianki <iankigit@gmail.com>
|
||||||
|
|
||||||
********************
|
********************
|
||||||
|
|
||||||
|
|
|
@ -355,6 +355,7 @@ class AnkiPackageExporter(AnkiExporter):
|
||||||
media = {}
|
media = {}
|
||||||
for c, file in enumerate(files):
|
for c, file in enumerate(files):
|
||||||
cStr = str(c)
|
cStr = str(c)
|
||||||
|
file = hooks.media_file_filter(file)
|
||||||
mpath = os.path.join(fdir, file)
|
mpath = os.path.join(fdir, file)
|
||||||
if os.path.isdir(mpath):
|
if os.path.isdir(mpath):
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -32,6 +32,12 @@ hooks = [
|
||||||
args=["exporters: List[Tuple[str, Any]]"],
|
args=["exporters: List[Tuple[str, Any]]"],
|
||||||
legacy_hook="exportersList",
|
legacy_hook="exportersList",
|
||||||
),
|
),
|
||||||
|
Hook(
|
||||||
|
name="media_file_filter",
|
||||||
|
args=["txt: str"],
|
||||||
|
return_type="str",
|
||||||
|
doc="""Allows manipulating the file path that media will be read from""",
|
||||||
|
),
|
||||||
Hook(
|
Hook(
|
||||||
name="field_filter",
|
name="field_filter",
|
||||||
args=[
|
args=[
|
||||||
|
|
|
@ -1374,6 +1374,7 @@ will be lost. Continue?"""
|
||||||
check_db(self)
|
check_db(self)
|
||||||
|
|
||||||
def on_check_media_db(self) -> None:
|
def on_check_media_db(self) -> None:
|
||||||
|
gui_hooks.media_check_will_start()
|
||||||
check_media_db(self)
|
check_media_db(self)
|
||||||
|
|
||||||
def onStudyDeck(self):
|
def onStudyDeck(self):
|
||||||
|
|
|
@ -19,6 +19,7 @@ from flask import Response, request
|
||||||
from waitress.server import create_server
|
from waitress.server import create_server
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
from anki import hooks
|
||||||
from anki.rsbackend import from_json_bytes
|
from anki.rsbackend import from_json_bytes
|
||||||
from anki.utils import devMode
|
from anki.utils import devMode
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
@ -224,6 +225,8 @@ def _redirectWebExports(path):
|
||||||
print(f"collection not open, ignore request for {path}")
|
print(f"collection not open, ignore request for {path}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
path = hooks.media_file_filter(path)
|
||||||
|
|
||||||
return aqt.mw.col.media.dir(), path
|
return aqt.mw.col.media.dir(), path
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from operator import itemgetter
|
||||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
from typing import Any, Callable, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
from anki import hooks
|
||||||
from anki.cards import Card
|
from anki.cards import Card
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.sound import AV_REF_RE, AVTag, SoundOrVideoTag
|
from anki.sound import AV_REF_RE, AVTag, SoundOrVideoTag
|
||||||
|
@ -390,7 +391,9 @@ class MpvManager(MPV, SoundOrVideoPlayer):
|
||||||
def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
|
def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
|
||||||
assert isinstance(tag, SoundOrVideoTag)
|
assert isinstance(tag, SoundOrVideoTag)
|
||||||
self._on_done = on_done
|
self._on_done = on_done
|
||||||
path = os.path.join(os.getcwd(), tag.filename)
|
filename = hooks.media_file_filter(tag.filename)
|
||||||
|
path = os.path.join(os.getcwd(), filename)
|
||||||
|
|
||||||
self.command("loadfile", path, "append-play")
|
self.command("loadfile", path, "append-play")
|
||||||
gui_hooks.av_player_did_begin_playing(self, tag)
|
gui_hooks.av_player_did_begin_playing(self, tag)
|
||||||
|
|
||||||
|
@ -434,8 +437,11 @@ class SimpleMplayerSlaveModePlayer(SimpleMplayerPlayer):
|
||||||
|
|
||||||
def _play(self, tag: AVTag) -> None:
|
def _play(self, tag: AVTag) -> None:
|
||||||
assert isinstance(tag, SoundOrVideoTag)
|
assert isinstance(tag, SoundOrVideoTag)
|
||||||
|
|
||||||
|
filename = hooks.media_file_filter(tag.filename)
|
||||||
|
|
||||||
self._process = subprocess.Popen(
|
self._process = subprocess.Popen(
|
||||||
self.args + [tag.filename],
|
self.args + [filename],
|
||||||
env=self.env,
|
env=self.env,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
|
|
|
@ -584,6 +584,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||||
|
|
||||||
Note that the media sync did not necessarily finish at this point.""",
|
Note that the media sync did not necessarily finish at this point.""",
|
||||||
),
|
),
|
||||||
|
Hook(name="media_check_will_start", args=[]),
|
||||||
# Adding cards
|
# Adding cards
|
||||||
###################
|
###################
|
||||||
Hook(
|
Hook(
|
||||||
|
|
Loading…
Reference in a new issue