TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicdownloadmetadatarequest.cpp
Go to the documentation of this file.
3 #include "musiccoverrequest.h"
4 
5 MusicDownloadMetaDataRequest::MusicDownloadMetaDataRequest(const QString &url, const QString &path, QObject *parent)
6  : MusicDownloadMetaDataRequest(url, path, TTK::Record::NormalDownload, parent)
7 {
8 
9 }
10 
11 MusicDownloadMetaDataRequest::MusicDownloadMetaDataRequest(const QString &url, const QString &path, TTK::Record record, QObject *parent)
12  : MusicDownloadDataRequest(url, path, TTK::Download::Music, record, parent)
13 {
14  m_needUpdate = false;
15 }
16 
18 {
19  m_songMeta = std::move(meta);
20 }
21 
23 {
24  if(!m_file || (m_file->exists() && m_file->size() >= 4) || !m_file->open(QIODevice::WriteOnly))
25  {
26  TTK_ERROR_STREAM("The data file create failed");
27  Q_EMIT downLoadDataChanged("The data file create failed");
28  deleteAll();
29  return;
30  }
31 
33  disconnect(m_reply, SIGNAL(finished()), this, SLOT(downLoadFinished()));
34  connect(m_reply, SIGNAL(finished()), this, SLOT(downLoadFinished()));
35 }
36 
38 {
39  bool save = (m_file != nullptr);
41 
42  if(m_redirection)
43  {
44  return;
45  }
46 
47  if(save)
48  {
49  TTKSemaphoreLoop loop;
50  connect(this, SIGNAL(finished()), &loop, SLOT(quit()));
51 
52  MusicCoverRequest *d = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
53  connect(d, SIGNAL(downLoadRawDataChanged(QByteArray)), SLOT(downLoadFinished(QByteArray)));
55  loop.exec();
56  }
57 
59  TTK_INFO_STREAM("Data download has finished");
60 }
61 
63 {
64  MusicSongMeta meta;
65  if(meta.read(m_savePath))
66  {
68  {
69  meta.setTitle(m_songMeta.title());
70  meta.setArtist(m_songMeta.artist());
71  meta.setAlbum(m_songMeta.album());
73  meta.setYear(m_songMeta.year());
74  }
75 
77  {
78  if(bytes.isEmpty())
79  {
80  TTK_ERROR_STREAM("Input byte data is empty");
81  }
82  else
83  {
84  meta.setCover(bytes);
85  }
86  }
87  meta.save();
88  TTK_INFO_STREAM("Write tag has finished");
89  }
90 
91  Q_EMIT finished();
92 }
QString comment() noexcept
bool read(const QString &url)
void downLoadDataChanged(const QString &bytes)
void setTrackNum(const QString &track) noexcept
QString title() noexcept
MusicDownloadMetaDataRequest(const QString &url, const QString &path, QObject *parent=nullptr)
void downLoadRawDataChanged(const QByteArray &bytes)
QNetworkReply * m_reply
QString artist() noexcept
virtual void startToRequest(const QString &url)=0
The class of the download the type of data.
int exec(ProcessEventsFlags flags=AllEvents)
virtual void downLoadFinished() overridefinal
virtual void startToRequest() overridefinal
void setYear(const QString &year) noexcept
void setTitle(const QString &title) noexcept
QString album() noexcept
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
The namespace of the process utils.
Definition: ttkcompat.h:24
virtual void deleteAll() overridefinal
virtual void downLoadFinished() override
QString trackNum() noexcept
#define G_DOWNLOAD_QUERY_PTR
The class of the download the type of data by custom tags.
The class of the music song meta.
Definition: musicsongmeta.h:30
The class of the cover data download request.
void setAlbum(const QString &album) noexcept
QString year() noexcept
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
The class of the semaphore event loop.
virtual void startToRequest() override
void setArtist(const QString &artist) noexcept
void setCover(const QPixmap &cover) noexcept
#define G_SETTING_PTR