mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Read tags from dropbox files.
This commit is contained in:
parent
47cc767daf
commit
3c9b3d99e6
@ -110,7 +110,9 @@ TagLib::ByteVector CloudStream::readBlock(ulong length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QNetworkRequest request = QNetworkRequest(url_);
|
QNetworkRequest request = QNetworkRequest(url_);
|
||||||
request.setRawHeader("Authorization", auth_.toUtf8());
|
if (!auth_.isNull()) {
|
||||||
|
request.setRawHeader("Authorization", auth_.toUtf8());
|
||||||
|
}
|
||||||
request.setRawHeader(
|
request.setRawHeader(
|
||||||
"Range", QString("bytes=%1-%2").arg(start).arg(end).toUtf8());
|
"Range", QString("bytes=%1-%2").arg(start).arg(end).toUtf8());
|
||||||
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
|
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
|
||||||
|
@ -1060,10 +1060,12 @@ optional_source(HAVE_DROPBOX
|
|||||||
internet/dropboxauthenticator.cpp
|
internet/dropboxauthenticator.cpp
|
||||||
internet/dropboxservice.cpp
|
internet/dropboxservice.cpp
|
||||||
internet/dropboxsettingspage.cpp
|
internet/dropboxsettingspage.cpp
|
||||||
|
internet/dropboxurlhandler.cpp
|
||||||
HEADERS
|
HEADERS
|
||||||
internet/dropboxauthenticator.h
|
internet/dropboxauthenticator.h
|
||||||
internet/dropboxservice.h
|
internet/dropboxservice.h
|
||||||
internet/dropboxsettingspage.h
|
internet/dropboxsettingspage.h
|
||||||
|
internet/dropboxurlhandler.h
|
||||||
UI
|
UI
|
||||||
internet/dropboxsettingspage.ui
|
internet/dropboxsettingspage.ui
|
||||||
)
|
)
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
#include "dropboxservice.h"
|
#include "dropboxservice.h"
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
|
|
||||||
|
#include "core/application.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/network.h"
|
#include "core/network.h"
|
||||||
|
#include "core/player.h"
|
||||||
|
#include "core/waitforsignal.h"
|
||||||
#include "internet/dropboxauthenticator.h"
|
#include "internet/dropboxauthenticator.h"
|
||||||
|
#include "internet/dropboxurlhandler.h"
|
||||||
|
|
||||||
const char* DropboxService::kServiceName = "Dropbox";
|
const char* DropboxService::kServiceName = "Dropbox";
|
||||||
const char* DropboxService::kSettingsGroup = "Dropbox";
|
const char* DropboxService::kSettingsGroup = "Dropbox";
|
||||||
@ -15,8 +21,8 @@ static const char* kServiceId = "dropbox";
|
|||||||
|
|
||||||
static const char* kMetadataEndpoint =
|
static const char* kMetadataEndpoint =
|
||||||
"https://api.dropbox.com/1/metadata/dropbox/";
|
"https://api.dropbox.com/1/metadata/dropbox/";
|
||||||
//static const char* kMediaEndpoint =
|
static const char* kMediaEndpoint =
|
||||||
// "https://api.dropbox.com/1/media/dropbox/";
|
"https://api.dropbox.com/1/media/dropbox/";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -31,6 +37,7 @@ DropboxService::DropboxService(Application* app, InternetModel* parent)
|
|||||||
settings.beginGroup(kSettingsGroup);
|
settings.beginGroup(kSettingsGroup);
|
||||||
access_token_ = settings.value("access_token").toString();
|
access_token_ = settings.value("access_token").toString();
|
||||||
access_token_secret_ = settings.value("access_token_secret").toString();
|
access_token_secret_ = settings.value("access_token_secret").toString();
|
||||||
|
app->player()->RegisterUrlHandler(new DropboxUrlHandler(this, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DropboxService::has_credentials() const {
|
bool DropboxService::has_credentials() const {
|
||||||
@ -99,9 +106,57 @@ void DropboxService::RequestFileListFinished(QNetworkReply* reply) {
|
|||||||
const bool directory = item["is_dir"].toBool();
|
const bool directory = item["is_dir"].toBool();
|
||||||
if (directory) {
|
if (directory) {
|
||||||
RequestFileList(item["path"].toString());
|
RequestFileList(item["path"].toString());
|
||||||
} else {
|
} else if (IsSupportedMimeType(item["mime_type"].toString())) {
|
||||||
qLog(Debug) << "Found:" << item["path"].toString()
|
qLog(Debug) << "Found:" << item["path"].toString();
|
||||||
<< IsSupportedMimeType(item["mime_type"].toString());
|
QUrl url;
|
||||||
|
url.setScheme("dropbox");
|
||||||
|
url.setPath(item["path"].toString());
|
||||||
|
QNetworkReply* reply = FetchContentUrl(url);
|
||||||
|
NewClosure(reply, SIGNAL(finished()),
|
||||||
|
this, SLOT(FetchContentUrlFinished(QNetworkReply*, QVariantMap)),
|
||||||
|
reply, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QNetworkReply* DropboxService::FetchContentUrl(const QUrl& url) {
|
||||||
|
QUrl request_url(QString(kMediaEndpoint) + url.path());
|
||||||
|
QNetworkRequest request(request_url);
|
||||||
|
request.setRawHeader("Authorization", GenerateAuthorisationHeader());
|
||||||
|
return network_->post(request, QByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DropboxService::FetchContentUrlFinished(
|
||||||
|
QNetworkReply* reply, const QVariantMap& data) {
|
||||||
|
reply->deleteLater();
|
||||||
|
QJson::Parser parser;
|
||||||
|
QVariantMap response = parser.parse(reply).toMap();
|
||||||
|
QFileInfo info(data["path"].toString());
|
||||||
|
qLog(Debug) << response["url"].toUrl()
|
||||||
|
<< info.fileName()
|
||||||
|
<< data["bytes"].toInt()
|
||||||
|
<< data["mime_type"].toString();
|
||||||
|
TagReaderClient::ReplyType* tag_reply = app_->tag_reader_client()->ReadCloudFile(
|
||||||
|
response["url"].toUrl(),
|
||||||
|
info.fileName(),
|
||||||
|
data["bytes"].toInt(),
|
||||||
|
data["mime_type"].toString(),
|
||||||
|
QString::null);
|
||||||
|
NewClosure(tag_reply, SIGNAL(Finished(bool)),
|
||||||
|
this, SLOT(ReadTagsFinished(TagReaderClient::ReplyType*,QVariantMap)),
|
||||||
|
tag_reply, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DropboxService::ReadTagsFinished(
|
||||||
|
TagReaderClient::ReplyType* reply, const QVariantMap& file) {
|
||||||
|
qLog(Debug) << reply->message().DebugString().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl DropboxService::GetStreamingUrlFromSongId(const QUrl& url) {
|
||||||
|
QNetworkReply* reply = FetchContentUrl(url);
|
||||||
|
WaitForSignal(reply, SIGNAL(finished()));
|
||||||
|
|
||||||
|
QJson::Parser parser;
|
||||||
|
QVariantMap response = parser.parse(reply).toMap();
|
||||||
|
return response["url"].toUrl();
|
||||||
|
}
|
||||||
|
@ -19,6 +19,8 @@ class DropboxService : public CloudFileService {
|
|||||||
|
|
||||||
virtual bool has_credentials() const;
|
virtual bool has_credentials() const;
|
||||||
|
|
||||||
|
QUrl GetStreamingUrlFromSongId(const QUrl& url);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Connected();
|
void Connected();
|
||||||
|
|
||||||
@ -28,10 +30,15 @@ class DropboxService : public CloudFileService {
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void RequestFileListFinished(QNetworkReply* reply);
|
void RequestFileListFinished(QNetworkReply* reply);
|
||||||
|
void FetchContentUrlFinished(QNetworkReply* reply, const QVariantMap& file);
|
||||||
|
void ReadTagsFinished(
|
||||||
|
TagReaderClient::ReplyType* reply,
|
||||||
|
const QVariantMap& file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RequestFileList(const QString& path);
|
void RequestFileList(const QString& path);
|
||||||
QByteArray GenerateAuthorisationHeader();
|
QByteArray GenerateAuthorisationHeader();
|
||||||
|
QNetworkReply* FetchContentUrl(const QUrl& url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString access_token_;
|
QString access_token_;
|
||||||
|
15
src/internet/dropboxurlhandler.cpp
Normal file
15
src/internet/dropboxurlhandler.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "dropboxurlhandler.h"
|
||||||
|
|
||||||
|
#include "internet/dropboxservice.h"
|
||||||
|
|
||||||
|
DropboxUrlHandler::DropboxUrlHandler(
|
||||||
|
DropboxService* service,
|
||||||
|
QObject* parent)
|
||||||
|
: UrlHandler(parent),
|
||||||
|
service_(service) {
|
||||||
|
}
|
||||||
|
|
||||||
|
UrlHandler::LoadResult DropboxUrlHandler::StartLoading(const QUrl& url) {
|
||||||
|
return LoadResult(url, LoadResult::TrackAvailable,
|
||||||
|
service_->GetStreamingUrlFromSongId(url));
|
||||||
|
}
|
21
src/internet/dropboxurlhandler.h
Normal file
21
src/internet/dropboxurlhandler.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef DROPBOXURLHANDLER_H
|
||||||
|
#define DROPBOXURLHANDLER_H
|
||||||
|
|
||||||
|
#include "core/urlhandler.h"
|
||||||
|
|
||||||
|
class DropboxService;
|
||||||
|
|
||||||
|
class DropboxUrlHandler : public UrlHandler {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DropboxUrlHandler(DropboxService* service, QObject* parent = 0);
|
||||||
|
|
||||||
|
QString scheme() const { return "dropbox"; }
|
||||||
|
QIcon icon() const { return QIcon(":providers/dropbox.png"); }
|
||||||
|
LoadResult StartLoading(const QUrl& url);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DropboxService* service_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user