Skip to content

Commit

Permalink
2.9.003
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Jul 23, 2024
1 parent 40a0097 commit c974957
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 30 deletions.
6 changes: 5 additions & 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.9.002; 81 subcommands)
library (v2.9.003; 81 subcommands)

Create database subcommands:
╭─────────────────┬──────────────────────────────────────────╮
Expand Down Expand Up @@ -2272,6 +2272,10 @@ BTW, for some cols like time_deleted you'll need to specify a where clause so th
echo 'playlist-next force' | socat - /run/user/1000/mpv_socket # library listen default
echo 'playlist-next force' | socat - /home/xk/.config/mpv/socket # library watch default

If you prefer you can also send mpv the playlist, but this is incompatible with post-actions
mpv --playlist=(lb wt videos.db --ext mp4 -l 50 -p fw | psub) # fish shell, mark 50 videos as watched
mpv --playlist=<(lb wt videos.db --ext mp4 -p f) # BASH, all videos

Print an aggregate report of deleted media

library fs -w time_deleted!=0 -pa
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ __pycache__/
*.JPG
*.JPEG
*.jpeg
*.webp
*.png
*.csv
*.json
Expand Down
1 change: 0 additions & 1 deletion tests/utils/test_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_col_naturalsize():
assert printing.col_filesize([{"t": 946684800, "t1": 1}], "t") == [{"t": "902.8 MiB", "t1": 1}]



def test_col_duration():
assert printing.col_duration([{"t": 0, "t1": 1}], "t") == [{"t": "", "t1": 1}]
assert printing.col_duration([{"t": 946684800, "t1": 1}], "t") == [{"t": "30 years and 7 days", "t1": 1}]
Expand Down
1 change: 1 addition & 0 deletions tests/utils/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def test_no_matching_string(self):
with pytest.raises(ValueError):
strings.partial_startswith(my_string, my_list)


def test_human_time():
assert strings.duration(0) == ""
assert strings.duration(946684800) == "30 years and 7 days"
2 changes: 1 addition & 1 deletion xklb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.9.002"
__version__ = "2.9.003"
3 changes: 1 addition & 2 deletions xklb/createdb/hn_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def hacker_news_add() -> None:
args.db.enable_wal()

max_item_id = (
args.max_id
or web.session.get("https://hacker-news.firebaseio.com/v0/maxitem.json", timeout=120).json()
args.max_id or web.session.get("https://hacker-news.firebaseio.com/v0/maxitem.json", timeout=120).json()
)

tables = args.db.table_names()
Expand Down
2 changes: 1 addition & 1 deletion xklb/createdb/links_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def add_playlist(args, path):
"time_modified": 0,
"time_deleted": 0,
}
return db_playlists.add(args, str(path), info, extractor_key='LinksDB')
return db_playlists.add(args, str(path), info, extractor_key="LinksDB")


def consolidate_media(args, path: str) -> dict:
Expand Down
3 changes: 0 additions & 3 deletions xklb/files/similar_files.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import humanize

from xklb import usage
from xklb.folders.similar_folders import cluster_folders, map_and_name
from xklb.utils import arg_utils, arggroups, argparse_utils, file_utils, nums, printing, strings
from xklb.utils.log_utils import log



def parse_args():
parser = argparse_utils.ArgumentParser(usage=usage.similar_files)
arggroups.cluster(parser)
Expand Down
4 changes: 1 addition & 3 deletions xklb/folders/move_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from copy import deepcopy
from pathlib import Path

import humanize

from xklb import usage
from xklb.utils import arggroups, argparse_utils, consts, devices, iterables, printing, sqlgroups, strings

Expand Down Expand Up @@ -170,7 +168,7 @@ def move_list() -> None:
"selected paths:",
strings.file_size(selected_paths_size),
"; future free space:",
strings.file_size(selected_paths_size + free)
strings.file_size(selected_paths_size + free),
)

if selected_paths:
Expand Down
2 changes: 0 additions & 2 deletions xklb/folders/similar_folders.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from pathlib import Path

import humanize

from xklb import usage
from xklb.folders import big_dirs
from xklb.text import cluster_sort
Expand Down
2 changes: 0 additions & 2 deletions xklb/mediadb/block.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import sys

import humanize

from xklb import usage
from xklb.createdb import tube_backend
from xklb.playback import media_printer, post_actions
Expand Down
2 changes: 1 addition & 1 deletion xklb/mediadb/db_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def add(args, entry):
entry.pop("description", None)

media_id = args.db.pop("select id from media where path = ?", [entry["path"]])
if not media_id and 'webpath' in entry and not entry.get('errors'):
if not media_id and "webpath" in entry and not entry.get("errors"):
media_id = args.db.pop("select id from media where path = ?", [entry["webpath"]])

try:
Expand Down
2 changes: 1 addition & 1 deletion xklb/mediadb/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
consts,
db_utils,
iterables,
strings,
processes,
sql_utils,
strings,
web,
)
from xklb.utils.consts import DBType
Expand Down
2 changes: 1 addition & 1 deletion xklb/mediafiles/media_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def decode(scan):
cmd = []
if which("systemd-run"):
cmd += ["systemd-run"]
if not 'SUDO_UID' in os.environ: # ok..
if not "SUDO_UID" in os.environ: # ok..
cmd += ["--user"]
cmd += [
"-p",
Expand Down
1 change: 0 additions & 1 deletion xklb/misc/dedupe_czkawka.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path

import humanize
from screeninfo import get_monitors

from xklb import usage
Expand Down
9 changes: 8 additions & 1 deletion xklb/utils/arggroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,14 @@ def requests(parent_parser):
help='Allow loading data from non-TLS, non-"https" servers',
)
parser.add_argument("--http-max-retries", "--max-retries", "--retries", type=int, default=8, help="Use N retries")
parser.add_argument("--http-max-redirects", "--max-redirects", "--redirects", type=int, default=4, help="Allow N redirects (also counted as a retry)")
parser.add_argument(
"--http-max-redirects",
"--max-redirects",
"--redirects",
type=int,
default=4,
help="Allow N redirects (also counted as a retry)",
)


def selenium(parent_parser):
Expand Down
4 changes: 3 additions & 1 deletion xklb/utils/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def reddit_frequency(frequency) -> str:

SPEECH_RECOGNITION_EXTENSIONS = set("mp3|ogg|wav".split("|"))
OCR_EXTENSIONS = set("gif|jpg|jpeg|png|tif|tff|tiff".split("|"))
AUDIO_ONLY_EXTENSIONS = set("mka|opus|oga|ogg|mp3|mpga|m2a|m4a|m4b|flac|wav|aif|aiff|wma|aac|aa3|ac3|ape|mid|midi".split("|"))
AUDIO_ONLY_EXTENSIONS = set(
"mka|opus|oga|ogg|mp3|mpga|m2a|m4a|m4b|flac|wav|aif|aiff|wma|aac|aa3|ac3|ape|mid|midi".split("|")
)
VIDEO_EXTENSIONS = set(
(
"str|aa|aax|acm|adf|adp|dtk|ads|ss2|adx|aea|afc|aix|al|apl|avifs|gif|gifv"
Expand Down
2 changes: 0 additions & 2 deletions xklb/utils/devices.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os, random, shutil, sys

import humanize

from xklb.files import sample_compare
from xklb.utils import arggroups, consts, file_utils, strings
from xklb.utils.log_utils import log
Expand Down
6 changes: 3 additions & 3 deletions xklb/utils/strings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime, timedelta
import math
import html, re, textwrap
import html, math, re, textwrap
from copy import deepcopy
from datetime import datetime, timedelta
from itertools import zip_longest

import humanize
Expand Down Expand Up @@ -294,6 +293,7 @@ def format_two_columns(text1, text2, width1=25, width2=75, left_gutter=2, middle

return "\n".join(formatted_lines) + "\n"


def file_size(n):
return humanize.naturalsize(n, binary=True)

Expand Down
8 changes: 5 additions & 3 deletions xklb/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _get_retry_adapter(args):
status=max_retries // 2,
other=1,
redirect=max_redirects,
raise_on_redirect=max_redirects<=0,
raise_on_redirect=max_redirects <= 0,
backoff_factor=3,
backoff_jitter=2,
backoff_max=22 * 60,
Expand Down Expand Up @@ -473,7 +473,7 @@ def download_url(url, output_path=None, output_prefix=None, chunk_size=8 * 1024
if retry_num > max_retries:
raise RuntimeError(f"Max retries exceeded for {url}")

log.debug('%s retry %s', url, retry_num)
log.debug("%s retry %s", url, retry_num)
with session.get(url, stream=True) as r:
if not 200 <= r.status_code < 400:
log.error(f"Error {r.status_code} {url}")
Expand All @@ -498,7 +498,9 @@ def download_url(url, output_path=None, output_prefix=None, chunk_size=8 * 1024
elif local_size < 5242880: # TODO: check if first few kilobytes match what already exists locally...
p.unlink()
else:
log.warning(f"Download resuming from {strings.file_size(local_size)} ({strings.safe_percent(local_size/remote_size)}): {output_path}")
log.warning(
f"Download resuming from {strings.file_size(local_size)} ({strings.safe_percent(local_size/remote_size)}): {output_path}"
)
headers = {"Range": f"bytes={local_size}-"}
r.close()
r = session.get(url, headers=headers, stream=True)
Expand Down

0 comments on commit c974957

Please sign in to comment.