mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-28 01:59:24 +01:00
Support sky.fm as well
This commit is contained in:
parent
52550acb75
commit
b31c118256
@ -1,11 +0,0 @@
|
||||
# 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"},
|
||||
]
|
51
scripts/digitallyimported-radio/diservice.py
Normal file
51
scripts/digitallyimported-radio/diservice.py
Normal file
@ -0,0 +1,51 @@
|
||||
import clementine
|
||||
|
||||
from servicebase import DigitallyImportedServiceBase
|
||||
|
||||
from PyQt4.QtCore import QSettings, QUrl
|
||||
from PyQt4.QtNetwork import QNetworkCookie, QNetworkCookieJar
|
||||
|
||||
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)
|
BIN
scripts/digitallyimported-radio/icon-sky.png
Normal file
BIN
scripts/digitallyimported-radio/icon-sky.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 864 B |
Binary file not shown.
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 6.3 KiB |
@ -1,4 +1,5 @@
|
||||
from service import DigitallyImportedService
|
||||
from diservice import DigitallyImportedService
|
||||
from skyservice import SkyFmService
|
||||
from settingsdialog import SettingsDialog
|
||||
|
||||
import clementine
|
||||
@ -7,21 +8,25 @@ class Plugin:
|
||||
def __init__(self):
|
||||
self.settings_dialog = None
|
||||
|
||||
# Create the service and add it to the Internet tab
|
||||
self.service = DigitallyImportedService(clementine.radio_model)
|
||||
clementine.radio_model.AddService(self.service)
|
||||
# Create the services and add them to the Internet tab
|
||||
self.di_service = DigitallyImportedService(clementine.radio_model)
|
||||
self.sky_service = SkyFmService(clementine.radio_model)
|
||||
clementine.radio_model.AddService(self.di_service)
|
||||
clementine.radio_model.AddService(self.sky_service)
|
||||
|
||||
# Register for when the user clicks the Settings button
|
||||
script.SettingsDialogRequested.connect(self.ShowSettings)
|
||||
|
||||
# Register for the "Configure..." right click menu item
|
||||
self.service.SettingsDialogRequested.connect(self.ShowSettings)
|
||||
# Register for the "Configure..." right click menu items
|
||||
self.di_service.SettingsDialogRequested.connect(self.ShowSettings)
|
||||
self.sky_service.SettingsDialogRequested.connect(self.ShowSettings)
|
||||
|
||||
def ShowSettings(self):
|
||||
if not self.settings_dialog:
|
||||
# Create the dialog the first time it's shown
|
||||
self.settings_dialog = SettingsDialog()
|
||||
self.settings_dialog.accepted.connect(self.service.ReloadSettings)
|
||||
self.settings_dialog.accepted.connect(self.di_service.ReloadSettings)
|
||||
self.settings_dialog.accepted.connect(self.sky_service.ReloadSettings)
|
||||
|
||||
self.settings_dialog.show()
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Script]
|
||||
name=Digitally Imported internet radio
|
||||
description=Digitally Imported is a multi-channel Internet radio service specializing in Electronic Dance Music genres. Installing this plugin will add the list of Digitally Imported radio stations to your Internet tab.
|
||||
name=Digitally Imported and SKY.fm
|
||||
description=Digitally Imported and SKY.fm are sister sites offering a variety of internet radio stations. Installing this plugin will add Digitally Imported and SKY.fm radio stations to your Internet tab.
|
||||
author=David Sansome <me@davidsansome.com>
|
||||
url=http://www.di.fm
|
||||
icon=icon.png
|
||||
|
@ -1,21 +1,26 @@
|
||||
import common
|
||||
|
||||
import clementine
|
||||
|
||||
from PyQt4.QtCore import QSettings, QUrl
|
||||
from PyQt4.QtGui import QAction, QDesktopServices, QIcon, QMenu, \
|
||||
QStandardItem
|
||||
from PyQt4.QtNetwork import QNetworkCookie, QNetworkCookieJar, QNetworkRequest
|
||||
from PyQt4.QtNetwork import QNetworkRequest
|
||||
import PyQt4.QtCore
|
||||
|
||||
import json
|
||||
import operator
|
||||
import os.path
|
||||
|
||||
class DigitallyImportedService(clementine.RadioService):
|
||||
SERVICE_NAME = "digitally_imported"
|
||||
HOMEPAGE_URL = QUrl("http://www.di.fm/")
|
||||
STREAM_LIST_URL = QUrl("http://listen.di.fm/")
|
||||
class DigitallyImportedServiceBase(clementine.RadioService):
|
||||
# Set these in subclasses
|
||||
HOMEPAGE_URL = None
|
||||
HOMEPAGE_NAME = None
|
||||
STREAM_LIST_URL = None
|
||||
ICON_FILENAME = None
|
||||
SERVICE_NAME = None
|
||||
SERVICE_DESCRIPTION = None
|
||||
PLAYLISTS = []
|
||||
|
||||
SETTINGS_GROUP = "digitally_imported"
|
||||
|
||||
SettingsDialogRequested = PyQt4.QtCore.pyqtSignal()
|
||||
|
||||
@ -26,39 +31,28 @@ class DigitallyImportedService(clementine.RadioService):
|
||||
self.path = os.path.dirname(__file__)
|
||||
|
||||
self.audio_type = 0
|
||||
self.username = ""
|
||||
self.password = ""
|
||||
|
||||
self.context_index = None
|
||||
self.last_original_url = None
|
||||
self.menu = None
|
||||
self.root = None
|
||||
self.song_loader = None
|
||||
self.task_id = None
|
||||
|
||||
self.ReloadSettings()
|
||||
|
||||
def ReloadSettings(self):
|
||||
settings = QSettings()
|
||||
settings.beginGroup(self.SERVICE_NAME)
|
||||
settings.beginGroup(self.SETTINGS_GROUP)
|
||||
|
||||
self.audio_type = int(settings.value("audio_type", 0).toPyObject())
|
||||
username = unicode(settings.value("username", "").toPyObject().toUtf8())
|
||||
password = unicode(settings.value("password", "").toPyObject().toUtf8())
|
||||
|
||||
# If a username and password were set by the user then set them in the
|
||||
# cookies we pass to www.di.fm
|
||||
cookie_jar = None
|
||||
if len(username) and len(password):
|
||||
cookie_jar = QNetworkCookieJar()
|
||||
cookie_jar.setCookiesFromUrl([
|
||||
QNetworkCookie("_amember_ru", username),
|
||||
QNetworkCookie("_amember_rp", password),
|
||||
], QUrl("http://www.di.fm/"))
|
||||
|
||||
self.network.setCookieJar(cookie_jar)
|
||||
self.username = unicode(settings.value("username", "").toPyObject().toUtf8())
|
||||
self.password = unicode(settings.value("password", "").toPyObject().toUtf8())
|
||||
|
||||
def CreateRootItem(self):
|
||||
self.root = QStandardItem(QIcon(os.path.join(self.path, "icon-small.png")),
|
||||
"Digitally Imported")
|
||||
self.root = QStandardItem(QIcon(os.path.join(self.path, self.ICON_FILENAME)),
|
||||
self.SERVICE_DESCRIPTION)
|
||||
self.root.setData(True, clementine.RadioModel.Role_CanLazyLoad)
|
||||
return self.root
|
||||
|
||||
@ -78,14 +72,14 @@ class DigitallyImportedService(clementine.RadioService):
|
||||
self.menu.addSeparator()
|
||||
|
||||
self.menu.addAction(clementine.IconLoader.Load("download"),
|
||||
self.tr("Open www.di.fm in browser"), self.Homepage)
|
||||
self.tr("Open " + self.HOMEPAGE_NAME + " in browser"), self.Homepage)
|
||||
self.menu.addAction(clementine.IconLoader.Load("view-refresh"),
|
||||
self.tr("Refresh streams"), self.RefreshStreams)
|
||||
|
||||
self.menu.addSeparator()
|
||||
|
||||
self.menu.addAction(clementine.IconLoader.Load("configure"),
|
||||
self.tr("Configure Digitally Imported..."), self.SettingsDialogRequested.emit)
|
||||
self.tr("Configure..."), self.SettingsDialogRequested.emit)
|
||||
|
||||
self.context_index = index
|
||||
self.menu.popup(global_pos)
|
||||
@ -140,7 +134,7 @@ class DigitallyImportedService(clementine.RadioService):
|
||||
item.setData("digitallyimported://%s" % stream["key"], clementine.RadioModel.Role_Url)
|
||||
item.setData(clementine.RadioModel.PlayBehaviour_SingleItem, clementine.RadioModel.Role_PlayBehaviour)
|
||||
item.setData(stream["name"], clementine.RadioModel.Role_Title)
|
||||
item.setData("Digitally Imported", clementine.RadioModel.Role_Artist)
|
||||
item.setData(self.SERVICE_DESCRIPTION, clementine.RadioModel.Role_Artist)
|
||||
self.root.appendRow(item)
|
||||
|
||||
def playlistitem_options(self):
|
||||
@ -155,14 +149,13 @@ class DigitallyImportedService(clementine.RadioService):
|
||||
return result
|
||||
if original_url.scheme() != "digitallyimported":
|
||||
return result
|
||||
if self.PLAYLISTS[self.audio_type]["premium"] and \
|
||||
(len(self.username) == 0 or len(self.password) == 0):
|
||||
self.StreamError.emit(self.tr("You have selected a Premium-only audio type but do not have any account details entered"))
|
||||
return result
|
||||
|
||||
key = original_url.host()
|
||||
playlist_url = common.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)
|
||||
self.LoadStation(key)
|
||||
|
||||
# Save the original URL so we can emit it in the finished signal later
|
||||
self.last_original_url = original_url
|
||||
@ -174,6 +167,9 @@ class DigitallyImportedService(clementine.RadioService):
|
||||
result.original_url_ = original_url
|
||||
return result
|
||||
|
||||
def LoadStation(self, key):
|
||||
raise NotImplementedError()
|
||||
|
||||
def LoadPlaylistFinished(self):
|
||||
# Get the QNetworkReply that called this slot
|
||||
reply = self.sender()
|
||||
@ -192,7 +188,7 @@ class DigitallyImportedService(clementine.RadioService):
|
||||
|
||||
# Failed to get the playlist?
|
||||
if len(songs) == 0:
|
||||
self.StreamError.emit("Error loading playlist '%s'" % self.song_loader.url().toString())
|
||||
self.StreamError.emit("Error loading playlist '%s'" % reply.url().toString())
|
||||
return
|
||||
|
||||
result = clementine.PlaylistItem.SpecialLoadResult()
|
@ -1,4 +1,4 @@
|
||||
from service import DigitallyImportedService
|
||||
from servicebase import DigitallyImportedServiceBase
|
||||
|
||||
from PyQt4.QtCore import QSettings
|
||||
from PyQt4.QtGui import QDialog, QIcon
|
||||
@ -21,7 +21,7 @@ class SettingsDialog(QDialog):
|
||||
def showEvent(self, event):
|
||||
# Load the settings
|
||||
settings = QSettings()
|
||||
settings.beginGroup(DigitallyImportedService.SERVICE_NAME)
|
||||
settings.beginGroup(DigitallyImportedServiceBase.SETTINGS_GROUP)
|
||||
self.type.setCurrentIndex(int(settings.value("audio_type", 0).toPyObject()))
|
||||
self.username.setText(settings.value("username", "").toPyObject())
|
||||
self.password.setText(settings.value("password", "").toPyObject())
|
||||
@ -31,7 +31,7 @@ class SettingsDialog(QDialog):
|
||||
def accept(self):
|
||||
# Save the settings
|
||||
settings = QSettings()
|
||||
settings.beginGroup(DigitallyImportedService.SERVICE_NAME)
|
||||
settings.beginGroup(DigitallyImportedServiceBase.SETTINGS_GROUP)
|
||||
settings.setValue("audio_type", self.type.currentIndex())
|
||||
settings.setValue("username", self.username.text())
|
||||
settings.setValue("password", self.password.text())
|
||||
|
85
scripts/digitallyimported-radio/skyservice.py
Normal file
85
scripts/digitallyimported-radio/skyservice.py
Normal file
@ -0,0 +1,85 @@
|
||||
import clementine
|
||||
|
||||
from servicebase import DigitallyImportedServiceBase
|
||||
|
||||
from PyQt4.QtCore import QSettings, QString, QUrl
|
||||
from PyQt4.QtNetwork import QNetworkCookie, QNetworkCookieJar, QNetworkRequest
|
||||
|
||||
import re
|
||||
|
||||
class SkyFmService(DigitallyImportedServiceBase):
|
||||
HOMEPAGE_URL = QUrl("http://www.sky.fm/")
|
||||
HOMEPAGE_NAME = "sky.fm"
|
||||
STREAM_LIST_URL = QUrl("http://listen.sky.fm/")
|
||||
ICON_FILENAME = "icon-sky.png"
|
||||
SERVICE_NAME = "sky_fm"
|
||||
SERVICE_DESCRIPTION = "SKY.fm"
|
||||
|
||||
HASHKEY_RE = re.compile(r'hashKey\s*=\s*\'([0-9a-f]+)\'')
|
||||
|
||||
# These have to be in the same order as in the settings dialog
|
||||
PLAYLISTS = [
|
||||
{"premium": False, "url": "http://listen.sky.fm/public3/%s.pls"},
|
||||
{"premium": True, "url": "http://listen.sky.fm/premium_high/%s.pls?hash=%s"},
|
||||
{"premium": False, "url": "http://listen.sky.fm/public1/%s.pls"},
|
||||
{"premium": True, "url": "http://listen.sky.fm/premium_medium/%s.pls?hash=%s"},
|
||||
{"premium": True, "url": "http://listen.sky.fm/premium/%s.pls?hash=%s"},
|
||||
{"premium": False, "url": "http://listen.sky.fm/public5/%s.asx"},
|
||||
{"premium": True, "url": "http://listen.sky.fm/premium_wma_low/%s.asx?hash=%s"},
|
||||
{"premium": True, "url": "http://listen.sky.fm/premium_wma/%s.asx?hash=%s"},
|
||||
]
|
||||
|
||||
def __init__(self, model):
|
||||
DigitallyImportedServiceBase.__init__(self, model)
|
||||
|
||||
self.last_key = None
|
||||
|
||||
def LoadStation(self, key):
|
||||
# Non-premium streams can just start loading straight away
|
||||
if not self.PLAYLISTS[self.audio_type]["premium"]:
|
||||
self.LoadPlaylist(key)
|
||||
return
|
||||
|
||||
# Otherwise we have to get the user's hashKey
|
||||
request = QNetworkRequest(QUrl("http://www.sky.fm/configure_player.php"))
|
||||
postdata = "amember_login=%s&amember_pass=%s" % (
|
||||
QUrl.toPercentEncoding(self.username),
|
||||
QUrl.toPercentEncoding(self.password))
|
||||
|
||||
reply = self.network.post(request, postdata)
|
||||
reply.finished.connect(self.LoadHashKeyFinished)
|
||||
|
||||
self.last_key = key
|
||||
|
||||
def LoadHashKeyFinished(self):
|
||||
# Get the QNetworkReply that called this slot
|
||||
reply = self.sender()
|
||||
reply.deleteLater()
|
||||
|
||||
# Parse the hashKey out of the reply
|
||||
data = QString.fromUtf8(reply.readAll())
|
||||
match = self.HASHKEY_RE.search(data)
|
||||
|
||||
if match:
|
||||
hash_key = match.group(1)
|
||||
else:
|
||||
clementine.task_manager.SetTaskFinished(self.task_id)
|
||||
self.task_id = None
|
||||
self.StreamError.emit(self.tr("Invalid SKY.fm username or password"))
|
||||
return
|
||||
|
||||
# Now we can load the playlist
|
||||
self.LoadPlaylist(self.last_key, hash_key)
|
||||
|
||||
def LoadPlaylist(self, key, hash_key=None):
|
||||
playlist_url = self.PLAYLISTS[self.audio_type]["url"]
|
||||
|
||||
if hash_key:
|
||||
playlist_url = playlist_url % (key, hash_key)
|
||||
else:
|
||||
playlist_url = playlist_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)
|
Loading…
x
Reference in New Issue
Block a user