geigerzaehler / beets-alternatives

Beets plugin to manage external files
MIT License
91 stars 21 forks source link

custom paths with inline plugin broken? #68

Open RainbowPants opened 1 year ago

RainbowPants commented 1 year ago

Hello! Some of my paths make use of the built in inline plugin (I'm guessing most people using beets use it) but beets-alternatives throws a NameError 'len' not defined which is kinda weird since it's a builtin function of python. This might of course be an inline issue but i know of no other plugins making use of it in the same way and so don't know how to test it.


Traceback (most recent call last):
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/inline.py", line 120, in _func_func
    return func()
  File "inline", line 3, in __INLINE_FUNC__
NameError: name 'len' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/util/functemplate.py", line 574, in substitute
    res = self.compiled(values, functions)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/util/functemplate.py", line 598, in wrapper_func
    args[VARIABLE_PREFIX + varname] = values[varname]
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/library.py", line 428, in __getitem__
    value = self._get(key)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/library.py", line 416, in _get
    return self._get_formatted(self.album, key)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/dbcore/db.py", line 86, in _get_formatted
    value = model._type(key).format(model.get(key))
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/dbcore/db.py", line 371, in _get
    return getters[key](self)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/inline.py", line 122, in _func_func
    raise InlineError(python_code, exc)
beetsplug.inline.InlineError: error in inline path field code:
allowedLength = 64
if len(album)  > allowedLength:
    return album[0:allowedLength] + '...'
return album

NameError: name 'len' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/inline.py", line 120, in _func_func
    return func()
  File "inline", line 3, in __INLINE_FUNC__
NameError: name 'len' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/rainbowpants/.local/bin/beet", line 8, in <module>
    sys.exit(main())
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/ui/__init__.py", line 1285, in main
    _raw_main(args)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/ui/__init__.py", line 1272, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/alternatives.py", line 135, in func
    opts.func(lib, opts)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/alternatives.py", line 63, in update
    alt.update(create=options.create)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/alternatives.py", line 258, in update
    dest = self.destination(item)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/alternatives.py", line 365, in destination
    dest = super(ExternalConvert, self).destination(item)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/alternatives.py", line 290, in destination
    return item.destination(basedir=self.directory,
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/library.py", line 979, in destination
    subpath = self.evaluate_template(subpath_tmpl, True)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/dbcore/db.py", line 625, in evaluate_template
    return template.substitute(self.formatted(for_path=for_path),
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/util/functemplate.py", line 576, in substitute
    res = self.interpret(values, functions)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/util/functemplate.py", line 568, in interpret
    return self.expr.evaluate(Environment(values, functions))
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/util/functemplate.py", line 256, in evaluate
    out.append(part.evaluate(env))
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/util/functemplate.py", line 163, in evaluate
    if self.ident in env.values:
  File "/usr/lib/python3.8/_collections_abc.py", line 666, in __contains__
    self[key]
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/library.py", line 428, in __getitem__
    value = self._get(key)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/library.py", line 416, in _get
    return self._get_formatted(self.album, key)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/dbcore/db.py", line 86, in _get_formatted
    value = model._type(key).format(model.get(key))
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beets/dbcore/db.py", line 371, in _get
    return getters[key](self)
  File "/home/rainbowpants/.local/lib/python3.8/site-packages/beetsplug/inline.py", line 122, in _func_func
    raise InlineError(python_code, exc)
beetsplug.inline.InlineError: error in inline path field code:
allowedLength = 64
if len(album)  > allowedLength:
    return album[0:allowedLength] + '...'
return album

NameError: name 'len' is not defined```
wisp3rwind commented 1 year ago

Hi! Please, provide the configuration file that generates this issue, and beets and beets-alternatives' versions.

You could probably test this by using the particular inline field in a regular path format, (and maybe run beet move -p to show what the effect would be without actually moving anything).

One of the examples at https://beets.readthedocs.io/en/stable/plugins/inline.html does use len().

RainbowPants commented 1 year ago

Sorry, I fat-fingered the wrong button! here's the output of beet config. it works fine during import and move! both are latest versions, so beet 1.6.0 and beets-alternatives 0.10.2. this plugin also throws an error on running beet alt --version

directory: /media/altaria/lib/music
library: /media/altaria/lib/db/beets.db

plugins: inline fetchart info copyartifacts edit originquery mbsync subsonicupdate duplicates ftintitle convert scrub zero embedart unimported convert alternatives

ui:
    color: yes
threaded: yes
ignore_hidden: yes
per_disc_numbering: yes

import:
    copy: yes
    write: yes
    bell: yes
    log: /usr/lib/beets/log.txt
    resume: ask
item_fields:
    multidisc: 1 if disctotal > 1 else 0
    material: 'if ''Digital'' in media or ''File'' in media: return ''WEB''

        if ''12" Vinyl'' in media or ''7" Vinyl'' in media or ''10" Vinyl'' in media: return ''Vinyl''

        if ''SHM-CD'' in media or ''CD-R'' in media or ''CD'' in media: return ''CD''

        if ''USB Flash Drive'' in media: return ''WEB''

        if not media: return ''WEB''

        else: return media

        '
album_fields:
    codec: "if 'FLAC' in items[0].format:\n    if items[0].bitdepth == 24:\n        sr=str(items[0].samplerate)\n        return 'FLAC 24 '+sr[:2]+'.'+sr[2]\n    else:\n        return 'FLAC'\ntotal = 0\nfor item in items:\n    total += item.bitrate\nabr = total / items.size / 1000\nif abr > 320:\n    return 'FLAC'\nelif abr == 320:\n    return '320'\nelif abr < 320 and abr >= 215:\n    return 'V0'\nelif abr < 215:\n    return 'REPME'\n"
    alb_title: "allowedLength = 64\nif len(album)  > allowedLength:\n    return album[0:allowedLength] + '...'\nreturn album\n"

match:
    max_rec:
        source:
            bandcamp: medium
        missing_tracks: low
        track_length: low
        media: medium
        catalognum: medium
    distance_weights:
        missing_tracks: 10

paths:
    default: $albumartist/$alb_title (%if{$original_year,$original_year,$year}) [${material} ${codec}]/%if{$multidisc,Disc $disc/}$track - $title
    comp: Various Artists/$album (%if{$original_year,$original_year,$year}) [${material} ${codec}]/%if{$multidisc,Disc $disc/}$track - $title
    singleton: $albumartist/Singletons/$title
alternatives:
    hiby:
        directory: /media/altaria/temp/hiby/

        paths:
            default: $albumartist/(%if{$original_year,$original_year,$year}) $alb_title [${material}]/%if{$multidisc,Disc $disc/}$track - $title
            comp: Various Artists/$alb_title (%if{$original_year,$original_year,$year}) [${material}]/%if{$multidisc,Disc $disc/}$track - $title
        formats: mp3 aac
        query: ''
        removable: yes
fetchart:
    sources: filesystem coverart bandcamp itunes amazon fanarttv albumart
    auto: yes
    minwidth: 0
    maxwidth: 0
    quality: 0
    max_filesize: 0
    enforce_ratio: no
    cautious: no
    cover_names:
    - cover
    - front
    - art
    - album
    - folder
    google_key: REDACTED
    google_engine: 001442825323518660753:hrh5ch1gjzm
    fanarttv_key: REDACTED
    lastfm_key: REDACTED
    store_source: no
    high_resolution: no
    deinterlace: no
    cover_format:
embedart:
    auto: no
    maxwidth: 0
    compare_threshold: 0
    ifempty: no
    remove_art_file: no
    quality: 0
bandcamp:
    art: yes
copyartifacts:
    extensions: .log .LOG .cue .CUE .jpg .jpeg .png .yaml .m3u .gif
    print_ignored: no
subsonic:
    url: http://192.168.149.70/navidrome/
    user: rainbowpants
    pass: REDACTED
    auth: password
scrub:
    auto: no
zero:
    auto: no
    fields: lyrics comments
    keep_fields: []
    update_database: no
unimported:
    ignore_extensions: jpg png jpeg m3u log cue yaml LOG CUE M3U
    ignore_subdirectories: hej
convert:
    delete_originals: no
    dest: /media/altaria/temp/
    formats:
        mp3: ffmpeg -i $source -y -vn -aq 0 $dest
        aac:
            command: ffmpeg -i $source -y -vn -acodec aac -aq 1 $dest
            extension: m4a
        alac:
            command: ffmpeg -i $source -y -vn -acodec alac $dest
            extension: m4a
        flac: ffmpeg -i $source -y -vn -acodec flac $dest
        opus: ffmpeg -i $source -y -vn -acodec libopus -ab 96k $dest
        ogg: ffmpeg -i $source -y -vn -acodec libvorbis -aq 3 $dest
        wma: ffmpeg -i $source -y -vn -acodec wmav2 -vn $dest
    pretend: no
    link: no
    hardlink: no
    threads: 4
    format: mp3
    id3v23: inherit
    max_bitrate: 500
    auto: no
    tmpdir:
    quiet: no
    embed: yes

    paths: {}
    no_convert: ''
    never_convert_lossy_files: no
    copy_album_art: no
    album_art_maxwidth: 0

musicbrainz:
    extra_tags:
    - year
    - catalognum
    - country
    - media
    - label
originquery:
    origin_file: origin.yaml
    use_origin_on_conflict: yes
    tag_patterns:
        media: $.Media
        year: $."Edition year"
        label: $."Record label"
        catalognum: $."Catalog number"
        albumdisambig: $.Edition
pathfields: {}
duplicates:
    album: no
    checksum: ''
    copy: ''
    count: no
    delete: no
    format: ''
    full: no
    keys: []
    merge: no
    move: ''
    path: no
    tiebreak: {}
    strict: no
    tag: ''
ftintitle:
    auto: yes
    drop: no
    format: feat. {0}
edit:
    albumfields: album albumartist
    itemfields: track title artist album
    ignore_fields: id path