Change transcoder output file and add missing suffix
This commit is contained in:
parent
18087fd797
commit
ec5ec83edc
@ -243,40 +243,6 @@ QString MakeTempDir(const QString template_name) {
|
||||
|
||||
}
|
||||
|
||||
QString GetTemporaryFileName() {
|
||||
|
||||
QString file;
|
||||
{
|
||||
QTemporaryFile tempfile;
|
||||
// Do not delete the file, we want to do something with it
|
||||
tempfile.setAutoRemove(false);
|
||||
tempfile.open();
|
||||
file = tempfile.fileName();
|
||||
}
|
||||
|
||||
return file;
|
||||
|
||||
}
|
||||
|
||||
QString SaveToTemporaryFile(const QByteArray &data) {
|
||||
|
||||
QTemporaryFile tempfile;
|
||||
tempfile.setAutoRemove(false);
|
||||
|
||||
if (!tempfile.open()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
if (tempfile.write(data) != data.size()) {
|
||||
tempfile.remove();
|
||||
return QString();
|
||||
}
|
||||
|
||||
tempfile.close();
|
||||
return tempfile.fileName();
|
||||
|
||||
}
|
||||
|
||||
bool RemoveRecursive(const QString &path) {
|
||||
|
||||
QDir dir(path);
|
||||
|
@ -61,8 +61,6 @@ quint64 FileSystemCapacity(const QString &path);
|
||||
quint64 FileSystemFreeSpace(const QString &path);
|
||||
|
||||
QString MakeTempDir(const QString template_name = QString());
|
||||
QString GetTemporaryFileName();
|
||||
QString SaveToTemporaryFile(const QByteArray &data);
|
||||
|
||||
bool RemoveRecursive(const QString &path);
|
||||
bool CopyRecursive(const QString &source, const QString &destination);
|
||||
|
@ -63,9 +63,6 @@ Organise::Organise(TaskManager *task_manager, std::shared_ptr<MusicStorage> dest
|
||||
mark_as_listened_(mark_as_listened),
|
||||
eject_after_(eject_after),
|
||||
task_count_(songs_info.count()),
|
||||
#ifdef HAVE_GSTREAMER
|
||||
transcode_suffix_(1),
|
||||
#endif
|
||||
tasks_complete_(0),
|
||||
started_(false),
|
||||
task_id_(0),
|
||||
@ -100,11 +97,6 @@ void Organise::Start() {
|
||||
void Organise::ProcessSomeFiles() {
|
||||
|
||||
if (!started_) {
|
||||
transcode_temp_name_.setFileTemplate(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/transcoder");
|
||||
#ifdef HAVE_GSTREAMER
|
||||
transcode_temp_name_.open();
|
||||
#endif
|
||||
|
||||
if (!destination_->StartCopy(&supported_filetypes_)) {
|
||||
// Failed to start - mark everything as failed :(
|
||||
for (const Task &task : tasks_pending_) files_with_errors_ << task.song_info_.song_.url().toLocalFile();
|
||||
@ -182,12 +174,10 @@ void Organise::ProcessSomeFiles() {
|
||||
TranscoderPreset preset = Transcoder::PresetForFileType(dest_type);
|
||||
qLog(Debug) << "Transcoding with" << preset.name_;
|
||||
|
||||
// Get a temporary name for the transcoded file
|
||||
task.transcoded_filename_ = transcode_temp_name_.fileName() + "-" + QString::number(transcode_suffix_++);
|
||||
task.transcoded_filename_ = transcoder_->GetFile(task.song_info_.song_.url().toLocalFile(), preset);
|
||||
task.new_extension_ = preset.extension_;
|
||||
task.new_filetype_ = dest_type;
|
||||
tasks_transcoding_[task.song_info_.song_.url().toLocalFile()] = task;
|
||||
|
||||
qLog(Debug) << "Transcoding to" << task.transcoded_filename_;
|
||||
|
||||
// Start the transcoding - this will happen in the background and FileTranscoded() will get called when it's done.
|
||||
|
@ -121,8 +121,6 @@ class Organise : public QObject {
|
||||
|
||||
#ifdef HAVE_GSTREAMER
|
||||
QBasicTimer transcode_progress_timer_;
|
||||
QTemporaryFile transcode_temp_name_;
|
||||
int transcode_suffix_;
|
||||
#endif
|
||||
|
||||
QList<Task> tasks_pending_;
|
||||
|
@ -30,9 +30,11 @@
|
||||
#include <QtGlobal>
|
||||
#include <QThread>
|
||||
#include <QCoreApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QByteArray>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
@ -286,40 +288,46 @@ Song::FileType Transcoder::PickBestFormat(QList<Song::FileType> supported) {
|
||||
|
||||
}
|
||||
|
||||
QString Transcoder::GetFile(const QString &input, const TranscoderPreset &preset, const QString output) {
|
||||
|
||||
QFileInfo fileinfo_output;
|
||||
|
||||
if (!output.isEmpty()) {
|
||||
fileinfo_output.setFile(output);
|
||||
}
|
||||
|
||||
if (!fileinfo_output.isFile() || fileinfo_output.filePath().isEmpty() || fileinfo_output.path().isEmpty() || fileinfo_output.fileName().isEmpty() || fileinfo_output.suffix().isEmpty()) {
|
||||
QFileInfo fileinfo_input(input);
|
||||
QString filename = fileinfo_input.baseName() + "." + preset.extension_;
|
||||
fileinfo_output.setFile(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/transcoder/" + filename);
|
||||
QDir dir;
|
||||
dir.mkdir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/transcoder");
|
||||
}
|
||||
|
||||
// Never overwrite existing files
|
||||
if (fileinfo_output.exists()) {
|
||||
QString path = fileinfo_output.path();
|
||||
QString filename = fileinfo_output.baseName();
|
||||
QString suffix = fileinfo_output.suffix();
|
||||
for (int i = 0;; ++i) {
|
||||
QString new_filename = QString("%1/%2-%3.%4").arg(path).arg(filename).arg(i).arg(suffix);
|
||||
fileinfo_output.setFile(new_filename);
|
||||
if (!fileinfo_output.exists()) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return fileinfo_output.filePath();
|
||||
}
|
||||
|
||||
void Transcoder::AddJob(const QString &input, const TranscoderPreset &preset, const QString &output) {
|
||||
|
||||
Job job;
|
||||
job.input = input;
|
||||
job.preset = preset;
|
||||
|
||||
// Use the supplied filename if there was one, otherwise take the file extension off the input filename and append the correct one.
|
||||
if (!output.isEmpty())
|
||||
job.output = output;
|
||||
else
|
||||
job.output = input.section('.', 0, -2) + '.' + preset.extension_;
|
||||
|
||||
// Never overwrite existing files
|
||||
if (QFile::exists(job.output)) {
|
||||
for (int i = 0;; ++i) {
|
||||
QString new_filename = QString("%1.%2.%3").arg(job.output.section('.', 0, -2)).arg(i).arg( preset.extension_);
|
||||
if (!QFile::exists(new_filename)) {
|
||||
job.output = new_filename;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
queued_jobs_ << job;
|
||||
|
||||
}
|
||||
|
||||
void Transcoder::AddTemporaryJob(const QString &input, const TranscoderPreset &preset) {
|
||||
|
||||
Job job;
|
||||
job.input = input;
|
||||
job.output = Utilities::GetTemporaryFileName();
|
||||
job.preset = preset;
|
||||
|
||||
job.output = output;
|
||||
queued_jobs_ << job;
|
||||
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ class Transcoder : public QObject {
|
||||
int max_threads() const { return max_threads_; }
|
||||
void set_max_threads(int count) { max_threads_ = count; }
|
||||
|
||||
void AddJob(const QString &input, const TranscoderPreset &preset, const QString &output = QString());
|
||||
void AddTemporaryJob(const QString &input, const TranscoderPreset &preset);
|
||||
QString GetFile(const QString &input, const TranscoderPreset &preset, const QString output = QString());
|
||||
void AddJob(const QString &input, const TranscoderPreset &preset, const QString &output);
|
||||
|
||||
QMap<QString, float> GetProgress() const;
|
||||
int QueuedJobsCount() const { return queued_jobs_.count(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user