mirror of https://github.com/KDE/kasts.git
Add additional checks after enclosure has been downloaded
The file size in the database will be corrected if it doesn't match the real file size. The "new" status will be unset once the file has been downloaded.
This commit is contained in:
parent
61e3af704b
commit
7232238d7b
|
@ -35,7 +35,6 @@ Enclosure::Enclosure(Entry *entry)
|
||||||
m_url = query.value(QStringLiteral("url")).toString();
|
m_url = query.value(QStringLiteral("url")).toString();
|
||||||
m_playposition = query.value(QStringLiteral("playposition")).toInt();
|
m_playposition = query.value(QStringLiteral("playposition")).toInt();
|
||||||
|
|
||||||
// TODO: what to do if the rss-reported filesize doesn't match the real file size???
|
|
||||||
QFile file(path());
|
QFile file(path());
|
||||||
if(file.size() == m_size) {
|
if(file.size() == m_size) {
|
||||||
m_status = Downloaded;
|
m_status = Downloaded;
|
||||||
|
@ -61,6 +60,8 @@ void Enclosure::download()
|
||||||
connect(downloadJob, &KJob::result, this, [this, downloadJob]() {
|
connect(downloadJob, &KJob::result, this, [this, downloadJob]() {
|
||||||
if(downloadJob->error() == 0) {
|
if(downloadJob->error() == 0) {
|
||||||
m_status = Downloaded;
|
m_status = Downloaded;
|
||||||
|
processDownloadedFile();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
m_status = Downloadable;
|
m_status = Downloadable;
|
||||||
if(downloadJob->error() != QNetworkReply::OperationCanceledError) {
|
if(downloadJob->error() != QNetworkReply::OperationCanceledError) {
|
||||||
|
@ -88,6 +89,28 @@ void Enclosure::download()
|
||||||
Q_EMIT statusChanged();
|
Q_EMIT statusChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Enclosure::processDownloadedFile() {
|
||||||
|
// This will be run if the enclosure has been downloaded successfully
|
||||||
|
|
||||||
|
// Unset "new" status of item
|
||||||
|
if (m_entry->getNew()) m_entry->setNew(false);
|
||||||
|
|
||||||
|
// Check if reported filesize in rss feed corresponds to real file size
|
||||||
|
// if not, correct the filesize in the database
|
||||||
|
// otherwise the file will get deleted because of mismatch in signature
|
||||||
|
QFile file(path());
|
||||||
|
if(file.size() != m_size) {
|
||||||
|
qDebug() << "enclosure file size mismatch" << m_entry->title();
|
||||||
|
m_size = file.size();
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare(QStringLiteral("UPDATE Enclosures SET size=:size WHERE id=:id AND feed=:feed"));
|
||||||
|
query.bindValue(QStringLiteral(":id"), m_entry->id());
|
||||||
|
query.bindValue(QStringLiteral(":feed"), m_entry->feed()->url());
|
||||||
|
query.bindValue(QStringLiteral(":size"), m_size);
|
||||||
|
Database::instance().execute(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Enclosure::deleteFile()
|
void Enclosure::deleteFile()
|
||||||
{
|
{
|
||||||
qDebug() << "Trying to delete enclosure file" << path();
|
qDebug() << "Trying to delete enclosure file" << path();
|
||||||
|
|
|
@ -50,6 +50,8 @@ Q_SIGNALS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void processDownloadedFile();
|
||||||
|
|
||||||
Entry *m_entry;
|
Entry *m_entry;
|
||||||
int m_duration;
|
int m_duration;
|
||||||
int m_size;
|
int m_size;
|
||||||
|
|
Loading…
Reference in New Issue