# Track number format in paths

**URL:** https://discourse.beets.io/t/track-number-format-in-paths/377
**Category:** Help
**Created:** [June 11, 2018, 8:14pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377 "2018-06-11T20:14:12Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 11, 2018, 8:14pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/1 "2018-06-11T20:14:12Z")

</div>

I’m afraid, the answer exist already but I search the wrong terms.  
Anyway, I’d like to insure for example 3 digit track number in path expressions of the config.yaml.

Is there an easy way to expand $track with padding zeroes if necessary ?

Actually I get with “$albumartist/$album%aunique{}/$disc-$track $title” as soon as I have more than 99 tracks a wrong order .

---

<div class="post-metadata">

### Author: ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)
#### Post date: [June 11, 2018, 8:47pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/2 "2018-06-11T20:47:06Z")

</div>

Hi! One simple way would be to use the `inline` plugin, which would let you use Python formatting to get this effect. For example, `'{:03n}'.format(track)` gives me three digits, padded with zeroes.

---

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 11, 2018, 9:04pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/3 "2018-06-11T21:04:11Z")

</div>

Great, thanks ! ( I’d never located that solution on my own )

---

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 12, 2018, 8:15am UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/4 "2018-06-12T08:15:43Z")

</div>

Hi,  
now I am a few steps ahead but still kind of confused.

I applied the example above like that:

> plugins: convert lastgenre edit fetchart inline  
> item\_fields:  
> threeDigitTrack: ‘{:03n}’.format(track)  
> paths:  
> default: $albumartist/$album%aunique{}/$threeDigitTrack\_$title

But this gives a syntax problem:

> configuration error: file /home/mpcww/.config/beets/hoerbuch/config\_hoerbuch.yaml could not be read: while parsing a block mapping  
> in “/home/mpcww/.config/beets/hoerbuch/config\_hoerbuch.yaml”, line 29, column 9  
> expected , but found ‘’  
> in “/home/mpcww/.config/beets/hoerbuch/config\_hoerbuch.yaml”, line 29, column 34

In the meantime I encountered the docu for [“inline plugin”](http://beets.readthedocs.io/en/v1.3.16/plugins/inline.html)

According the example I changed the syntax to

> item\_fields:  
> threeDigitTrack: u’%03i’ % (track)  
> paths:  
> default: $albumartist/$album%aunique{}/$threeDigitTrack\_$title

Syntax seemed to be ok but the result is not resolved:

> $threeDigitTrack\_Track\_001.mp3

I decided to apply the example:

> paths:  
> default: $albumartist/$album%aunique{}/‘$disc\_and\_track’\_$title  
> item\_fields:  
> disc\_and\_track: u’%02i.%03i’ % (disc, track) if disctotal \> 1 else u’%03i’ % (track)

with little changes:  
Due to underscore in disc\_and\_track I had to use ‘’'.  
I change 2i to 3i for the track part.

The result looks kind of closer to what I want:

> \_001\_\_Track\_001.mp3  
> \_017\_\_Track\_017.mp3

However now I have the leading ‘\_’ in front of the tracknumber and (!) an additional wone after it and I not even see how it is produced ?

I hope I don’t have to learn python, do I ? 😉

Regarding the syntax of [padding](https://pyformat.info/#number_padding) I assume my pthyon version doesn’t support it:

> python -V  
> Python 2.7.13

But I guessed wrong, actually it works:

> Welcome to Python 2.7! This is the online help utility.  
> […]  
> ‘{:03n}’.format(11)  
> ‘011’

From the beginning of the post (syntax error) there is the question why beets or “inline plugine” are complaing about the new syntax:

> configuration error: file …/config\_hoerbuch.yaml could not be read: while parsing a block mapping  
> in “…config\_hoerbuch.yaml”, line 29, column 9  
> expected , but found ‘’  
> in “…config\_hoerbuch.yaml”, line 29, column 34

and force me to switch to the old one

> item\_fields:  
> # threeDigitTrack: ‘{:03n}’.format(track)  
> threedigittrack: u’%03d’ % (track,)

---

<div class="post-metadata">

### Author: ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)
#### Post date: [June 12, 2018, 11:48am UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/5 "2018-06-12T11:48:50Z")

</div>

Please use code blocks, not quotes, to paste your config syntax.

You’re seeing a YAML parse error. You can read more about YAML syntax elsewhere on the internet. Here, you might try surrounding the Python expression with quotes (‘ or “).

---

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 12, 2018, 1:47pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/6 "2018-06-12T13:47:00Z")

</div>

Sorry, but I don’t have “code blocks” as edit option, just “hyperlink, block quote, preformatted text”, which ist surroundd by “Emphasis” left and “Upload” on the right.

---

<div class="post-metadata">

### Author: ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)
#### Post date: [June 12, 2018, 1:57pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/7 "2018-06-12T13:57:51Z")

</div>

The “preformatted text” button gives you a code block.

---

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 12, 2018, 2:13pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/8 "2018-06-12T14:13:27Z")

</div>

> [@adrian](#):
>
> Here, you might try surrounding the Python expression with quotes (‘ or “).

Using it this way : `threedigittrack: "'{:03n}'.format(track)"` worked!  
However, the “old” syntax `threedigittrack: u’%03d’ % (track,)` didn’t need extra quotation.

Both deliver the same result now with the extra ‘underscores’ which is ok.

Anyway, I don’t wan’t to undestand the details of yaml’s digestion for that purpose.

Thank you again for the hint and the slim solution .

---

<div class="post-metadata">

### Author: ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)
#### Post date: [June 12, 2018, 2:25pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/9 "2018-06-12T14:25:30Z")

</div>

I think the extra underscores in your paths are arising because of the extra quotes you have in your path formats, like this one:

```auto
default: $albumartist/$album%aunique{}/’$disc_and_track’_$title

```

---

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 12, 2018, 3:30pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/10 "2018-06-12T15:30:02Z")

</div>

You could be right !  
I introduced it while fumbeling aorund with those parsing errors, hence without it

default: $albumartist/$album%aunique{}/$disc-$threedigittrack\_$title`  
and  
threedigittrack: ‘’’{:03n}’’.format(track)’  
results with:  
00-$threedigittrack\_Track\_162.mp3

I’ll check the other quoation-form  
default: $albumartist/$album%aunique{}/$disc-"$threedigittrack"\_$title  
and rececive the well-known :  
00-\_162\_\_Track\_162.mp3

Quotation ( " or ’ ) seem to be inevitable in the path, doesn’t it ?

---

<div class="post-metadata">

### Author: ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)
#### Post date: [June 12, 2018, 3:41pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/11 "2018-06-12T15:41:46Z")

</div>

Again, it’s super helpful if you paste you configuration in code blocks. Otherwise, the indentation is removed and it’s hard to see what you actually wrote.

It would be useful to look at general documentation about YAML. Putting quotes inside a value includes those quotes in the string; _surrounding_ a value with quotes just delimits the string.

---

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 12, 2018, 3:53pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/12 "2018-06-12T15:53:00Z")

</div>

I don’t have the edit option for block quotes here (hence I didn’t apply any other neither ).  
I’d like to use a screenshot, but I don’t know how to show my edit menu .

Let’s leave it how it is now.

---

<div class="post-metadata">

### Author: ![8h2a](https://avatars.discourse-cdn.com/v4/letter/8/4491bb/32.png) [@8h2a](https://discourse.beets.io/u/8h2a)
#### Post date: [June 12, 2018, 4:23pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/13 "2018-06-12T16:23:55Z")

</div>

````
```yaml
your config goes here
```

````

You can use 3 backticks (see above) as well if you want to paste your config file.

Can you please show us your config file with this method as well as the filenames you get _and_ and filenames you want.

I don’t clearly understand your problem, but you can try to surround threedigittrack with curly braces like this: `${threedigittrack}`  
The problem might be that the parse cannot find the variable named `threedigittrack_` and simply uses the string itself in the filename. This is because it doesn’t know where the variable name ends ( “`_`” might be a valid character for variable names).

This is also mentioned in the [wiki](https://beets.readthedocs.io/en/v1.4.7/reference/pathformat.html):  
`${title} is equivalent to $title; you can use this if you need to separate a field name from the text that follows it.`  
However I can see how it can benefit from, a clearer description, as it is non-trivial to figure out (for non-programmers) the meaning, its implications, and which errors it might cause if used incorrectly.

As far as I can see, currently for you the `"` act as a separator for the variable name (which should be solved with the curly braces), and then get converted to underscores because they’re invalid characters for filenames.

---

<div class="post-metadata">

### Author: ![wa0815](https://avatars.discourse-cdn.com/v4/letter/w/8edcca/32.png) [@wa0815](https://discourse.beets.io/u/wa0815)
#### Post date: [June 12, 2018, 7:00pm UTC](https://discourse.beets.io/t/track-number-format-in-paths/377/14 "2018-06-12T19:00:47Z")

</div>

Thank you, the curly braces did it finally !

For excercise purposes I paste the whole but small config now and how I use it:

```auto
plugins: convert lastgenre edit fetchart inline
directory: /marvin/mucke/hoerbuch/
library: library_hoerbuch.db
replace:
    ' ': _
    '[\\/]': _ 
    '^\.': _
    '[\x00-\x1f]': _   
    '[<>:"\?\*\|;,\.]': _ 
    '[\(\)]': __ 
    '\.$': _ 
    '\s+$': ''  
    '^\s+': ''  
    '&': _
    '\''' : _ 
    '\â' : _ 
log: /marvin/mucke/beet_hoerbuch.log
languages: en de es
import:
     languages: de en
     media: CD
convert:
   dest: ~/converted_music
   copy_album_art: yes
   formats:
    mp3: ffmpeg -i $source -acodec libmp3lame -b:a 320k $dest
per_disc_numbering: yes
item_fields:
        threedigittrack: "'{:03n}'.format(track)"
# threedigittrack: u'%03d' % (track,)
paths:
    default: $albumartist/$album%aunique{}/$disc-${threedigittrack}_$title
#	default: "$albumartist/$album%aunique{}/$disc-$threedigittrack_$title"
# default: $albumartist/$album%aunique{}/$disc-$threedigittrack_$title
# default: $albumartist/$album%aunique{}/'$disc_and_track'_$title
lastgenre:
    auto: yes 
    whitelist: ~/.config/beets/whitelist.yaml
    canonical: ~/.config/beets/genres-tree.yaml
    force: no
edit:
    albumfields: album albumartist genre
fetchart:
    minwidth: 500

```

There you can see the variants I tried to have a file name very close to the original default path,  
but with at leas three digits for the track with padding zeros.  
That is exactly what I get now: 00- **001** \_Track\_001.mp3

So thats fine.  
The file itself doesn’t have a lot of tags. (no musicbrainz id … )  
id3v2 --list-rfc822 00-001\_Track\_001.mp3 -:

```auto
Filename: 00-001_Track_001.mp3
TIT2: Track 001
TPE1: <artistname>
TPE2: <artistname>
TALB: <albumtitle>
TYER: 2011
TCON: Unknown (183)
TRCK: 001
00-001_Track_001.mp3: No ID3v1 tag
`` 
As you notice it is not the standard config.yaml .
I created a separated configuration for audiobooks and here tracks > 100 isn't so unusually.

Nevertheless I had to rename the standard config.yaml as well because even with --config full-path to config_hoerbuch.yaml , I had the experience that both where used .

So this is actually my configuration tree:

```

├── beetsConfig  
│ ├── config.yaml  
│ ├── library.db  
│ └── state.pickle  
├── config\_albumartist.yaml  
├── config\_mucke.yaml  
├── genres-tree.yaml  
├── hoerbuch  
│ └── config\_hoerbuch.yaml  
├── library.db  
├── library\_hoerbuch.db  
├── state.pickle  
└── whitelist.yaml

```auto

```
