lofty 0.24.0

Audio metadata library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
use crate::tag::TagType;
use crate::tag::items::{Lang, UNKNOWN_LANGUAGE};

use std::borrow::Cow;
use std::collections::HashMap;

#[cfg(doc)]
use crate::{
	id3::v1::Id3v1Tag,
	tag::{Accessor, Tag},
};

macro_rules! first_key {
	($key:tt $(| $remaining:expr)*) => {
		$key
	};
}

pub(crate) use first_key;

// This is used to create the key/ItemKey maps
//
// First comes the name of the map.
// Ex:
//
// APE_MAP;
//
// This is followed by the key value pairs separated by `=>`, with the key being the
// format-specific key and the value being the appropriate ItemKey variant.
// Ex. "Artist" => Artist
//
// Some formats have multiple keys that map to the same ItemKey variant, which can be added with '|'.
// The standard key(s) **must** come before any popular non-standard keys.
// Keys should appear in order of popularity.
//
// The inverse is also true, where a single key may apply to multiple ItemKey variants. The most applicable
// variant must appear first.
macro_rules! gen_map {
	(
		$(#[$meta:meta])?
		$NAME:ident;

		$(
			$($key:literal)|+ => $($variant:ident)|+
		),+ $(,)?
	) => {
		paste::paste! {
			$(#[$meta])?
			#[allow(non_camel_case_types)]
			struct $NAME;

			$(#[$meta])?
			impl $NAME {
				pub(crate) fn get_item_key(&self, key: &str) -> Option<ItemKey> {
					static INSTANCE: std::sync::OnceLock<HashMap<&'static str, &'static [ItemKey]>> = std::sync::OnceLock::new();
					INSTANCE.get_or_init(|| {
						let mut map = HashMap::new();
						$(
							let values: &'static [ItemKey] = &[$(ItemKey::$variant,)+];
							$(
								map.insert($key, values);
							)+
						)+
						map
					}).iter().find(|(k, _)| k.eq_ignore_ascii_case(key)).map(|(_, v)| v[0])
				}

				pub(crate) fn get_key(&self, item_key: ItemKey) -> Option<&'static str> {
					match item_key {
						$(
							$(ItemKey::$variant)|+ => Some(first_key!($($key)|*)),
						)+
						_ => None
					}
				}
			}
		}
	}
}

gen_map!(
	AIFF_TEXT_MAP;

	"NAME"          => TrackTitle,
	"AUTH"          => TrackArtist,
	"(c) "          => CopyrightMessage,
	"COMM" | "ANNO" => Comment
);

gen_map!(
	APE_MAP;

	"Album"                          => AlbumTitle,
	"DiscSubtitle"                   => SetSubtitle,
	"Grouping"                       => ContentGroup,
	"Title"                          => TrackTitle,
	"Subtitle"                       => TrackSubtitle,
	"WORKTITLE"                      => Work,
	"MOVEMENTNAME"                   => Movement,
	"MOVEMENT"                       => MovementNumber,
	"MOVEMENTTOTAL"                  => MovementTotal,
	"RELEASECOUNTRY"                 => ReleaseCountry,
	"ALBUMSORT"                      => AlbumTitleSortOrder,
	"ALBUMARTISTSORT"                => AlbumArtistSortOrder,
	"TITLESORT"                      => TrackTitleSortOrder,
	"ARTISTSORT"                     => TrackArtistSortOrder,
	"Album Artist" | "ALBUMARTIST"   => AlbumArtist,
	"ALBUMARTISTS" | "ALBUM ARTISTS" => AlbumArtists,
	"Artist"                         => TrackArtist,
	"Artists"                        => TrackArtists,
	"Arranger"                       => Arranger,
	"Writer"                         => Writer,
	"Composer"                       => Composer,
	"Conductor"                      => Conductor,
	"Director"                       => Director,
	"Engineer"                       => Engineer,
	"Lyricist"                       => Lyricist,
	"DjMixer"                        => MixDj,
	"Mixer"                          => MixEngineer,
	"Performer"                      => Performer,
	"Producer"                       => Producer,
	"Label"                          => Label,
	"MixArtist"                      => Remixer,
	"Disc"                           => DiscNumber,
	"Disc"                           => DiscTotal,
	"Track"                          => TrackNumber,
	"Track"                          => TrackTotal,
	// For some reason, the ecosystem agreed on the key "Year", even for full date strings.
	"Year"                           => RecordingDate | Year,
	"ORIGINALYEAR"                   => OriginalReleaseDate,
	"RELEASEDATE"                    => ReleaseDate,
	"ISRC"                           => Isrc,
	"Barcode"                        => Barcode,
	"ACOUSTID_ID"                    => AcoustId,
	"ACOUSTID_FINGERPRINT"           => AcoustIdFingerprint,
	"CatalogNumber"                  => CatalogNumber,
	"Compilation"                    => FlagCompilation,
	"Media"                          => OriginalMediaType,
	"EncodedBy"                      => EncodedBy,
	"REPLAYGAIN_ALBUM_GAIN"          => ReplayGainAlbumGain,
	"REPLAYGAIN_ALBUM_PEAK"          => ReplayGainAlbumPeak,
	"REPLAYGAIN_TRACK_GAIN"          => ReplayGainTrackGain,
	"REPLAYGAIN_TRACK_PEAK"          => ReplayGainTrackPeak,
	"Genre"                          => Genre,
	"Color"                          => Color,
	"Mood"                           => Mood,
	"Copyright"                      => CopyrightMessage,
	"Comment"                        => Comment,
	"language"                       => Language,
	"Script"                         => Script,
	"Lyrics"                         => Lyrics,
	"UnsyncedLyrics"                 => UnsyncLyrics,
	"MUSICBRAINZ_TRACKID"            => MusicBrainzRecordingId,
	"MUSICBRAINZ_RELEASETRACKID"     => MusicBrainzTrackId,
	"MUSICBRAINZ_ALBUMID"            => MusicBrainzReleaseId,
	"MUSICBRAINZ_RELEASEGROUPID"     => MusicBrainzReleaseGroupId,
	"MUSICBRAINZ_ARTISTID"           => MusicBrainzArtistId,
	"MUSICBRAINZ_ALBUMARTISTID"      => MusicBrainzReleaseArtistId,
	"MUSICBRAINZ_WORKID"             => MusicBrainzWorkId,
	"MUSICBRAINZ_ALBUMTYPE"			 => MusicBrainzReleaseType,
);

gen_map!(
	ID3V2_MAP;

	"TALB"                                  => AlbumTitle,
	"TSST"                                  => SetSubtitle,
	"TIT1"                                  => ContentGroup,
	"GRP1"                                  => AppleId3v2ContentGroup,
	"TIT2"                                  => TrackTitle,
	"TIT3"                                  => TrackSubtitle,
	"TOAL"                                  => OriginalAlbumTitle,
	"TOPE"                                  => OriginalArtist,
	"TOLY"                                  => OriginalLyricist,
	"TSOA"                                  => AlbumTitleSortOrder,
	"TSO2"                                  => AlbumArtistSortOrder,
	"TSOT"                                  => TrackTitleSortOrder,
	"TSOP"                                  => TrackArtistSortOrder,
	"TSOC"                                  => ComposerSortOrder,
	"TPE2" | "ALBUMARTIST" | "ALBUM ARTIST" => AlbumArtist,
	"ALBUMARTISTS" | "ALBUM ARTISTS"        => AlbumArtists,
	"TPE1"                                  => TrackArtist,
	"ARTISTS"                               => TrackArtists,
	"TEXT"                                  => Writer,
	"TCOM"                                  => Composer,
	"TPE3"                                  => Conductor,
	"DIRECTOR"                              => Director,
	"TEXT"                                  => Lyricist,
	"TPUB"                                  => Publisher | Label,
	"TRSN"                                  => InternetRadioStationName,
	"TRSO"                                  => InternetRadioStationOwner,
	"TPE4"                                  => Remixer,
	"TPOS"                                  => DiscNumber,
	"TPOS"                                  => DiscTotal,
	"TRCK"                                  => TrackNumber,
	"TRCK"                                  => TrackTotal,
	"POPM"                                  => Popularimeter,
	"ITUNESADVISORY"                        => ParentalAdvisory,
	"TDRC"                                  => RecordingDate,
	"TDOR"                                  => OriginalReleaseDate,
	"TSRC"                                  => Isrc,
	"BARCODE"                               => Barcode,
	"Acoustid Id"                           => AcoustId,
	"Acoustid Fingerprint"                  => AcoustIdFingerprint,
	"CATALOGNUMBER"                         => CatalogNumber,
	"WORK"                                  => Work, // ID3v2.4: TXXX:WORK (Apple uses TIT1/ContentGroup, see GRP1/AppleId3v2ContentGroup for disambiguation)
	"MVNM"                                  => Movement,
	"MVIN"                                  => MovementNumber,
	"MVIN"                                  => MovementTotal,
	"TCMP"                                  => FlagCompilation,
	"PCST"                                  => FlagPodcast,
	"TOWN"                                  => FileOwner,
	"TDTG"                                  => TaggingTime,
	"TLEN"                                  => Length,
	"TOFN"                                  => OriginalFileName,
	"TMED"                                  => OriginalMediaType,
	"TENC"                                  => EncodedBy,
	"TSSE"                                  => EncoderSoftware,
	"TSSE"                                  => EncoderSettings,
	"TDEN"                                  => EncodingTime,
	"REPLAYGAIN_ALBUM_GAIN"                 => ReplayGainAlbumGain,
	"REPLAYGAIN_ALBUM_PEAK"                 => ReplayGainAlbumPeak,
	"REPLAYGAIN_TRACK_GAIN"                 => ReplayGainTrackGain,
	"REPLAYGAIN_TRACK_PEAK"                 => ReplayGainTrackPeak,
	"WOAF"                                  => AudioFileUrl,
	"WOAS"                                  => AudioSourceUrl,
	"WCOM"                                  => CommercialInformationUrl,
	"WCOP"                                  => CopyrightUrl,
	"WOAR"                                  => TrackArtistUrl,
	"WORS"                                  => RadioStationUrl,
	"WPAY"                                  => PaymentUrl,
	"WPUB"                                  => PublisherUrl,
	"TCON"                                  => Genre,
	"TKEY"                                  => InitialKey,
	"COLOR"                                 => Color,
	"TMOO"                                  => Mood,
	"TBPM"                                  => IntegerBpm,
	"TCOP"                                  => CopyrightMessage,
	"TDES"                                  => PodcastDescription,
	"TCAT"                                  => PodcastSeriesCategory,
	"WFED"                                  => PodcastUrl,
	"TDRL"                                  => ReleaseDate,
	"TGID"                                  => PodcastGlobalUniqueId,
	"TKWD"                                  => PodcastKeywords,
	"COMM"                                  => Comment,
	"TLAN"                                  => Language,
	// Since ID3v2 has its own standard for synchronized lyrics (SYLT frame), and it'd be out of scope
	// to attempt to parse and convert LRC text into one. So we can't reasonably support `ItemKey::Lyrics`,
	// with it being overloaded with both synchronized and unsynchronized lyrics.
	"USLT"                                  => UnsyncLyrics,
	// Mapping of MusicBrainzRecordingId is implemented as a special case
	"MusicBrainz Release Track Id"          => MusicBrainzTrackId,
	"MusicBrainz Album Id"                  => MusicBrainzReleaseId,
	"MusicBrainz Release Group Id"          => MusicBrainzReleaseGroupId,
	"MusicBrainz Artist Id"                 => MusicBrainzArtistId,
	"MusicBrainz Album Artist Id"           => MusicBrainzReleaseArtistId,
	"MusicBrainz Work Id"                   => MusicBrainzWorkId,
	"MusicBrainz Album Type"				=> MusicBrainzReleaseType,
	"MusicBrainz Album Release Country" 	=> ReleaseCountry,
);

gen_map!(
	ILST_MAP;

	"\u{a9}alb"                                               => AlbumTitle,
	"----:com.apple.iTunes:DISCSUBTITLE"                      => SetSubtitle,
	"tvsh"                                                    => ShowName,
	"\u{a9}grp"                                               => ContentGroup,
	"\u{a9}nam"                                               => TrackTitle,
	"----:com.apple.iTunes:SUBTITLE"                          => TrackSubtitle,
	"\u{a9}wrk"                                               => Work,
	"\u{a9}mvn"                                               => Movement,
	"\u{a9}mvi"                                               => MovementNumber,
	"\u{a9}mvc"                                               => MovementTotal,
	"soal"                                                    => AlbumTitleSortOrder,
	"soaa"                                                    => AlbumArtistSortOrder,
	"sonm"                                                    => TrackTitleSortOrder,
	"soar"                                                    => TrackArtistSortOrder,
	"sosn"                                                    => ShowNameSortOrder,
	"soco"                                                    => ComposerSortOrder,
	"aART"                                                    => AlbumArtist,
	"----:com.apple.iTunes:ALBUMARTISTS"                      => AlbumArtists,
	"\u{a9}ART"                                               => TrackArtist,
	"----:com.apple.iTunes:ARTISTS"                           => TrackArtists,
	"\u{a9}wrt"                                               => Composer,
	"\u{a9}dir"                                               => Director,
	"----:com.apple.iTunes:CONDUCTOR"                         => Conductor,
	"----:com.apple.iTunes:ENGINEER"                          => Engineer,
	"----:com.apple.iTunes:LYRICIST"                          => Lyricist,
	"----:com.apple.iTunes:DJMIXER"                           => MixDj,
	"----:com.apple.iTunes:MIXER"                             => MixEngineer,
	"----:com.apple.iTunes:PRODUCER"                          => Producer,
	"----:com.apple.iTunes:LABEL"                             => Label,
	"----:com.apple.iTunes:REMIXER"                           => Remixer,
	"disk"                                                    => DiscNumber,
	"disk"                                                    => DiscTotal,
	"trkn"                                                    => TrackNumber,
	"trkn"                                                    => TrackTotal,
	"rate"                                                    => Popularimeter,
	"rtng"                                                    => ParentalAdvisory,
	"\u{a9}day"                                               => RecordingDate,
	"----:com.apple.iTunes:ORIGINALDATE"                      => OriginalReleaseDate, // TagLib v2.0
	"----:com.apple.iTunes:RELEASEDATE"                       => ReleaseDate,
	"----:com.apple.iTunes:ISRC"                              => Isrc,
	"----:com.apple.iTunes:BARCODE"                           => Barcode,
	"----:com.apple.iTunes:Acoustid Id"                       => AcoustId,
	"----:com.apple.iTunes:Acoustid Fingerprint"              => AcoustIdFingerprint,
	"----:com.apple.iTunes:CATALOGNUMBER"                     => CatalogNumber,
	"cpil"                                                    => FlagCompilation,
	"pcst"                                                    => FlagPodcast,
	"----:com.apple.iTunes:MEDIA"                             => OriginalMediaType,
	"\u{a9}enc"                                               => EncodedBy,
	"\u{a9}too"                                               => EncoderSoftware,
	"\u{a9}gen"                                               => Genre,
	"----:com.apple.iTunes:COLOR"                             => Color,
	"----:com.apple.iTunes:MOOD"                              => Mood,
	"tmpo"                                                    => IntegerBpm,
	"----:com.apple.iTunes:BPM"                               => Bpm,
	"----:com.apple.iTunes:initialkey"                        => InitialKey,
	"----:com.apple.iTunes:replaygain_album_gain"             => ReplayGainAlbumGain,
	"----:com.apple.iTunes:replaygain_album_peak"             => ReplayGainAlbumPeak,
	"----:com.apple.iTunes:replaygain_track_gain"             => ReplayGainTrackGain,
	"----:com.apple.iTunes:replaygain_track_peak"             => ReplayGainTrackPeak,
	"cprt"                                                    => CopyrightMessage,
	"----:com.apple.iTunes:LICENSE"                           => License,
	"ldes"                                                    => PodcastDescription,
	"catg"                                                    => PodcastSeriesCategory,
	"purl"                                                    => PodcastUrl,
	"egid"                                                    => PodcastGlobalUniqueId,
	"keyw"                                                    => PodcastKeywords,
	"\u{a9}cmt"                                               => Comment,
	"desc"                                                    => Description,
	"----:com.apple.iTunes:LANGUAGE"                          => Language,
	"----:com.apple.iTunes:SCRIPT"                            => Script,
	// Don't know of any key for synchronized lyrics, nor if any apps actually support them, so
	// just treat both keys the same like ID3v2.
	"\u{a9}lyr"                                               => Lyrics  | UnsyncLyrics,
	"xid "                                                    => AppleXid,
	"----:com.apple.iTunes:MusicBrainz Track Id"              => MusicBrainzRecordingId,
	"----:com.apple.iTunes:MusicBrainz Release Track Id"      => MusicBrainzTrackId,
	"----:com.apple.iTunes:MusicBrainz Album Id"              => MusicBrainzReleaseId,
	"----:com.apple.iTunes:MusicBrainz Release Group Id"      => MusicBrainzReleaseGroupId,
	"----:com.apple.iTunes:MusicBrainz Artist Id"             => MusicBrainzArtistId,
	"----:com.apple.iTunes:MusicBrainz Album Artist Id"       => MusicBrainzReleaseArtistId,
	"----:com.apple.iTunes:MusicBrainz Work Id"               => MusicBrainzWorkId,
	"----:com.apple.iTunes:MusicBrainz Album Type"		  	  => MusicBrainzReleaseType,
	"----:com.apple.iTunes:MusicBrainz Album Release Country" => ReleaseCountry,
);

gen_map!(
	RIFF_INFO_MAP;

	"IPRD"          => AlbumTitle,
	"INAM"          => TrackTitle,
	"IART"          => TrackArtist,
	"IWRI"          => Writer,
	"IMUS"          => Composer,
	"IPRO"          => Producer,
	"IPRT" | "ITRK" => TrackNumber,
	"IFRM"          => TrackTotal,
	"IRTD"          => Popularimeter,
	"ICRD"          => RecordingDate,
	"TLEN"          => Length,
	"ISRF"          => OriginalMediaType,
	"ITCH"          => EncodedBy,
	"ISFT"          => EncoderSoftware,
	"IGNR"          => Genre,
	"ICOP"          => CopyrightMessage,
	"ICMT"          => Comment,
	"ILNG"          => Language,
	"ICNT"	        => ReleaseCountry
);

gen_map!(
	VORBIS_MAP;

	"ALBUM"                                   => AlbumTitle,
	"DISCSUBTITLE"                            => SetSubtitle,
	"GROUPING"                                => ContentGroup,
	"TITLE"                                   => TrackTitle,
	"SUBTITLE"                                => TrackSubtitle,
	"WORK"                                    => Work,
	"MOVEMENTNAME"                            => Movement,
	"MOVEMENT"                                => MovementNumber,
	"MOVEMENTTOTAL"                           => MovementTotal,
	"RELEASECOUNTRY"                          => ReleaseCountry,
	"ALBUMSORT"                               => AlbumTitleSortOrder,
	"ALBUMARTISTSORT"                         => AlbumArtistSortOrder,
	"TITLESORT"                               => TrackTitleSortOrder,
	"ARTISTSORT"                              => TrackArtistSortOrder,
	"ALBUMARTIST"  | "ALBUM ARTIST"           => AlbumArtist,
	"ALBUMARTISTS" | "ALBUM ARTISTS"          => AlbumArtists,
	"ARTIST"                                  => TrackArtist,
	"ARTISTS"                                 => TrackArtists,
	"ARRANGER"                                => Arranger,
	"AUTHOR" | "WRITER"                       => Writer,
	"COMPOSER"                                => Composer,
	"CONDUCTOR"                               => Conductor,
	"DIRECTOR"                                => Director,
	"ENGINEER"                                => Engineer,
	"LYRICIST"                                => Lyricist,
	"DJMIXER"                                 => MixDj,
	"MIXER"                                   => MixEngineer,
	"PERFORMER"                               => Performer,
	"PRODUCER"                                => Producer,
	"PUBLISHER"                               => Publisher,
	"LABEL" | "ORGANIZATION"                  => Label,
	"REMIXER" | "MIXARTIST"                   => Remixer,
	"DISCNUMBER"                              => DiscNumber,
	"DISCTOTAL" | "TOTALDISCS"                => DiscTotal,
	"TRACKNUMBER"                             => TrackNumber,
	"TRACKTOTAL" | "TOTALTRACKS"              => TrackTotal,
	"RATING"                                  => Popularimeter,
	"DATE"                                    => RecordingDate,
	"YEAR"                                    => Year,
	"ORIGINALDATE" | "ORIGINALYEAR"           => OriginalReleaseDate,
	"RELEASEDATE"                             => ReleaseDate,
	"ISRC"                                    => Isrc,
	"BARCODE"                                 => Barcode,
	"ACOUSTID_ID"                             => AcoustId,
	"ACOUSTID_FINGERPRINT"                    => AcoustIdFingerprint,
	"CATALOGNUMBER"                           => CatalogNumber,
	"COMPILATION"                             => FlagCompilation,
	"MEDIA"                                   => OriginalMediaType,
	"ENCODEDBY" | "ENCODED-BY" | "ENCODED_BY" => EncodedBy,
	"ENCODER"                                 => EncoderSoftware,
	"ENCODING" | "ENCODERSETTINGS"            => EncoderSettings,
	"REPLAYGAIN_ALBUM_GAIN"                   => ReplayGainAlbumGain,
	"REPLAYGAIN_ALBUM_PEAK"                   => ReplayGainAlbumPeak,
	"REPLAYGAIN_TRACK_GAIN"                   => ReplayGainTrackGain,
	"REPLAYGAIN_TRACK_PEAK"                   => ReplayGainTrackPeak,
	"GENRE"                                   => Genre,
	"COLOR"                                   => Color,
	"MOOD"                                    => Mood,
	"BPM"                                     => Bpm,
	// MusicBrainz Picard suggests "KEY" (VirtualDJ, Denon Engine DJ), but "INITIALKEY"
	// seems to be more common (Rekordbox, Serato DJ, Traktor DJ, Mixxx).
	// <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#initial-key>
	// <https://github.com/beetbox/beets/issues/637#issuecomment-39528023>
	"INITIALKEY" | "KEY"                      => InitialKey,
	"COPYRIGHT"                               => CopyrightMessage,
	"LICENSE"                                 => License,
	"COMMENT"                                 => Comment,
	// This field comes from the spec: <https://xiph.org/vorbis/doc/v-comment.html#fieldnames>
	//
	// But doesn't seem to actually be used anywhere? AFAICT, it was meant to serve the same purpose as
	// "COMMENT". I haven't found any cases of taggers converting this field to "COMMENT" though, so
	// it's probably safest to keep the two distinct.
	"DESCRIPTION"                             => Description,
	"LANGUAGE"                                => Language,
	"SCRIPT"                                  => Script,
	"LYRICS"                                  => Lyrics,
	"UNSYNCEDLYRICS"                          => UnsyncLyrics,
	"MUSICBRAINZ_TRACKID"                     => MusicBrainzRecordingId,
	"MUSICBRAINZ_RELEASETRACKID"              => MusicBrainzTrackId,
	"MUSICBRAINZ_ALBUMID"                     => MusicBrainzReleaseId,
	"MUSICBRAINZ_RELEASEGROUPID"              => MusicBrainzReleaseGroupId,
	"MUSICBRAINZ_ARTISTID"                    => MusicBrainzArtistId,
	"MUSICBRAINZ_ALBUMARTISTID"               => MusicBrainzReleaseArtistId,
	"MUSICBRAINZ_WORKID"                      => MusicBrainzWorkId,
	"RELEASETYPE"							  => MusicBrainzReleaseType,
);

macro_rules! gen_item_keys {
	(
		MAPS => [
			$(
				$(#[$feat:meta])?
				[$tag_type:pat, $MAP:ident]
			),+
		];
		KEYS => [
			$(
				$(#[$variant_meta:meta])*
				$variant_ident:ident
			),+
			$(,)?
		]
	) => {
		#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
		#[non_exhaustive]
		/// A generic representation of a tag's key
		pub enum ItemKey {
			$(
				$(#[$variant_meta])*
				$variant_ident,
			)+
		}

		impl ItemKey {
			/// Map a format specific key to an `ItemKey`, if a variant exists
			///
			/// NOTE: If used with ID3v2, this will only check against the ID3v2.4 keys.
			/// If you wish to use a V2 or V3 key, see [`upgrade_v2`](crate::id3::v2::upgrade_v2) and [`upgrade_v3`](crate::id3::v2::upgrade_v3)
			pub fn from_key(tag_type: TagType, key: &str) -> Option<Self> {
				match tag_type {
					$(
						$(#[$feat])?
						$tag_type => $MAP.get_item_key(key),
					)+
					_ => None
				}
			}
			/// Maps the variant to a format-specific key
			pub fn map_key(self, tag_type: TagType) -> Option<&'static str> {
				match tag_type {
					$(
						$(#[$feat])?
						$tag_type => if let Some(key) = $MAP.get_key(self) {
							return Some(key)
						},
					)+
					_ => {}
				}

				None
			}
		}
	}
}

gen_item_keys!(
	MAPS => [
		[TagType::AiffText, AIFF_TEXT_MAP],

		[TagType::Ape, APE_MAP],

		[TagType::Id3v2, ID3V2_MAP],

		[TagType::Mp4Ilst, ILST_MAP],

		[TagType::RiffInfo, RIFF_INFO_MAP],

		[TagType::VorbisComments, VORBIS_MAP]
	];

	KEYS => [
		// Titles
		/// The album title
		AlbumTitle,
		/// The subtitle of the set (e.g. box set title)
		SetSubtitle,
		/// The show name (for podcasts/TV series)
		ShowName,
		/// The content group description
		ContentGroup,
		/// The track title
		TrackTitle,
		/// The track subtitle
		TrackSubtitle,

		// Original names
		/// The original album title
		OriginalAlbumTitle,
		/// The original artist
		OriginalArtist,
		/// The original lyricist/text writer
		OriginalLyricist,

		// Sorting
		/// The album title sort order key
		AlbumTitleSortOrder,
		/// The album artist sort order key
		AlbumArtistSortOrder,
		/// The track title sort order key
		TrackTitleSortOrder,
		/// The track artist sort order key
		TrackArtistSortOrder,
		/// The show name sort order key
		ShowNameSortOrder,
		/// The composer sort order key
		ComposerSortOrder,

		// People & Organizations
		/// The album artist
		AlbumArtist,
		/// The name of each credited album-level artist
		///
		/// This tag is meant to appear multiple times in a tag, so it should be retrieved with
		/// [`Tag::get_strings`] or [`Tag::take_strings`].
		///
		/// [`Tag::get_strings`]: crate::tag::Tag::get_strings
		/// [`Tag::take_strings`]: crate::tag::Tag::take_strings
		AlbumArtists,
		/// The track artist
		TrackArtist,
		/// The name of each credited artist
		///
		/// This tag is meant to appear multiple times in a tag, so it should be retrieved with
		/// [`Tag::get_strings`] or [`Tag::take_strings`].
		///
		/// [`Tag::get_strings`]: crate::tag::Tag::get_strings
		/// [`Tag::take_strings`]: crate::tag::Tag::take_strings
		TrackArtists,
		/// The arranger
		Arranger,
		/// The writer
		Writer,
		/// The composer
		Composer,
		/// The conductor
		Conductor,
		/// The director
		Director,
		/// The engineer
		Engineer,
		/// The lyricist/text writer
		Lyricist,
		/// The mix DJ
		MixDj,
		/// The mix engineer
		MixEngineer,
		/// The performer
		Performer,
		/// The producer
		Producer,
		/// The publisher
		Publisher,
		/// The record label
		Label,
		/// The internet radio station name
		InternetRadioStationName,
		/// The internet radio station owner
		InternetRadioStationOwner,
		/// The remixer
		Remixer,

		// Counts & Indexes
		/// The disc number
		DiscNumber,
		/// The total number of discs
		DiscTotal,
		/// The track number
		TrackNumber,
		/// The total number of tracks
		TrackTotal,
		/// User-specific ratings (a.k.a. "Popularimeter")
		///
		/// This key is not intended to be used with arbitrary text.
		/// **See the [`popularimeter`] module docs**
		///
		/// # Examples
		///
		/// ```
		/// use lofty::tag::items::popularimeter::{Popularimeter, StarRating};
		/// use lofty::tag::{ItemKey, TagType, Tag};
		///
		/// // Construct a MusicBee-style popularimeter rating
		/// let play_counter = 15;
		/// let popularimeter = Popularimeter::musicbee(StarRating::Four, play_counter);
		///
		/// let mut tag = Tag::new(TagType::Id3v2);
		///
		/// // The popularimeter can be inserted like any other text value.
		/// // All format-specific encoding is handled behind the scenes.
		/// tag.insert_text(ItemKey::Popularimeter, popularimeter.to_string());
		///
		/// // Then `Tag::ratings()` can be used to retrieve the ratings
		/// let all_ratings = tag.ratings().collect::<Vec<_>>();
		/// assert_eq!(all_ratings.len(), 1);
		/// ```
		///
		/// [`popularimeter`]: crate::tag::items::popularimeter
		Popularimeter,
		/// The parental advisory rating
		ParentalAdvisory,

		// Dates
		/// Recording date
		///
		/// Note that most applications unfortunately interpret this as the *release* date, so this
		/// is the key used in [`Accessor::date()`].
		///
		/// [`ItemKey::ReleaseDate`] also exists, but its use is not generally recommended.
		///
		/// <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#date-10>
		RecordingDate,

		/// Release year
		///
		/// This is not a commonly used field, but still appears occasionally in the wild. Typically,
		/// you should use a date field, such as [`ItemKey::RecordingDate`] for wider application support.
		///
		/// ## Note for ID3v1
		///
		/// Since ID3v1 only supports years, when converting a [`Tag`] to an [`Id3v1Tag`], this key will
		/// have priority over [`ItemKey::RecordingDate`].
		Year,

		/// Release date
		///
		/// The release date of a podcast episode or any other kind of release.
		///
		/// Note that this is **not widely used**, and you should likely be using [`ItemKey::RecordingDate`].
		///
		/// <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#release-date-10>
		ReleaseDate,

		/// Original release date/year
		///
		/// <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#original-release-date-1>
		/// <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#original-release-year-1>
		OriginalReleaseDate,

		// Identifiers
		/// The International Standard Recording Code (ISRC)
		Isrc,
		/// The barcode (typically [UPC]/[EAN])
		///
		/// [UPC]: https://en.wikipedia.org/wiki/Universal_Product_Code
		/// [EAN]: https://en.wikipedia.org/wiki/European_Article_Number
		Barcode,
		/// [AcoustID] audio identifiers
		///
		/// Note that this may appear multiple times in a single tag.
		///
		/// [AcoustID]: https://acoustid.org/
		AcoustId,
		/// [AcoustID] audio fingerprints
		///
		/// Note that this may appear multiple times in a single tag.
		///
		/// [AcoustID]: https://acoustid.org/
		AcoustIdFingerprint,
		/// The label catalog number
		///
		/// See also: <https://musicbrainz.org/doc/Release/Catalog_Number>
		CatalogNumber,
		/// The work title
		Work,
		/// The movement name
		Movement,
		/// The movement number
		MovementNumber,
		/// The total number of movements
		MovementTotal,
		/// The country in which this was released
		///
		/// NOTE: This should contain an [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.
		ReleaseCountry,

		///////////////////////////////////////////////////////////////
		// MusicBrainz Identifiers

		/// MusicBrainz Recording ID
		///
		/// Textual representation of the UUID.
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#id21>
		MusicBrainzRecordingId,

		/// MusicBrainz Track ID
		///
		/// Textual representation of the UUID.
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#id24>
		MusicBrainzTrackId,

		/// MusicBrainz Release ID
		///
		/// Textual representation of the UUID.
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#id23>
		MusicBrainzReleaseId,

		/// MusicBrainz Release Group ID
		///
		/// Textual representation of the UUID.
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#musicbrainz-release-group-id>
		MusicBrainzReleaseGroupId,

		/// MusicBrainz Artist ID
		///
		/// Textual representation of the UUID.
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#id17>
		MusicBrainzArtistId,

		/// MusicBrainz Release Artist ID
		///
		/// Textual representation of the UUID.
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#id22>
		MusicBrainzReleaseArtistId,

		/// MusicBrainz Work ID
		///
		/// Textual representation of the UUID.
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#musicbrainz-work-id>
		MusicBrainzWorkId,

		/// MusicBrainz Release Type
		///
		/// A description of the MusicBrainz release group type (e.g. `album`, `single`, `ep`, etc.).
		///
		/// <https://musicbrainz.org/doc/Release_Group/Type>
		///
		/// Reference: <https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#id32>
		MusicBrainzReleaseType,

		///////////////////////////////////////////////////////////////

		// Flags
		/// Whether the track is part of a compilation
		///
		/// NOTE: The value will always be `"1"` or `"0"` for `true` and `false`, respectively.
		FlagCompilation,
		/// Whether the track is a podcast
		///
		/// NOTE: The value will always be `"1"` or `"0"` for `true` and `false`, respectively.
		FlagPodcast,

		// File Information
		/// The file owner/licensee
		FileOwner,
		/// The tagging date/time
		TaggingTime,
		/// The audio length in milliseconds
		Length,
		/// The original file name
		OriginalFileName,
		/// The original media type
		OriginalMediaType,

		// Encoder information
		/// The person or organization that encoded the audio
		EncodedBy,
		/// The encoder software/hardware and settings
		EncoderSoftware,
		/// The encoder settings
		EncoderSettings,
		/// The encoding date/time
		EncodingTime,
		/// The ReplayGain album gain value
		ReplayGainAlbumGain,
		/// The ReplayGain album peak value
		ReplayGainAlbumPeak,
		/// The ReplayGain track gain value
		ReplayGainTrackGain,
		/// The ReplayGain track peak value
		ReplayGainTrackPeak,

		// URLs
		/// A URL link to the audio file
		AudioFileUrl,
		/// A URL link to the audio source
		AudioSourceUrl,
		/// A URL for commercial information
		CommercialInformationUrl,
		/// A URL for copyright/legal information
		CopyrightUrl,
		/// A URL for the track artist
		TrackArtistUrl,
		/// A URL for the internet radio station
		RadioStationUrl,
		/// A URL for payment
		PaymentUrl,
		/// A URL for the publisher
		PublisherUrl,

		// Style
		/// The genre of the track
		Genre,
		/// The initial musical key
		InitialKey,
		/// The color associated with the track
		Color,
		/// The mood of the track
		Mood,
		/// Decimal BPM value with arbitrary precision
		///
		/// Only read and written if the tag format supports a field for decimal BPM values
		/// that are not restricted to integer values.
		///
		/// Not supported by ID3v2 that restricts BPM values to integers in `TBPM`.
		Bpm,
		/// Non-fractional BPM value with integer precision
		///
		/// Only read and written if the tag format has a field for integer BPM values,
		/// e.g. ID3v2 ([`TBPM` frame](https://github.com/id3/ID3v2.4/blob/516075e38ff648a6390e48aff490abed987d3199/id3v2.4.0-frames.txt#L376))
		/// and MP4 (`tmpo` integer atom).
		IntegerBpm,

		// Legal
		/// The copyright message
		CopyrightMessage,
		/// The license under which the release is available
		///
		/// NOTE: This is typically a URL to a license.
		License,

		// Podcast
		/// The podcast episode description
		PodcastDescription,
		/// The podcast series category
		PodcastSeriesCategory,
		/// The podcast URL
		PodcastUrl,
		/// The podcast globally unique identifier
		PodcastGlobalUniqueId,
		/// The podcast keywords
		PodcastKeywords,

		// Miscellaneous
		/// A comment
		Comment,
		/// A description
		Description,
		/// The language of the content ([ISO 639-2])
		///
		/// [ISO 639-2]: https://en.wikipedia.org/wiki/ISO_639-3
		Language,
		/// The script used to write the release and track titles ([ISO 15924])
		///
		/// [ISO 15924]: https://en.wikipedia.org/wiki/ISO_15924
		Script,
		/// (Possibly synchronized) lyrics text
		///
		/// Despite not being specified, this field has been overloaded in some formats (such as Vorbis Comments)
		/// to store both synchronized lyrics (in [LRC format]) and unsynchronized lyrics.
		///
		/// Unfortunately, the best way to handle this field is to just attempt to parse it as LRC.
		///
		/// See [`ItemKey::UnsyncLyrics`] for lyrics that are *guaranteed* to be unsynchronized.
		///
		/// ## Note for ID3v2
		///
		/// ID3v2 is the only format that has a *specified* way of storing synchronized lyrics, and
		/// with it being a binary frame, it's only supported through [`Id3v2Tag`] via [`SynchronizedTextFrame`].
		/// [`ItemKey::Lyrics`] is **not** supported in ID3v2, you must use [`ItemKey::UnsyncLyrics`].
		///
		/// [LRC format]: https://en.wikipedia.org/wiki/LRC_(file_format)
		/// [`Id3v2Tag`]: crate::id3::v2::Id3v2Tag
		/// [`SynchronizedTextFrame`]: crate::id3::v2::SynchronizedTextFrame
		Lyrics,
		/// Unsynchronized lyrics text
		///
		/// Unlike [`ItemKey::Lyrics`], this is *guaranteed* to be unsynchronized lyrics (no timecodes).
		///
		/// This only has special meaning in some formats, mapping to a separate key. In others, it's
		/// identical to [`ItemKey::Lyrics`].
		///
		/// You should only use this key if you're absolutely sure you need it, otherwise [`ItemKey::Lyrics`]
		/// is the safer default.
		UnsyncLyrics,

		// Vendor-specific
		/// Apple's XID identifier
		AppleXid,
		/// Apple's ID3v2 content group (GRP1 frame)
		AppleId3v2ContentGroup, // GRP1
	]
);

/// Represents a tag item's value
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ItemValue {
	/// Any UTF-8 encoded text
	Text(String),
	/// Any UTF-8 encoded locator of external information
	///
	/// This only gets special treatment in `ID3v2` and `APE` tags, being written
	/// as a normal string in other tags
	Locator(String),
	/// Binary information
	Binary(Vec<u8>),
}

impl ItemValue {
	/// Returns the value if the variant is `Text`
	pub fn text(&self) -> Option<&str> {
		match self {
			Self::Text(text) => Some(text),
			_ => None,
		}
	}

	/// Returns the value if the variant is `Locator`
	pub fn locator(&self) -> Option<&str> {
		match self {
			Self::Locator(locator) => Some(locator),
			_ => None,
		}
	}

	/// Returns the value if the variant is `Binary`
	pub fn binary(&self) -> Option<&[u8]> {
		match self {
			Self::Binary(bin) => Some(bin),
			_ => None,
		}
	}

	/// Consumes the `ItemValue`, returning a `String` if the variant is `Text` or `Locator`
	pub fn into_string(self) -> Option<String> {
		match self {
			Self::Text(s) | Self::Locator(s) => Some(s),
			_ => None,
		}
	}

	/// Consumes the `ItemValue`, returning a `Vec<u8>` if the variant is `Binary`
	pub fn into_binary(self) -> Option<Vec<u8>> {
		match self {
			Self::Binary(b) => Some(b),
			_ => None,
		}
	}

	/// Check for emptiness
	pub fn is_empty(&self) -> bool {
		match self {
			Self::Binary(binary) => binary.is_empty(),
			Self::Locator(locator) => locator.is_empty(),
			Self::Text(text) => text.is_empty(),
		}
	}
}

pub(crate) enum ItemValueRef<'a> {
	Text(Cow<'a, str>),
	Locator(&'a str),
	Binary(&'a [u8]),
}

impl<'a> Into<ItemValueRef<'a>> for &'a ItemValue {
	fn into(self) -> ItemValueRef<'a> {
		match self {
			ItemValue::Text(text) => ItemValueRef::Text(Cow::Borrowed(text)),
			ItemValue::Locator(locator) => ItemValueRef::Locator(locator),
			ItemValue::Binary(binary) => ItemValueRef::Binary(binary),
		}
	}
}

/// Represents a tag item (key/value)
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct TagItem {
	pub(crate) lang: Lang,
	pub(crate) description: String,
	pub(crate) item_key: ItemKey,
	pub(crate) item_value: ItemValue,
}

impl TagItem {
	/// Create a new [`TagItem`]
	///
	/// NOTES:
	///
	/// * This will check for validity based on the [`TagType`].
	/// * If the [`ItemKey`] does not map to a key in the target format, `None` will be returned.
	/// * This is unnecessary if you plan on using [`Tag::insert`](crate::tag::Tag::insert), as it does validity checks itself.
	pub fn new_checked(
		tag_type: TagType,
		item_key: ItemKey,
		item_value: ItemValue,
	) -> Option<Self> {
		item_key
			.map_key(tag_type)
			.is_some()
			.then_some(Self::new(item_key, item_value))
	}

	/// Create a new [`TagItem`]
	///
	/// # Examples
	///
	/// ```
	/// use lofty::tag::{ItemKey, ItemValue, TagItem};
	///
	/// let item = TagItem::new(
	/// 	ItemKey::TrackTitle,
	/// 	ItemValue::Text(String::from("My Song")),
	/// );
	/// assert_eq!(item.key(), ItemKey::TrackTitle);
	/// ```
	#[must_use]
	pub const fn new(item_key: ItemKey, item_value: ItemValue) -> Self {
		Self {
			lang: UNKNOWN_LANGUAGE,
			description: String::new(),
			item_key,
			item_value,
		}
	}

	/// Set a language for the [`TagItem`]
	///
	/// The default language is empty.
	///
	/// NOTE: This will not be reflected in most tag formats.
	pub fn set_lang(&mut self, lang: Lang) {
		self.lang = lang;
	}

	/// Returns a reference to the language of the [`TagItem`]
	///
	/// NOTE: This will not be reflected in most tag formats.
	pub fn lang(&self) -> &Lang {
		&self.lang
	}

	/// Set a description for the [`TagItem`]
	///
	/// The default description is empty.
	///
	/// NOTE: This will not be reflected in most tag formats.
	pub fn set_description(&mut self, description: String) {
		self.description = description;
	}

	/// Returns a reference to the description of the [`TagItem`]
	///
	/// NOTE: This will not be reflected in most tag formats.
	pub fn description(&self) -> &str {
		&self.description
	}

	/// Returns the [`ItemKey`]
	pub fn key(&self) -> ItemKey {
		self.item_key
	}

	/// Returns a reference to the [`ItemValue`]
	pub fn value(&self) -> &ItemValue {
		&self.item_value
	}

	/// Consumes the `TagItem`, returning its [`ItemValue`]
	pub fn into_value(self) -> ItemValue {
		self.item_value
	}

	/// Consumes the `TagItem`, returning its [`ItemKey`] and [`ItemValue`]
	pub fn consume(self) -> (ItemKey, ItemValue) {
		(self.item_key, self.item_value)
	}

	pub(crate) fn re_map(&self, tag_type: TagType) -> bool {
		if tag_type == TagType::Id3v1 {
			use crate::id3::v1::constants::VALID_ITEMKEYS;

			return VALID_ITEMKEYS.contains(&self.item_key);
		}

		self.item_key.map_key(tag_type).is_some()
	}
}

#[cfg(test)]
mod tests {
	use super::*;

	#[test]
	fn one_to_many() {
		assert_eq!(ItemKey::Publisher.map_key(TagType::Id3v2), Some("TPUB"));
		assert_eq!(ItemKey::Label.map_key(TagType::Id3v2), Some("TPUB"));
	}

	#[test]
	fn many_to_one() {
		assert_eq!(
			ItemKey::from_key(TagType::VorbisComments, "ALBUMARTIST"),
			Some(ItemKey::AlbumArtist)
		);
		assert_eq!(
			ItemKey::from_key(TagType::VorbisComments, "ALBUM ARTIST"),
			Some(ItemKey::AlbumArtist)
		);
	}
}