Skip to content

Commit 8d879b2

Browse files
committed
Prefer HTTP streams setting + py2.6 fixes
1 parent c5d5888 commit 8d879b2

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

resources/language/English/strings.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,7 @@ msgstr ""
139139
msgctxt "#30606"
140140
msgid "By country"
141141
msgstr ""
142+
143+
msgctxt "#30607"
144+
msgid "Prefer HTTP streams over HTTS"
145+
msgstr ""

resources/lib/api.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import random
2222
import xbmc
2323

24-
PY3 = sys.version_info.major >= 3
24+
# avoid using named attributes since they were introduced with python 2.7 only
25+
PY3 = sys.version_info[0] >= 3
2526

2627
if PY3:
2728
from urllib.parse import urlencode
@@ -109,16 +110,27 @@ def get_stations_by_genre(self, genre, sorttype, sizeperpage, pageindex):
109110
raise ValueError('Bad category_type')
110111
return response.get('numberPages'), self.__format_stations_v2(response.get('categories')[0].get('matches'))
111112

112-
def get_station_by_station_id(self, station_id, resolve_playlists=True):
113+
def get_station_by_station_id(self, station_id, resolve_playlists=True, force_http=False):
113114
self.log('get_station_by_station_id started with station_id=%s'
114115
% station_id)
115116
path = 'v2/search/station'
116117
param = {'station': str(station_id)}
117118
station = self.__api_call(path, param)
118119

119120
streams = station.get('streamUrls')
121+
120122
if streams:
121-
station['streamUrl'] = station.get('streamUrls')[0]['streamUrl']
123+
station['streamUrl'] = streams[0].get('streamUrl')
124+
125+
if force_http:
126+
for stream in streams:
127+
if "http://" in stream.get('streamUrl'):
128+
station['streamUrl'] = stream['streamUrl']
129+
break
130+
131+
if not station.get('streamUrl'):
132+
self.log('Unable to detect a playable stream for station')
133+
return None
122134

123135
if resolve_playlists and self.__check_paylist(station['streamUrl']):
124136
playlist_url = station['streamUrl']

resources/lib/plugin.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,20 +439,25 @@ def get_stream_url(station_id):
439439
stream_url = station['stream_url']
440440
current_track = ''
441441
else:
442-
station = radio_api.get_station_by_station_id(station_id)
443-
stream_url = station['stream_url']
444-
current_track = station['current_track']
445-
__log('get_stream_url result: %s' % stream_url)
446-
return plugin.set_resolved_url(
447-
listitem.ListItem(
448-
label=station['name'],
449-
label2=current_track,
450-
path=stream_url,
451-
icon=station['thumbnail'],
452-
thumbnail=station['thumbnail'],
453-
fanart=__get_plugin_fanart(),
442+
station = radio_api.get_station_by_station_id(
443+
station_id,
444+
force_http=plugin.get_setting('prefer-http', bool)
445+
)
446+
if station:
447+
stream_url = station['stream_url']
448+
current_track = station['current_track']
449+
if station:
450+
__log('get_stream_url result: %s' % stream_url)
451+
return plugin.set_resolved_url(
452+
listitem.ListItem(
453+
label=station['name'],
454+
label2=current_track,
455+
path=stream_url,
456+
icon=station['thumbnail'],
457+
thumbnail=station['thumbnail'],
458+
fanart=__get_plugin_fanart(),
459+
)
454460
)
455-
)
456461

457462

458463
def __add_stations(stations, add_custom=False, browse_more=None):

resources/settings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<category label="30601">
44
<setting id="language" type="enum" label="30300" lvalues="30301|30302|30303|30304" default="0" />
55
<setting id="hide-fanart" type="bool" label="30602" default="false"/>
6+
<setting id="prefer-http" type="bool" label="30607" default="true"/>
67
</category>
78
</settings>

0 commit comments

Comments
 (0)