@@ -19,15 +19,35 @@ use id3::frame::{Comment, Lyrics, ExtendedText, ExtendedLink};
1919use std:: io:: empty;
2020use std:: path:: Path ;
2121
22- /// Convenience wrapper for getting any simple text content.
23- pub fn get_content_text ( frame : & Frame ) -> Result < & str > {
24- match frame. content ( ) . text ( ) {
25- Some ( x) => Ok ( x) ,
26- None => Err ( anyhow ! ( "Frame claims to be {} with T but has no text content: {frame:?}" , frame. id( ) ) ) ,
22+ #[ derive( Debug ) ]
23+ pub enum FrameIdCompliance {
24+ Declared ,
25+ Compliant ,
26+ Invalid ,
27+ }
28+
29+ /// Returns whether a frame ID is compliant with the ID3v2.2 standard.
30+ pub fn id_is_id3v2_2 ( id : & str ) -> bool {
31+ match id {
32+ // https://web.archive.org/web/20150214031143/http://id3.org/id3v2-00
33+ "BUF" | "CNT" | "COM" | "CRA" | "CRM" | "EQU" | "MLL" | "POP" |
34+ "RVA" | "STC" | "TBP" | "TCM" | "TCO" | "TCR" | "TDA" | "TDY" |
35+ "TEN" | "TFT" | "TIM" | "TKE" | "TLA" | "TLE" | "TMT" | "TOA" |
36+ "TOF" | "TOL" | "TOR" | "TOT" | "TP1" | "TP2" | "TP3" | "TP4" |
37+ "TPA" | "TPB" | "TRC" | "TRD" | "TRK" | "TSI" | "TSS" | "TT1" |
38+ "TT2" | "TT3" | "TXT" | "TXX" | "TYE" | "ULT" | "WAR" | "WAS" |
39+ "WCM" | "WCP" | "WPB" => true ,
40+
41+ // ID3v2.2 URL frames have names "W00" - "WZZ", excluding "WXX".
42+ // "WXX", on the other hand, is a user-defined URL link frame.
43+ str if str. starts_with ( 'W' ) && str[ 2 ..] . chars ( ) . all (
44+ |c| c. is_ascii_uppercase ( ) || c. is_ascii_digit ( )
45+ ) => true ,
46+
47+ _ => false ,
2748 }
2849}
2950
30- /// Convenience wrapper for getting any link content.
3151pub fn get_content_link ( frame : & Frame ) -> Result < & str > {
3252 match frame. content ( ) . link ( ) {
3353 Some ( x) => Ok ( x) ,
0 commit comments