Syndication

enclosurerss2impl.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "enclosurerss2impl.h"
9#include <constants.h>
10
11#include <QString>
12#include <QStringList>
13
14namespace Syndication
15{
16EnclosureRSS2Impl::EnclosureRSS2Impl(const Syndication::RSS2::Item &item, const Syndication::RSS2::Enclosure &enc)
17 : m_item(item)
18 , m_enclosure(enc)
19{
20}
21
23{
24 return m_enclosure.isNull();
25}
26
28{
29 return m_enclosure.url();
30}
31
33{
34 // RSS2 enclosures have no title
35 return QString();
36}
37
39{
40 return m_enclosure.type();
41}
42
44{
45 return m_enclosure.length();
46}
47
49{
50 QString durStr = m_item.extractElementTextNS(itunesNamespace(), QStringLiteral("duration"));
51
52 if (durStr.isEmpty()) {
53 return 0;
54 }
55
56 const QStringList strTokens = durStr.split(QLatin1Char(':'));
57 QList<int> intTokens;
58
59 const int count = strTokens.count();
60 bool ok;
61
62 for (int i = 0; i < count; ++i) {
63 int intVal = strTokens.at(i).toInt(&ok);
64 if (ok) {
65 intTokens.append(intVal >= 0 ? intVal : 0); // do not accept negative values
66 } else {
67 return 0;
68 }
69 }
70
71 if (count == 3) {
72 return intTokens.at(0) * 3600 + intTokens.at(1) * 60 + intTokens.at(2);
73 } else if (count == 2) {
74 return intTokens.at(0) * 60 + intTokens.at(1);
75 } else if (count == 1) {
76 return intTokens.at(0);
77 }
78
79 return 0;
80}
81
82} // namespace Syndication
QString title() const override
title of the enclosure.
uint duration() const override
for audio/video files, the duration of the file in seconds
uint length() const override
returns the length of the linked file in bytes
bool isNull() const override
returns whether this enclosure is a null object.
QString url() const override
The URL of the linked resource (required).
QString type() const override
mimetype of the enclosure.
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:48:38 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.