1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Support iTunes and Zune podcast URL schemes through SongLoader

This commit is contained in:
David Sansome 2012-03-11 18:14:53 +00:00
parent f16fc8867e
commit 2750877a72
3 changed files with 27 additions and 14 deletions

View File

@ -30,6 +30,7 @@
#include "playlistparsers/playlistparser.h"
#include "podcasts/podcastparser.h"
#include "podcasts/podcastservice.h"
#include "podcasts/podcasturlloader.h"
#include <QBuffer>
#include <QDirIterator>
@ -95,6 +96,8 @@ SongLoader::Result SongLoader::Load(const QUrl& url) {
return Success;
}
url_ = PodcastUrlLoader::FixPodcastUrl(url_);
timeout_timer_->start(timeout_);
return LoadRemote();
}

View File

@ -37,25 +37,26 @@ PodcastUrlLoader::PodcastUrlLoader(QObject* parent)
{
html_link_re_.setMinimal(true);
html_link_re_.setCaseSensitivity(Qt::CaseInsensitive);
// Thanks gpodder!
quick_prefixes_ << QuickPrefix("fb:", "http://feeds.feedburner.com/%1")
<< QuickPrefix("yt:", "http://www.youtube.com/rss/user/%1/videos.rss")
<< QuickPrefix("sc:", "http://soundcloud.com/%1")
<< QuickPrefix("fm4od:", "http://onapp1.orf.at/webcam/fm4/fod/%1.xspf")
<< QuickPrefix("ytpl:", "http://gdata.youtube.com/feeds/api/playlists/%1");
}
PodcastUrlLoader::~PodcastUrlLoader() {
delete parser_;
}
QUrl PodcastUrlLoader::FixPodcastUrl(const QString& url_text) const {
QUrl PodcastUrlLoader::FixPodcastUrl(const QString& url_text) {
QString url_text_copy(url_text.trimmed());
// Thanks gpodder!
static QuickPrefixList quick_prefixes = QuickPrefixList()
<< QuickPrefix("fb:", "http://feeds.feedburner.com/%1")
<< QuickPrefix("yt:", "http://www.youtube.com/rss/user/%1/videos.rss")
<< QuickPrefix("sc:", "http://soundcloud.com/%1")
<< QuickPrefix("fm4od:", "http://onapp1.orf.at/webcam/fm4/fod/%1.xspf")
<< QuickPrefix("ytpl:", "http://gdata.youtube.com/feeds/api/playlists/%1");
// Check if it matches one of the quick prefixes.
for (QuickPrefixList::const_iterator it = quick_prefixes_.constBegin() ;
it != quick_prefixes_.constEnd() ; ++it) {
for (QuickPrefixList::const_iterator it = quick_prefixes.constBegin() ;
it != quick_prefixes.constEnd() ; ++it) {
if (url_text_copy.startsWith(it->first)) {
url_text_copy = it->second.arg(url_text_copy.mid(it->first.length()));
}
@ -65,8 +66,13 @@ QUrl PodcastUrlLoader::FixPodcastUrl(const QString& url_text) const {
url_text_copy.prepend("http://");
}
return FixPodcastUrl(QUrl(url_text_copy));
}
QUrl PodcastUrlLoader::FixPodcastUrl(const QUrl& url_orig) {
QUrl url(url_orig);
// Replace schemes
QUrl url(url_text_copy);
if (url.scheme().isEmpty() || url.scheme() == "feed" ||
url.scheme() == "itpc" || url.scheme() == "itms") {
url.setScheme("http");

View File

@ -79,6 +79,13 @@ public:
PodcastUrlLoaderReply* Load(const QString& url_text);
PodcastUrlLoaderReply* Load(const QUrl& url);
// Both the FixPodcastUrl functions replace common podcatcher URL schemes
// like itpc:// or zune:// with their http:// equivalents. The QString
// overload also cleans up user-entered text a bit - stripping whitespace and
// applying shortcuts like sc:tag.
static QUrl FixPodcastUrl(const QString& url_text);
static QUrl FixPodcastUrl(const QUrl& url);
private:
struct RequestState {
int redirects_remaining_;
@ -92,7 +99,6 @@ private slots:
void RequestFinished(RequestState* state, QNetworkReply* reply);
private:
QUrl FixPodcastUrl(const QString& url_text) const;
void SendErrorAndDelete(const QString& error_text, RequestState* state);
void NextRequest(const QUrl& url, RequestState* state);
@ -100,8 +106,6 @@ private:
QNetworkAccessManager* network_;
PodcastParser* parser_;
QuickPrefixList quick_prefixes_;
QRegExp html_link_re_;
QRegExp whitespace_re_;
QRegExp html_link_rel_re_;