File indexing completed on 2023-11-26 07:40:08
0001 /* 0002 This file is part of the syndication library 0003 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "enclosurerss2impl.h" 0009 #include <constants.h> 0010 0011 #include <QString> 0012 #include <QStringList> 0013 0014 namespace Syndication 0015 { 0016 EnclosureRSS2Impl::EnclosureRSS2Impl(const Syndication::RSS2::Item &item, const Syndication::RSS2::Enclosure &enc) 0017 : m_item(item) 0018 , m_enclosure(enc) 0019 { 0020 } 0021 0022 bool EnclosureRSS2Impl::isNull() const 0023 { 0024 return m_enclosure.isNull(); 0025 } 0026 0027 QString EnclosureRSS2Impl::url() const 0028 { 0029 return m_enclosure.url(); 0030 } 0031 0032 QString EnclosureRSS2Impl::title() const 0033 { 0034 // RSS2 enclosures have no title 0035 return QString(); 0036 } 0037 0038 QString EnclosureRSS2Impl::type() const 0039 { 0040 return m_enclosure.type(); 0041 } 0042 0043 uint EnclosureRSS2Impl::length() const 0044 { 0045 return m_enclosure.length(); 0046 } 0047 0048 uint EnclosureRSS2Impl::duration() const 0049 { 0050 QString durStr = m_item.extractElementTextNS(itunesNamespace(), QStringLiteral("duration")); 0051 0052 if (durStr.isEmpty()) { 0053 return 0; 0054 } 0055 0056 const QStringList strTokens = durStr.split(QLatin1Char(':')); 0057 QList<int> intTokens; 0058 0059 const int count = strTokens.count(); 0060 bool ok; 0061 0062 for (int i = 0; i < count; ++i) { 0063 int intVal = strTokens.at(i).toInt(&ok); 0064 if (ok) { 0065 intTokens.append(intVal >= 0 ? intVal : 0); // do not accept negative values 0066 } else { 0067 return 0; 0068 } 0069 } 0070 0071 if (count == 3) { 0072 return intTokens.at(0) * 3600 + intTokens.at(1) * 60 + intTokens.at(2); 0073 } else if (count == 2) { 0074 return intTokens.at(0) * 60 + intTokens.at(1); 0075 } else if (count == 1) { 0076 return intTokens.at(0); 0077 } 0078 0079 return 0; 0080 } 0081 0082 } // namespace Syndication