1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-28 02:21:14 +01:00
Clementine-audio-player-Mac.../scripts/digitallyimported-radio/diservice.py

52 lines
2.1 KiB
Python
Raw Normal View History

2011-01-15 16:48:09 +01:00
import clementine
from servicebase import DigitallyImportedServiceBase
from PyQt4.QtCore import QSettings, QUrl
2011-01-15 18:17:37 +01:00
from PyQt4.QtNetwork import QNetworkCookie, QNetworkCookieJar, QNetworkRequest
2011-01-15 16:48:09 +01:00
class DigitallyImportedService(DigitallyImportedServiceBase):
HOMEPAGE_URL = QUrl("http://www.di.fm/")
HOMEPAGE_NAME = "di.fm"
STREAM_LIST_URL = QUrl("http://listen.di.fm/")
ICON_FILENAME = "icon-small.png"
SERVICE_NAME = "digitally_imported"
SERVICE_DESCRIPTION = "Digitally Imported"
# These have to be in the same order as in the settings dialog
PLAYLISTS = [
{"premium": False, "url": "http://listen.di.fm/public3/%s.pls"},
{"premium": True, "url": "http://www.di.fm/listen/%s/premium.pls"},
{"premium": False, "url": "http://listen.di.fm/public2/%s.pls"},
{"premium": True, "url": "http://www.di.fm/listen/%s/64k.pls"},
{"premium": True, "url": "http://www.di.fm/listen/%s/128k.pls"},
{"premium": False, "url": "http://listen.di.fm/public5/%s.asx"},
{"premium": True, "url": "http://www.di.fm/listen/%s/64k.asx"},
{"premium": True, "url": "http://www.di.fm/listen/%s/128k.asx"},
]
def __init__(self, model):
DigitallyImportedServiceBase.__init__(self, model)
def ReloadSettings(self):
DigitallyImportedServiceBase.ReloadSettings(self)
# If a username and password were set by the user then set them in the
# cookies we pass to www.di.fm
self.network = clementine.NetworkAccessManager(self)
if len(self.username) and len(self.password):
cookie_jar = QNetworkCookieJar()
cookie_jar.setCookiesFromUrl([
QNetworkCookie("_amember_ru", self.username),
QNetworkCookie("_amember_rp", self.password),
], QUrl("http://www.di.fm/"))
self.network.setCookieJar(cookie_jar)
def LoadStation(self, key):
playlist_url = self.PLAYLISTS[self.audio_type]["url"] % key
# Start fetching the playlist. Can't use a SongLoader to do this because
# we have to use the cookies we set in ReloadSettings()
reply = self.network.get(QNetworkRequest(QUrl(playlist_url)))
reply.finished.connect(self.LoadPlaylistFinished)