1
0
Fork 0
beets/_notes.org

8.9 KiB
Executable file

beets

misc commands

  • beets web # web ui
  • beets info --library | less # library data
  • beets info | less # file data
  • beets replaygain # run replay gain checks on all tracks
  • beets xtractor # run xtractor on all tracks
  • beets-flac xt 'mb_trackid::^.+$'
  • jq '.metadata.tags' /opt/music/beets/xtraction_data/[uid].json | less
  • beets-flac ls -f '$artist - $title - $mb_trackid' 'mb_trackid::^.+$'

tagging and searches

https://beets.readthedocs.io/en/stable/reference/query.html

  • use carat (^) to negate queries
  • beets fields to print database fields
  • beets describe to aggregate queries
  • beets ls -f '$albumartist - $title - is_mail: $is_male'

    • -f is for format strings and can be used adjust output string
    • can print any fields/tags from library database
  • beets ls [-a] trust in trance

    • -a prints album info using passed query string ; no -a prints tracks
  • beets ls -p trust in trance

    • prints paths
    • can be used to print album folder path, not just track paths
  • beets-library info -l -a albumartist:Shinedown sound madness

    • show library data for an album
    • remove -a to operate at item level
  • beets ls -f '$id - $albumartist - $album - $path' path:/opt/music/beets/dupes/

    • finds items at a specific path
    • use this to cleanup bad items (deleted dupes/similar)
    • follow up with the following to remove items at the path

      • beets rm path:/opt/music/beets/dupes/
  • beets-library ls -f '$albumartist - $album - $title - $mb_albumid' mb_albumid::^$

    • find all tracks without music brains id
    • add -a flag to get albums
  • beets ls -a 'added:2024-05-08'

    • show all albums added on a specific day
    • remove -a to search by item
  • beets ls -a 'added:-1w..'

    • show all albums added in the last week
    • remove -a to search by item
  • beets ls -f '$added - $albumartist - $album %ifdef{title, - $title}'

    • list when all tracks were added to library
    • using -a will show for album (this can differ from tracks if 'missing' were filled in later)
  • beets modify [-a] [query] [field=value] [field!]

    • -a operates at album level
    • field=value to set field values
    • field! to remove field from items
  • beets ls my_seed:True

    • show all items with custom tag set to true
  • beets ls ^my_seed:True

    • show all items missing custom tag or having it set to false
  • beets ls my_import:..2

    • show all items with int field less than or equal to 2
    • use n.. for greater than
    • omit .. and just give n to match explicit value
  • commands related to replay gain

    • beets-library ls rg_album_gain::^$
    • beets-library ls rg_track_gain::^$
    beets-library ls -a -f '$r128_album_gain - $rg_album_gain' \
       my_import:[n] ^rg_album_gain::^$ , my_import:[n] ^r128_album_gain::^$
    beets-library ls -f '$r128_album_gain - $r128_track_gain - $rg_album_gain - $rg_track_gain' \
       my_import:[n] ^rg_track_gain::^$ , my_import:[n] ^r128_track_gain::^$
  • command to set music brains id and update Metadata accordingly

    • beets modify -a $id mb_albumid=blah && beets mbsync...
    • beets modify $id mb_trackid=blah && beets mbsync...

importing new files/tracks/etc (full order of operations)

# beets commands to run, in order for every import/addition to beets
beets-library unimported # list all the files in the library folder which are not in the beets database
beets-library describe my_import # check to figure out what the next serial number is for custom import tag
#beets-library import --set my_import=[n] --set my_seed=[True|False] /opt/music/to_import # main import
beets-library import -l /opt/music/beets/import.log --set my_import=[n] --set my_seed=True /opt/music/to_import
#beets-library stats # check library data is ok or at least 'looks reasonable plus or minus dupes or bad tracks'
#beets-library info --library | less # show file metadata (in bulk)
beets-library duplicates | uniq -d # check for dupes
beets-library duplicates --move /opt/music/dupes # remove dupes from lib and move dupes for verification / follow up as appropriate
beets-library unimported # ensure no dangling files in library prior to missing track cleanup
beets-library unimported | xargs -I{} mv {} /opt/music/unimported/ # move unimported 'cruft' out of library for future follow up
beets-library missing # check for missing tracks
beets-library ls -f '$albumartist - $album - $path' -a missing:1.. # list all ablums with one or more missing tracks
beets-library remove -a missing:1.. # does not change filesystem ; removes albums with missing tracks from library
beets-library unimported # verify this looks appropriate and matches the output from missing
beets-library unimported | xargs -I{} mv {} /opt/music/missing/ # move missing out of library for future follow up
beets-library bad my_import:[n] # bad/missing files check
beets-library move # move files to library directory
beets-library describe my_import # figure out what imorts to process - use as query (filter) with remaining commands
# use my_import:[n].. to filter on import n and later, see query ranges for added options
#    best to add the import filter to below commands to save processing time
#beets-library mbsync my_import:[n] # update music brainz data (not stricly required but smart if re-importing or re-exporting in bulk)
beets-library ftintitle my_import:[n] # move 'featured by' to track title
beets-library modify -a my_import:[n] r128_album_gain! rg_album_gain! # wipe album replay gain info in full
beets-library modify my_import:[n] r128_album_gain! r128_track_gain! rg_album_gain! rg_track_gain! # wipe track replay gain info in full
beets-library lastgenre my_import:[n] # pull down last.fm genre stuff
beets-library fetchart  my_import:[n] # fetch cover art
beets-library fingerprint my_import:[n] # chromaprint analysis
beets-library ls -f '$artist - $title - $acoustid_fingerprint' | less # verify chromaprint worked (optional)
beets-library xtractor my_import:[n] # essentia data extraction -- music analysis (long runtime)
beets-library ls -f '$artist - $title - $mood_aggressive - $mood_electronic' | less # verify xtractor worked (optional)
#\beet --config /opt/music/beets/library.yaml ls -a -f '$albumartist' | uniq | sort > /opt/music/to_import/_artists_for_rg.txt
#cat /opt/music/to_import/_artists_for_rg.txt | xargs -d "\n" -n1 -o -t -I{} beet --config /opt/music/beets/library.yaml -v replaygain -w -f {}
# replay gain with -a and non -a form of below for /full/ library replay gain analysis
#beets-library -v replaygain -f -a my_import:[n] # do replaygain analysis on albums
#beets-library -v replaygain -f my_import:[n] # do replaygain analysis on tracks
# replay gain albums, can be resumed
beets-library ls -a -f '$id' my_import:[n] rg_album_gain::^$ | \
xargs -d "\n" -n1 -o -t -I{} beet --config /opt/music/beets/library.yaml -v replaygain -a id:{}
# replay gain tracks, can be resumed
beets-library ls -f '$id' my_import:[n] rg_track_gain::^$ | \
xargs -d "\n" -n1 -o -t -I{} beet --config /opt/music/beets/library.yaml -v replaygain id:{}
beets-library ls -f '$artist - $title - $rg_album_gain - $rg_track_gain' | less # verify replay gain worked (optional / limited test)
beets-library scrub my_import:[n] # scrub file tags & write only beets tracked metadata to files
#beets-library embedart # not needed if calling scrub -- embed cover art in files
#beets-library write # not needed if calling scrub -- write changes to files
beets-library move my_import:[n] # re-organize files based on latest metadata
beets-library alt update airsonic # run conversion for airsonic alternatives profile -- manage the 'compressed audio library' automagically
duplicate_alternatives # check for dupes in 'alternatives' area

xtractor json decode exception monkey patch

#~/.local/lib/python3.8/site-packages/beetsplug/xtractor/helper.py
def extract_from_output(output_path, target_map: Subview):
    """extracts data from the json file as mapped out in the
    `low_level_targets` / `high_level_targets` configuration keys
    """
    data = {}

    if os.path.isfile(output_path):
        with open(output_path, "r") as json_file:
            audiodata = None
            try:
                audiodata = json.load(json_file)
            except json.decoder.JSONDecodeError:
               print('Error processing ', output_path)
               from pathlib import Path
               Path(output_path).unlink(missing_ok=True)
               for key in target_map.keys():
                   data[key] = None
               return data
            for key in target_map.keys():
                try:
                    val = extract_value_from_audiodata(audiodata, target_map[key])
                except AttributeError:
                    val = None

                data[key] = val
    else:
        raise FileNotFoundError("Output file({}) not found!".format(output_path))

    return data