1 /***************************************************************************
2  *   Copyright (C) 2008-2021 by Ilya Kotov                                 *
3  *   forkotov02@ya.ru                                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20 #ifndef TAGEXTRACTOR_H
21 #define TAGEXTRACTOR_H
22 
23 #include <QMap>
24 #include <QTextCodec>
25 #include <taglib/tag.h>
26 #include <taglib/fileref.h>
27 #include <taglib/id3v1tag.h>
28 #include <taglib/id3v2tag.h>
29 #include <taglib/id3v2header.h>
30 #include <qmmp/qmmp.h>
31 
32 class QIODevice;
33 class QBuffer;
34 class QByteArray;
35 
36 /**
37     @author Ilya Kotov <forkotov02@ya.ru>
38 */
39 class TagExtractor
40 {
41 public:
42     explicit TagExtractor(QIODevice *d);
43 
44     ~TagExtractor();
45 
46     QMap<Qmmp::MetaData, QString> id3v2tag() const;
47     static void setForceUtf8(bool enabled);
48     static QTextCodec *detectCharset(const TagLib::Tag *tag);
49 
50 private:
51     QMap<Qmmp::MetaData, QString> m_tag;
52     QIODevice *m_input;
53     static bool m_using_rusxmms;
54 };
55 
56 class ID3v2Tag : public TagLib::ID3v2::Tag
57 {
58 public:
59     ID3v2Tag(QByteArray *array, long offset);
60     ~ID3v2Tag();
61 
62 protected:
63     void read();
64 
65 private:
66     QBuffer *m_buf;
67     long m_offset;
68 };
69 
70 #endif
71