@@ -699,7 +699,6 @@ impl Accessor for Id3v2Tag {
699
699
title => "TIT2" ;
700
700
artist => "TPE1" ;
701
701
album => "TALB" ;
702
- genre => "TCON" ;
703
702
) ;
704
703
705
704
fn track ( & self ) -> Option < u32 > {
@@ -760,6 +759,31 @@ impl Accessor for Id3v2Tag {
760
759
}
761
760
}
762
761
762
+ fn genre ( & self ) -> Option < Cow < ' _ , str > > {
763
+ let mut genres = self . genres ( ) ?. peekable ( ) ;
764
+ let first = genres. next ( ) ?;
765
+
766
+ if genres. peek ( ) . is_none ( ) {
767
+ return Some ( Cow :: Borrowed ( first) ) ;
768
+ } ;
769
+
770
+ let mut joined = String :: from ( first) ;
771
+ for genre in genres {
772
+ joined. push_str ( " / " ) ;
773
+ joined. push_str ( genre) ;
774
+ }
775
+
776
+ Some ( Cow :: Owned ( joined) )
777
+ }
778
+
779
+ fn set_genre ( & mut self , value : String ) {
780
+ self . insert ( new_text_frame ( GENRE_ID , value, FrameFlags :: default ( ) ) ) ;
781
+ }
782
+
783
+ fn remove_genre ( & mut self ) {
784
+ let _ = self . remove ( & GENRE_ID ) ;
785
+ }
786
+
763
787
fn year ( & self ) -> Option < u32 > {
764
788
if let Some ( Frame {
765
789
value : FrameValue :: Text ( TextInformationFrame { value, .. } ) ,
@@ -2542,6 +2566,32 @@ mod tests {
2542
2566
tag
2543
2567
}
2544
2568
2569
+ #[ test]
2570
+ fn genre_text ( ) {
2571
+ let tag = id3v2_tag_with_genre ( "Dream Pop" ) ;
2572
+ assert_eq ! ( tag. genre( ) , Some ( Cow :: Borrowed ( "Dream Pop" ) ) ) ;
2573
+ }
2574
+ #[ test]
2575
+ fn genre_id_brackets ( ) {
2576
+ let tag = id3v2_tag_with_genre ( "(21)" ) ;
2577
+ assert_eq ! ( tag. genre( ) , Some ( Cow :: Borrowed ( "Ska" ) ) ) ;
2578
+ }
2579
+
2580
+ #[ test]
2581
+ fn genre_id_numeric ( ) {
2582
+ let tag = id3v2_tag_with_genre ( "21" ) ;
2583
+ assert_eq ! ( tag. genre( ) , Some ( Cow :: Borrowed ( "Ska" ) ) ) ;
2584
+ }
2585
+
2586
+ #[ test]
2587
+ fn genre_id_multiple_joined ( ) {
2588
+ let tag = id3v2_tag_with_genre ( "(51)(39)" ) ;
2589
+ assert_eq ! (
2590
+ tag. genre( ) ,
2591
+ Some ( Cow :: Borrowed ( "Techno-Industrial / Noise" ) )
2592
+ ) ;
2593
+ }
2594
+
2545
2595
#[ test]
2546
2596
fn genres_id_multiple ( ) {
2547
2597
let tag = id3v2_tag_with_genre ( "(51)(39)" ) ;
0 commit comments