diff --git a/scripts/digitallyimported-radio/diservice.py b/scripts/digitallyimported-radio/diservice.py index 7429212ad..1a5b2d73a 100644 --- a/scripts/digitallyimported-radio/diservice.py +++ b/scripts/digitallyimported-radio/diservice.py @@ -5,6 +5,11 @@ from servicebase import DigitallyImportedServiceBase from PythonQt.QtCore import QSettings, QUrl from PythonQt.QtNetwork import QNetworkCookie, QNetworkCookieJar, QNetworkRequest +import logging + +LOGGER = logging.getLogger("di.service") + + class DigitallyImportedService(DigitallyImportedServiceBase): HOMEPAGE_URL = QUrl("http://www.di.fm/") HOMEPAGE_NAME = "di.fm" @@ -29,8 +34,15 @@ class DigitallyImportedService(DigitallyImportedServiceBase): def __init__(self, model, settings_dialog_callback): DigitallyImportedServiceBase.Init(self, model, settings_dialog_callback) - def ReloadSettings(self): - DigitallyImportedServiceBase.ReloadSettings(self) + self.last_username_password = None + self.MaybeReloadCookies() + + def MaybeReloadCookies(self): + if self.last_username_password == (self.username, self.password): + return + self.last_username_password = (self.username, self.password) + + LOGGER.debug("Setting network cookies after config change") # If a username and password were set by the user then set them in the # cookies we pass to www.di.fm @@ -38,14 +50,17 @@ class DigitallyImportedService(DigitallyImportedServiceBase): if len(self.username) and len(self.password): cookie_jar = QNetworkCookieJar() cookie_jar.setCookiesFromUrl([ - QNetworkCookie("_amember_ru", self.username), - QNetworkCookie("_amember_rp", self.password), + QNetworkCookie("_amember_ru", self.username.encode("utf-8")), + QNetworkCookie("_amember_rp", self.password.encode("utf-8")), ], QUrl("http://www.di.fm/")) self.network.setCookieJar(cookie_jar) def LoadStation(self, key): + self.MaybeReloadCookies() playlist_url = self.PLAYLISTS[self.audio_type]["url"] % key + LOGGER.info("Getting playlist URL '%s'" % playlist_url) + # Start fetching the playlist. Can't use a SongLoader to do this because # we have to use the cookies we set in ReloadSettings() self.load_station_reply = self.network.get(QNetworkRequest(QUrl(playlist_url))) diff --git a/scripts/digitallyimported-radio/settingsdialog.py b/scripts/digitallyimported-radio/settingsdialog.py index e17af8e36..e4cf2e1fc 100644 --- a/scripts/digitallyimported-radio/settingsdialog.py +++ b/scripts/digitallyimported-radio/settingsdialog.py @@ -26,7 +26,7 @@ class SettingsDialog(QDialog): self.username.setText(settings.value("username", "")) self.password.setText(settings.value("password", "")) - QDialog.showEvent(self, event) + #QDialog.showEvent(self, event) def accept(self): # Save the settings diff --git a/scripts/digitallyimported-radio/skyservice.py b/scripts/digitallyimported-radio/skyservice.py index e81de7e04..e9b2ed7f8 100644 --- a/scripts/digitallyimported-radio/skyservice.py +++ b/scripts/digitallyimported-radio/skyservice.py @@ -34,6 +34,7 @@ class SkyFmService(DigitallyImportedServiceBase): DigitallyImportedServiceBase.Init(self, model, settings_dialog_callback) self.last_key = None + self.load_station_reply = None def LoadStation(self, key): # Non-premium streams can just start loading straight away @@ -47,19 +48,19 @@ class SkyFmService(DigitallyImportedServiceBase): QUrl.toPercentEncoding(self.username), QUrl.toPercentEncoding(self.password)) - reply = self.network.post(request, postdata) - reply.connect("finished()", self.LoadHashKeyFinished) + self.load_station_reply = self.network.post(request, postdata) + self.load_station_reply.connect("finished()", self.LoadHashKeyFinished) self.last_key = key def LoadHashKeyFinished(self): - # Get the QNetworkReply that called this slot - reply = self.sender() - reply.deleteLater() + if self.load_station_reply is None: + return # Parse the hashKey out of the reply - data = reply.readAll() + data = self.load_station_reply.readAll().data() match = self.HASHKEY_RE.search(data) + self.load_station_reply = None if match: hash_key = match.group(1) diff --git a/src/main.cpp b/src/main.cpp index 21d4890fa..c609588ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,6 +59,7 @@ #include #include +#include #include #include #include @@ -215,6 +216,8 @@ int main(int argc, char *argv[]) { qRegisterMetaType("smart_playlists::GeneratorPtr"); qRegisterMetaType("ColumnAlignmentMap"); qRegisterMetaTypeStreamOperators >("ColumnAlignmentMap"); + qRegisterMetaType("QNetworkCookie"); + qRegisterMetaType >("QList"); qRegisterMetaType("GstBuffer*"); qRegisterMetaType("GstElement*"); diff --git a/src/scripting/python/pythonengine.cpp b/src/scripting/python/pythonengine.cpp index 25374a7f0..f5a367ec9 100644 --- a/src/scripting/python/pythonengine.cpp +++ b/src/scripting/python/pythonengine.cpp @@ -43,6 +43,7 @@ #include #include +#include #include Q_DECLARE_METATYPE(QModelIndex) @@ -126,6 +127,7 @@ bool PythonEngine::EnsureInitialised() { RegisterListConverter("QList"); RegisterListConverter("QList"); RegisterListConverter("QList"); + RegisterListConverter("QList"); // Connect stdout, stderr connect(python_qt, SIGNAL(pythonStdOut(QString)), SLOT(PythonStdOut(QString)));