Skip to content

Commit

Permalink
settings: simplify stream key handling
Browse files Browse the repository at this point in the history
The specification of valid stream keys in settings.json was
previously defined for each network. During early development
there had been differences between quality settings and the
associated stream keys. These differences could be now unified
and thus it isn't needed anymore to specify the mapping between
quality_key and stream_key for each network separately.

The implementation in settings.py has been modified with the goal
to keep other parts of the code untouched. Therefore the streams
definition is now given to the network class.

This also leaves the possibility to react on future changes of
the mapping between quality_key and stream_key in the AudioAddict
API to go back to a more differentiated specification if needed
without touching too much code.
  • Loading branch information
ssapalski committed Jun 23, 2017
1 parent fd85519 commit 9225dc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
34 changes: 9 additions & 25 deletions resources/data/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,30 @@
"stream_url": {
"user_agent": "Mozilla/5.0"
},
"streams": {
"public": {"low": "android_low", "moderate": "android"},
"premium": {"low": "premium_low", "moderate": "premium", "medium": "premium_medium", "high": "premium_high"}
},
"networks": {
"di": {
"domain": "di.fm",
"display_name": "DigitallyImported",
"streams": {
"public": {"low": "android_low", "moderate": "android"},
"premium": {"low": "premium_low", "moderate": "premium", "medium": "premium_medium", "high": "premium_high"}
}
"display_name": "DigitallyImported"
},
"radiotunes": {
"domain": "radiotunes.com",
"display_name": "RadioTunes",
"streams": {
"public": {"low": "android_low", "moderate": "android"},
"premium": {"low": "premium_low", "moderate": "premium", "medium": "premium_medium", "high": "premium_high"}
}
"display_name": "RadioTunes"
},
"rockradio": {
"domain": "rockradio.com",
"display_name": "RockRadio",
"streams": {
"public": {"low": "android_low", "moderate": "android"},
"premium": {"low": "premium_low", "moderate": "premium", "medium": "premium_medium", "high": "premium_high"}
}
"display_name": "RockRadio"
},
"jazzradio": {
"domain": "jazzradio.com",
"display_name": "JazzRadio",
"streams": {
"public": {"low": "android_low", "moderate": "android"},
"premium": {"low": "premium_low", "moderate": "premium", "medium": "premium_medium", "high": "premium_high"}
}
"display_name": "JazzRadio"
},
"classicalradio": {
"domain": "classicalradio.com",
"display_name": "ClassicalRadio",
"streams": {
"public": {"low": "android_low", "moderate": "android"},
"premium": {"low": "premium_low", "moderate": "premium", "medium": "premium_medium", "high": "premium_high"}
}
"display_name": "ClassicalRadio"
}
},
"network_order": ["di", "radiotunes", "rockradio", "jazzradio", "classicalradio"]
Expand Down
13 changes: 7 additions & 6 deletions resources/lib/audioaddict/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def user_agent(self):

def get_network(self, network_key):
return NetworkSettings(network_key,
self._settings['networks'][network_key])
self._settings['networks'][network_key],
self._settings['streams'])

@property
def networks(self):
Expand All @@ -45,8 +46,10 @@ def networks(self):


class NetworkSettings(object):
def __init__(self, key, network):
def __init__(self, key, network, streams):
self._network = network
self._streams = streams

self.key = key

@property
Expand All @@ -62,11 +65,9 @@ def referer(self):
return "http://www.%s/" % self.domain

def get_stream_key(self, quality_key, premium=False):
streams = self._network['streams']

if premium:
stream_key = streams['premium'][quality_key]
stream_key = self._streams['premium'][quality_key]
else:
stream_key = streams['public'][quality_key]
stream_key = self._streams['public'][quality_key]

return stream_key

0 comments on commit 9225dc3

Please sign in to comment.