@@ -240,6 +240,16 @@ def __init__(self,
240
240
pyradio_info = None ,
241
241
search_return_function = None ,
242
242
message_function = None ):
243
+ '''
244
+ When first_search is True, it means that we are opening
245
+ the browser. If empty result is returned by the first
246
+ browser search, we show an empty stations' list.
247
+ if it is False and an empty result is returned by the first
248
+ browser search, which means we are already in the browser's
249
+ search screen, we just display the 'no result message'.
250
+ All of this is done at radio.py
251
+ '''
252
+ self .first_search = True
243
253
self ._cnf = config
244
254
if session :
245
255
self ._session = session
@@ -272,14 +282,13 @@ def initialize(self):
272
282
'term' : 'big band' ,
273
283
'post_data' : {'order' : 'votes' , 'reverse' : 'true' },
274
284
})
275
- self ._search_history_index = 1
276
285
277
286
self ._search_history .append ({
278
287
'type' : 'search' ,
279
288
'term' : '' ,
280
- 'post_data' : {'name' : 'jazsssss ' },
289
+ 'post_data' : {'name' : 'jaz ' },
281
290
})
282
- self ._search_history_index = 2
291
+ self ._search_history_index = 1
283
292
return True
284
293
return False
285
294
@@ -465,8 +474,6 @@ def search(self, go_back_in_history=True):
465
474
self ._old_search_by = self .search_by
466
475
self ._sort = None
467
476
url = self ._format_url (self ._search_history [self ._search_history_index ])
468
- if logger .isEnabledFor (logging .DEBUG ):
469
- logger .debug ('== search url = "{}"' .format (url ))
470
477
post_data = {}
471
478
if self ._search_history [self ._search_history_index ]['post_data' ]:
472
479
post_data = deepcopy (self ._search_history [self ._search_history_index ]['post_data' ])
@@ -477,25 +484,31 @@ def search(self, go_back_in_history=True):
477
484
post_data ['limit' ] = 100
478
485
if not 'hidebroken' not in post_data .keys ():
479
486
post_data ['hidebroken' ] = True
480
- # url = 'https://' + self._server + '/json/stations/search'
487
+
481
488
if logger .isEnabledFor (logging .DEBUG ):
482
- logger .debug ('== headers = "{}"' .format (self ._headers ))
483
- logger .debug ('== post_data = "{}"' .format (post_data ))
489
+ logger .debug (' == history = {}' .format (self ._search_history [self ._search_history_index ]))
490
+ logger .debug (' == url = "{}"' .format (url ))
491
+ logger .debug (' == headers = "{}"' .format (self ._headers ))
492
+ logger .debug (' == post_data = "{}"' .format (post_data ))
493
+
494
+ ''' keep server results here '''
495
+ new_raw_stations = []
496
+
484
497
try :
485
- # r = requests.get(url=url)
486
498
r = self ._session .get (url = url , headers = self ._headers , params = post_data , timeout = (self ._search_timeout , 2 * self ._search_timeout ))
487
- logger .error ('== request sent ' )
488
499
r .raise_for_status ()
489
- logger .error ('== request raised ' )
490
- self ._raw_stations = self ._extract_data (json .loads (r .text ))
491
- logger .error ('== got reply' )
492
- logger .error ('DE \n \n {}' .format (self ._raw_stations ))
493
- ret = True , go_back_in_history
500
+ new_raw_stations = self ._extract_data (json .loads (r .text ))
501
+ # logger.error('DE \n\n{}'.format(new_raw_stations))
502
+ ret = True , len (new_raw_stations ), go_back_in_history
494
503
except requests .exceptions .RequestException as e :
495
504
if logger .isEnabledFor (logging .ERROR ):
496
505
logger .error (e )
497
506
self ._raw_stations = []
498
- ret = False , go_back_in_history
507
+ ret = False , 0 , go_back_in_history
508
+
509
+ ''' use server result '''
510
+ if len (new_raw_stations ) > 0 :
511
+ self ._raw_stations = new_raw_stations [:]
499
512
500
513
if self ._search_return_function :
501
514
self ._search_return_function (ret )
@@ -506,6 +519,7 @@ def _get_search_elements(self, a_search):
506
519
values from a search dict.
507
520
To be used with the sort function
508
521
'''
522
+ logger .error ('DE search in function is "{}"' .format (a_search ))
509
523
a_term = a_search ['term' ]
510
524
p_data = a_search ['post_data' ]
511
525
self .search_by = None
@@ -516,12 +530,14 @@ def _get_search_elements(self, a_search):
516
530
if 'reverse' in a_search ['post_data' ]:
517
531
self .reverse = True if a_search ['post_data' ]['reverse' ] == 'true' else False
518
532
533
+ logger .error ('DE search by was "{}"' .format (self .search_by ))
519
534
if self .search_by is None :
520
535
a_type = a_search ['type' ]
521
536
if a_type == 'byname' :
522
537
self .search_by = 'name'
523
- elif a_type == 'topvotes ' :
538
+ elif a_type == 'topvote ' :
524
539
self .search_by = 'votes'
540
+ logger .error ('DE search by is votes' )
525
541
elif a_type == 'clickcount' :
526
542
self .search_by = 'clickcount'
527
543
elif a_type == 'bitrate' :
@@ -541,9 +557,13 @@ def _get_search_elements(self, a_search):
541
557
if p_data :
542
558
if 'name' in p_data .keys ():
543
559
self .search_by = 'name'
560
+ logger .error ('DE search by is name (default)' )
544
561
545
562
if self .search_by is None :
546
563
self .search_by = 'name'
564
+ logger .error ('DE search by is name (default)' )
565
+
566
+ logger .error ('DE search by is "{}"' .format (self .search_by ))
547
567
548
568
def get_next (self , search_term , start = 0 , stop = None ):
549
569
if search_term :
@@ -1227,27 +1247,27 @@ def show(self):
1227
1247
for i , n in enumerate (self ._widgets ):
1228
1248
if n is None :
1229
1249
if i == 0 :
1230
- self ._widgets [2 ] = SimpleCursesCheckBox (
1231
- 1 , 2 , 'Display by' ,
1232
- curses .color_pair (9 ),
1233
- curses .color_pair (4 ),
1234
- curses .color_pair (5 ))
1235
- # self._widgets[0] = SimpleCursesLineEdit(
1236
- # parent=self._win,
1237
- # width=-2,
1238
- # begin_y=3,
1239
- # begin_x=2,
1240
- # boxed=False,
1241
- # has_history=False,
1242
- # caption='',
1243
- # box_color=curses.color_pair(9),
1244
- # caption_color=curses.color_pair(4),
1245
- # edit_color=curses.color_pair(9),
1246
- # cursor_color=curses.color_pair(8),
1247
- # unfocused_color=curses.color_pair(5),
1248
- # string_changed_handler='')
1249
- # self._widgets[0].bracket = False
1250
- # self._line_editor = self._widgets[0]
1250
+ # self._widgets[2] = SimpleCursesCheckBox(
1251
+ # 1, 2, 'Display by',
1252
+ # curses.color_pair(9),
1253
+ # curses.color_pair(4),
1254
+ # curses.color_pair(5))
1255
+ self ._widgets [0 ] = SimpleCursesLineEdit (
1256
+ parent = self ._win ,
1257
+ width = - 2 ,
1258
+ begin_y = 3 ,
1259
+ begin_x = 2 ,
1260
+ boxed = False ,
1261
+ has_history = False ,
1262
+ caption = '' ,
1263
+ box_color = curses .color_pair (9 ),
1264
+ caption_color = curses .color_pair (4 ),
1265
+ edit_color = curses .color_pair (9 ),
1266
+ cursor_color = curses .color_pair (8 ),
1267
+ unfocused_color = curses .color_pair (5 ),
1268
+ string_changed_handler = '' )
1269
+ self ._widgets [0 ].bracket = False
1270
+ self ._line_editor = self ._widgets [0 ]
1251
1271
elif i == 1 :
1252
1272
''' search by '''
1253
1273
self ._widgets [i ] = SimpleCursesWidgetColumns (
0 commit comments