~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to scripts/digitallyimported-radio/diservice.py

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import clementine
2
 
 
3
 
from servicebase import DigitallyImportedServiceBase
4
 
 
5
 
from PyQt4.QtCore    import QSettings, QUrl
6
 
from PyQt4.QtNetwork import QNetworkCookie, QNetworkCookieJar, QNetworkRequest
7
 
 
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"
15
 
 
16
 
  # These have to be in the same order as in the settings dialog
17
 
  PLAYLISTS = [
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"},
26
 
  ]
27
 
 
28
 
  def __init__(self, model):
29
 
    DigitallyImportedServiceBase.__init__(self, model)
30
 
 
31
 
  def ReloadSettings(self):
32
 
    DigitallyImportedServiceBase.ReloadSettings(self)
33
 
 
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)
44
 
 
45
 
  def LoadStation(self, key):
46
 
    playlist_url = self.PLAYLISTS[self.audio_type]["url"] % key
47
 
 
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)