3
from servicebase import DigitallyImportedServiceBase
5
from PyQt4.QtCore import QSettings, QUrl
6
from PyQt4.QtNetwork import QNetworkCookie, QNetworkCookieJar, QNetworkRequest
8
class DigitallyImportedService(DigitallyImportedServiceBase):
9
HOMEPAGE_URL = QUrl("http://www.di.fm/")
10
HOMEPAGE_NAME = "di.fm"
11
STREAM_LIST_URL = QUrl("http://listen.di.fm/")
12
ICON_FILENAME = "icon-small.png"
13
SERVICE_NAME = "DigitallyImported"
14
SERVICE_DESCRIPTION = "Digitally Imported"
16
# These have to be in the same order as in the settings dialog
18
{"premium": False, "url": "http://listen.di.fm/public3/%s.pls"},
19
{"premium": True, "url": "http://www.di.fm/listen/%s/premium.pls"},
20
{"premium": False, "url": "http://listen.di.fm/public2/%s.pls"},
21
{"premium": True, "url": "http://www.di.fm/listen/%s/64k.pls"},
22
{"premium": True, "url": "http://www.di.fm/listen/%s/128k.pls"},
23
{"premium": False, "url": "http://listen.di.fm/public5/%s.asx"},
24
{"premium": True, "url": "http://www.di.fm/listen/%s/64k.asx"},
25
{"premium": True, "url": "http://www.di.fm/listen/%s/128k.asx"},
28
def __init__(self, model):
29
DigitallyImportedServiceBase.__init__(self, model)
31
def ReloadSettings(self):
32
DigitallyImportedServiceBase.ReloadSettings(self)
34
# If a username and password were set by the user then set them in the
35
# cookies we pass to www.di.fm
36
self.network = clementine.NetworkAccessManager(self)
37
if len(self.username) and len(self.password):
38
cookie_jar = QNetworkCookieJar()
39
cookie_jar.setCookiesFromUrl([
40
QNetworkCookie("_amember_ru", self.username),
41
QNetworkCookie("_amember_rp", self.password),
42
], QUrl("http://www.di.fm/"))
43
self.network.setCookieJar(cookie_jar)
45
def LoadStation(self, key):
46
playlist_url = self.PLAYLISTS[self.audio_type]["url"] % key
48
# Start fetching the playlist. Can't use a SongLoader to do this because
49
# we have to use the cookies we set in ReloadSettings()
50
reply = self.network.get(QNetworkRequest(QUrl(playlist_url)))
51
reply.finished.connect(self.LoadPlaylistFinished)