mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-05 12:56:52 +01:00
Use correct file extension in organize preview and resulting filename
Fixes #564
This commit is contained in:
parent
cf17ff4478
commit
2ad1a60e59
@ -174,6 +174,7 @@ void Organize::ProcessSomeFiles() {
|
||||
// Fiddle the filename extension as well to match the new type
|
||||
song.set_url(QUrl::fromLocalFile(Utilities::FiddleFileExtension(song.basefilename(), task.new_extension_)));
|
||||
song.set_basefilename(Utilities::FiddleFileExtension(song.basefilename(), task.new_extension_));
|
||||
task.song_info_.new_filename_ = Utilities::FiddleFileExtension(task.song_info_.new_filename_, task.new_extension_);
|
||||
|
||||
// Have to set this to the size of the new file or else funny stuff happens
|
||||
song.set_filesize(QFileInfo(task.transcoded_filename_).size());
|
||||
|
@ -68,6 +68,9 @@
|
||||
#include "organizedialog.h"
|
||||
#include "organizeerrordialog.h"
|
||||
#include "ui_organizedialog.h"
|
||||
#ifdef HAVE_GSTREAMER
|
||||
# include "transcoder/transcoder.h"
|
||||
#endif
|
||||
|
||||
const char *OrganizeDialog::kDefaultFormat = "%albumartist/%album{ (Disc %disc)}/{%track - }{%albumartist - }%album{ (Disc %disc)} - %title.%extension";
|
||||
|
||||
@ -405,7 +408,7 @@ void OrganizeDialog::InsertTag(const QString &tag) {
|
||||
ui_->naming->insertPlainText("%" + tag);
|
||||
}
|
||||
|
||||
Organize::NewSongInfoList OrganizeDialog::ComputeNewSongsFilenames(const SongList &songs, const OrganizeFormat &format) {
|
||||
Organize::NewSongInfoList OrganizeDialog::ComputeNewSongsFilenames(const SongList &songs, const OrganizeFormat &format, const QString &extension) {
|
||||
|
||||
// Check if we will have multiple files with the same name.
|
||||
// If so, they will erase each other if the overwrite flag is set.
|
||||
@ -414,7 +417,7 @@ Organize::NewSongInfoList OrganizeDialog::ComputeNewSongsFilenames(const SongLis
|
||||
Organize::NewSongInfoList new_songs_info;
|
||||
|
||||
for (const Song &song : songs) {
|
||||
QString new_filename = format.GetFilenameForSong(song);
|
||||
QString new_filename = format.GetFilenameForSong(song, extension);
|
||||
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();
|
||||
@ -473,7 +476,15 @@ void OrganizeDialog::UpdatePreviews() {
|
||||
ui_->button_box->button(QDialogButtonBox::Ok)->setEnabled(ok);
|
||||
if (!format_valid) return;
|
||||
|
||||
new_songs_info_ = ComputeNewSongsFilenames(songs_, format_);
|
||||
QString extension;
|
||||
#ifdef HAVE_GSTREAMER
|
||||
if (storage && storage->GetTranscodeMode() == MusicStorage::Transcode_Always) {
|
||||
const Song::FileType format = storage->GetTranscodeFormat();
|
||||
TranscoderPreset preset = Transcoder::PresetForFileType(format);
|
||||
extension = preset.extension_;
|
||||
}
|
||||
#endif
|
||||
new_songs_info_ = ComputeNewSongsFilenames(songs_, format_, extension);
|
||||
|
||||
// Update the previews
|
||||
ui_->preview->clear();
|
||||
|
@ -73,7 +73,7 @@ class OrganizeDialog : public QDialog {
|
||||
|
||||
void SetCopy(bool copy);
|
||||
|
||||
static Organize::NewSongInfoList ComputeNewSongsFilenames(const SongList &songs, const OrganizeFormat &format);
|
||||
static Organize::NewSongInfoList ComputeNewSongsFilenames(const SongList &songs, const OrganizeFormat &format, const QString &extension = QString());
|
||||
|
||||
void SetPlaylist(const QString &playlist);
|
||||
|
||||
|
@ -108,7 +108,7 @@ bool OrganizeFormat::IsValid() const {
|
||||
|
||||
}
|
||||
|
||||
QString OrganizeFormat::GetFilenameForSong(const Song &song) const {
|
||||
QString OrganizeFormat::GetFilenameForSong(const Song &song, QString extension) const {
|
||||
|
||||
QString filename = ParseBlock(format_, song);
|
||||
|
||||
@ -144,7 +144,7 @@ QString OrganizeFormat::GetFilenameForSong(const Song &song) const {
|
||||
filename = filename.simplified();
|
||||
|
||||
QFileInfo info(filename);
|
||||
QString extension = info.suffix();
|
||||
if (extension.isEmpty()) extension = info.suffix();
|
||||
QString filepath;
|
||||
if (!info.path().isEmpty() && info.path() != ".") {
|
||||
filepath.append(info.path());
|
||||
|
@ -65,7 +65,7 @@ class OrganizeFormat {
|
||||
void set_replace_spaces(const bool v) { replace_spaces_ = v; }
|
||||
|
||||
bool IsValid() const;
|
||||
QString GetFilenameForSong(const Song &song) const;
|
||||
QString GetFilenameForSong(const Song &song, QString extension = QString()) const;
|
||||
|
||||
class Validator : public QValidator {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user