@@ -38,16 +38,16 @@ def __init__(self, search=None):
38
38
self ._raw_stations = []
39
39
self ._last_search = None
40
40
self ._have_to_retrieve_url = False
41
- self ._uses_internal_header = False
41
+ self ._internal_header_height = 0
42
42
self ._url_timeout = 3
43
43
self ._search_timeout = 3
44
44
45
45
@property
46
- def uses_internal_header (self ):
47
- return self ._uses_internal_header
46
+ def internal_header_height (self ):
47
+ return self ._internal_header_height
48
48
49
- @uses_internal_header .setter
50
- def uses_internal_header (self , value ):
49
+ @internal_header_height .setter
50
+ def internal_header_height (self , value ):
51
51
raise ValueError ('property is read only' )
52
52
53
53
@property
@@ -135,7 +135,7 @@ class PyRadioBrowserInfoBrowser(PyRadioStationsBrowser):
135
135
_info_name_len = 0
136
136
137
137
_have_to_retrieve_url = True
138
- _uses_internal_header = True
138
+ _internal_header_height = 1
139
139
140
140
_url_timeout = 3
141
141
_search_timeout = 3
@@ -230,7 +230,7 @@ def real_url(self, stationid):
230
230
else :
231
231
return ''
232
232
except requests .exceptions .RequestException as e :
233
- if logger .isEnabledFor (logger .ERROR ):
233
+ if logger .isEnabledFor (logging .ERROR ):
234
234
logger .error (e )
235
235
return ''
236
236
@@ -327,11 +327,11 @@ def format_station_line(self, id_in_list, pad, width):
327
327
"""
328
328
329
329
info = (u'' ,
330
- u' {0} {1}kb' ,
331
- u' {0} {1}│ {2}kb' ,
332
- u' {0} {1}│ {2}│ {3}kb' ,
333
- u' {0} {1}│ {2}│ {3}kb│{4}' ,
334
- u' {0} {1}│ {2}│ {3}kb│{4}│{5}' ,
330
+ u' {0}{1}kb' ,
331
+ u' {0}{1}│{2}kb' ,
332
+ u' {0}{1}│{2}│{3}kb' ,
333
+ u' {0}{1}│{2}│{3}kb│{4}' ,
334
+ u' {0}{1}│{2}│{3}kb│{4}│{5}' ,
335
335
)
336
336
self ._get_output_format (width )
337
337
#logger.error('DE self._output_format = {}'.format(self._output_format))
@@ -343,39 +343,40 @@ def format_station_line(self, id_in_list, pad, width):
343
343
# full with state
344
344
out [2 ] = ' ' + info [self ._output_format ].format (
345
345
pl ,
346
- self ._raw_stations [id_in_list ]['votes' ].rjust (self . _max_len [ 0 ]) ,
347
- self ._raw_stations [id_in_list ]['clickcount' ].rjust (self . _max_len [ 1 ]) ,
348
- self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ],
346
+ self ._raw_stations [id_in_list ]['votes' ].rjust (7 )[: 7 ] ,
347
+ self ._raw_stations [id_in_list ]['clickcount' ].rjust (7 )[: 7 ] ,
348
+ self ._raw_stations [id_in_list ]['bitrate' ].rjust (5 )[:5 ],
349
349
self ._raw_stations [id_in_list ]['country' ].ljust (14 )[:14 ],
350
350
self ._raw_stations [id_in_list ]['language' ].ljust (15 )[:15 ]
351
351
)
352
352
if self ._output_format == 4 :
353
353
# full or condensed info
354
+ aa = self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ]
354
355
out [2 ] = ' ' + info [self ._output_format ].format (
355
356
pl ,
356
- self ._raw_stations [id_in_list ]['votes' ].rjust (self . _max_len [ 0 ]) ,
357
- self ._raw_stations [id_in_list ]['clickcount' ].rjust (self . _max_len [ 1 ]) ,
358
- self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ],
357
+ self ._raw_stations [id_in_list ]['votes' ].rjust (7 )[: 7 ] ,
358
+ self ._raw_stations [id_in_list ]['clickcount' ].rjust (7 )[: 7 ] ,
359
+ self ._raw_stations [id_in_list ]['bitrate' ].rjust (5 )[:5 ],
359
360
self ._raw_stations [id_in_list ]['country' ].ljust (14 )[:14 ]
360
361
)
361
362
elif self ._output_format == 2 :
362
363
out [2 ] = ' ' + info [self ._output_format ].format (
363
364
pl ,
364
- self ._raw_stations [id_in_list ]['votes' ].rjust (self . _max_len [ 0 ]) ,
365
- self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ]
365
+ self ._raw_stations [id_in_list ]['votes' ].rjust (7 )[: 7 ] ,
366
+ self ._raw_stations [id_in_list ]['bitrate' ].rjust (5 )[:5 ]
366
367
)
367
368
elif self ._output_format == 3 :
368
369
out [2 ] = ' ' + info [self ._output_format ].format (
369
370
pl ,
370
- self ._raw_stations [id_in_list ]['votes' ].rjust (self . _max_len [ 0 ]) ,
371
- self ._raw_stations [id_in_list ]['clickcount' ].rjust (self . _max_len [ 1 ]) ,
372
- self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ]
371
+ self ._raw_stations [id_in_list ]['votes' ].rjust (7 )[: 7 ] ,
372
+ self ._raw_stations [id_in_list ]['clickcount' ].rjust (7 )[: 7 ] ,
373
+ self ._raw_stations [id_in_list ]['bitrate' ].rjust (5 )[:5 ]
373
374
)
374
375
elif self ._output_format == 1 :
375
376
# Bitrate only
376
377
out [2 ] = info [self ._output_format ].format (
377
378
pl ,
378
- self ._raw_stations [id_in_list ]['bitrate' ].rjust (7 )[:7 ]
379
+ self ._raw_stations [id_in_list ]['bitrate' ].rjust (5 )[:5 ]
379
380
)
380
381
381
382
name_width = width - len (out [0 ])- len (out [2 ])
@@ -477,45 +478,53 @@ def _get_output_format(self, width):
477
478
else :
478
479
self ._output_format = 5
479
480
480
- def get_columns_separators (self , width ):
481
- self ._get_output_format (width )
481
+ def get_columns_separators (self , width , use_old_output_format = False , adjust = 0 ):
482
+ actual_width = width - 2
483
+ actual_width = width
484
+ if not use_old_output_format :
485
+ self ._get_output_format (actual_width )
482
486
if self ._output_format == 0 :
483
- return ()
487
+ columns_separotors = []
484
488
elif self ._output_format == 1 :
485
- return ( width - 10 )
489
+ columns_separotors = [ actual_width - 7 ]
486
490
elif self ._output_format == 2 :
487
- return ( width - 18 ,
488
- width - 10
489
- )
491
+ columns_separotors = [ actual_width - 15 ,
492
+ actual_width - 7
493
+ ]
490
494
elif self ._output_format == 3 :
491
- return ( width - 27 ,
492
- width - 19 ,
493
- width - 10
494
- )
495
+ columns_separotors = [ actual_width - 23 ,
496
+ actual_width - 15 ,
497
+ actual_width - 7
498
+ ]
495
499
elif self ._output_format == 4 :
496
- return ( width - 42 ,
497
- width - 34 ,
498
- width - 25 ,
499
- width - 14
500
- )
500
+ columns_separotors = [ actual_width - 38 ,
501
+ actual_width - 30 ,
502
+ actual_width - 22 ,
503
+ actual_width - 14
504
+ ]
501
505
elif self ._output_format == 5 :
502
- return (width - 58 ,
503
- width - 50 ,
504
- width - 41 ,
505
- width - 30 ,
506
- width - 15
507
- )
508
-
509
- def get_internal_header (self , width ):
510
- title = ((),
511
- ('Bitrate' ),
512
- ('Votes' , 'Bitrate' ),
513
- ('Votes' , 'Clicks' , 'Bitrate' ),
514
- ('Votes' , 'Clicks' , 'Bitrate' , 'Country' ),
515
- ('Votes' , 'Clicks' , 'Bitrate' , 'Country' , 'Language' )
516
- )
517
- col_sep = self .get_columns_separators (width )
518
- return col_sep , title [self ._output_format ]
506
+ columns_separotors = [actual_width - 54 ,
507
+ actual_width - 46 ,
508
+ actual_width - 38 ,
509
+ actual_width - 30 ,
510
+ actual_width - 15
511
+ ]
512
+ if adjust > 0 :
513
+ for n in range (0 , len (columns_separotors )):
514
+ columns_separotors [n ] -= 2
515
+ return columns_separotors
516
+
517
+ def get_internal_header (self , pad , width ):
518
+ columns = ((),
519
+ ('Bitrate' , ),
520
+ (' Votes' , 'Bitrate' ),
521
+ (' Votes' , ' Clicks' , 'Bitrate' ),
522
+ (' Votes' , ' Clicks' , 'Bitrate' , 'Country' ),
523
+ (' Votes' , ' Clicks' , 'Bitrate' , 'Country' , 'Language' )
524
+ )
525
+ columns_separotors = self .get_columns_separators (width , use_old_output_format = True , adjust = 2 )
526
+ title = '#' .rjust (pad ) + ' Name'
527
+ return ((title , columns_separotors , columns [self ._output_format ]), )
519
528
520
529
521
530
class PyRadioBrowserInfoData (object ):
0 commit comments