Debian Codegraph @

src/core/podcasts/PodcastProvider.cpp

raw
1 /****************************************************************************************
2 * Copyright (c) 2009 Bart Cerneels <[email protected]> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17 #include "core/podcasts/PodcastProvider.h"
18
19 #include "core/support/Debug.h"
20
21 #include <QRegularExpression>
22 #include <QUrl>
23
24 using namespace Podcasts;
25
26 bool
27 PodcastProvider::couldBeFeed( const QString &urlString )
28 {
29 DEBUG_BLOCK
30
31 QStringList feedProtocols;
32 feedProtocols << QStringLiteral("itpc");
33 feedProtocols << QStringLiteral("pcast");
34 feedProtocols << QStringLiteral("feed");
35
36 QString matchString = QStringLiteral( "^(%1)" ).arg( feedProtocols.join( QStringLiteral("|") ) );
37 QRegularExpression rx( matchString );
38 int pos = urlString.trimmed().indexOf( rx );
39
40 return pos != -1;
41 }
42
43 QUrl
44 PodcastProvider::toFeedUrl( const QString &urlString )
45 {
46 DEBUG_BLOCK
47 debug() << urlString;
48
49 QUrl kurl( urlString.trimmed() );
50
51 if( kurl.scheme() == QLatin1String("itpc") )
52 {
53 debug() << "itpc:// url.";
54 kurl.setScheme( QStringLiteral("http") );
55 }
56 else if( kurl.scheme() == QLatin1String("pcast") )
57 {
58 debug() << "pcast:// url.";
59 kurl.setScheme( QStringLiteral("http") );
60 }
61 else if( kurl.scheme() == QLatin1String("feed") )
62 {
63 //TODO: also handle the case feed:https://example.com/entries.atom
64 debug() << "feed:// url.";
65 kurl.setScheme( QStringLiteral("http") );
66 }
67
68 return kurl;
69 }
70
71 Playlists::PlaylistPtr
72 PodcastProvider::addPlaylist(Playlists::PlaylistPtr playlist )
73 {
74 PodcastChannelPtr channel = PodcastChannelPtr::dynamicCast( playlist );
75 if( channel.isNull() )
76 return Playlists::PlaylistPtr();
77
78 return Playlists::PlaylistPtr::dynamicCast( addChannel( channel ) );
79 }
80
81 Meta::TrackPtr
82 PodcastProvider::addTrack( const Meta::TrackPtr &track )
83 {
84 PodcastEpisodePtr episode = PodcastEpisodePtr::dynamicCast( track );
85 if( episode.isNull() )
86 return Meta::TrackPtr();
87
88 return Meta::TrackPtr::dynamicCast( addEpisode( episode ) );
89 }