-
Notifications
You must be signed in to change notification settings - Fork 53
/
qqmusicplaylist.cpp
96 lines (90 loc) · 2.67 KB
/
qqmusicplaylist.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "qqmusicplaylist.h"
#include "QtDebug"
qqMusicPlaylist::qqMusicPlaylist(QObject *parent) : QObject(parent)
{
d=new downloader();
connect(d,SIGNAL(downloadError(QString)),this,SLOT(playlistGotFailed(QString)));
connect(d,SIGNAL(redirected(QString)),this,SLOT(playlistGotFailed(QString)));
connect(d,SIGNAL(finished()),this,SLOT(playlistGot()));
}
void qqMusicPlaylist::doJob(QString inMid)
{
playListMid=inMid;
refererString =QString("https://y.qq.com/n/yqq/playsquare/")+inMid+QString(".html");
playListDownloadLink=QString(PLAYLISTLINKHEAD)+playListMid+QString(PALYLISTLINKTAIL);
d->init(playListDownloadLink,QString(PLAYLISTFILE));
qDebug()<<refererString;
d->setReferer(refererString);
qDebug()<<"准备下载歌单列表";
emit status("准备下载歌单json数据");
d->doGet();
}
void qqMusicPlaylist::playlistGotFailed(QString errorString)
{
QStringList a;
emit status(QString("QQMusic playlist json data download failed:")+errorString);
finished(-1,a);
}
void qqMusicPlaylist::playlistGot()
{
songMidList.clear();
QFile file(PLAYLISTFILE);
int index=0;
QString songmid;
QString playListName;
file.open(QIODevice::ReadOnly);
QString str=file.readAll();
file.close();
//将歌单名字作为目录名
if(-1!=(index=str.indexOf("dissname",index)))
{
index+=11;
playListName="";
while(str.at(index)!='\"')
{
playListName+=str.at(index);
index++;
}
playListName.remove(QChar('|'));
playListName.remove(QChar('>'));
playListName.remove(QChar('<'));
playListName.remove(QChar('*'));
playListName.remove(QChar('?'));
playListName.remove(QChar('/'));
playListName.remove(QChar('\\'));
playListName.remove(QChar(':'));
qDebug()<<playListName;
}
else{
emit status("json 文件下载内容错误");
QStringList a;
finished(-1,a);
}
if(!playListName.isEmpty())
{
mp3Dir=mp3Dir+QString("/")+playListName;
QDir tmp(mp3Dir);
if(!tmp.exists())
{
tmp.mkdir(mp3Dir);
}
}
else{
emit status("json 文件下载内容错误");
QStringList a;
finished(-1,a);
}
while(-1!=(index=str.indexOf("songmid",index)))
{
index+=10;
songmid="";
while(str.at(index)!='\"')
{
songmid+=str.at(index);
index++;
}
songMidList.append(songmid);
}
qDebug()<<songMidList;
finished(0,songMidList);
}