Changeset View
Changeset View
Standalone View
Standalone View
src/lyrics/LyricsManager.cpp
Show All 25 Lines | |||||
26 | 26 | | |||
27 | #include <QDomDocument> | 27 | #include <QDomDocument> | ||
28 | #include <QTextEdit> | 28 | #include <QTextEdit> | ||
29 | #include <QXmlStreamReader> | 29 | #include <QXmlStreamReader> | ||
30 | 30 | | |||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | 32 | | |||
33 | 33 | | |||
34 | #define APIURL "http://lyrics.wikia.com/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" | 34 | #define APIURL "https://lyrics.fandom.com/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" | ||
35 | 35 | | |||
36 | 36 | | |||
37 | LyricsManager* LyricsManager::s_self = nullptr; | 37 | LyricsManager* LyricsManager::s_self = nullptr; | ||
38 | 38 | | |||
39 | LyricsManager::LyricsManager() | 39 | LyricsManager::LyricsManager() | ||
40 | { | 40 | { | ||
41 | s_self = this; | 41 | s_self = this; | ||
42 | connect( The::engineController(), &EngineController::trackChanged, this, &LyricsManager::newTrack ); | 42 | connect( The::engineController(), &EngineController::trackChanged, this, &LyricsManager::newTrack ); | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 115 | { | |||
131 | if( !isEmpty( track->cachedLyrics() ) && !overwrite ) | 131 | if( !isEmpty( track->cachedLyrics() ) && !overwrite ) | ||
132 | { | 132 | { | ||
133 | debug() << "Lyrics already cached."; | 133 | debug() << "Lyrics already cached."; | ||
134 | return; | 134 | return; | ||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | QUrl url( APIURL + artist + QLatin1Char(':') + title ); | 137 | QUrl url( APIURL + artist + QLatin1Char(':') + title ); | ||
138 | m_trackMap.insert( url, track ); | 138 | m_trackMap.insert( url, track ); | ||
139 | | ||||
140 | connect( NetworkAccessManagerProxy::instance(), &NetworkAccessManagerProxy::requestRedirectedUrl, | ||||
141 | this, &LyricsManager::updateRedirectedUrl); | ||||
142 | | ||||
139 | NetworkAccessManagerProxy::instance()->getData( url, this, &LyricsManager::lyricsLoaded ); | 143 | NetworkAccessManagerProxy::instance()->getData( url, this, &LyricsManager::lyricsLoaded ); | ||
140 | } | 144 | } | ||
141 | 145 | | |||
142 | void LyricsManager::lyricsLoaded( const QUrl& url, const QByteArray& data, const NetworkAccessManagerProxy::Error &err ) | 146 | void LyricsManager::lyricsLoaded( const QUrl& url, const QByteArray& data, const NetworkAccessManagerProxy::Error &err ) | ||
143 | { | 147 | { | ||
144 | DEBUG_BLOCK | 148 | DEBUG_BLOCK | ||
145 | 149 | | |||
146 | if( err.code ) | 150 | if( err.code ) | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 264 | { | |||
268 | 272 | | |||
269 | // Get the plaintext content. | 273 | // Get the plaintext content. | ||
270 | // We use toPlainText() to strip all Html formatting, | 274 | // We use toPlainText() to strip all Html formatting, | ||
271 | // so we can test if there's any text given. | 275 | // so we can test if there's any text given. | ||
272 | QString testText = testItem.toPlainText().trimmed(); | 276 | QString testText = testItem.toPlainText().trimmed(); | ||
273 | 277 | | |||
274 | return testText.isEmpty(); | 278 | return testText.isEmpty(); | ||
275 | } | 279 | } | ||
280 | | ||||
281 | void LyricsManager::updateRedirectedUrl(const QUrl& oldUrl, const QUrl& newUrl) | ||||
282 | { | ||||
283 | if( m_trackMap.contains( oldUrl ) && !m_trackMap.contains( newUrl ) ) | ||||
284 | { | ||||
285 | // Get track for the old URL. | ||||
286 | Meta::TrackPtr track = m_trackMap.value( oldUrl ); | ||||
287 | | ||||
288 | // Replace with redirected url for correct lookup | ||||
289 | m_trackMap.insert( newUrl, track ); | ||||
290 | m_trackMap.remove( oldUrl ); | ||||
291 | } | ||||
292 | } |