Merge pull request #5193 from Chocobozzz/difm

Disable digitally imported for free user (premium account required)
This commit is contained in:
John Maguire 2016-01-11 15:10:48 +00:00
commit c4c094aa71
4 changed files with 29 additions and 42 deletions

View File

@ -53,7 +53,6 @@ DigitallyImportedServiceBase::DigitallyImportedServiceBase(
api_service_name_(api_service_name), api_service_name_(api_service_name),
network_(new NetworkAccessManager(this)), network_(new NetworkAccessManager(this)),
url_handler_(new DigitallyImportedUrlHandler(app, this)), url_handler_(new DigitallyImportedUrlHandler(app, this)),
basic_audio_type_(1),
premium_audio_type_(2), premium_audio_type_(2),
has_premium_(has_premium), has_premium_(has_premium),
root_(nullptr), root_(nullptr),
@ -66,10 +65,6 @@ DigitallyImportedServiceBase::DigitallyImportedServiceBase(
model->app()->global_search()->AddProvider( model->app()->global_search()->AddProvider(
new DigitallyImportedSearchProvider(this, app_, this)); new DigitallyImportedSearchProvider(this, app_, this));
basic_playlists_ << "http://%1/public3/%2.pls"
<< "http://%1/public1/%2.pls"
<< "http://%1/public5/%2.asx";
premium_playlists_ << "http://%1/premium_high/%2.pls?hash=%3" premium_playlists_ << "http://%1/premium_high/%2.pls?hash=%3"
<< "http://%1/premium_medium/%2.pls?hash=%3" << "http://%1/premium_medium/%2.pls?hash=%3"
<< "http://%1/premium/%2.pls?hash=%3" << "http://%1/premium/%2.pls?hash=%3"
@ -135,9 +130,8 @@ void DigitallyImportedServiceBase::PopulateStreams() {
Song song; Song song;
SongFromChannel(channel, &song); SongFromChannel(channel, &song);
QStandardItem* item = QStandardItem* item = new QStandardItem(
new QStandardItem(IconLoader::Load("icon_radio", IconLoader::Load("icon_radio", IconLoader::Lastfm), song.title());
IconLoader::Lastfm), song.title());
item->setData(channel.description_, Qt::ToolTipRole); item->setData(channel.description_, Qt::ToolTipRole);
item->setData(InternetModel::PlayBehaviour_SingleItem, item->setData(InternetModel::PlayBehaviour_SingleItem,
InternetModel::Role_PlayBehaviour); InternetModel::Role_PlayBehaviour);
@ -162,7 +156,6 @@ void DigitallyImportedServiceBase::ReloadSettings() {
QSettings s; QSettings s;
s.beginGroup(kSettingsGroup); s.beginGroup(kSettingsGroup);
basic_audio_type_ = s.value("basic_audio_type", 1).toInt();
premium_audio_type_ = s.value("premium_audio_type", 2).toInt(); premium_audio_type_ = s.value("premium_audio_type", 2).toInt();
username_ = s.value("username").toString(); username_ = s.value("username").toString();
listen_hash_ = s.value("listen_hash").toString(); listen_hash_ = s.value("listen_hash").toString();
@ -180,8 +173,8 @@ void DigitallyImportedServiceBase::ShowContextMenu(const QPoint& global_pos) {
tr("Refresh streams"), this, tr("Refresh streams"), this,
SLOT(ForceRefreshStreams())); SLOT(ForceRefreshStreams()));
context_menu_->addSeparator(); context_menu_->addSeparator();
context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base), context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base),
tr("Configure..."), this, tr("Configure..."), this,
SLOT(ShowSettingsDialog())); SLOT(ShowSettingsDialog()));
} }
@ -224,12 +217,8 @@ void DigitallyImportedServiceBase::LoadStation(const QString& key) {
// Replace "www." with "listen." in the hostname. // Replace "www." with "listen." in the hostname.
const QString host = "listen." + homepage_url_.host().remove("www."); const QString host = "listen." + homepage_url_.host().remove("www.");
if (is_premium_account()) { playlist_url = QUrl(
playlist_url = QUrl( premium_playlists_[premium_audio_type_].arg(host, key, listen_hash_));
premium_playlists_[premium_audio_type_].arg(host, key, listen_hash_));
} else {
playlist_url = QUrl(basic_playlists_[basic_audio_type_].arg(host, key));
}
qLog(Debug) << "Getting playlist URL" << playlist_url; qLog(Debug) << "Getting playlist URL" << playlist_url;
@ -241,32 +230,28 @@ void DigitallyImportedServiceBase::LoadStation(const QString& key) {
DigitallyImportedService::DigitallyImportedService(Application* app, DigitallyImportedService::DigitallyImportedService(Application* app,
InternetModel* model, InternetModel* model,
QObject* parent) QObject* parent)
: DigitallyImportedServiceBase("DigitallyImported", "Digitally Imported", : DigitallyImportedServiceBase(
QUrl("http://www.di.fm"), "DigitallyImported", "Digitally Imported", QUrl("http://www.di.fm"),
IconLoader::Load("digitallyimported", IconLoader::Load("digitallyimported", IconLoader::Provider), "di",
IconLoader::Provider), app, model, true, parent) {}
"di", app, model, true, parent) {}
RadioTunesService::RadioTunesService(Application* app, InternetModel* model, RadioTunesService::RadioTunesService(Application* app, InternetModel* model,
QObject* parent) QObject* parent)
: DigitallyImportedServiceBase("RadioTunes", "RadioTunes.com", : DigitallyImportedServiceBase(
QUrl("http://www.radiotunes.com/"), "RadioTunes", "RadioTunes.com", QUrl("http://www.radiotunes.com/"),
IconLoader::Load("radiotunes", IconLoader::Load("radiotunes", IconLoader::Provider), "radiotunes",
IconLoader::Provider), app, model, true, parent) {}
"radiotunes", app, model, true, parent) {}
JazzRadioService::JazzRadioService(Application* app, InternetModel* model, JazzRadioService::JazzRadioService(Application* app, InternetModel* model,
QObject* parent) QObject* parent)
: DigitallyImportedServiceBase("JazzRadio", "JAZZRADIO.com", : DigitallyImportedServiceBase(
QUrl("http://www.jazzradio.com"), "JazzRadio", "JAZZRADIO.com", QUrl("http://www.jazzradio.com"),
IconLoader::Load("jazzradio", IconLoader::Load("jazzradio", IconLoader::Provider), "jazzradio", app,
IconLoader::Provider), model, true, parent) {}
"jazzradio", app, model, true, parent) {}
RockRadioService::RockRadioService(Application* app, InternetModel* model, RockRadioService::RockRadioService(Application* app, InternetModel* model,
QObject* parent) QObject* parent)
: DigitallyImportedServiceBase("RockRadio", "ROCKRADIO.com", : DigitallyImportedServiceBase(
QUrl("http://www.rockradio.com"), "RockRadio", "ROCKRADIO.com", QUrl("http://www.rockradio.com"),
IconLoader::Load("rockradio", IconLoader::Load("rockradio", IconLoader::Provider), "rockradio", app,
IconLoader::Provider), model, false, parent) {}
"rockradio", app, model, false, parent) {}

View File

@ -89,13 +89,11 @@ signals:
QString service_description_; QString service_description_;
QString api_service_name_; QString api_service_name_;
QStringList basic_playlists_;
QStringList premium_playlists_; QStringList premium_playlists_;
QNetworkAccessManager* network_; QNetworkAccessManager* network_;
DigitallyImportedUrlHandler* url_handler_; DigitallyImportedUrlHandler* url_handler_;
int basic_audio_type_;
int premium_audio_type_; int premium_audio_type_;
QString username_; QString username_;
QString listen_hash_; QString listen_hash_;

View File

@ -45,9 +45,7 @@ DigitallyImportedSettingsPage::DigitallyImportedSettingsPage(
ui_->login_state->AddCredentialField(ui_->password); ui_->login_state->AddCredentialField(ui_->password);
ui_->login_state->AddCredentialGroup(ui_->credential_group); ui_->login_state->AddCredentialGroup(ui_->credential_group);
ui_->login_state->SetAccountTypeText( ui_->login_state->SetAccountTypeText(tr("A premium account is required"));
tr("You can listen for free without an account, but Premium members can "
"listen to higher quality streams without advertisements."));
ui_->login_state->SetAccountTypeVisible(true); ui_->login_state->SetAccountTypeVisible(true);
} }

View File

@ -56,6 +56,12 @@ UrlHandler::LoadResult DigitallyImportedUrlHandler::StartLoading(
return ret; return ret;
} }
if (!service_->is_premium_account()) {
service_->StreamError(tr("A premium account is required"));
ret.type_ = LoadResult::NoMoreTracks;
return ret;
}
// Start loading the station // Start loading the station
const QString key = url.host(); const QString key = url.host();
qLog(Info) << "Loading station" << key; qLog(Info) << "Loading station" << key;