Skip to content

Commit

Permalink
2.8.023
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed May 20, 2024
1 parent d106003 commit b36b160
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ To stop playing press Ctrl+C in either the terminal or mpv
<details><summary>List all subcommands</summary>

$ library
library (v2.8.022; 72 subcommands)
library (v2.8.023; 72 subcommands)

Create database subcommands:
╭───────────────┬──────────────────────────────────────────╮
Expand Down
19 changes: 4 additions & 15 deletions tests/playback/test_media_player.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys, tempfile, unittest
import tempfile, unittest
from pathlib import Path
from types import SimpleNamespace
from unittest import mock
Expand All @@ -11,7 +11,6 @@
from xklb.lb import library as lb
from xklb.mediadb import db_history, db_media
from xklb.playback.media_player import MediaPrefetcher
from xklb.playback.play_actions import watch as wt
from xklb.utils import consts
from xklb.utils.log_utils import log
from xklb.utils.objects import NoneSpace
Expand Down Expand Up @@ -80,13 +79,6 @@ def test_prefetch(media):
def test_wt_help(capsys):
wt_help_text = "usage:,where,sort,--duration".split(",")

sys.argv = ["wt", "-h"]
with pytest.raises(SystemExit):
wt()
captured = capsys.readouterr().out.replace("\n", "")
for help_text in wt_help_text:
assert help_text in captured

with pytest.raises(SystemExit):
lb(["wt", "-h"])
captured = capsys.readouterr().out.replace("\n", "")
Expand Down Expand Up @@ -123,8 +115,7 @@ def test_lb_fs(self, play_mocked):
assert out["duration"] == 12
assert out["size"] == 136057

sys.argv = ["wt", v_db, "-w", "path like '%test.mp4'"]
wt()
lb(["wt", v_db, "-w", "path like '%test.mp4'"])
out = play_mocked.call_args[0][1]
assert "test.mp4" in out["path"]
assert out["duration"] == 12
Expand All @@ -138,15 +129,13 @@ def test_lb_fs(self, play_mocked):

@mock.patch("xklb.playback.media_player.single_player", return_value=SimpleNamespace(returncode=0))
def test_wt_sort(self, play_mocked):
sys.argv = ["wt", v_db, "-u", "duration"]
wt()
lb(["wt", v_db, "-u", "duration"])
out = play_mocked.call_args[0][1]
assert out is not None

@mock.patch("xklb.playback.media_player.single_player", return_value=SimpleNamespace(returncode=0))
def test_wt_size(self, play_mocked):
sys.argv = ["wt", v_db, "--size", "-1"] # less than 1MB
wt()
lb(["wt", v_db, "--size", "-1"]) # less than 1MB
out = play_mocked.call_args[0][1]
assert out is not None

Expand Down
37 changes: 18 additions & 19 deletions tests/playback/test_play_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shlex
from argparse import ArgumentParser
from pathlib import Path
from types import SimpleNamespace
from unittest import mock
Expand All @@ -7,18 +8,19 @@

from tests.utils import v_db
from xklb.lb import library as lb
from xklb.utils import arggroups

fs_flags = [
("--modified-within '1 second'", 0, ""),
("--deleted-within '1 day'", 0, ""),
("--downloaded-before '1 day'", 0, ""),
("--limit 1", 1, "corrupt.mp4"),
("-L 1", 1, "corrupt.mp4"),
# ("--created-within '1 day'", 1, "https://test"),
("--online-media-only", 1, "https://test"),
("--offset 1", 4, "test.mp4"),
("-s tests -s 'tests AND data' -E 2 -s test -E 3", 4, "corrupt.mp4"),
# ("--created-before '1 day'", 4, "corrupt.mp4"),
("--created-within '30 years'", 5, "corrupt.mp4"),
("--created-before '1 second'", 5, "corrupt.mp4"),
("--downloaded-within '1 day'", 4, "corrupt.mp4"),
("--playlists tests/data/", 4, ""),
("--local-media-only", 4, "corrupt.mp4"),
Expand All @@ -39,21 +41,21 @@

media_flags = [
("--no-video", 0, ""),
# ("--played-within '3 days'", 0, ""),
# ("--played-before '1 day'", 0, ""),
("-B --solo", 0, ""),
# ("-w 'play_count>0'", 0, ""),
# ("-w 'time_played>0'", 0, ""),
# ("-w 'done>0'", 0, ""),
("-p -P", 0, ""),
("--partial n", 0, ""),
# ("-P f", 0, ""),
# ("-P fo", 0, ""),
("-P o", 0, ""),
("-P p", 0, ""),
("-P pt", 0, ""),
# ("-P s", 0, ""),
("-P t", 0, ""),
("-P s", 0, ""), # test_media_player must run first # TODO: move to new function to test before / after
("-w 'play_count=0'", 0, ""),
("--partial n", 5, "corrupt.mp4"),
("-P f", 5, "test"),
("-P fo", 5, "test.mp4"),
("-P o", 5, "corrupt.mp4"),
("-P p", 5, "corrupt.mp4"),
("-P pt", 5, "corrupt.mp4"),
("-P t", 5, "corrupt.mp4"),
("-w 'play_count>0'", 5, "corrupt.mp4"),
("-w 'time_played>0'", 5, "corrupt.mp4"),
("-w 'done>0'", 5, "corrupt.mp4"),
("--played-within '3 days'", 5, "corrupt.mp4"),
("--played-before '10 years'", 0, ""),
("--no-subtitles", 1, "test_frame.gif"),
("-w subtitle_count=1", 1, "corrupt.mp4"),
("--fetch-siblings each", 1, "corrupt.mp4"),
Expand Down Expand Up @@ -84,12 +86,10 @@
("-O reverse_path_path", 5, "https://test"),
("-O size", 5, "test_frame.gif"),
("-O", 5, "corrupt.mp4"),
# ("-w 'play_count=0'", 5, "corrupt.mp4"),
("-w 'playhead is NULL'", 5, "corrupt.mp4"),
("-w time_deleted=0", 5, "corrupt.mp4"),
]

"""
temp_parser = ArgumentParser(add_help=False)
arggroups.sql_fs(temp_parser)
opts = temp_parser._actions
Expand All @@ -100,7 +100,6 @@ def test_flags_covered(o):
assert any(s in xs for s in o.option_strings for xs in [t[0] for t in fs_flags] + [t[0] for t in media_flags]), (
"Option %s is not covered" % o.option_strings
)
"""


@mock.patch("xklb.playback.media_player.play_list", return_value=SimpleNamespace(returncode=0))
Expand Down
2 changes: 1 addition & 1 deletion xklb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.8.022"
__version__ = "2.8.023"
8 changes: 4 additions & 4 deletions xklb/playback/play_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ def process_playqueue(args) -> None:
if args.fetch_siblings:
media = db_media.get_sibling_media(args, media)

if args.partial:
media = history_sort(args, media)
log.debug("utils.history_sort: %s", t.elapsed())

if args.folder_counts:
media = filter_episodic(args, media)
log.debug("utils.filter_episodic: %s", t.elapsed())
Expand Down Expand Up @@ -386,6 +382,10 @@ def process_playqueue(args) -> None:
media.append(media_keyed[key])
log.debug("double for loop compare_block_strings: %s", t.elapsed())

if args.partial:
media = history_sort(args, media)
log.debug("utils.history_sort: %s", t.elapsed())

if args.play_in_order:
media = db_media.natsort_media(args, media)

Expand Down
6 changes: 3 additions & 3 deletions xklb/utils/arggroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,16 @@ def sql_fs_post(args, table_prefix="m.") -> None:

if args.played_within:
args.aggregate_filter_sql.append(
f"and time_last_played >= cast(STRFTIME('%s', datetime( 'now', '-{nums.sql_human_time(args.played_within)}')) as int)",
f"and time_last_played >= cast(STRFTIME('%s', datetime( 'now', '-{nums.sql_human_time(args.played_within)}')) as int) ",
)
if args.played_before:
args.aggregate_filter_sql.append(
f"and time_last_played < cast(STRFTIME('%s', datetime( 'now', '-{nums.sql_human_time(args.played_before)}')) as int)",
f"and time_last_played < cast(STRFTIME('%s', datetime( 'now', '-{nums.sql_human_time(args.played_before)}')) as int) ",
)

if args.partial:
args.aggregate_filter_sql.append(
"AND COALESCE(time_first_played,0) = 0" if "s" in args.partial else "AND time_first_played>0"
"AND COALESCE(time_first_played,0) = 0 " if "s" in args.partial else "AND time_first_played>0 "
)

if args.duration:
Expand Down

0 comments on commit b36b160

Please sign in to comment.