Skip to content

Commit 93c714a

Browse files
committed
implementing online browser internal header
1 parent 5ffa561 commit 93c714a

File tree

3 files changed

+220
-158
lines changed

3 files changed

+220
-158
lines changed

pyradio/browser.py

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ def __init__(self, search=None):
3838
self._raw_stations = []
3939
self._last_search = None
4040
self._have_to_retrieve_url = False
41-
self._uses_internal_header = False
41+
self._internal_header_height = 0
4242
self._url_timeout = 3
4343
self._search_timeout = 3
4444

4545
@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
4848

49-
@uses_internal_header.setter
50-
def uses_internal_header(self, value):
49+
@internal_header_height.setter
50+
def internal_header_height(self, value):
5151
raise ValueError('property is read only')
5252

5353
@property
@@ -135,7 +135,7 @@ class PyRadioBrowserInfoBrowser(PyRadioStationsBrowser):
135135
_info_name_len = 0
136136

137137
_have_to_retrieve_url = True
138-
_uses_internal_header = True
138+
_internal_header_height = 1
139139

140140
_url_timeout = 3
141141
_search_timeout = 3
@@ -230,7 +230,7 @@ def real_url(self, stationid):
230230
else:
231231
return ''
232232
except requests.exceptions.RequestException as e:
233-
if logger.isEnabledFor(logger.ERROR):
233+
if logger.isEnabledFor(logging.ERROR):
234234
logger.error(e)
235235
return ''
236236

@@ -327,11 +327,11 @@ def format_station_line(self, id_in_list, pad, width):
327327
"""
328328

329329
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}',
335335
)
336336
self._get_output_format(width)
337337
#logger.error('DE self._output_format = {}'.format(self._output_format))
@@ -343,39 +343,40 @@ def format_station_line(self, id_in_list, pad, width):
343343
# full with state
344344
out[2] = ' ' + info[self._output_format].format(
345345
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],
349349
self._raw_stations[id_in_list]['country'].ljust(14)[:14],
350350
self._raw_stations[id_in_list]['language'].ljust(15)[:15]
351351
)
352352
if self._output_format == 4:
353353
# full or condensed info
354+
aa = self._raw_stations[id_in_list]['bitrate'].rjust(7)[:7]
354355
out[2] = ' ' + info[self._output_format].format(
355356
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],
359360
self._raw_stations[id_in_list]['country'].ljust(14)[:14]
360361
)
361362
elif self._output_format == 2:
362363
out[2] = ' ' + info[self._output_format].format(
363364
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]
366367
)
367368
elif self._output_format == 3:
368369
out[2] = ' ' + info[self._output_format].format(
369370
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]
373374
)
374375
elif self._output_format == 1:
375376
# Bitrate only
376377
out[2] = info[self._output_format].format(
377378
pl,
378-
self._raw_stations[id_in_list]['bitrate'].rjust(7)[:7]
379+
self._raw_stations[id_in_list]['bitrate'].rjust(5)[:5]
379380
)
380381

381382
name_width = width-len(out[0])-len(out[2])
@@ -477,45 +478,53 @@ def _get_output_format(self, width):
477478
else:
478479
self._output_format = 5
479480

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)
482486
if self._output_format == 0:
483-
return ()
487+
columns_separotors = []
484488
elif self._output_format == 1:
485-
return ( width - 10 )
489+
columns_separotors = [ actual_width - 7 ]
486490
elif self._output_format == 2:
487-
return (width -18,
488-
width -10
489-
)
491+
columns_separotors = [actual_width -15,
492+
actual_width -7
493+
]
490494
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+
]
495499
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+
]
501505
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]), )
519528

520529

521530
class PyRadioBrowserInfoData(object):

pyradio/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@ def _check_config_file(self, usr):
832832
if not path.exists(user_config_file):
833833
copyfile(package_config_file, user_config_file)
834834

835+
def internal_header_height(self):
836+
if self._browsing_station_service:
837+
return self.online_browser.internal_header_height
838+
else:
839+
return 0
835840
def read_config(self):
836841
lines = []
837842
try:

0 commit comments

Comments
 (0)