Skip to content

Commit 07e8ce6

Browse files
committed
stash
1 parent 3dff462 commit 07e8ce6

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/id3_helpers.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,35 @@ use id3::frame::{Comment, Lyrics, ExtendedText, ExtendedLink};
1919
use std::io::empty;
2020
use 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.
3151
pub fn get_content_link(frame: &Frame) -> Result<&str> {
3252
match frame.content().link() {
3353
Some(x) => Ok(x),

0 commit comments

Comments
 (0)