mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Change Clementine to request the icecast directory from data.clementine-player.org, and to follow redirects
This commit is contained in:
parent
d775ef5c4c
commit
92520a911e
@ -40,7 +40,7 @@ using std::unique;
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
const char* IcecastService::kServiceName = "Icecast";
|
||||
const char* IcecastService::kDirectoryUrl = "http://dir.xiph.org/yp.xml";
|
||||
const char* IcecastService::kDirectoryUrl = "http://data.clementine-player.org/icecast-directory";
|
||||
const char* IcecastService::kHomepage = "http://dir.xiph.org/";
|
||||
|
||||
IcecastService::IcecastService(RadioModel* parent)
|
||||
@ -86,12 +86,7 @@ void IcecastService::LazyPopulate(QStandardItem* item) {
|
||||
}
|
||||
|
||||
void IcecastService::LoadDirectory() {
|
||||
QNetworkRequest req = QNetworkRequest(QUrl(kDirectoryUrl));
|
||||
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
|
||||
QNetworkRequest::AlwaysNetwork);
|
||||
|
||||
QNetworkReply* reply = network_->get(req);
|
||||
connect(reply, SIGNAL(finished()), SLOT(DownloadDirectoryFinished()));
|
||||
RequestDirectory(QUrl(kDirectoryUrl));
|
||||
|
||||
if (!load_directory_task_id_) {
|
||||
load_directory_task_id_ = model()->task_manager()->StartTask(
|
||||
@ -99,10 +94,26 @@ void IcecastService::LoadDirectory() {
|
||||
}
|
||||
}
|
||||
|
||||
void IcecastService::RequestDirectory(const QUrl& url) {
|
||||
QNetworkRequest req = QNetworkRequest(url);
|
||||
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
|
||||
QNetworkRequest::AlwaysNetwork);
|
||||
|
||||
QNetworkReply* reply = network_->get(req);
|
||||
connect(reply, SIGNAL(finished()), SLOT(DownloadDirectoryFinished()));
|
||||
}
|
||||
|
||||
void IcecastService::DownloadDirectoryFinished() {
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
Q_ASSERT(reply);
|
||||
|
||||
if (reply->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) {
|
||||
// Discard the old reply and follow the redirect
|
||||
reply->deleteLater();
|
||||
RequestDirectory(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
|
||||
return;
|
||||
}
|
||||
|
||||
QFuture<IcecastBackend::StationList> future =
|
||||
QtConcurrent::run(this, &IcecastService::ParseDirectory, reply);
|
||||
QFutureWatcher<IcecastBackend::StationList>* watcher =
|
||||
|
@ -32,7 +32,7 @@ class QMenu;
|
||||
|
||||
class IcecastService : public RadioService {
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
IcecastService(RadioModel* parent);
|
||||
~IcecastService();
|
||||
|
||||
@ -55,11 +55,12 @@ class IcecastService : public RadioService {
|
||||
protected:
|
||||
QModelIndex GetCurrentIndex();
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void LoadDirectory();
|
||||
void Homepage();
|
||||
|
||||
private:
|
||||
private:
|
||||
void RequestDirectory(const QUrl& url);
|
||||
void EnsureMenuCreated();
|
||||
IcecastBackend::StationList ParseDirectory(QIODevice* device) const;
|
||||
IcecastBackend::Station ReadStation(QXmlStreamReader* reader) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user