@@ -2,11 +2,13 @@ use super::tag::VorbisComments;
22use super :: verify_signature;
33use crate :: error:: { ErrorKind , LoftyError , Result } ;
44use crate :: macros:: { decode_err, err, parse_mode_choice} ;
5- use crate :: picture:: Picture ;
5+ use crate :: picture:: { MimeType , Picture , PictureInformation , PictureType } ;
66use crate :: probe:: ParsingMode ;
77
8+ use std:: borrow:: Cow ;
89use std:: io:: { Read , Seek , SeekFrom } ;
910
11+ use base64:: Engine ;
1012use byteorder:: { LittleEndian , ReadBytesExt } ;
1113use ogg_pager:: { Packets , PageHeader } ;
1214
@@ -104,6 +106,37 @@ where
104106 } ,
105107 }
106108 } ,
109+ k if k. eq_ignore_ascii_case ( b"COVERART" ) => {
110+ // `COVERART` is an old deprecated image storage format. We have to convert it
111+ // to a `METADATA_BLOCK_PICTURE` for it to be useful.
112+ //
113+ // <https://wiki.xiph.org/VorbisComment#Conversion_to_METADATA_BLOCK_PICTURE>
114+ let picture_data = base64:: engine:: general_purpose:: STANDARD . decode ( value) ;
115+
116+ match picture_data {
117+ Ok ( picture_data) => {
118+ let mime_type = Picture :: mimetype_from_bin ( & picture_data)
119+ . unwrap_or_else ( |_| MimeType :: Unknown ( String :: from ( "image/" ) ) ) ;
120+
121+ let picture = Picture {
122+ pic_type : PictureType :: Other ,
123+ mime_type,
124+ description : None ,
125+ data : Cow :: from ( picture_data) ,
126+ } ;
127+
128+ tag. pictures . push ( ( picture, PictureInformation :: default ( ) ) )
129+ } ,
130+ Err ( _) => {
131+ if parse_mode == ParsingMode :: Strict {
132+ return Err ( LoftyError :: new ( ErrorKind :: NotAPicture ) ) ;
133+ }
134+
135+ log:: warn!( "Failed to decode FLAC picture, discarding field" ) ;
136+ continue ;
137+ } ,
138+ }
139+ } ,
107140 // The valid range is 0x20..=0x7D not including 0x3D
108141 k if k. iter ( ) . all ( |c| ( b' ' ..=b'}' ) . contains ( c) && * c != b'=' ) => {
109142 // SAFETY: We just verified that all of the bytes fall within the subset of ASCII
0 commit comments