Miam-Player  0.8.0
A nice music player
filehelper.h
Go to the documentation of this file.
1 #ifndef FILEHELPER_H
2 #define FILEHELPER_H
3 
4 #include <QtMultimedia/QMediaContent>
5 #include <QStringList>
6 
7 #include "miamcore_global.h"
8 
9 #include <QFileInfo>
10 
12 class Cover;
13 
15 namespace TagLib {
16  class File;
17 
18  namespace ID3v2 {
19  class Tag;
20  }
21 
22  namespace MP4 {
23  class Item;
24  }
25 }
26 
33 {
34 private:
35  TagLib::File *_file;
36 
37  int _fileType;
38  bool _isValid;
39 
40  QFileInfo _fileInfo;
41 
42  Q_ENUMS(Extension)
43  Q_ENUMS(ExtensionType)
44  Q_ENUMS(Field)
45 
46 public:
47  enum Extension {
48  EXT_UNKNOWN = -1,
49  EXT_APE = 0,
50  EXT_ASF = 1,
51  EXT_FLAC = 2,
52  EXT_MP4 = 4,
53  EXT_MPC = 5,
54  EXT_MP3 = 6,
55  EXT_OGG = 7
56  };
57 
59  ET_Standard = 0x1,
60  ET_GameMusicEmu = 0x2,
61  ET_All = ET_Standard | ET_GameMusicEmu
62  };
63 
64  enum TagKey {
65  Artist
66  };
67 
68  enum Field {
69  Field_AbsPath = 1,
70  Field_Album = 2,
71  Field_Artist = 3,
72  Field_ArtistAlbum = 4,
73  Field_Comment = 5,
74  Field_Cover = 6,
75  Field_Disc = 7,
76  Field_FileName = 8,
77  Field_Genre = 9,
78  Field_Title = 10,
79  Field_Track = 11,
80  Field_Year = 12
81  };
82 
83  explicit FileHelper(const QMediaContent &track);
84 
85  explicit FileHelper(const QString &filePath);
86 
87  static std::string keyToStdString(Field f);
88 
89 private:
90  bool init(const QString &filePath);
91 
92 public:
93  virtual ~FileHelper();
94 
95  static const QStringList suffixes(ExtensionType et = ET_Standard, bool withPrefix = false);
96 
98  QString artistAlbum() const;
99  void setArtistAlbum(const QString &artistAlbum);
100 
102  int discNumber(bool canBeZero = false) const;
103 
105  Cover* extractCover();
106 
107  bool insert(Field key, const QVariant &value);
108 
110  bool hasCover() const;
111 
113  int rating() const;
114 
116  void setCover(Cover *cover);
117 
119  void setDiscNumber(const QString &disc);
120 
122  void setRating(int rating);
123 
125  bool isValid() const;
126  QString title() const;
127  QString trackNumber() const;
128  QString album() const;
129  QString length() const;
130  QString artist() const;
131  QString year() const;
132  QString genre() const;
133  QString comment() const;
134  bool save();
135  inline QFileInfo fileInfo() const { return _fileInfo; }
136 
137  inline TagLib::File *file() { return _file; }
138 
139 private:
140  QString convertKeyToID3v2Key(QString key) const;
141 
142  QString extractFlacFeature(const QString &featureToExtract) const;
143  QString extractGenericFeature(const QString &featureToExtract) const;
144  QString extractMp4Feature(const QString &featureToExtract) const;
145  QString extractMpegFeature(const QString &featureToExtract) const;
146  QString extractVorbisFeature(const QString &featureToExtract) const;
147 
148  int ratingForID3v2(TagLib::ID3v2::Tag *tag) const;
149  void setFlacAttribute(const std::string &attribute, const QString &value);
150  void setMp4Attribute(const std::string &attribute, const TagLib::MP4::Item &value);
151  void setRatingForID3v2(int rating, TagLib::ID3v2::Tag *tag);
152 };
153 
155 Q_DECLARE_METATYPE(FileHelper::Field)
156 
157 #endif // FILEHELPER_H
Field
Definition: filehelper.h:68
ExtensionType
Definition: filehelper.h:58
The Cover class.
Definition: cover.h:14
QFileInfo fileInfo() const
Definition: filehelper.h:135
The FileHelper class is used to extract various but relevant fields in all types of tags (MP3...
Definition: filehelper.h:32
TagKey
Definition: filehelper.h:64
Forward declaration.
Definition: filehelper.h:15
#define MIAMCORE_LIBRARY
Definition: miamcore_global.h:10
TagLib::File * file()
Definition: filehelper.h:137
Extension
Definition: filehelper.h:47