Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
z52c authored Feb 21, 2018
1 parent a04f694 commit 00c3dfc
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 22 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ https://y.qq.com/n/yqq/song/002TGLL108wKSf.html
https://y.qq.com/n/yqq/album/000nw1yB4XOs9j.html

下载歌单所有单曲:
只需在QQ音乐网页(https://y.qq.com/)找到歌单页面链接(playlist或者playsquare),粘贴到下载软件中,选择保存目录,音质,名称格式,下载即可。
只需在QQ音乐网页(https://y.qq.com/)找到歌单页面链接,粘贴到下载软件中,选择保存目录,音质,名称格式,下载即可。
https://y.qq.com/n/yqq/playsquare/2387043531.html




若QQ音乐中没有无损音质的内容,则默认下载128音质。
不提供歌手所有歌曲下载。
1 change: 1 addition & 0 deletions downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void downloader::downloadFinished(QNetworkReply *reply)
if(reply->error())
{
qDebug()<<"download "<<tmpUrl.toEncoded().constData()<<"failed : "<<reply->errorString();
emit downloadError();
} else {
if(isHttpRedirect(reply)){
qDebug()<<"request was redirected.";
Expand Down
1 change: 1 addition & 0 deletions downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private slots:
signals:
void progress(qint64, qint64);
void finished();
void downloadError();
};

#endif // DOWNLOADER_H
113 changes: 113 additions & 0 deletions id3tag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "id3tag.h"

ID3tag::ID3tag(QObject *parent) : QObject(parent)
{

}

ID3tag::~ID3tag()
{
delete fileN;
delete fileS;
delete fileImage;
delete dStreamS;
delete dStream;
// delete tStream;
}

ID3tag::ID3tag(QString fileName)
{
mp3FileName=fileName;
mp3FileNameTmp=fileName+QString(".tmp");
fileS=new QFile(mp3FileName);
fileS->open(QIODevice::ReadOnly);
fileN=new QFile(mp3FileNameTmp);
fileN->open(QIODevice::WriteOnly);
dStream=new QDataStream(fileN);
memset(&tagHeader,0,sizeof(tagHeader));
memset(&titleHeader,0,sizeof(titleHeader));
memset(&artistHeader,0,sizeof(artistHeader));
memset(&albumHeader,0,sizeof(albumHeader));
memset(&picHeader,0,sizeof(picHeader));
tagHeader.identifier[0]='I';
tagHeader.identifier[1]='D';
tagHeader.identifier[2]='3';
tagHeader.version[0]=0x03;
titleHeader.frameID[0]='T';titleHeader.frameID[1]='I';titleHeader.frameID[2]='T';titleHeader.frameID[3]='2';
artistHeader.frameID[0]='T';artistHeader.frameID[1]='P';artistHeader.frameID[2]='E';artistHeader.frameID[3]='1';
albumHeader.frameID[0]='T';albumHeader.frameID[1]='A';albumHeader.frameID[2]='L';albumHeader.frameID[3]='B';
picHeader.frameID[0]='A';picHeader.frameID[1]='P';picHeader.frameID[2]='I';picHeader.frameID[3]='C';

//获取mp3音频内容
dStreamS =new QDataStream(fileS);
dStreamS->readRawData((char*)&tagHeaderOld,10);
int oldHeaderSize=128*128*128*tagHeaderOld.size[0]+128*128*tagHeaderOld.size[1]+128*tagHeaderOld.size[2]+tagHeaderOld.size[3];
fileS->seek(10+oldHeaderSize);
mp3File=fileS->readAll();
}

void ID3tag::setTitle(QString t)
{
title=t;
titleSize=2*sizeof(title)+3;
titleHeader.size[3]=titleSize;
}

void ID3tag::setArtist(QString a)
{
artist=a;
artistSize=2*sizeof(a)+3;
artistHeader.size[3]=artistSize;
}

void ID3tag::setAlbum(QString a)
{
album=a;
albumSize=2*sizeof(album)+3;
albumHeader.size[3]=albumSize;
}

void ID3tag::setPic(QString imageFileName)
{
fileImage=new QFile(imageFileName);
fileImage->open(QIODevice::ReadOnly);
image=fileImage->readAll();
memset(mimeInfo,0,14);
char tmp[14]={0x00,0x69,0x6D,0x61,0x67,0x65,0x2F,0x6A,0x70,0x65,0x67,0x00,0x03,0x00};
memcpy(mimeInfo,tmp,14);
picSize=image.size()+14;
picHeader.size[0]=picSize/(256*256*256);
picHeader.size[1]=picSize%(256*256*256)/(256*256);
picHeader.size[2]=picSize%(256*256*256)%(256*256)/256;
picHeader.size[3]=picSize%(256*256*256)%(256*256)%256;
}

void ID3tag::doJob()
{
uchar unicodeBom[3]={0x01,0xFF,0xFE};
int size=40+titleSize+artistSize+albumSize+picSize;
tagHeader.size[0]=size/(128*128*128);
tagHeader.size[1]=size%(128*128*128)/(128*128);
tagHeader.size[2]=size%(128*128*128)%(128*128)/128;
tagHeader.size[3]=size%(128*128*128)%(128*128)%128;
dStream->writeRawData((char*)&tagHeader,10);
dStream->writeRawData((char*)&titleHeader,10);
dStream->writeRawData((char*)unicodeBom,3);
dStream->writeRawData((char*)title.data(),sizeof(title)*2);
dStream->writeRawData((char*)&artistHeader,10);
dStream->writeRawData((char*)unicodeBom,3);
dStream->writeRawData((char*)artist.data(),sizeof(artist)*2);
dStream->writeRawData((char*)&albumHeader,10);
dStream->writeRawData((char*)unicodeBom,3);
dStream->writeRawData((char*)album.data(),sizeof(album)*2);
dStream->writeRawData((char*)&picHeader,10);
dStream->writeRawData(mimeInfo,14);
dStream->writeRawData((char*)image.data(),image.size());
dStream->writeRawData((char*)mp3File.data(),mp3File.size());
fileImage->close();
fileN->close();
fileS->close();
fileS->remove();
fileN->rename(mp3FileName);
emit finished();
}
71 changes: 71 additions & 0 deletions id3tag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef ID3TAG_H
#define ID3TAG_H

#include <QObject>
#include <QFile>
#include <QTextStream>
#include <QDataStream>

typedef struct ID3HEADER{
char identifier[3];
char version[2];
char flags;
char size[4];
}id3Header;

typedef struct FRAMEHEADER{
char frameID[4];
char size[4];
char flags[2];
}frameHeader;

class ID3tag : public QObject
{
Q_OBJECT
private:
id3Header tagHeaderOld;
QString mp3FileName;
QString mp3FileNameTmp;

id3Header tagHeader;
frameHeader titleHeader;
frameHeader artistHeader;
frameHeader albumHeader;
frameHeader picHeader;

int titleSize;
int artistSize;
int albumSize;
int picSize;

QString title;
QString artist;
QString album;
QByteArray image;
QByteArray mp3File;
char mimeInfo[14];

QFile *fileN; //新的的文件
QFile *fileS; //原来的文件
QFile *fileImage;
QDataStream *dStreamS;
QDataStream *dStream;
// QTextStream *tStream;

public:
explicit ID3tag(QObject *parent = nullptr);
ID3tag(QString fileName);
~ID3tag();
void setTitle(QString t);
void setArtist(QString a);
void setAlbum(QString a);
void setPic(QString imageFileName);
void doJob();

signals:
processState(QString );
finished();
public slots:
};

#endif // ID3TAG_H
17 changes: 6 additions & 11 deletions playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

playlist::playlist()
{

d=new downloader();
tmpSong=new song();
connect(tmpSong,SIGNAL(finished()),this,SLOT(songDownloaded()));
connect(tmpSong,SIGNAL(progress(qint64,qint64)),this,SIGNAL(progress(qint64,qint64)));
connect(tmpSong,SIGNAL(beginToDownload()),this,SIGNAL(beginToDownload()));
connect(d,SIGNAL(finished()),this,SLOT(songListGot()));
}

void playlist::init(QString mid)
{
playListMid=mid;
refererString =QString("https://y.qq.com/n/yqq/playsquare/")+mid+QString(".html");
d=NULL;
tmpSong=NULL;
connect(tmpSong,SIGNAL(finished()),this,SLOT(songDownloaded()));
connect(tmpSong,SIGNAL(progress(qint64,qint64)),this,SIGNAL(progress(qint64,qint64)));
connect(tmpSong,SIGNAL(beginToDownload()),this,SIGNAL(beginToDownload()));
connect(d,SIGNAL(finished()),this,SLOT(songListGot()));
qDebug()<<"playlist chushihua";
getSongList();
}
Expand Down Expand Up @@ -68,10 +67,6 @@ void playlist::songDownloaded()
}
else
{
if(d!=NULL)
delete d;
if(tmpSong!=NULL)
delete tmpSong;
emit finished();
}
}
8 changes: 5 additions & 3 deletions qqmusic.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ SOURCES += \
daye.cpp \
song.cpp \
album.cpp \
playlist.cpp
playlist.cpp \
id3tag.cpp

HEADERS += \
qqmusic.h \
Expand All @@ -42,12 +43,13 @@ HEADERS += \
daye.h \
song.h \
album.h \
playlist.h
playlist.h \
id3tag.h

FORMS += \
qqmusic.ui

VERSION = 1.1.1
VERSION = 1.2.0

QMAKE_TARGET_PRODUCT = QQMusicDownloader
QMAKE_TARGET_COMPANY = z52c
Expand Down
2 changes: 1 addition & 1 deletion qqmusic.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.5.0, 2018-02-12T22:10:49. -->
<!-- Written by QtCreator 4.5.0, 2018-02-21T13:23:15. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
39 changes: 34 additions & 5 deletions song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,31 @@ song::song()
connect(d,SIGNAL(finished()),this,SLOT(shtmlLinkDownloaded()));
m=new downloader();
connect(m,SIGNAL(progress(qint64,qint64)),this,SIGNAL(progress(qint64,qint64)));
connect(m,SIGNAL(finished()),this,SIGNAL(finished()));

connect(m,SIGNAL(finished()),this,SLOT(musicDownloaded()));
p=new downloader();
connect(p,SIGNAL(finished()),this,SLOT(picDownloaded()));
connect(p,SIGNAL(downloadError()),this,SIGNAL(finished()));
}

song::~song()
{
delete d;
delete m;
delete p;
}

song::song(QString mid)
{
songMid=mid;
d=new downloader();
m=new downloader();
p=new downloader();
htmlLink=QString(GETVKEYLINKHEAD)+songMid+QString(GETVKEYLINKTAIL);
connect(d,SIGNAL(finished()),this,SLOT(shtmlLinkDownloaded()));
connect(m,SIGNAL(progress(qint64,qint64)),this,SIGNAL(progress(qint64,qint64)));
connect(m,SIGNAL(finished()),this,SIGNAL(finished()));
connect(m,SIGNAL(finished()),this,SIGNAL(musicDownloaded()));
connect(p,SIGNAL(finished()),this,SLOT(picDownloaded()));
connect(p,SIGNAL(downloadError()),this,SIGNAL(finished()));
d->init(htmlLink,QString(SONGHTMLFILE));
d->setUserAgent(QString(USERAGENT));
d->doDownload();
Expand Down Expand Up @@ -55,21 +61,24 @@ void song::shtmlLinkDownloaded()
flag=1;
char tmpGuid[200];
char tmpVkey[200];
char tmpPicUrl[200];
char tmpSongName[100];
char tmpSingerName[100];
char tmpsizeape[20];
char tmpMediaMid[20];

char tmpAlbumName[100];
getStringBetweenAandB(line.toStdString().c_str(),"songname\":\"","\"",tmpSongName);
getStringBetweenAandB(line.toStdString().c_str(),"sizeape\":",",",tmpsizeape);
getStringBetweenAandB(line.toStdString().c_str(),"singername\":\"","\"",tmpSingerName);
getStringBetweenAandB(line.toStdString().c_str(),"strMediaMid\":\"","\"",tmpMediaMid);

getStringBetweenAandB(line.toStdString().c_str(),"\"pic\":\"//","\"",tmpPicUrl);
getStringBetweenAandB(line.toStdString().c_str(),"\"albumname\":\"","\",",tmpAlbumName);

line=file.readLine();
getStringBetweenAandB(line.toStdString().c_str(),"guid\":",",",tmpGuid);
getStringBetweenAandB(line.toStdString().c_str(),"vkey\":\"","\"",tmpVkey);


mediaMid=QString(tmpMediaMid);
sizeape=QString(tmpsizeape).toInt();
singerName=QString(tmpSingerName);
Expand All @@ -80,6 +89,8 @@ void song::shtmlLinkDownloaded()
songName.remove("/");
vkey=QString(tmpVkey);
guid=QString(tmpGuid);
picUrl=QString("https://")+QString(tmpPicUrl);
albumName=QString(tmpAlbumName);
qDebug()<<"sizeape:"<<sizeape;
downloadSong();
break;
Expand Down Expand Up @@ -155,4 +166,22 @@ void song::downloadSong()
}
}

void song::musicDownloaded()
{
qDebug()<<"准备下载图片";
qDebug()<<picUrl;
p->init(picUrl,"tmp.jpg");
p->doDownload();
}

void song::picDownloaded()
{
tagtmp=new ID3tag(mp3FileName);
connect(tagtmp,SIGNAL(finished()),this,SIGNAL(finished()));
tagtmp->setTitle(songName);
tagtmp->setArtist(singerName);
tagtmp->setAlbum(albumName);
tagtmp->setPic(QString("tmp.jpg"));
tagtmp->doJob();
}

Loading

0 comments on commit 00c3dfc

Please sign in to comment.