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
This commit is contained in:
Bart De Vries 2024-12-14 14:48:15 +01:00
parent 02aefde5d9
commit e77f317f91
No known key found for this signature in database
GPG Key ID: 7285665DA6E2D42B

View File

@ -17,6 +17,7 @@
#include <QSqlQuery>
#include <attachedpictureframe.h>
#include <fileref.h>
#include <id3v2frame.h>
#include <id3v2tag.h>
#include <mpegfile.h>
@ -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);