mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 03:09:57 +01:00
Add dropbox files locally after tagging and make them playable.
This commit is contained in:
parent
3c9b3d99e6
commit
8e91e42dcc
@ -618,7 +618,8 @@ bool TagReaderWorker::ReadCloudFile(const QUrl& download_url,
|
||||
stream,
|
||||
true,
|
||||
TagLib::AudioProperties::Accurate));
|
||||
} else if (mime_type == "application/ogg") {
|
||||
} else if (mime_type == "application/ogg" ||
|
||||
mime_type == "audio/ogg") {
|
||||
tag.reset(new TagLib::Ogg::Vorbis::File(
|
||||
stream,
|
||||
true,
|
||||
|
@ -8,9 +8,13 @@
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
#include "core/player.h"
|
||||
#include "core/utilities.h"
|
||||
#include "core/waitforsignal.h"
|
||||
#include "internet/dropboxauthenticator.h"
|
||||
#include "internet/dropboxurlhandler.h"
|
||||
#include "library/librarybackend.h"
|
||||
|
||||
using Utilities::ParseRFC822DateTime;
|
||||
|
||||
const char* DropboxService::kServiceName = "Dropbox";
|
||||
const char* DropboxService::kSettingsGroup = "Dropbox";
|
||||
@ -106,19 +110,31 @@ void DropboxService::RequestFileListFinished(QNetworkReply* reply) {
|
||||
const bool directory = item["is_dir"].toBool();
|
||||
if (directory) {
|
||||
RequestFileList(item["path"].toString());
|
||||
} else if (IsSupportedMimeType(item["mime_type"].toString())) {
|
||||
qLog(Debug) << "Found:" << item["path"].toString();
|
||||
} else {
|
||||
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);
|
||||
MaybeAddFileToDatabase(url, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DropboxService::MaybeAddFileToDatabase(
|
||||
const QUrl& url, const QVariantMap& file) {
|
||||
if (!IsSupportedMimeType(file["mime_type"].toString())) {
|
||||
return;
|
||||
}
|
||||
Song song = library_backend_->GetSongByUrl(url);
|
||||
if (song.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkReply* reply = FetchContentUrl(url);
|
||||
NewClosure(reply, SIGNAL(finished()),
|
||||
this, SLOT(FetchContentUrlFinished(QNetworkReply*, QVariantMap)),
|
||||
reply, file);
|
||||
}
|
||||
|
||||
QNetworkReply* DropboxService::FetchContentUrl(const QUrl& url) {
|
||||
QUrl request_url(QString(kMediaEndpoint) + url.path());
|
||||
QNetworkRequest request(request_url);
|
||||
@ -132,10 +148,6 @@ void DropboxService::FetchContentUrlFinished(
|
||||
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(),
|
||||
@ -144,12 +156,36 @@ void DropboxService::FetchContentUrlFinished(
|
||||
QString::null);
|
||||
NewClosure(tag_reply, SIGNAL(Finished(bool)),
|
||||
this, SLOT(ReadTagsFinished(TagReaderClient::ReplyType*,QVariantMap)),
|
||||
tag_reply, response);
|
||||
tag_reply, data);
|
||||
}
|
||||
|
||||
void DropboxService::ReadTagsFinished(
|
||||
TagReaderClient::ReplyType* reply, const QVariantMap& file) {
|
||||
qLog(Debug) << reply->message().DebugString().c_str();
|
||||
|
||||
const auto& message = reply->message().read_cloud_file_response();
|
||||
if (!message.has_metadata() ||
|
||||
!message.metadata().filesize()) {
|
||||
qLog(Debug) << "Failed to tag:" << file["path"].toString();
|
||||
return;
|
||||
}
|
||||
|
||||
Song song;
|
||||
song.InitFromProtobuf(message.metadata());
|
||||
song.set_directory_id(0);
|
||||
song.set_etag(file["rev"].toString());
|
||||
song.set_mtime(ParseRFC822DateTime(file["modified"].toString()).toTime_t());
|
||||
QUrl url;
|
||||
url.setScheme("dropbox");
|
||||
url.setPath(file["path"].toString());
|
||||
song.set_url(url);
|
||||
if (song.title().isEmpty()) {
|
||||
QFileInfo info(file["path"].toString());
|
||||
song.set_title(info.fileName());
|
||||
}
|
||||
|
||||
qLog(Debug) << "Adding song to db:" << song.title();
|
||||
library_backend_->AddOrUpdateSongs(SongList() << song);
|
||||
}
|
||||
|
||||
QUrl DropboxService::GetStreamingUrlFromSongId(const QUrl& url) {
|
||||
|
@ -39,6 +39,7 @@ class DropboxService : public CloudFileService {
|
||||
void RequestFileList(const QString& path);
|
||||
QByteArray GenerateAuthorisationHeader();
|
||||
QNetworkReply* FetchContentUrl(const QUrl& url);
|
||||
void MaybeAddFileToDatabase(const QUrl& url, const QVariantMap& file);
|
||||
|
||||
private:
|
||||
QString access_token_;
|
||||
|
Loading…
Reference in New Issue
Block a user