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(Field)
44 
45 public:
46  enum Extension {
47  EXT_APE = 0,
48  EXT_ASF = 1,
49  EXT_FLAC = 2,
50  EXT_MP4 = 4,
51  EXT_MPC = 5,
52  EXT_MP3 = 6,
53  EXT_OGG = 7,
54  EXT_UNKNOWN = -1
55  };
56 
58  ET_Standard = 0x001,
59  ET_GameMusicEmu = 0x002,
60  ET_Playlist = 0x004,
61  ET_All = ET_Standard | ET_GameMusicEmu | ET_Playlist
62  };
63  Q_DECLARE_FLAGS(ExtensionTypes, ExtensionType)
64 
65  enum TagKey {
66  Artist
67  };
68 
69  enum Field {
70  Field_AbsPath = 1,
71  Field_Album = 2,
72  Field_Artist = 3,
73  Field_ArtistAlbum = 4,
74  Field_Comment = 5,
75  Field_Cover = 6,
76  Field_Disc = 7,
77  Field_FileName = 8,
78  Field_Genre = 9,
79  Field_Title = 10,
80  Field_Track = 11,
81  Field_Year = 12
82  };
83 
84  explicit FileHelper(const QMediaContent &track);
85 
86  explicit FileHelper(const QString &filePath);
87 
88  static std::string keyToStdString(Field f);
89 
90 private:
91  bool init(const QString &filePath);
92 
93 public:
94  virtual ~FileHelper();
95 
96  static const QStringList suffixes(FileHelper::ExtensionTypes et = FileHelper::ET_Standard, bool withPrefix = false);
97 
99  QString artistAlbum() const;
100  void setArtistAlbum(const QString &artistAlbum);
101 
103  int discNumber(bool canBeZero = false) const;
104 
106  Cover* extractCover();
107 
108  bool insert(Field key, const QVariant &value);
109 
111  bool hasCover() const;
112 
114  int rating() const;
115 
117  void setCover(Cover *cover);
118 
120  void setDiscNumber(const QString &disc);
121 
123  void setRating(int rating);
124 
126  bool isValid() const;
127  QString title() const;
128  QString trackNumber() const;
129  QString album() const;
130  QString length() const;
131  QString artist() const;
132  QString year() const;
133  QString genre() const;
134  QString comment() const;
135  bool save();
136  inline QFileInfo fileInfo() const { return _fileInfo; }
137 
138  inline TagLib::File *file() { return _file; }
139 
140 private:
141  QString convertKeyToID3v2Key(QString key) const;
142 
143  QString extractFlacFeature(const QString &featureToExtract) const;
144  QString extractGenericFeature(const QString &featureToExtract) const;
145  QString extractMp4Feature(const QString &featureToExtract) const;
146  QString extractMpegFeature(const QString &featureToExtract) const;
147  QString extractVorbisFeature(const QString &featureToExtract) const;
148 
149  int ratingForID3v2(TagLib::ID3v2::Tag *tag) const;
150  void setFlacAttribute(const std::string &attribute, const QString &value);
151  void setMp4Attribute(const std::string &attribute, const TagLib::MP4::Item &value);
152  void setRatingForID3v2(int rating, TagLib::ID3v2::Tag *tag);
153 };
154 
156 Q_DECLARE_METATYPE(FileHelper::Field)
157 Q_DECLARE_OPERATORS_FOR_FLAGS(FileHelper::ExtensionTypes)
158 
159 #endif // FILEHELPER_H
Field
Definition: filehelper.h:69
ExtensionType
Definition: filehelper.h:57
A file class with some useful methods for tag manipulation.
Definition: tfile.h:50
String TAGLIB_EXPORT genre(int index)
Returns the name of the genre at index in the ID3v1 genre list.
The Cover class.
Definition: cover.h:14
Definition: filehelper.h:58
QFileInfo fileInfo() const
Definition: filehelper.h:136
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:65
A namespace for all TagLib related classes and functions.
Definition: aifffile.h:33
The main class in the ID3v2 implementation.
Definition: id3v2tag.h:135
#define MIAMCORE_LIBRARY
Definition: miamcore_global.h:11
Definition: mp4item.h:37
TagLib::File * file()
Definition: filehelper.h:138
Extension
Definition: filehelper.h:46