strawberry-audio-player-win.../src/lyrics/lyricsfetcher.h

97 lines
2.5 KiB
C
Raw Normal View History

/*
* Strawberry Music Player
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef LYRICSFETCHER_H
#define LYRICSFETCHER_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
2020-02-09 02:29:35 +01:00
#include <QMetaType>
#include <QQueue>
2020-02-09 02:29:35 +01:00
#include <QSet>
#include <QList>
2020-02-09 02:29:35 +01:00
#include <QHash>
#include <QString>
#include <QUrl>
2020-02-09 02:29:35 +01:00
class QTimer;
class LyricsProviders;
class LyricsFetcherSearch;
struct LyricsSearchRequest {
2021-10-30 17:10:05 +02:00
explicit LyricsSearchRequest() : id(0) {}
quint64 id;
QString artist;
QString album;
QString title;
};
struct LyricsSearchResult {
2020-04-07 16:49:15 +02:00
explicit LyricsSearchResult() : score(0.0) {}
QString provider;
QString artist;
QString album;
QString title;
QString lyrics;
float score;
};
2022-10-13 22:39:31 +02:00
using LyricsSearchResults = QList<LyricsSearchResult>;
Q_DECLARE_METATYPE(LyricsSearchResult)
2019-09-15 20:27:32 +02:00
Q_DECLARE_METATYPE(QList<LyricsSearchResult>)
class LyricsFetcher : public QObject {
Q_OBJECT
public:
2020-04-07 16:49:15 +02:00
explicit LyricsFetcher(LyricsProviders *lyrics_providers, QObject *parent = nullptr);
2020-06-15 21:55:05 +02:00
~LyricsFetcher() override {}
quint64 Search(const QString &artist, const QString &album, const QString &title);
void Clear();
private:
void AddRequest(const LyricsSearchRequest &req);
signals:
void LyricsFetched(quint64 request_id, QString provider, QString lyrics);
void SearchFinished(quint64 request_id, LyricsSearchResults results);
private slots:
void SingleSearchFinished(const quint64 request_id, const LyricsSearchResults &results);
void SingleLyricsFetched(const quint64 request_id, const QString &provider, const QString &lyrics);
void StartRequests();
private:
static const int kMaxConcurrentRequests;
LyricsProviders *lyrics_providers_;
quint64 next_id_;
QQueue<LyricsSearchRequest> queued_requests_;
QHash<quint64, LyricsFetcherSearch*> active_requests_;
QTimer *request_starter_;
2018-10-02 00:38:52 +02:00
};
#endif // LYRICSFETCHER_H