File indexing completed on 2024-05-19 04:49:30

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Bart Cerneels <bart.cerneels@kde.org>                             *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "core/podcasts/PodcastProvider.h"
0018 
0019 #include "core/support/Debug.h"
0020 
0021 #include <QUrl>
0022 
0023 using namespace Podcasts;
0024 
0025 bool
0026 PodcastProvider::couldBeFeed( const QString &urlString )
0027 {
0028     DEBUG_BLOCK
0029 
0030     QStringList feedProtocols;
0031     feedProtocols << QStringLiteral("itpc");
0032     feedProtocols << QStringLiteral("pcast");
0033     feedProtocols << QStringLiteral("feed");
0034 
0035     QString matchString = QStringLiteral( "^(%1)" ).arg( feedProtocols.join( QStringLiteral("|") ) );
0036     QRegExp rx( matchString );
0037     int pos = rx.indexIn( urlString.trimmed() );
0038 
0039     return pos != -1;
0040 }
0041 
0042 QUrl
0043 PodcastProvider::toFeedUrl( const QString &urlString )
0044 {
0045     DEBUG_BLOCK
0046     debug() << urlString;
0047 
0048     QUrl kurl( urlString.trimmed() );
0049 
0050     if( kurl.scheme() == QLatin1String("itpc") )
0051     {
0052         debug() << "itpc:// url.";
0053         kurl.setScheme( QStringLiteral("http") );
0054     }
0055     else if( kurl.scheme() == QLatin1String("pcast") )
0056     {
0057         debug() << "pcast:// url.";
0058         kurl.setScheme( QStringLiteral("http") );
0059     }
0060     else if( kurl.scheme() == QLatin1String("feed") )
0061     {
0062         //TODO: also handle the case feed:https://example.com/entries.atom
0063         debug() << "feed:// url.";
0064         kurl.setScheme( QStringLiteral("http") );
0065     }
0066 
0067     return kurl;
0068 }
0069 
0070 Playlists::PlaylistPtr
0071 PodcastProvider::addPlaylist(Playlists::PlaylistPtr playlist )
0072 {
0073     PodcastChannelPtr channel = PodcastChannelPtr::dynamicCast( playlist );
0074     if( channel.isNull() )
0075         return Playlists::PlaylistPtr();
0076 
0077     return Playlists::PlaylistPtr::dynamicCast( addChannel( channel ) );
0078 }
0079 
0080 Meta::TrackPtr
0081 PodcastProvider::addTrack( const Meta::TrackPtr &track )
0082 {
0083     PodcastEpisodePtr episode = PodcastEpisodePtr::dynamicCast( track );
0084     if( episode.isNull() )
0085         return Meta::TrackPtr();
0086 
0087     return Meta::TrackPtr::dynamicCast( addEpisode( episode ) );
0088 }