-
Notifications
You must be signed in to change notification settings - Fork 1
/
localsong.cpp
82 lines (66 loc) · 2.13 KB
/
localsong.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* ListenToSomeMusic Player
* zhangyu:2020051615216
* hulu:2020051615204
* zahngyu:2020051615218
*/
#include "localsong.h"
#include <fstream>
#include <iostream>
#include <id3/tag.h>
#include <QVariant>
#include <taglib/id3v1tag.h>
#include <taglib/id3v2tag.h>
#include <taglib/tag.h>
#include <taglib/wavfile.h>
#include <taglib/mpegfile.h>
#include <taglib/flacfile.h>
#include <taglib/vorbisfile.h>
#include <taglib/xiphcomment.h>
#include <taglib/attachedpictureframe.h>
#include <QDebug>
LocalSong::LocalSong(QObject *parent)
: QObject{parent}
{
}
void LocalSong::songInfo(QString url)
{
m_Tags.clear();
// qDebug()<< "url:" << url;
QString locaUrl = url.remove(url.left(7));
QByteArray ba=locaUrl.toUtf8();
const char *ch=ba.data();
// qDebug() << "ch"<<ch;
TagLib::MPEG::File *localFile = new TagLib::MPEG::File(ch);
if(localFile->isOpen()){
m_Tags["歌名"] = localFile->tag()->title().toCString();
m_Tags["艺术家"] = localFile->tag()->artist().toCString();
m_Tags["专辑"] = localFile->tag()->album().toCString();
// qDebug() << localFile->tag()->title().toCString() <<" " << localFile->tag()->artist().toCString();
}
TagLib::ID3v2::Tag *id3v2tag = localFile->ID3v2Tag();
if(id3v2tag){
TagLib::ID3v2::FrameList frameList = localFile->ID3v2Tag()->frameListMap()["APIC"];
if(!frameList.isEmpty()){
TagLib::ID3v2::AttachedPictureFrame *picFrame = static_cast<TagLib::ID3v2::AttachedPictureFrame *> (frameList.front());
char *jpgFileName = "/tmp/cover.jpg";
FILE *fd = fopen(jpgFileName,"wb");
if(fd != NULL){
fwrite(picFrame->picture().data(),picFrame->size(),1,fd);
fclose(fd);
}
// std::cout <<" The album picture has been written to cover.jpg";
qDebug() << " The album picture has been written to cover.jpg";
}
}
}
const QVariantMap &LocalSong::Tags() const
{
return m_Tags;
}
void LocalSong::setTags(const QVariantMap &newTags)
{
if (m_Tags == newTags)
return;
m_Tags = newTags;
emit TagsChanged();
}