-
Notifications
You must be signed in to change notification settings - Fork 53
/
singerallalbum.cpp
171 lines (155 loc) · 5.03 KB
/
singerallalbum.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "singerallalbum.h"
#include "ui_singerallalbum.h"
singerAllAlbum::singerAllAlbum(QWidget *parent) :
QWidget(parent),
ui(new Ui::singerAllAlbum)
{
songNameType=0;
songQuality=0;
ui->setupUi(this);
d=new downloader();
connect(d,SIGNAL(finished()),this,SLOT(downloadFinished()));
connect(d,SIGNAL(downloadError(QString)),this,SLOT(downloadFailed(QString)));
connect(d,SIGNAL(redirected(QString)),this,SLOT(downloadFailed(QString)));
}
singerAllAlbum::~singerAllAlbum()
{
delete ui;
}
void singerAllAlbum::on_pushButtonChosePath_clicked()
{
mp3Dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
ui->lineEditMp3Path->setText(mp3Dir);
}
void singerAllAlbum::on_radioButtonSongNameType1_clicked()
{
songNameType=1;
}
void singerAllAlbum::on_radioButtonSongNameType2_clicked()
{
songNameType=2;
}
void singerAllAlbum::on_radioButtonQuality128_clicked()
{
songQuality=1;
}
void singerAllAlbum::on_radioButtonQuality320_clicked()
{
songQuality=2;
}
void singerAllAlbum::on_radioButtonQualityflac_clicked()
{
songQuality=3;
}
void singerAllAlbum::on_radioButtonQualityape_clicked()
{
songQuality=4;
}
void singerAllAlbum::on_pushButton_clicked()
{
ui->textEdit->clear();
mp3Dir=ui->lineEditMp3Path->text();
if(!songNameType || !songQuality || ui->lineEditMp3Path->text().isEmpty() || ui->lineEditSingerUrl->text().isEmpty())
{
ui->textEdit->append("请输入合法的设置");
}
else{
if(ui->lineEditSingerUrl->text().contains("y.qq.com/n/yqq/singer"))
{
if(ui->lineEditSingerUrl->text().contains("num"))
{
ui->textEdit->append("请选择不含num的链接");
return;
}
ui->pushButton->setEnabled(false);
doJob();
}
else{
ui->textEdit->append("请填入如https://y.qq.com/n/yqq/singer/002J4UUk29y8BY.html的歌手链接");
}
}
}
void singerAllAlbum::setDownloadQueue(downloadQueue *inDQ)
{
dq=inDQ;
}
void singerAllAlbum::doJob()
{
singerName="";
albumList.clear();
albumNum=0;
nowNum=30;
char tmp[30];
getStringBetweenAandB(ui->lineEditSingerUrl->text().toStdString().c_str(),"yqq/singer/",".html",tmp);
singerMid=tmp;
QString link=QString(SINGERALBUMHEAD)+singerMid+QString(SINGERALBUMMID1)+QString("0")+QString(SINGERALBUMMID2)+QString("30")+QString(SINGERALBUMTAIL);
d->init(link,"singerAllAlbum.tmp");
d->setUserAgent(UA);
d->setReferer("https://y.qq.com");
d->doGet();
}
void singerAllAlbum::downloadFailed(QString inStr)
{
ui->textEdit->append("获取专辑信息失败,请联系作者");
ui->textEdit->append(inStr);
}
void singerAllAlbum::downloadFinished()
{
char tmp[200];
QFile file("singerAllAlbum.tmp");
if(file.open(QIODevice::ReadOnly))
{
QByteArray b=file.readAll();
QJsonParseError jsonError;
QJsonDocument doucment = QJsonDocument::fromJson(b,&jsonError);
if(jsonError.error!=QJsonParseError::NoError)
{
qDebug() << "read singerAllAlbum.tmp file failed";
qDebug()<<jsonError.error;
qDebug()<<jsonError.errorString();
ui->textEdit->append("read singerAllAlbum.tmp file failed");
file.close();
ui->pushButton->setEnabled(true);
return;
}
QJsonObject obj=doucment.object();
obj=obj["data"].toObject();
if(nowNum==30)
{
singerName=obj["singer_name"].toString();
albumNum=obj["total"].toInt();
mp3Dir=mp3Dir+QString("/")+singerName;
QDir tmp(mp3Dir);
if(!tmp.exists())
{
tmp.mkdir(mp3Dir);
}
}
QJsonArray tmpArray=obj["list"].toArray();
while(tmpArray.count()>0)
{
obj=tmpArray.first().toObject();
albumList.append(obj["albumMID"].toString());
qDebug()<<albumList.last();
tmpArray.removeFirst();
}
file.close();
}
if(nowNum<albumNum)
{
QString link=QString(SINGERALBUMHEAD)+singerMid+QString(SINGERALBUMMID1)+QString::number(nowNum)+QString(SINGERALBUMMID2)+QString::number(nowNum+30)+QString(SINGERALBUMTAIL);
nowNum+=30;
d->init(link,"singerAllAlbum.tmp");
d->doGet();
}
else
{
while(albumList.count()>0)
{
dq->insertQueue(0,songQuality,songNameType,mp3Dir,QString("https://y.qq.com/n/yqq/album/%1.html").arg(albumList.first()));
albumList.removeFirst();
}
ui->pushButton->setEnabled(true);
ui->textEdit->append(QString("%1张专辑已经添加到下载队列,请回到主页面查看进度,当前界面可以关闭").arg(albumNum));
}
}