Skip to content

Commit 1a5e729

Browse files
committed
adding playlist history to config
1 parent a68bb52 commit 1a5e729

File tree

3 files changed

+286
-44
lines changed

3 files changed

+286
-44
lines changed

pyradio/browser.py

Lines changed: 89 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class PyRadioStationsBrowser(object):
3535
# This property value is half the difference (normally 2 / 2 = 1)
3636
# Used to chgat the columns' separators in internal body
3737
# Check if the cursor is divided as required and adjust
38-
_outer_internal_body_diff = 1
38+
_outer_internal_body_diff = 2
39+
_outer_internal_body_half_diff = 1
3940

4041
def __init__(self, search=None):
4142
"""Initialize the station's browser.
@@ -53,11 +54,11 @@ def __init__(self, search=None):
5354
pass
5455

5556
@property
56-
def outer_internal_body_diff(self):
57-
return self._outer_internal_body_diff
57+
def outer_internal_body_half_diff(self):
58+
return self._outer_internal_body_half_diff
5859

59-
@outer_internal_body_diff.setter
60-
def outer_internal_body_diff(self, value):
60+
@outer_internal_body_half_diff.setter
61+
def outer_internal_body_half_diff(self, value):
6162
raise ValueError('property is read only')
6263

6364
@property
@@ -158,6 +159,14 @@ class PyRadioBrowserInfoBrowser(PyRadioStationsBrowser):
158159
_have_to_retrieve_url = True
159160
_internal_header_height = 1
160161

162+
_columns_width = {
163+
'votes': 7,
164+
'clickcount': 7,
165+
'bitrate': 7,
166+
'country': 14,
167+
'language': 15
168+
}
169+
161170
def __init__(self, search=None):
162171
if search:
163172
self.search(search)
@@ -495,40 +504,88 @@ def _get_output_format(self, width):
495504
else:
496505
self._output_format = 5
497506

498-
def get_columns_separators(self, width, use_old_output_format=False, adjust=0):
499-
actual_width = width - 2
500-
actual_width = width
507+
def _populate_columns_separators(self, a_tuple, width):
508+
ret = []
509+
for i, n in enumerate(a_tuple):
510+
if i == 0:
511+
ret.append(width - self._columns_width[n])
512+
else:
513+
ret.append(ret[-1] - 1 - self._columns_width[n])
514+
ret.reverse()
515+
return ret
516+
517+
def get_columns_separators(self,
518+
width,
519+
use_old_output_format=False,
520+
adjust=0,
521+
adjust_for_body=False,
522+
adjust_for_header=False,
523+
):
524+
"""Calculates columns separators for a given width
525+
based on self._output_format.
526+
527+
Parameters
528+
----------
529+
width
530+
Window width to use for the calculation.
531+
use_old_output_format
532+
If True, do not calculate self._output_format
533+
(use what's already calculated).
534+
adjust
535+
Delete adjust from the output
536+
Example:
537+
if the output was [55, 67]
538+
and adjust was 2
539+
the output would become [53, 65]
540+
adjust_for_header
541+
Delete self._outer_internal_body_diff from output
542+
This is to be used for displaying the internal header
543+
adjust_for_body
544+
Delete self._outer_internal_body_half_diff from output
545+
This is to be used for changing columns' separators
546+
color, when displaying body lines (stations' lines).
547+
548+
IMPORTANT
549+
---------
550+
The adjust* parameters are mutually exclusive, which means
551+
that ONLY ONE of them can be used at any given call to the
552+
function. If you fail to comply, the result will be wrong.
553+
554+
Returns
555+
-------
556+
A list containing columns_separotors (e.g. [55, 65]).
557+
"""
558+
559+
columns_separotors = []
501560
if not use_old_output_format:
502-
self._get_output_format(actual_width)
561+
self._get_output_format(width)
503562
if self._output_format == 0:
504563
columns_separotors = []
505564
elif self._output_format == 1:
506-
columns_separotors = [ actual_width - 7 ]
565+
columns_separotors = [width - col_width['bitrate']]
507566
elif self._output_format == 2:
508-
columns_separotors = [actual_width -15,
509-
actual_width -7
510-
]
567+
columns_separotors = self._populate_columns_separators(('bitrate', 'votes'), width)
568+
511569
elif self._output_format == 3:
512-
columns_separotors = [actual_width -23,
513-
actual_width -15,
514-
actual_width -7
515-
]
570+
columns_separotors = self._populate_columns_separators(('bitrate', 'clickcount', 'votes'), width)
571+
516572
elif self._output_format == 4:
517-
columns_separotors = [actual_width -38,
518-
actual_width -30,
519-
actual_width -22,
520-
actual_width -14
521-
]
573+
columns_separotors = self._populate_columns_separators(('country', 'bitrate', 'clickcount', 'votes'), width)
574+
522575
elif self._output_format == 5:
523-
columns_separotors = [actual_width -54,
524-
actual_width -46,
525-
actual_width -38,
526-
actual_width -30,
527-
actual_width -15
528-
]
576+
columns_separotors = self._populate_columns_separators(('language', 'country', 'bitrate', 'clickcount', 'votes'), width)
577+
578+
if adjust_for_header:
579+
for n in range(0, len(columns_separotors)):
580+
columns_separotors[n] -= self._outer_internal_body_diff
581+
582+
if adjust_for_body:
583+
for n in range(0, len(columns_separotors)):
584+
columns_separotors[n] -= self._outer_internal_body_half_diff
585+
529586
if adjust > 0:
530587
for n in range(0, len(columns_separotors)):
531-
columns_separotors[n] -= 2
588+
columns_separotors[n] -= adjust
532589
return columns_separotors
533590

534591
def get_internal_header(self, pad, width):
@@ -539,7 +596,9 @@ def get_internal_header(self, pad, width):
539596
(' Votes', ' Clicks', 'Bitrate', 'Country'),
540597
(' Votes', ' Clicks', 'Bitrate', 'Country', 'Language')
541598
)
542-
columns_separotors = self.get_columns_separators(width, use_old_output_format=True, adjust=2)
599+
columns_separotors = self.get_columns_separators(width, use_old_output_format=True)
600+
for i in range(0, len(columns_separotors)):
601+
columns_separotors[i] -= 2
543602
title = '#'.rjust(pad) + ' Name'
544603
return ((title, columns_separotors, columns[self._output_format]), )
545604

0 commit comments

Comments
 (0)