Copy album covers to file system devices
This commit is contained in:
parent
ec5ec83edc
commit
1ce553fb65
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
@ -44,6 +45,13 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
|||
const QFileInfo src = QFileInfo(job.source_);
|
||||
const QFileInfo dest = QFileInfo(root_ + "/" + job.destination_);
|
||||
|
||||
QFileInfo cover_src;
|
||||
QFileInfo cover_dest;
|
||||
if (job.albumcover_ && !job.cover_source_.isEmpty() && !job.cover_dest_.isEmpty()) {
|
||||
cover_src = QFileInfo(job.cover_source_);
|
||||
cover_dest = QFileInfo(root_ + "/" + job.cover_dest_);
|
||||
}
|
||||
|
||||
// Don't do anything if the destination is the same as the source
|
||||
if (src == dest) return true;
|
||||
|
||||
|
@ -55,13 +63,29 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
|||
}
|
||||
|
||||
// Remove the destination file if it exists and we want to overwrite
|
||||
if (job.overwrite_ && dest.exists()) QFile::remove(dest.absoluteFilePath());
|
||||
if (job.overwrite_) {
|
||||
if (dest.exists()) QFile::remove(dest.absoluteFilePath());
|
||||
if (!cover_dest.filePath().isEmpty() && cover_dest.exists()) QFile::remove(cover_dest.absoluteFilePath());
|
||||
}
|
||||
|
||||
// Copy or move
|
||||
if (job.remove_original_)
|
||||
return QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
|
||||
else
|
||||
return QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath());
|
||||
bool result(true);
|
||||
if (job.remove_original_) {
|
||||
result = QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
|
||||
if (!cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty()) {
|
||||
QFile::rename(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!dest.exists()) {
|
||||
result = QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath());
|
||||
}
|
||||
if (!cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty() && !cover_dest.exists()) {
|
||||
QFile::copy(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -76,4 +100,3 @@ bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob &job) {
|
|||
return QFile::remove(path);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
@ -43,4 +44,3 @@ private:
|
|||
};
|
||||
|
||||
#endif // FILESYSTEMMUSICSTORAGE_H
|
||||
|
||||
|
|
|
@ -20,6 +20,4 @@
|
|||
|
||||
#include "musicstorage.h"
|
||||
|
||||
MusicStorage::MusicStorage()
|
||||
{
|
||||
}
|
||||
MusicStorage::MusicStorage() {}
|
||||
|
|
|
@ -61,6 +61,9 @@ class MusicStorage {
|
|||
bool overwrite_;
|
||||
bool mark_as_listened_;
|
||||
bool remove_original_;
|
||||
bool albumcover_;
|
||||
QString cover_source_;
|
||||
QString cover_dest_;
|
||||
ProgressFunction progress_;
|
||||
};
|
||||
|
||||
|
|
|
@ -135,12 +135,12 @@ DeviceManager::DeviceManager(Application *app, QObject *parent)
|
|||
AddLister(new iLister);
|
||||
#endif
|
||||
|
||||
AddDeviceClass<FilesystemDevice>();
|
||||
|
||||
#if defined(HAVE_AUDIOCD) && defined(HAVE_GSTREAMER)
|
||||
AddDeviceClass<CddaDevice>();
|
||||
#endif
|
||||
|
||||
AddDeviceClass<FilesystemDevice>();
|
||||
|
||||
#ifdef HAVE_LIBGPOD
|
||||
AddDeviceClass<GPodDevice>();
|
||||
#endif
|
||||
|
|
|
@ -146,26 +146,27 @@ bool GPodDevice::CopyToStorage(const CopyJob &job) {
|
|||
|
||||
Itdb_Track *track = AddTrackToITunesDb(job.metadata_);
|
||||
|
||||
bool result(false);
|
||||
if (!job.metadata_.image().isNull()) {
|
||||
if (job.albumcover_) {
|
||||
bool result = false;
|
||||
if (!job.metadata_.image().isNull()) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().sizeInBytes());
|
||||
result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().sizeInBytes());
|
||||
track->has_artwork = 1;
|
||||
#else
|
||||
result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().byteCount());
|
||||
result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().byteCount());
|
||||
track->has_artwork = 1;
|
||||
#endif
|
||||
}
|
||||
else if (!job.metadata_.art_manual().isEmpty()) {
|
||||
result = itdb_track_set_thumbnails(track, QDir::toNativeSeparators(job.metadata_.art_manual()).toLocal8Bit().constData());
|
||||
}
|
||||
else if (!job.metadata_.art_automatic().isEmpty()) {
|
||||
result = itdb_track_set_thumbnails(track, QDir::toNativeSeparators(job.metadata_.art_automatic()).toLocal8Bit().constData());
|
||||
}
|
||||
if (result) {
|
||||
track->has_artwork = 1;
|
||||
}
|
||||
else {
|
||||
track->has_artwork = 0;
|
||||
qLog(Error) << "failed to set album cover image";
|
||||
}
|
||||
else if (!job.cover_source_.isEmpty()) {
|
||||
result = itdb_track_set_thumbnails(track, job.cover_source_.toLocal8Bit().constData());
|
||||
track->has_artwork = 1;
|
||||
}
|
||||
else {
|
||||
result = true;
|
||||
}
|
||||
if (!result) {
|
||||
qLog(Error) << "failed to set album cover image";
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the file
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
@ -50,7 +51,7 @@ const int Organise::kBatchSize = 10;
|
|||
const int Organise::kTranscodeProgressInterval = 500;
|
||||
#endif
|
||||
|
||||
Organise::Organise(TaskManager *task_manager, std::shared_ptr<MusicStorage> destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, const NewSongInfoList &songs_info, bool eject_after)
|
||||
Organise::Organise(TaskManager *task_manager, std::shared_ptr<MusicStorage> destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, bool albumcover, const NewSongInfoList &songs_info, bool eject_after)
|
||||
: thread_(nullptr),
|
||||
task_manager_(task_manager),
|
||||
#ifdef HAVE_GSTREAMER
|
||||
|
@ -61,6 +62,7 @@ Organise::Organise(TaskManager *task_manager, std::shared_ptr<MusicStorage> dest
|
|||
copy_(copy),
|
||||
overwrite_(overwrite),
|
||||
mark_as_listened_(mark_as_listened),
|
||||
albumcover_(albumcover),
|
||||
eject_after_(eject_after),
|
||||
task_count_(songs_info.count()),
|
||||
tasks_complete_(0),
|
||||
|
@ -195,7 +197,19 @@ void Organise::ProcessSomeFiles() {
|
|||
job.metadata_ = song;
|
||||
job.overwrite_ = overwrite_;
|
||||
job.mark_as_listened_ = mark_as_listened_;
|
||||
job.albumcover_ = albumcover_;
|
||||
job.remove_original_ = !copy_;
|
||||
|
||||
if (!task.song_info_.song_.art_manual().isEmpty()) {
|
||||
job.cover_source_ = task.song_info_.song_.art_manual();
|
||||
}
|
||||
else if (!task.song_info_.song_.art_automatic().isEmpty()) {
|
||||
job.cover_source_ = task.song_info_.song_.art_automatic();
|
||||
}
|
||||
if (!job.cover_source_.isEmpty()) {
|
||||
job.cover_dest_ = QFileInfo(job.destination_).path() + "/" + QFileInfo(job.cover_source_).fileName();
|
||||
}
|
||||
|
||||
job.progress_ = std::bind(&Organise::SetSongProgress, this, _1, !task.transcoded_filename_.isEmpty());
|
||||
|
||||
if (!destination_->CopyToStorage(job)) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
@ -59,7 +60,7 @@ class Organise : public QObject {
|
|||
};
|
||||
typedef QList<NewSongInfo> NewSongInfoList;
|
||||
|
||||
Organise(TaskManager *task_manager, std::shared_ptr<MusicStorage> destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, const NewSongInfoList &songs, bool eject_after);
|
||||
Organise(TaskManager *task_manager, std::shared_ptr<MusicStorage> destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, bool albumcover, const NewSongInfoList &songs, bool eject_after);
|
||||
|
||||
static const int kBatchSize;
|
||||
#ifdef HAVE_GSTREAMER
|
||||
|
@ -116,6 +117,7 @@ class Organise : public QObject {
|
|||
const bool copy_;
|
||||
const bool overwrite_;
|
||||
const bool mark_as_listened_;
|
||||
const bool albumcover_;
|
||||
const bool eject_after_;
|
||||
int task_count_;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
@ -250,6 +251,7 @@ Organise::NewSongInfoList OrganiseDialog::ComputeNewSongsFilenames(const SongLis
|
|||
|
||||
for (const Song &song : songs) {
|
||||
QString new_filename = format.GetFilenameForSong(song);
|
||||
//QString new_cover_filename = format.GetCoverFilenameForSong(song);
|
||||
if (filenames.contains(new_filename)) {
|
||||
QString song_number = QString::number(++filenames[new_filename]);
|
||||
new_filename = Utilities::PathWithoutFilenameExtension(new_filename) + "(" + song_number + ")." + QFileInfo(new_filename).suffix();
|
||||
|
@ -335,6 +337,7 @@ void OrganiseDialog::Reset() {
|
|||
ui_->replace_spaces->setChecked(true);
|
||||
ui_->overwrite->setChecked(false);
|
||||
ui_->mark_as_listened->setChecked(false);
|
||||
ui_->albumcover->setChecked(true);
|
||||
ui_->eject_after->setChecked(false);
|
||||
|
||||
}
|
||||
|
@ -350,6 +353,7 @@ void OrganiseDialog::showEvent(QShowEvent*) {
|
|||
ui_->remove_non_ascii->setChecked(s.value("remove_non_ascii", false).toBool());
|
||||
ui_->replace_spaces->setChecked(s.value("replace_spaces", true).toBool());
|
||||
ui_->overwrite->setChecked(s.value("overwrite", false).toBool());
|
||||
ui_->albumcover->setChecked(s.value("albumcover", true).toBool());
|
||||
ui_->mark_as_listened->setChecked(s.value("mark_as_listened", false).toBool());
|
||||
ui_->eject_after->setChecked(s.value("eject_after", false).toBool());
|
||||
|
||||
|
@ -372,6 +376,7 @@ void OrganiseDialog::accept() {
|
|||
s.setValue("replace_spaces", ui_->replace_spaces->isChecked());
|
||||
s.setValue("overwrite", ui_->overwrite->isChecked());
|
||||
s.setValue("mark_as_listened", ui_->overwrite->isChecked());
|
||||
s.setValue("albumcover", ui_->albumcover->isChecked());
|
||||
s.setValue("destination", ui_->destination->currentText());
|
||||
s.setValue("eject_after", ui_->eject_after->isChecked());
|
||||
|
||||
|
@ -382,7 +387,7 @@ void OrganiseDialog::accept() {
|
|||
|
||||
// It deletes itself when it's finished.
|
||||
const bool copy = ui_->aftercopying->currentIndex() == 0;
|
||||
Organise *organise = new Organise(task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), ui_->mark_as_listened->isChecked(), new_songs_info_, ui_->eject_after->isChecked());
|
||||
Organise *organise = new Organise(task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), ui_->mark_as_listened->isChecked(), ui_->albumcover->isChecked(), new_songs_info_, ui_->eject_after->isChecked());
|
||||
connect(organise, SIGNAL(Finished(QStringList, QStringList)), SLOT(OrganiseFinished(QStringList, QStringList)));
|
||||
connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int)));
|
||||
organise->Start();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
|
|
@ -126,6 +126,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="albumcover">
|
||||
<property name="text">
|
||||
<string>Copy album cover artwork</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2019, 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
|
||||
|
|
Loading…
Reference in New Issue