Skip to content

Commit a0832bb

Browse files
committed
Avoid errors when the stream id or url cannot be determined
1 parent d9f5d59 commit a0832bb

4 files changed

Lines changed: 89 additions & 62 deletions

File tree

resources/language/resource.language.en_gb/strings.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,11 @@ msgstr ""
155155
msgctxt "#30607"
156156
msgid "Prefer HTTP streams over HTTS"
157157
msgstr ""
158+
159+
msgctxt "#30608"
160+
msgid "Unable to get radio stream url"
161+
msgstr ""
162+
163+
msgctxt "#30609"
164+
msgid "Sucessfully added to my stations!"
165+
msgstr ""

resources/language/resource.language.pt_pt/strings.po

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,20 @@ msgstr ""
147147

148148
msgctxt "#30605"
149149
msgid "Page (%s/%s) | Next >>"
150-
msgstr ""
150+
msgstr "Página (%s/%s) | Próxima >>"
151151

152152
msgctxt "#30606"
153153
msgid "By country"
154-
msgstr ""
154+
msgstr "Por país"
155155

156156
msgctxt "#30607"
157157
msgid "Prefer HTTP streams over HTTS"
158-
msgstr ""
158+
msgstr "Preferir streams HTTP ao inves de HTTPS"
159+
160+
msgctxt "#30608"
161+
msgid "Unable to get radio stream url"
162+
msgstr "Incapaz de determinar o endereço da stream de rádio"
163+
164+
msgctxt "#30609"
165+
msgid "Sucessfully added to my stations!"
166+
msgstr "Adicionado com sucesso à lista de estações!"

resources/lib/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def get_station_by_station_id(self, station_id, resolve_playlists=True, force_ht
117117

118118
if not station.get('streamUrl'):
119119
self.log('Unable to detect a playable stream for station')
120+
120121
return None
121122

122123
if resolve_playlists and self.__check_paylist(station['streamUrl']):

resources/lib/plugin.py

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
'most_popular': 30603,
3434
'az': 30604,
3535
'next_page': 30605,
36-
'by_country': 30606
36+
'by_country': 30606,
37+
'error_stream': 30608,
38+
'station_add_success': 30609
3739
}
3840

3941
SORT_TYPES = {
@@ -205,8 +207,12 @@ def custom_my_station(station_id):
205207
@plugin.route('/stations/my/add/<station_id>')
206208
def add_to_my_stations(station_id):
207209
station = radio_api.get_station_by_station_id(station_id)
208-
my_stations[station_id] = station
209-
my_stations.sync()
210+
if station:
211+
my_stations[station_id] = station
212+
my_stations.sync()
213+
plugin.notify("Radio", _('station_add_success'), image=plugin.icon)
214+
else:
215+
plugin.notify("Radio", _('error_stream'), image=plugin.icon)
210216

211217

212218
@plugin.route('/stations/my/del/<station_id>')
@@ -506,7 +512,8 @@ def sub_menu_entry(option, category, value, page=1):
506512

507513
@plugin.route('/station/<station_id>')
508514
def get_stream_url(station_id):
509-
if my_stations.get(station_id, {}).get('is_custom', False):
515+
station = my_stations.get(station_id, {})
516+
if station and station.get('is_custom', False):
510517
station = my_stations[station_id]
511518
stream_url = radio_api.internal_resolver(station)
512519
current_track = ''
@@ -518,6 +525,8 @@ def get_stream_url(station_id):
518525
if station:
519526
stream_url = station['stream_url']
520527
current_track = station['current_track']
528+
else:
529+
plugin.notify("Radio", _('error_stream'), image=plugin.icon)
521530
if station:
522531
__log('get_stream_url result: %s' % stream_url)
523532
resolved_listitem = listitem.ListItem(
@@ -536,63 +545,64 @@ def __add_stations(stations, add_custom=False, browse_more=None):
536545
items = []
537546
my_station_ids = my_stations.keys()
538547
for i, station in enumerate(stations):
539-
station_id = str(station['id'])
540-
if not station_id in my_station_ids:
541-
context_menu = [(
542-
_('add_to_my_stations'),
543-
'RunPlugin(%s)' % plugin.url_for('add_to_my_stations',
544-
station_id=station_id),
545-
)]
546-
else:
547-
context_menu = [(
548-
_('remove_from_my_stations'),
549-
'RunPlugin(%s)' % plugin.url_for('del_from_my_stations',
550-
station_id=station_id),
551-
)]
552-
if station.get('is_custom', False):
553-
context_menu.append((
554-
_('edit_custom_station'),
555-
'RunPlugin(%s)' % plugin.url_for('custom_my_station',
556-
station_id=station_id),
557-
))
548+
if station:
549+
station_id = station.get('id')
550+
if station_id and not station_id in my_station_ids:
551+
context_menu = [(
552+
_('add_to_my_stations'),
553+
'RunPlugin(%s)' % plugin.url_for('add_to_my_stations',
554+
station_id=station_id),
555+
)]
556+
elif station_id and station_id in my_station_ids:
557+
context_menu = [(
558+
_('remove_from_my_stations'),
559+
'RunPlugin(%s)' % plugin.url_for('del_from_my_stations',
560+
station_id=station_id),
561+
)]
562+
if station.get('is_custom', False):
563+
context_menu.append((
564+
_('edit_custom_station'),
565+
'RunPlugin(%s)' % plugin.url_for('custom_my_station',
566+
station_id=station_id),
567+
))
558568

559-
items.append({
560-
'label': station.get('name', ''),
561-
'thumbnail': station['thumbnail'],
562-
'fanart': __get_plugin_fanart(),
563-
'info': {
564-
'title': station.get('name', ''),
565-
'rating': (10.0 - 0.0)*((float(station.get('rating', 0.0))-30.000)/(1.0-30.000)), # linear interpolation
566-
'genre': station.get('genre', ''),
567-
'size': int(station.get('bitrate', 0)),
568-
'comment': station.get('description', ''),
569-
'count': i,
570-
},
571-
'context_menu': context_menu,
572-
'path': plugin.url_for(
573-
'get_stream_url',
574-
station_id=station_id,
575-
),
576-
'is_playable': True,
577-
'properties': {
578-
'StationName': station.get('name', '') # Matrix++ only
579-
},
580-
'offscreen': True
581-
})
582-
if add_custom:
583-
items.append({
584-
'label': _('add_custom'),
585-
'path': plugin.url_for('custom_my_station', station_id='new'),
586-
})
569+
items.append({
570+
'label': station.get('name', ''),
571+
'thumbnail': station['thumbnail'],
572+
'fanart': __get_plugin_fanart(),
573+
'info': {
574+
'title': station.get('name', ''),
575+
'rating': (10.0 - 0.0)*((float(station.get('rating', 0.0))-30.000)/(1.0-30.000)), # linear interpolation
576+
'genre': station.get('genre', ''),
577+
'size': int(station.get('bitrate', 0)),
578+
'comment': station.get('description', ''),
579+
'count': i,
580+
},
581+
'context_menu': context_menu,
582+
'path': plugin.url_for(
583+
'get_stream_url',
584+
station_id=station_id,
585+
),
586+
'is_playable': True,
587+
'properties': {
588+
'StationName': station.get('name', '') # Matrix++ only
589+
},
590+
'offscreen': True
591+
})
592+
if add_custom:
593+
items.append({
594+
'label': _('add_custom'),
595+
'path': plugin.url_for('custom_my_station', station_id='new'),
596+
})
587597

588-
if browse_more:
589-
items.append({
590-
'label': '[B]%s[/B]' % _('next_page') % (browse_more['page'], browse_more['total_pages']),
591-
'path': browse_more['url'],
592-
'icon': browse_more['icon'],
593-
'fanart': browse_more['fanart'],
594-
'offscreen': True
595-
})
598+
if browse_more:
599+
items.append({
600+
'label': '[B]%s[/B]' % _('next_page') % (browse_more['page'], browse_more['total_pages']),
601+
'path': browse_more['url'],
602+
'icon': browse_more['icon'],
603+
'fanart': browse_more['fanart'],
604+
'offscreen': True
605+
})
596606

597607

598608
finish_kwargs = {

0 commit comments

Comments
 (0)