Support iTunes and Zune podcast URL schemes through SongLoader
This commit is contained in:
parent
f16fc8867e
commit
2750877a72
|
@ -30,6 +30,7 @@
|
||||||
#include "playlistparsers/playlistparser.h"
|
#include "playlistparsers/playlistparser.h"
|
||||||
#include "podcasts/podcastparser.h"
|
#include "podcasts/podcastparser.h"
|
||||||
#include "podcasts/podcastservice.h"
|
#include "podcasts/podcastservice.h"
|
||||||
|
#include "podcasts/podcasturlloader.h"
|
||||||
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
@ -95,6 +96,8 @@ SongLoader::Result SongLoader::Load(const QUrl& url) {
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
url_ = PodcastUrlLoader::FixPodcastUrl(url_);
|
||||||
|
|
||||||
timeout_timer_->start(timeout_);
|
timeout_timer_->start(timeout_);
|
||||||
return LoadRemote();
|
return LoadRemote();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,25 +37,26 @@ PodcastUrlLoader::PodcastUrlLoader(QObject* parent)
|
||||||
{
|
{
|
||||||
html_link_re_.setMinimal(true);
|
html_link_re_.setMinimal(true);
|
||||||
html_link_re_.setCaseSensitivity(Qt::CaseInsensitive);
|
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() {
|
PodcastUrlLoader::~PodcastUrlLoader() {
|
||||||
delete parser_;
|
delete parser_;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl PodcastUrlLoader::FixPodcastUrl(const QString& url_text) const {
|
QUrl PodcastUrlLoader::FixPodcastUrl(const QString& url_text) {
|
||||||
QString url_text_copy(url_text.trimmed());
|
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.
|
// Check if it matches one of the quick prefixes.
|
||||||
for (QuickPrefixList::const_iterator it = quick_prefixes_.constBegin() ;
|
for (QuickPrefixList::const_iterator it = quick_prefixes.constBegin() ;
|
||||||
it != quick_prefixes_.constEnd() ; ++it) {
|
it != quick_prefixes.constEnd() ; ++it) {
|
||||||
if (url_text_copy.startsWith(it->first)) {
|
if (url_text_copy.startsWith(it->first)) {
|
||||||
url_text_copy = it->second.arg(url_text_copy.mid(it->first.length()));
|
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://");
|
url_text_copy.prepend("http://");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return FixPodcastUrl(QUrl(url_text_copy));
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl PodcastUrlLoader::FixPodcastUrl(const QUrl& url_orig) {
|
||||||
|
QUrl url(url_orig);
|
||||||
|
|
||||||
// Replace schemes
|
// Replace schemes
|
||||||
QUrl url(url_text_copy);
|
|
||||||
if (url.scheme().isEmpty() || url.scheme() == "feed" ||
|
if (url.scheme().isEmpty() || url.scheme() == "feed" ||
|
||||||
url.scheme() == "itpc" || url.scheme() == "itms") {
|
url.scheme() == "itpc" || url.scheme() == "itms") {
|
||||||
url.setScheme("http");
|
url.setScheme("http");
|
||||||
|
|
|
@ -79,6 +79,13 @@ public:
|
||||||
PodcastUrlLoaderReply* Load(const QString& url_text);
|
PodcastUrlLoaderReply* Load(const QString& url_text);
|
||||||
PodcastUrlLoaderReply* Load(const QUrl& url);
|
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:
|
private:
|
||||||
struct RequestState {
|
struct RequestState {
|
||||||
int redirects_remaining_;
|
int redirects_remaining_;
|
||||||
|
@ -92,7 +99,6 @@ private slots:
|
||||||
void RequestFinished(RequestState* state, QNetworkReply* reply);
|
void RequestFinished(RequestState* state, QNetworkReply* reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl FixPodcastUrl(const QString& url_text) const;
|
|
||||||
void SendErrorAndDelete(const QString& error_text, RequestState* state);
|
void SendErrorAndDelete(const QString& error_text, RequestState* state);
|
||||||
void NextRequest(const QUrl& url, RequestState* state);
|
void NextRequest(const QUrl& url, RequestState* state);
|
||||||
|
|
||||||
|
@ -100,8 +106,6 @@ private:
|
||||||
QNetworkAccessManager* network_;
|
QNetworkAccessManager* network_;
|
||||||
PodcastParser* parser_;
|
PodcastParser* parser_;
|
||||||
|
|
||||||
QuickPrefixList quick_prefixes_;
|
|
||||||
|
|
||||||
QRegExp html_link_re_;
|
QRegExp html_link_re_;
|
||||||
QRegExp whitespace_re_;
|
QRegExp whitespace_re_;
|
||||||
QRegExp html_link_rel_re_;
|
QRegExp html_link_rel_re_;
|
||||||
|
|
Loading…
Reference in New Issue