TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongchecktoolsthread.cpp
Go to the documentation of this file.
2 #include "musicsongmeta.h"
3 
5  : TTKAbstractThread(parent),
6  m_songItems(nullptr),
7  m_operateMode(TTK::Mode::Check)
8 {
9 
10 }
11 
13 {
14  m_songItems = songs;
15 }
16 
18 {
19  if(m_songItems && !m_songItems->isEmpty())
20  {
22  {
23  m_datas.clear();
24  MusicSongMeta meta;
25  for(const MusicSong &song : qAsConst(*m_songItems))
26  {
27  if(!m_running)
28  {
29  Q_EMIT finished(MusicSongCheckToolsRenameList());
30  return;
31  }
32 
33  if(!meta.read(song.path()))
34  {
35  continue;
36  }
37 
38  if((!meta.artist().isEmpty() && !meta.title().isEmpty()) && (meta.artist() != song.artist() || meta.title() != song.title()))
39  {
40  m_datas << MusicSongCheckToolsRename(song.name(), TTK::generateSongName(meta.title(), meta.artist()), song.path());
41  }
42  }
43  }
44  else
45  {
46  for(const int index : qAsConst(m_itemIDs))
47  {
48  if(!m_running)
49  {
50  Q_EMIT finished(MusicSongCheckToolsRenameList());
51  return;
52  }
53 
54  const MusicSongCheckToolsRename &song = m_datas[index];
55  const QFileInfo fin(song.m_path);
56  QFile::rename(song.m_path, QString("%1/%2.%3").arg(fin.absolutePath(), song.m_recommendName, TTK_FILE_SUFFIX(fin)));
57  }
58  }
59  }
60  Q_EMIT finished(m_datas);
61 }
62 
63 
64 
66  : TTKAbstractThread(parent)
67 {
68  m_songItems = nullptr;
69 }
70 
72 {
73  m_songItems = songs;
74 }
75 
77 {
78  if(m_songItems && !m_songItems->isEmpty())
79  {
81  {
82  m_datas.clear();
83  MusicSongMeta meta;
84  for(const MusicSong &song : qAsConst(*m_songItems))
85  {
86  if(!m_running)
87  {
88  Q_EMIT finished(MusicSongCheckToolsDuplicateList());
89  return;
90  }
91 
92  if(!meta.read(song.path()))
93  {
94  continue;
95  }
96 
98  }
99  }
100  else
101  {
102  for(const int index : qAsConst(m_itemIDs))
103  {
104  if(!m_running)
105  {
106  Q_EMIT finished(MusicSongCheckToolsDuplicateList());
107  return;
108  }
109 
110  const MusicSongCheckToolsDuplicate &song = m_datas[index];
111  QFile::remove(song.m_song.path());
112  }
113  }
114  }
115  Q_EMIT finished(m_datas);
116 }
117 
118 
119 
121  : TTKAbstractThread(parent)
122 {
123  m_songItems = nullptr;
124 }
125 
127 {
128  m_songItems = songs;
129 }
130 
132 {
133  MusicSongCheckToolsQualityList items;
134  if(m_songItems && !m_songItems->isEmpty())
135  {
136  MusicSongMeta meta;
137  for(const MusicSong &song : qAsConst(*m_songItems))
138  {
139  if(!m_running)
140  {
141  Q_EMIT finished(MusicSongCheckToolsQualityList());
142  return;
143  }
144 
145  if(!meta.read(song.path()))
146  {
147  continue;
148  }
149 
150  items << MusicSongCheckToolsQuality(song, meta.bitrate());
151  }
152  }
153  Q_EMIT finished(items);
154 }
void finished(const MusicSongCheckToolsQualityList &items)
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist)
Definition: musicsong.cpp:112
bool read(const QString &url)
QString title() noexcept
void finished(const MusicSongCheckToolsDuplicateList &items)
QString artist() noexcept
QString path() const noexcept
Definition: musicsong.h:90
MusicSongCheckToolsRenameList m_datas
MusicSongCheckToolsQualityThread(QObject *parent=nullptr)
MusicSongCheckToolsDuplicateThread(QObject *parent=nullptr)
QString bitrate() noexcept
#define qAsConst
Definition: ttkqtglobal.h:53
The namespace of the process utils.
Definition: ttkcompat.h:24
MusicSongCheckToolsRenameThread(QObject *parent=nullptr)
void setRenameSongs(MusicSongList *songs)
The class of the song check tools duplicate.
MusicSongCheckToolsDuplicateList m_datas
The class of the ttk abstract thread.
#define TTK_FILE_SUFFIX(fin)
Definition: ttkqtglobal.h:173
The class of the music song meta.
Definition: musicsongmeta.h:30
The class of the music song info.
Definition: musicsong.h:28
The class of the song check tools rename.
void finished(const MusicSongCheckToolsRenameList &items)
The class of the song check tools quality.