MythTV  master
cddb.h
Go to the documentation of this file.
1 #ifndef CDDB_H_
2 #define CDDB_H_
3 
4 #include <utility>
5 
6 #include <QString>
7 #include <QStringList>
8 #include <QVector>
9 
10 /*
11  * CDDB lookup
12  */
13 struct Cddb
14 {
15  using discid_t = unsigned long;
16  struct Album;
17 
18  // A CDDB query match
19  struct Match
20  {
21  QString discGenre;
23  QString artist;
24  QString title;
25 
26  Match() = default;
27  Match(const char *g, discid_t d, const char *a, const char *t) :
28  discGenre(g), discID(d), artist(a), title(t)
29  {}
30  Match(QString g, discid_t d, QString a, QString t) :
31  discGenre(std::move(g)), discID(d), artist(std::move(a)), title(std::move(t))
32  {}
33  explicit Match(const Album& a) : discGenre(a.discGenre), discID(a.discID),
34  artist(a.artist), title(a.title)
35  {}
36  };
37 
38  // CDDB query results
39  struct Matches
40  {
41  discid_t discID { 0 }; // discID of query
42  bool isExact { false };
43  using match_t = QVector< Match >;
45 
46  Matches() = default;
47  };
48 
49  struct Msf
50  {
51  int min, sec, frame;
52  explicit Msf(int m = 0, int s = 0, int f = 0) : min(m), sec(s), frame(f) {}
53  };
54  using Toc = QVector< Msf >;
55 
56  struct Track
57  {
58  QString artist;
59  QString title;
60  };
61 
62  // CDDB detail result
63  struct Album
64  {
65  QString discGenre; // the genre used in the query to differentiate similar discID's
67  QString artist;
68  QString title;
69  QString genre; // the genre from the DGENRE= item
70  int year { 0 };
71  QString submitter;
72  int rev { 1 };
73  bool isCompilation { false };
74  using track_t = QVector< Track >;
76  QString extd;
77  using ext_t = QVector< QString >;
80 
81  explicit Album(discid_t d = 0, const char* g = nullptr) :
82  discGenre(g), discID(d) {}
83 
84  explicit Album(const QString& s) { *this = s; }
85 
86  Album& operator = (const QString& rhs);
87  operator QString () const;
88  };
89 
90  // Primary cddb access
91  static bool Query(Matches& res, const Toc& toc);
92  static bool Read(Album& album, const QString& genre, discid_t discID);
93  static bool Write(const Album& album, bool bLocalOnly = true);
94 
95  // Support
96  static discid_t Discid(unsigned& secs, const Msf v[], unsigned tracks);
97  static void Alias(const Album& album, discid_t discID);
98 };
99 
100 #endif //ndef CDDB_H_
QString artist
Definition: cddb.h:67
Msf(int m=0, int s=0, int f=0)
Definition: cddb.h:52
static bool Query(Matches &res, const Toc &toc)
CDDB query.
Definition: cddb.cpp:100
QString discGenre
Definition: cddb.h:65
Matches()=default
Match(const Album &a)
Definition: cddb.h:33
QString artist
Definition: cddb.h:58
static void Alias(const Album &album, discid_t discID)
Create a local alias for a matched discID.
Definition: cddb.cpp:283
Album(discid_t d=0, const char *g=nullptr)
Definition: cddb.h:81
QVector< Msf > Toc
Definition: cddb.h:54
Match(QString g, discid_t d, QString a, QString t)
Definition: cddb.h:30
QString extd
Definition: cddb.h:76
Definition: cddb.h:13
QString genre
Definition: cddb.h:69
QVector< Match > match_t
Definition: cddb.h:43
Match(const char *g, discid_t d, const char *a, const char *t)
Definition: cddb.h:27
ext_t ext
Definition: cddb.h:78
bool isCompilation
Definition: cddb.h:73
QString title
Definition: cddb.h:59
int year
Definition: cddb.h:70
discid_t discID
Definition: cddb.h:66
Album & operator=(const QString &rhs)
Parse CDDB text.
Definition: cddb.cpp:291
static const uint16_t * d
QString discGenre
Definition: cddb.h:21
QVector< Track > track_t
Definition: cddb.h:74
QString submitter
Definition: cddb.h:71
unsigned long discid_t
Definition: cddb.h:15
Toc toc
Definition: cddb.h:79
int rev
Definition: cddb.h:72
int sec
Definition: cddb.h:51
QString title
Definition: cddb.h:24
Album(const QString &s)
Definition: cddb.h:84
discid_t discID
Definition: cddb.h:41
bool isExact
Definition: cddb.h:42
QString artist
Definition: cddb.h:23
match_t matches
Definition: cddb.h:44
Definition: cddb.h:49
static bool Write(const Album &album, bool bLocalOnly=true)
CDDB write.
Definition: cddb.cpp:242
static bool Read(Album &album, const QString &genre, discid_t discID)
CDDB read.
Definition: cddb.cpp:196
track_t tracks
Definition: cddb.h:75
discid_t discID
Definition: cddb.h:22
int frame
Definition: cddb.h:51
QString title
Definition: cddb.h:68
int min
Definition: cddb.h:51
static discid_t Discid(unsigned &secs, const Msf v[], unsigned tracks)
discID calculation.
Definition: cddb.cpp:265
QVector< QString > ext_t
Definition: cddb.h:77
Match()=default