1 /*
2 
3   tag::read::ID3v2
4 
5   copyright (c) 2004, 2005 squell <squell@alumina.nl>
6 
7   use, modification, copying and distribution of this software is permitted
8   under the conditions described in the file 'COPYING'.
9 
10   Usage:
11 
12   The read::ID3v2 class implements the reader interface for ID3v2 tags
13 
14 */
15 
16 #ifndef __ZF_GETID3V2
17 #define __ZF_GETID3V2
18 
19 #include <string>
20 #include <cctype>
21 #include "set_base.h"
22 
23 namespace tag {
24     namespace read {
25 
26         class ID3v2 : public metadata {
27         public:
28             const void* const tag;
29 
30             typedef metadata::factory<ID3v2> factory;
31             explicit ID3v2(const char* fn);
32             explicit ID3v2(const void* id3v2_data);
33            ~ID3v2();
34             value_string operator[](ID3field field) const;
35             array listing() const;
36             operator bool() const { return tag; }
37 
has_lang(const std::string field)38             static bool has_lang(const std::string field)  // implies has_enc
39             { return field == "COMM" || field == "COM" ||
40                      field == "USLT" || field == "ULT" ||
41                      field == "USER"; }
42 
has_desc(const std::string field)43             static bool has_desc(const std::string field)  // implies has_enc
44             { return field == "TXXX" || field == "TXX" ||
45                      field == "WXXX" || field == "WXX" ||
46                      field == "COMM" || field == "COM" ||
47                      field == "USLT" || field == "ULT"; }
48 
is_counter(const std::string field)49             static bool is_counter(const std::string field)
50             { return field == "PCNT" || field == "CNT"; }
51 
is_url(const std::string field)52             static bool is_url(const std::string field)
53             { return field[0] == 'W'; }
54 
is_text(const std::string field)55             static bool is_text(const std::string field)
56             { return field[0] == 'T' || field == "IPLS" || field == "IPL"; }
57 
is_valid(const std::string field)58             static bool is_valid(const std::string field)
59             {
60                  using namespace std;
61                  string::size_type n;
62                  for(n = 0; n < field.length(); ++n) {
63                      if(!isupper(field[n]) && !isdigit(field[n]))
64                          return false;
65                  }
66                  return n == 3 || n == 4;
67             }
68         };
69 
70     }
71 }
72 
73 #endif
74 
75