Skip to content

Commit

Permalink
Fix preserve mtimes for Opus files
Browse files Browse the repository at this point in the history
  • Loading branch information
complexlogic committed Nov 16, 2024
1 parent 5c1bc20 commit 47b393b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
SwrContext *swr = nullptr;
AVFormatContext *format_ctx = nullptr;
const AVStream *stream = nullptr;
if (config.preserve_mtimes) {
mtime = std::make_unique<std::filesystem::file_time_type>();
*mtime = std::filesystem::last_write_time(path);
}

// For Opus files, FFmpeg always adjusts the decoded audio samples by the header output
// gain with no way to disable. To get the actual loudness of the audio signal,
Expand Down
1 change: 1 addition & 0 deletions src/scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ScanJob {
std::filesystem::path path;
FileType type;
std::unique_ptr<ebur128_state, decltype(&free_ebur128)> ebur128;
std::unique_ptr<std::filesystem::file_time_type> mtime;
std::string container;
ScanResult result;
int codec_id;
Expand Down
8 changes: 2 additions & 6 deletions src/tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ static_assert((size_t) R128Tag::MAX_VAL == R128_STRING.size());

void tag_track(ScanJob::Track &track, const Config &config)
{
std::filesystem::file_time_type mtime;
if (config.preserve_mtimes)
mtime = std::filesystem::last_write_time(track.path);

switch (track.type) {
case FileType::MP2:
case FileType::MP3:
Expand Down Expand Up @@ -257,8 +253,8 @@ void tag_track(ScanJob::Track &track, const Config &config)
default:
break;
}
if (config.preserve_mtimes)
std::filesystem::last_write_time(track.path, mtime);
if (track.mtime)
std::filesystem::last_write_time(track.path, *(track.mtime));
}

bool tag_exists(const ScanJob::Track &track)
Expand Down

0 comments on commit 47b393b

Please sign in to comment.