Original_year in folder name if different than year

Hello there, I’ve recently started using beets and I like it very much. I got my config file almost like I’d like it to be except for a small detail. I’d like to write the $original_year to the folder name if it’s different than $year. I guess it would be possible to substract $original_year-$year in Python with the inline plugin, but I don’t know anything about Python. Would someone be able to assist me with this?

Here’s my current config file:

Blockquote
plugins: fetchart embedart convert scrub replaygain lastgenre chroma web extrafiles inline discogs mbsync
directory: /music
library: /config/musiclibrary.blb
art_filename: cover
threaded: yes
original_date: no
#artist_credit: yes
per_disc_numbering: true

convert:
auto: no
ffmpeg: /usr/bin/ffmpeg
opts: -ab 320k -ac 2 -ar 48000
max_bitrate: 320
threads: 4
never_convert_lossy_files: yes

extrafiles:
patterns:
artworkdir:
- ‘[sS]cans/’
- ‘[sS]can/’
- ‘[aA]rtwork/’
- ‘[aA]rtworks/’
- ‘[aA]rt/’
- ‘[cC]overs/’
- ‘[cC]over/’
artworkfiles:
- ‘.png’
- '
/.png’
- '
.jpg’
- ‘/.jpg’
- ‘.jpeg’
- '
/.jpeg’
- '
.gif’
- ‘/.gif’
- ‘.pdf’
- '
/.pdf’
datafiles:
- '
.log’
- ‘/.log’
- ‘.txt’
- '
/.txt’
- '
.md5’
- ‘/.md5’
- ‘.ffp’
- '
/.ffp’
- '
.cue’
- ‘/.cue’
- ‘.CUE’
- '
/.CUE’
- '
.nfo’
- ‘/.nfo’
- ‘.st5’
- '
/.st5’
- '
.yaml’
- ‘/.yaml’

paths:
    artworkdir: $albumpath/artwork
    artworkfiles: $albumpath/artwork/$filename
    datafiles: $albumpath/data/$filename

#discogs:

source_weight: 0.0

match:
preferred:
media: [‘CD’,‘Digital Media|File’]
#original_year: yes
#countries: [‘US’]

item_fields:
disc_and_track: u’%2i%02i’ % (disc, track) if disctotal > 1 else u’%02i’ % (track)
disc_1_char: u’%2i’ % (disc)
multidisc: 1 if disctotal > 1 else 0
#v_year: 0 if release_year = year else 1

album_fields:
mediatype: |
mediaList = {
‘12" Vinyl’: “Vinyl”,
‘7" Vinyl’: “Vinyl”,
“Digital Media”: “WEB”,
“File”: “WEB”,
“Enhanced CD”: “CD”,
“CD-R”: “CD”,
“CDr”: “CD”,
}
try:
return mediaList[items[0].media]
except KeyError:
return items[0].media
bitdepthmost: |
bitdepths = dict()
for item in items:
try:
bitdepths[item.bitdepth] += 1
except KeyError:
bitdepths[item.bitdepth] = 1
sorted_depths = {k: v for k, v in sorted(bitdepths.items(), key=lambda item: item[1])}
return list(sorted_depths)[-1]
sampleratemost: |
samplerates = dict()
for item in items:
try:
samplerates[item.samplerate] += 1
except KeyError:
samplerates[item.samplerate] = 1
sorted_rates = {k: v for k, v in sorted(samplerates.items(), key=lambda item: item[1])}
formatted_num = int(list(sorted_rates)[-1]/1000) if int(list(sorted_rates)[-1]/1000) == float(list(sorted_rates)[-1]/1000) else float(list(sorted_rates)[-1]/1000)
return str(formatted_num) + “kHz”
#bettercatalognum: |
# return items[0].catalognum if items[0].catalognum != “[none]” else “”
mp3_quality: |
if items[0].format.upper() == “MP3”:
total_bitrate = 0
for item in items:
total_bitrate += item.bitrate
average_bitrate = total_bitrate / len(items) / 1000
if average_bitrate == 320:
return “320”
elif average_bitrate == 192:
return “192”
elif average_bitrate == 160:
return “160”
elif average_bitrate == 128:
return “128”
elif average_bitrate >= 200:
return “V0”
else:
return “TOO LOW FIND NEW SOURCE”
else:
return items[0].format
cd_no_bitrate_and_khz: |
if items[0].media.upper() == “CD”:
return 0
else:
return 1

paths:
#default: $albumartist/Gitara (1997) [WEB-FLAC] {2011$}/%if{$multidisc,disc$disc_1_char/}$track. $title
default: $albumartist/$album %if{$original_year,($original_year)} [%if{$mediatype,$mediatype-}$format] %if{$cd_no_bitrate_and_khz,{%if{$bitdepth,$bitdepthmost,$mp3_quality}-$sampleratemost$}} %if{$albumdisambig,{$year $albumdisambig$}}/%if{$multidisc,disc$disc_1_char/}$track. $title
#default: $albumartist/$album %if{$year,($year)} [%if{$mediatype,$mediatype-}$format] %if{$cd_no_bitrate_and_khz,{%if{$bitdepth,$bitdepthmost,$mp3_quality}-$sampleratemost$}} %if{$albumdisambig,{$albumdisambig$}}/%if{$multidisc,disc$disc_1_char/}$track. $title
singleton: Non-Album/$artist - $title
#comp: Compilations/$album %if{$year,($year)} [%if{$mediatype,$mediatype-}$format] %if{$cd_no_bitrate_and_khz,{%if{$bitdepth,$bitdepthmost,$mp3_quality}-$sampleratemost$}} %if{$albumdisambig,{$$albumdisambig$}}/%if{$multidisc,disc$disc_1_char/}$track. $artist - $title
comp: Compilations/$album %if{$original_year,($original_year)} [%if{$mediatype,$mediatype-}$format] %if{$cd_no_bitrate_and_khz,{%if{$bitdepth,$bitdepthmost,$mp3_quality}-$sampleratemost$}} %if{$albumdisambig,{$year $albumdisambig$}}/%if{$multidisc,disc$disc_1_char/}$track. $artist - $title
#comp: Compilations/$album%aunique{}/$disc$track. $title
albumtype_soundtrack: Soundtracks/$album %if{$original_year,($original_year)} [%if{$mediatype,$mediatype-}$format] %if{$cd_no_bitrate_and_khz,{%if{$bitdepth,$bitdepthmost,$mp3_quality}-$sampleratemost$}} %if{$albumdisambig,{$year $albumdisambig$}}/%if{$multidisc,disc$disc_1_char/}$track. $artist - $title

import:
write: yes
copy: yes
move: no
resume: ask
#incremental: yes
incremental: no
quiet_fallback: skip
timid: yes
log: /config/beet.log

lastgenre:
auto: yes
source: album
force: yes
count: 1
min_weight: 10
canonical: yes
#fallback: ‘Acoustic’
#whitelist: /config/genres.txt

embedart:
auto: yes

fetchart:
auto: yes

replaygain:
backend: gstreamer
auto: yes

scrub:
auto: yes

replace:
‘^.’: _
‘[\x00-\x1f]’: _
‘[<>:"?*|]’: _
‘[\xE8-\xEB]’: e
‘[\xEC-\xEF]’: i
‘[\xE2-\xE6]’: a
‘[\xF2-\xF6]’: o
‘[\xF8]’: o
‘.$’: _
‘\s+$’: ‘’
web:
host: 0.0.0.0
port: 8337

Thanks a lot!

Hi! I think you’re on the right track with this commented-out inline plugin declaration:

v_year: 0 if release_year = year else 1

…but you’ll need to be careful to get the field names right (e.g., original_year). You can debug this by running a command like:

beet ls -f '$artist - $title - $v_year`

…and then attempt to use this in an %if context next:

beet ls -f '$artist - $title - %if{$v_year,$original_year - $year,$year}`

or similar.

1 Like

thank you for your help, I was finally able to test it again. Because of your comment, I saw that I was using the release_year field instead of original_year. It’s now working!!
So, for anyone looking to do the same thing, here’s how I made it work:

item_fields:
disc_and_track: u’%2i%02i’ % (disc, track) if disctotal > 1 else u’%02i’ % (track)
disc_1_char: u’%2i’ % (disc)
multidisc: 1 if disctotal > 1 else 0
v_year_diff: 0 if original_year == year else 1

default: $albumartist/$album%if{$original_year, ($original_year)} [%if{$mediatype,$mediatype-}$format] %if{$cd_no_bitrate_and_khz,{%if{$bitdepth,$bitdepthmost,$mp3_quality}-$sampleratemost$}%if{$v_year_diff,%if{$albumdisambig, {$year $albumdisambig$}, ($year)},%if{$albumdisambig, {$albumdisambig$}}},%if{$v_year_diff,%if{$albumdisambig,{$year $albumdisambig$},($year)},%if{$albumdisambig,{$albumdisambig$}}}}/%if{$multidisc,disc$disc_1_char/}$track. $title
1 Like