|
21 | 21 | import random |
22 | 22 | import xbmc |
23 | 23 |
|
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 |
25 | 26 |
|
26 | 27 | if PY3: |
27 | 28 | from urllib.parse import urlencode |
@@ -109,16 +110,27 @@ def get_stations_by_genre(self, genre, sorttype, sizeperpage, pageindex): |
109 | 110 | raise ValueError('Bad category_type') |
110 | 111 | return response.get('numberPages'), self.__format_stations_v2(response.get('categories')[0].get('matches')) |
111 | 112 |
|
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): |
113 | 114 | self.log('get_station_by_station_id started with station_id=%s' |
114 | 115 | % station_id) |
115 | 116 | path = 'v2/search/station' |
116 | 117 | param = {'station': str(station_id)} |
117 | 118 | station = self.__api_call(path, param) |
118 | 119 |
|
119 | 120 | streams = station.get('streamUrls') |
| 121 | + |
120 | 122 | 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 |
122 | 134 |
|
123 | 135 | if resolve_playlists and self.__check_paylist(station['streamUrl']): |
124 | 136 | playlist_url = station['streamUrl'] |
|
0 commit comments