diff --git a/TODO.md b/TODO.md index 1caf630b5..59eaefa71 100644 --- a/TODO.md +++ b/TODO.md @@ -149,7 +149,7 @@ - have xdg-open parse ` URIs (or adjust them so that it _can_ parse) - sane-bt-search: show details like 5.1 vs stereo, h264 vs h265 - maybe just color these "keywords" in all search results? -- transmission: apply `sane-tag-music` path fix in `torrent-done` script +- transmission: apply `sane-tag-media` path fix in `torrent-done` script - many .mkv files do appear to be tagged: i'd just need to add support in my own tooling - uninsane.org: make URLs relative to allow local use (and as offline homepage) - email: fix so that local mail doesn't go to junk diff --git a/hosts/common/programs/sane-scripts.nix b/hosts/common/programs/sane-scripts.nix index 691f070d7..921b813d3 100644 --- a/hosts/common/programs/sane-scripts.nix +++ b/hosts/common/programs/sane-scripts.nix @@ -38,7 +38,7 @@ in "sane-scripts.secrets-update-keys" "sane-scripts.shutdown" "sane-scripts.sudo-redirect" - "sane-scripts.tag-music" + "sane-scripts.tag-media" "sane-scripts.vpn" "sane-scripts.which" "sane-scripts.wipe" @@ -218,10 +218,10 @@ in "sane-scripts.sync-music" = {}; "sane-scripts.sync-from-iphone" = {}; - "sane-scripts.tag-music".suggestedPrograms = [ + "sane-scripts.tag-media".suggestedPrograms = [ "exiftool" #< for (slightly) better sandboxing than default exiftool ]; - "sane-scripts.tag-music".sandbox = { + "sane-scripts.tag-media".sandbox = { method = "bwrap"; autodetectCliPaths = "existing"; whitelistPwd = true; # for music renaming diff --git a/pkgs/additional/sane-scripts/default.nix b/pkgs/additional/sane-scripts/default.nix index 09cc16568..fd4d0751c 100644 --- a/pkgs/additional/sane-scripts/default.nix +++ b/pkgs/additional/sane-scripts/default.nix @@ -197,8 +197,8 @@ let srcRoot = ./src; pkgs = [ "ffmpeg" "python3.pkgs.unidecode" "sox" ]; }; - tag-music = static-nix-shell.mkPython3 { - pname = "sane-tag-music"; + tag-media = static-nix-shell.mkPython3 { + pname = "sane-tag-media"; srcRoot = ./src; pkgs = [ "python3.pkgs.mutagen" "python3.pkgs.pyexiftool" "python3.pkgs.pykakasi" "python3.pkgs.unidecode" ]; }; diff --git a/pkgs/additional/sane-scripts/src/sane-tag-music b/pkgs/additional/sane-scripts/src/sane-tag-media similarity index 98% rename from pkgs/additional/sane-scripts/src/sane-tag-music rename to pkgs/additional/sane-scripts/src/sane-tag-media index 9efc99d11..b378e2dbe 100755 --- a/pkgs/additional/sane-scripts/src/sane-tag-music +++ b/pkgs/additional/sane-scripts/src/sane-tag-media @@ -61,7 +61,7 @@ # mutagen docs: # - """ -tool which runs over a complete music library or a subset of it and: +tool which runs over a complete music library (or audiobooks, videos, ebooks (limited)) or a subset of it and: - detect tags which are missing or likely incorrect - write new tags to existing media - new tags are specified manually (--artist, --album, ...) @@ -69,9 +69,9 @@ tool which runs over a complete music library or a subset of it and: this tool does NOT move or rename files. it only edits tags. -USAGE: cd MUSIC_LIBRARY_TOP && sane-tag-music [options] fix-paths|fix-tags|print-missing|show [cmd-specific options] DIRECTORY [DIRECTORY ...] +USAGE: cd MEDIA_LIBRARY_TOP && sane-tag-media [options] fix-paths|fix-tags|print-missing|show [cmd-specific options] DIRECTORY [DIRECTORY ...] -scans DIRECTORY and guesses artist/album/title for each track, based on path relative to pwd. +scans DIRECTORY and guesses artist/album/title for each file, based on path relative to pwd. if the guessed tags look more correct than the existing tags (i.e. if the existing file is missing a tag), then this updates the tags on-disk to reflect their path. @@ -87,7 +87,7 @@ options: --title TITLE --trackno TRACK_NUMBER --derive apply existing tags (e.g. album) found in the file set to any files in the set missing such tags - --type audio|image skip files which aren't of some specific media type + --type audio|image|text skip files which aren't of some specific media type fix-tags options: --force: apply path-based tag to each file, even those which already have tags @@ -130,6 +130,9 @@ IMAGE_EXTENSIONS = [ "jpeg", "png", ] +TEXT_EXTENSIONS = [ + "pdf", +] # some software encodes its name in the "producer" metadata field, # whereas i use that field to mean "producer" as "which studio produced this". @@ -145,6 +148,7 @@ KNOWN_SOFTWARE_PRODUCERS = [ class MediaType(Enum): Audio = "audio" Image = "image" + Text = "text" Other = "other" def maybe_romanize(a: str) -> str|None: @@ -746,10 +750,12 @@ class MediaFile: def is_type(self, ty: MediaType) -> bool: is_audio = self.ext in AUDIO_EXTENSIONS is_image = self.ext in IMAGE_EXTENSIONS + is_text = self.ext in TEXT_EXTENSIONS want_audio = ty == MediaType.Audio want_image = ty == MediaType.Image + want_text = ty == MediaType.Text - return is_audio == want_audio and is_image == want_image + return is_audio == want_audio and is_image == want_image and is_text == want_text def tags_on_disk(self) -> Tags: return Tags(