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
22bool EnclosureRSS2Impl::isNull() const
23{
24 return m_enclosure.isNull();
25}
26
27QString EnclosureRSS2Impl::url() const
28{
29 return m_enclosure.url();
30}
31
32QString EnclosureRSS2Impl::title() const
33{
34 // RSS2 enclosures have no title
35 return QString();
36}
37
38QString EnclosureRSS2Impl::type() const
39{
40 return m_enclosure.type();
41}
42
43uint EnclosureRSS2Impl::length() const
44{
45 return m_enclosure.length();
46}
47
48uint EnclosureRSS2Impl::duration() const
49{
50 QString durStr = m_item.extractElementTextNS(namespaceURI: itunesNamespace(), QStringLiteral("duration"));
51
52 if (durStr.isEmpty()) {
53 return 0;
54 }
55
56 const QStringList strTokens = durStr.split(sep: 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: &ok);
64 if (ok) {
65 intTokens.append(t: 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(i: 0) * 3600 + intTokens.at(i: 1) * 60 + intTokens.at(i: 2);
73 } else if (count == 2) {
74 return intTokens.at(i: 0) * 60 + intTokens.at(i: 1);
75 } else if (count == 1) {
76 return intTokens.at(i: 0);
77 }
78
79 return 0;
80}
81
82} // namespace Syndication
83

source code of syndication/src/mapper/enclosurerss2impl.cpp