Skip to content

Commit

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

$ library
xk media library subcommands (v2.3.004)
xk media library subcommands (v2.3.005)

Create database subcommands:
╭───────────────┬────────────────────────────────────────────────────╮
Expand Down
6 changes: 3 additions & 3 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xklb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.3.004"
__version__ = "2.3.005"
27 changes: 18 additions & 9 deletions xklb/fs_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def parse_args(action, usage) -> argparse.Namespace:
)
parser.set_defaults(profile=DBType.video)
parser.add_argument("--scan-all-files", "-a", action="store_true", help=argparse.SUPPRESS)
parser.add_argument("--ext", action=arg_utils.ArgparseList)

parser.add_argument(
"--io-multiplier",
Expand Down Expand Up @@ -117,7 +118,7 @@ def parse_args(action, usage) -> argparse.Namespace:
args = parser.parse_args()

if args.move:
args.move = Path(args.move).expanduser().resolve()
args.move = str(Path(args.move).expanduser().resolve())

args.gap = nums.float_from_percent(args.gap)
if args.delete_corrupt:
Expand Down Expand Up @@ -171,10 +172,6 @@ def extract_metadata(mp_args, path) -> Optional[Dict[str, int]]:
"time_deleted": 0,
}

if mp_args.hash:
# TODO: it would be better if this was saved to and checked against an external global file
media["hash"] = sample_hash.sample_hash_file(path)

if mp_args.profile in (DBType.audio, DBType.video):
media = av.munge_av_tags(mp_args, media, path)
if media is None:
Expand All @@ -192,8 +189,12 @@ def extract_metadata(mp_args, path) -> Optional[Dict[str, int]]:
else:
log.debug(f"{timer()-start} {path}")

if mp_args.move:
dest_path = bytes(mp_args.move / Path(path).relative_to(mp_args.playlist_path))
if getattr(mp_args, "hash", False):
# TODO: it would be better if this was saved to and checked against an external global file
media["hash"] = sample_hash.sample_hash_file(path)

if getattr(mp_args, "move", False):
dest_path = bytes(Path(mp_args.move) / Path(path).relative_to(mp_args.playlist_path))
dest_path = path_utils.clean_path(dest_path)
file_utils.rename_move_file(path, dest_path)
media["path"] = dest_path
Expand Down Expand Up @@ -271,7 +272,9 @@ def find_new_files(args, path) -> List[str]:
if path.is_file():
scanned_set = set(str(path))
else:
if args.scan_all_files:
if args.ext:
scanned_set = file_utils.rglob(path, args.ext)[0]
elif args.scan_all_files:
scanned_set = file_utils.rglob(path)[0]
elif args.profile == DBType.filesystem:
scanned_set = set.union(*file_utils.rglob(path))
Expand Down Expand Up @@ -362,7 +365,13 @@ def scan_path(args, path_str: str) -> int:

info = {
"extractor_key": "Local",
"extractor_config": objects.filter_namespace(args, ["ocr", "speech_recognition", "scan_subtitles"]),
"extractor_config": objects.dict_filter_bool(
{
k: v
for k, v in args.__dict__.items()
if k not in ["db", "database", "verbose", "extra_playlist_data", "force", "paths"]
}
),
"time_deleted": 0,
}
args.playlist_id = db_playlists.add(args, str(path), info, check_subpath=True)
Expand Down
9 changes: 7 additions & 2 deletions xklb/media/av.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,13 @@ def munge_av_tags(args, media, path) -> Optional[dict]:
raise

if media_check.corruption_threshold_exceeded(args.delete_corrupt, corruption, duration):
log.info("Deleting %s corruption %.1f%% exceeded threshold %s", path, corruption, args.delete_corrupt)
file_utils.trash(path)
threshold_str = (
strings.safe_percent(args.delete_corrupt)
if 0 < args.delete_corrupt < 1
else (args.delete_corrupt + "s")
)
log.warning("Deleting %s corruption %.1f%% exceeded threshold %s", path, corruption * 100, threshold_str)
file_utils.trash(path) # file is not open, checked during initial probe
return None

tags = format_.pop("tags", None)
Expand Down
10 changes: 9 additions & 1 deletion xklb/media/media_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def decode_full_scan(path, audio_scan=False, frames="frames", threads=5):
data = json.loads(output)["streams"][0]

r_frame_rate = fractions.Fraction(data["r_frame_rate"])
nb_frames = int(data[f"nb_read_{frames}"])
nb_frames = int(data.get(f"nb_read_{frames}") or 0)
metadata_duration = ffprobe.duration or 0
actual_duration = nb_frames * r_frame_rate.denominator / r_frame_rate.numerator

Expand Down Expand Up @@ -199,4 +199,12 @@ def media_check() -> None:
raise
else:
if corruption_threshold_exceeded(args.delete_corrupt, corruption, processes.FFProbe(path).duration):
threshold_str = (
strings.safe_percent(args.delete_corrupt)
if 0 < args.delete_corrupt < 1
else (args.delete_corrupt + "s")
)
log.warning(
"Deleting %s corruption %.1f%% exceeded threshold %s", path, corruption * 100, threshold_str
)
file_utils.trash(path)

0 comments on commit 892a803

Please sign in to comment.