From e77f317f911ddad40f9592994ba66150aaaccac9 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Sat, 14 Dec 2024 14:48:15 +0100 Subject: [PATCH] Retrieve duration from file as soon as it's downloaded This will replace the less reliable duration as retrieved from the rss feed entry. BUG: 497448 --- src/enclosure.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/enclosure.cpp b/src/enclosure.cpp index ee880cc1..eef9d20e 100644 --- a/src/enclosure.cpp +++ b/src/enclosure.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -237,11 +238,20 @@ void Enclosure::processDownloadedFile() // if not, correct the filesize in the database // otherwise the file will get deleted because of mismatch in signature if (m_sizeOnDisk != size()) { - qCDebug(kastsEnclosure) << "Correcting enclosure file size mismatch" << m_entry->title() << "from" << size() << "to" << m_sizeOnDisk; + qCDebug(kastsEnclosure) << "Correcting enclosure file size mismatch for" << m_entry->title() << "from" << size() << "to" << m_sizeOnDisk; setSize(m_sizeOnDisk); setStatus(Downloaded); } + // Check the duration inside the tag, it should be more accurate than the + // value from the feed entry + TagLib::FileRef f(path().toLatin1().data()); + int fileduration = f.audioProperties()->lengthInSeconds(); + if (fileduration > 0 && fileduration != duration()) { + qCDebug(kastsEnclosure) << "Correcting enclosure duration mismatch for" << m_entry->title() << "from" << duration() << "to" << fileduration; + setDuration(fileduration); + } + // Unset "new" status of item if (m_entry->getNew()) { m_entry->setNew(false);