Skip to content

Commit 7dee3ed

Browse files
committed
Fixed field names with subfields
1 parent 2c6b1e4 commit 7dee3ed

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,84 @@ The mdinfo command line tool can output selected metadata in CSV and JSON format
1212
Currently tested on Linux and macOS.
1313
## Synopsis
1414

15+
```bash
16+
$ mdinfo -p "{audio:artist}" -p "{audio:album}" -p "{audio:track}" -p "{size}" music/*.mp3
17+
track1.mp3: The Piano Guys Wonders 1 8806978
18+
track10.mp3: The Piano Guys Wonders 10 5765646
19+
track11.mp3: The Piano Guys Wonders 11 8048782
20+
track12.mp3: The Piano Guys Wonders 12 7834054
21+
track2.mp3: The Piano Guys Wonders 2 8563796
22+
track3.mp3: The Piano Guys Wonders 3 6162443
23+
track4.mp3: The Piano Guys Wonders 4 7863944
24+
track5.mp3: The Piano Guys Wonders 5 8194232
25+
track6.mp3: The Piano Guys Wonders 6 8794087
26+
track7.mp3: The Piano Guys Wonders 7 8873454
27+
track8.mp3: The Piano Guys feat. Shweta Subram Wonders 8 8582158
28+
track9.mp3: The Piano Guys Wonders 9 9011851
29+
```
30+
31+
CSV output:
32+
33+
```bash
34+
$ mdinfo -p "{audio:artist}" -p "{audio:album}" -p "{audio:track}" -p "{size}" music/*.mp3 --csv
35+
filename,audio:artist,audio:album,audio:track,size
36+
track1.mp3,The Piano Guys,Wonders,1,8806978
37+
track10.mp3,The Piano Guys,Wonders,10,5765646
38+
track11.mp3,The Piano Guys,Wonders,11,8048782
39+
track12.mp3,The Piano Guys,Wonders,12,7834054
40+
track2.mp3,The Piano Guys,Wonders,2,8563796
41+
track3.mp3,The Piano Guys,Wonders,3,6162443
42+
track4.mp3,The Piano Guys,Wonders,4,7863944
43+
track5.mp3,The Piano Guys,Wonders,5,8194232
44+
track6.mp3,The Piano Guys,Wonders,6,8794087
45+
track7.mp3,The Piano Guys,Wonders,7,8873454
46+
track8.mp3,The Piano Guys feat. Shweta Subram,Wonders,8,8582158
47+
track9.mp3,The Piano Guys,Wonders,9,9011851
48+
```
49+
50+
JSON output:
51+
52+
```bash
53+
$ mdinfo -p "{audio:artist}" -p "{audio:album}" -p "{audio:track}" -p "{size}" music/*.mp3 --json
54+
{
55+
"audio:album": "Wonders",
56+
"audio:artist": "The Piano Guys",
57+
"audio:track": "1",
58+
"filename": "track1.mp3",
59+
"size": "8806978"
60+
}
61+
{
62+
"audio:album": "Wonders",
63+
"audio:artist": "The Piano Guys",
64+
"audio:track": "10",
65+
"filename": "track10.mp3",
66+
"size": "5765646"
67+
}
68+
...
69+
```
70+
71+
JSON array output:
72+
73+
```bash
74+
$ mdinfo -p "{audio:artist}" -p "{audio:album}" -p "{audio:track}" -p "{size}" music/*.mp3 --json --array
75+
[
76+
{
77+
"audio:album": "Wonders",
78+
"audio:artist": "The Piano Guys",
79+
"audio:track": "1",
80+
"filename": "track1.mp3",
81+
"size": "8806978"
82+
},
83+
{
84+
"audio:album": "Wonders",
85+
"audio:artist": "The Piano Guys",
86+
"audio:track": "10",
87+
"filename": "track10.mp3",
88+
"size": "5765646"
89+
},
90+
...
91+
]
92+
```
1593

1694
## Command Line Usage
1795

mdinfo/mdinfo.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def print_templates(
5858
else (f"{filepath}: " if path else f"{pathlib.Path(filepath).name}: ")
5959
)
6060
rendered_templates = [
61-
str(t).replace( NONE_STR_SENTINEL, undefined or "") for t in rendered_templates
61+
str(t).replace(NONE_STR_SENTINEL, undefined or "") for t in rendered_templates
6262
]
6363
separator = "\0" if null_separator else " "
6464
print(f"{header}{separator.join(rendered_templates)}")
@@ -184,7 +184,12 @@ def get_field_name(template: str) -> str:
184184

185185
parser = MTLParser(get_field_values=lambda *x: x)
186186
if template_statements := parser.parse_statement(template):
187-
return template_statements[0].field or template
187+
if template_statements[0].field:
188+
field_name = template_statements[0].field
189+
if template_statements[0].subfield:
190+
field_name += f":{template_statements[0].subfield}"
191+
return field_name
192+
return template
188193

189194
raise ValueError(f"Could not find field in template: {template}")
190195

0 commit comments

Comments
 (0)