File tree Expand file tree Collapse file tree 5 files changed +49
-2
lines changed Expand file tree Collapse file tree 5 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
23
- ` Ilst::remove ` will now return all of the removed atoms
24
24
- ` Ilst::insert_picture ` will now combine all pictures into a single ` covr ` atom
25
25
- ` Ilst::insert ` will now merge atoms with the same identifier into a single atom
26
+ - ** FLAC** : Allow multiple Vorbis Comment blocks when not using ` ParsingMode::Strict `
27
+ - This is not allowed [ by spec] ( https://xiph.org/flac/format.html#def_VORBIS_COMMENT ) , but is still possible
28
+ to encounter in the wild. Now we will just tag whichever tag happens to be latest in the stream and
29
+ use it, they ** will not be merged** .
26
30
27
31
## [ 0.15.0] - 2023-07-11
28
32
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use crate::id3::{find_id3v2, ID3FindResults};
11
11
use crate :: macros:: decode_err;
12
12
use crate :: ogg:: read:: read_comments;
13
13
use crate :: picture:: Picture ;
14
- use crate :: probe:: ParseOptions ;
14
+ use crate :: probe:: { ParseOptions , ParsingMode } ;
15
15
16
16
use std:: io:: { Read , Seek , SeekFrom } ;
17
17
74
74
}
75
75
76
76
if block. ty == BLOCK_ID_VORBIS_COMMENTS {
77
- if flac_file. vorbis_comments_tag . is_some ( ) {
77
+ // NOTE: According to the spec
78
+ //
79
+ // <https://xiph.org/flac/format.html#def_VORBIS_COMMENT>:
80
+ // "There may be only one VORBIS_COMMENT block in a stream."
81
+ //
82
+ // But of course, we can't ever expect any spec compliant inputs, so we just
83
+ // take whatever happens to be the latest block in the stream. This is safe behavior,
84
+ // as when writing to a file with multiple tags, we end up removing all `VORBIS_COMMENT`
85
+ // blocks anyway.
86
+ if flac_file. vorbis_comments_tag . is_some ( )
87
+ && parse_options. parsing_mode == ParsingMode :: Strict
88
+ {
78
89
decode_err ! ( @BAIL Flac , "Streams are only allowed one Vorbis Comments block per stream" ) ;
79
90
}
80
91
Original file line number Diff line number Diff line change
1
+ use lofty:: flac:: FlacFile ;
2
+ use lofty:: { Accessor , AudioFile , ParseOptions , ParsingMode } ;
3
+
4
+ use std:: fs:: File ;
5
+ use std:: io:: Seek ;
6
+
7
+ #[ test]
8
+ fn multiple_vorbis_comments ( ) {
9
+ let mut file = File :: open ( "tests/files/assets/two_vorbis_comments.flac" ) . unwrap ( ) ;
10
+
11
+ // Reading a file with multiple VORBIS_COMMENT blocks should error when using `Strict`, as it is
12
+ // not allowed by spec.
13
+ assert ! ( FlacFile :: read_from(
14
+ & mut file,
15
+ ParseOptions :: new( )
16
+ . read_properties( false )
17
+ . parsing_mode( ParsingMode :: Strict )
18
+ )
19
+ . is_err( ) ) ;
20
+
21
+ file. rewind ( ) . unwrap ( ) ;
22
+
23
+ // But by default, we should just take the last tag in the stream
24
+ let f = FlacFile :: read_from ( & mut file, ParseOptions :: new ( ) . read_properties ( false ) ) . unwrap ( ) ;
25
+
26
+ // The first tag has the artist "Artist 1", the second has "Artist 2".
27
+ assert_eq ! (
28
+ f. vorbis_comments( ) . unwrap( ) . artist( ) . as_deref( ) ,
29
+ Some ( "Artist 2" )
30
+ ) ;
31
+ }
Original file line number Diff line number Diff line change 1
1
mod aac;
2
2
mod aiff;
3
3
mod ape;
4
+ mod flac;
4
5
mod mp4;
5
6
mod mpc;
6
7
mod mpeg;
You can’t perform that action at this time.
0 commit comments