Skip to content

Commit dd9c162

Browse files
committed
db_media media_printer post_actions usage
1 parent 621e944 commit dd9c162

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

xklb/db_media.py

+2
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ def filter_args_sql(args, m_columns):
296296
{'and COALESCE(time_deleted,0) = 0' if 'time_deleted' in m_columns and "deleted" not in (getattr(args, 'sort_groups_by',None) or '') and "time_deleted" not in " ".join(args.where) else ''}
297297
{'AND (score IS NULL OR score > 7)' if 'score' in m_columns else ''}
298298
{'AND (upvote_ratio IS NULL OR upvote_ratio > 0.73)' if 'upvote_ratio' in m_columns else ''}
299+
{'AND path not like "http%"' if args.local_media_only and 'time_downloaded' not in m_columns else ''}
300+
{'AND path like "http%"' if args.online_media_only and 'time_downloaded' not in m_columns else ''}
299301
{'AND COALESCE(time_downloaded,0) = 0' if args.online_media_only and 'time_downloaded' in m_columns else ''}
300302
{'AND COALESCE(time_downloaded,1)!= 0 AND path not like "http%"' if args.local_media_only and 'time_downloaded' in m_columns else ''}
301303
"""

xklb/media/media_printer.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from tabulate import tabulate
99

1010
from xklb import db_media, history
11-
from xklb.utils import consts, iterables, printing, processes, sql_utils, strings
11+
from xklb.utils import consts, db_utils, iterables, printing, processes, sql_utils, strings
1212
from xklb.utils.consts import SC
1313
from xklb.utils.log_utils import log
1414

@@ -92,6 +92,7 @@ def media_printer(args, data, units=None, media_len=None) -> None:
9292
action = getattr(args, "action", "")
9393
print_args = getattr(args, "print", "")
9494
cols = getattr(args, "cols", [])
95+
m_columns = db_utils.columns(args, "media")
9596

9697
media = deepcopy(data)
9798

@@ -119,7 +120,7 @@ def media_printer(args, data, units=None, media_len=None) -> None:
119120
D["avg_duration"] = duration / len(media)
120121

121122
if hasattr(args, "action"):
122-
if action in (SC.download, SC.download_status):
123+
if action in (SC.download, SC.download_status) and "time_downloaded" in m_columns:
123124
D["download_duration"] = cadence_adjusted_items(args, D["count"], time_column="time_downloaded")
124125
else:
125126
if duration > 0:
@@ -150,7 +151,7 @@ def media_printer(args, data, units=None, media_len=None) -> None:
150151
marked = history.add(args, [d["path"] for d in media])
151152
log.warning(f"Marked {marked} metadata records as watched")
152153

153-
if "a" not in print_args and action == SC.download_status:
154+
if "a" not in print_args and action == SC.download_status and "time_downloaded" in m_columns:
154155
for m in media:
155156
m["download_duration"] = cadence_adjusted_items(
156157
args, m["never_downloaded"] + m["retry_queued"], time_column="time_downloaded"

xklb/post_actions.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,16 @@ def external_action(args, log_action, media_file, player_exit_code, player_proce
141141
cmd = getattr(args, player_exit_code_cmd, None)
142142
if cmd:
143143
log_action(player_exit_code_cmd.upper())
144-
if "{}" in cmd:
144+
if cmd in ['pass', 'mark-watched']:
145+
pass
146+
elif cmd in ['soft-delete', 'mark-deleted']:
147+
db_media.mark_media_deleted(args, media_file)
148+
elif cmd in ['delete']:
149+
if media_file.startswith("http"):
150+
db_media.mark_media_deleted(args, media_file)
151+
else:
152+
delete_media(args, media_file)
153+
elif "{}" in cmd:
145154
processes.cmd_detach(media_file if s == "{}" else s for s in shlex.split(cmd))
146155
else:
147156
processes.cmd_detach(shlex.split(cmd), media_file)

xklb/usage.py

+56-1
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,62 @@ def play(action) -> str:
16991699
17001700
Scan open directories
17011701
1702-
library download open_dir.db --fs --prefix ~/d/dump/video/ --relative -vv -s factory -p
1702+
library web-add open_dir.db --video http://1.1.1.1/
1703+
1704+
Check download size of all videos matching some criteria
1705+
1706+
library download --fs open_dir.db --prefix ~/d/dump/video/ -w 'height<720' -E preview -pa
1707+
1708+
path count download_duration size avg_size
1709+
--------- ------- ---------------------------- --------- ----------
1710+
Aggregate 5694 2 years, 7 months and 5 days 724.4 GiB 130.3 MiB
1711+
1712+
Download all videos matching some criteria
1713+
1714+
library download --fs open_dir.db --prefix ~/d/dump/video/ -w 'height<720' -E preview
1715+
1716+
Stream directly to mpv
1717+
1718+
library watch open_dir.db
1719+
1720+
Check videos before downloading
1721+
1722+
library watch open_dir.db --online-media-only --loop --exit-code-confirm -i --action ask-keep -m 4 --start 35% --volume=0 -w 'height<720' -E preview
1723+
1724+
Assuming you have bound in mpv input.conf a key to 'quit' and another key to 'quit 4', using the ask-keep action will mark a video as deleted when you 'quit 4' and it will mark a video as watched when you 'quit'.
1725+
1726+
For example, here I bind "'" to "KEEP" and "j" to "DELETE"
1727+
1728+
' quit
1729+
j quit 4
1730+
1731+
This is pretty intuitive after you use it a few times but writing this out I realize this might seem a bit complicated and brittle. You could also do something like `--cmd5 'echo {} >> chosen.txt' --cmd6 'echo {} >> rejected.txt'` instead of post-actions like `ask-keep`; this might be a bit more transparent. But you will still need to bind some keys in mpv:
1732+
1733+
k quit 5
1734+
r quit 6
1735+
1736+
NB. It may help you to set simple focus-under-window rules while using this to prevent keys from accidenly being entered in the wrong mpv windows as new ones are created and capture focus. You can restore your previous mouse focus setting by wrapping the command like this:
1737+
1738+
focus-under-mouse
1739+
library watch ...
1740+
focus-follows-mouse
1741+
1742+
For example:
1743+
1744+
function focus-under-mouse
1745+
kwriteconfig5 --file kwinrc --group Windows --key FocusPolicy FocusUnderMouse
1746+
qdbus-qt5 org.kde.KWin /KWin reconfigure
1747+
end
1748+
1749+
function focus-follows-mouse
1750+
kwriteconfig5 --file kwinrc --group Windows --key FocusPolicy FocusFollowsMouse
1751+
kwriteconfig5 --file kwinrc --group Windows --key NextFocusPrefersMouse true
1752+
qdbus-qt5 org.kde.KWin /KWin reconfigure
1753+
end
1754+
1755+
Download checked videos
1756+
1757+
library download --fs open_dir.db --prefix ~/d/dump/video/ -w 'id in (select media_id from history)'
17031758
17041759
"""
17051760

0 commit comments

Comments
 (0)