-
Notifications
You must be signed in to change notification settings - Fork 51
/
neteasesong.cpp
74 lines (66 loc) · 2.09 KB
/
neteasesong.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
#include "neteasesong.h"
neteaseSong::neteaseSong(QObject *parent) : QObject(parent)
{
d=new downloader();
d->setUserAgent(UA);
connect(d,SIGNAL(finished()),this,SLOT(htmlFileGot()));
connect(d,SIGNAL(downloadError(QString)),this,SLOT(htmlFileGotFailed(QString)));
connect(d,SIGNAL(redirected(QString)),this,SLOT(htmlGotRedirected(QString)));
search=new qqMusicSearch();
connect(search,SIGNAL(finished(int,QString)),this,SLOT(searchResultGot(int,QString)));
}
void neteaseSong::doJob(QString inMid)
{
QString tmpUrl=QString("http://music.163.com/song?id=")+inMid;
qDebug()<<tmpUrl;
d->init(tmpUrl,QString(SONGHTMLFILE));
d->doGet();
}
void neteaseSong::htmlGotRedirected(QString redirectString)
{
d->init(redirectString,QString(SONGHTMLFILE));
d->doGet();
}
void neteaseSong::htmlFileGotFailed(QString errorString)
{
emit finished(-1,0,errorString);
}
void neteaseSong::htmlFileGot()
{
isGray=false;
QString line;
QFile file(SONGHTMLFILE);
file.open(QIODevice::ReadOnly);
char tmpSongName[200];
char tmpSinger[100];
char tmpAlbum[100];
while(!file.atEnd())
{
line=file.readLine();
if(line.contains(QString("appid")))
{
line=file.readLine();
getStringBetweenAandB(line.toStdString().c_str(),"\"title\": \"","\"",tmpSongName);
line=file.readLine();
line=file.readLine();
getStringBetweenAandB(line.toStdString().c_str(),"歌手:","。",tmpSinger);
getStringBetweenAandB(line.toStdString().c_str(),"所属专辑:","。",tmpAlbum);
break;
}
}
while(!file.atEnd())
{
line=file.readLine();
if(line.contains("u-btni-play"))
{
isGray=true;
break;
}
}
file.close();
search->doJob(QString(tmpSongName)+QString(" ")+QString(tmpSinger)+QString(" ")+QString(tmpAlbum));
}
void neteaseSong::searchResultGot(int inFlag, QString inString)
{
finished(inFlag,isGray,inString);
}