filter languages country directories and reduce genre by higher level of station-counts
This commit is contained in:
parent
3601528ad3
commit
c818934a69
3 changed files with 56 additions and 38 deletions
|
@ -63,7 +63,7 @@ def verify_value(ref_val, val):
|
|||
return False
|
||||
|
||||
|
||||
def chk_paramter(parameter_name, val):
|
||||
def chk_parameter(parameter_name, val):
|
||||
if black_list:
|
||||
if parameter_name in black_list:
|
||||
if verify_value(black_list[parameter_name], val):
|
||||
|
|
|
@ -4,14 +4,14 @@ import uuid
|
|||
import requests
|
||||
import logging
|
||||
|
||||
from ycast import __version__
|
||||
from ycast import __version__, my_filter
|
||||
import ycast.vtuner as vtuner
|
||||
import ycast.generic as generic
|
||||
from ycast.my_filter import check_station, init_filter, end_filter
|
||||
from ycast.generic import get_json_attr
|
||||
|
||||
API_ENDPOINT = "http://all.api.radio-browser.info"
|
||||
MINIMUM_COUNT_GENRE = 5
|
||||
MINIMUM_COUNT_GENRE = 40
|
||||
MINIMUM_COUNT_COUNTRY = 5
|
||||
MINIMUM_COUNT_LANGUAGE = 5
|
||||
DEFAULT_STATION_LIMIT = 200
|
||||
|
@ -72,14 +72,14 @@ def request(url):
|
|||
|
||||
def get_station_by_id(vtune_id):
|
||||
global station_cache
|
||||
# decode
|
||||
# decode
|
||||
uidbase64 = generic.get_stationid_without_prefix(vtune_id)
|
||||
uid = str(uuid.UUID(base64.urlsafe_b64decode(uidbase64).hex()))
|
||||
if station_cache:
|
||||
station = station_cache[vtune_id]
|
||||
if station:
|
||||
return station
|
||||
# no item in cache, do request
|
||||
# no item in cache, do request
|
||||
station_json = request('stations/byuuid?uuids=' + uid)
|
||||
if station_json and len(station_json):
|
||||
station = Station(station_json[0])
|
||||
|
@ -99,8 +99,9 @@ def get_country_directories():
|
|||
for country_raw in countries_raw:
|
||||
if get_json_attr(country_raw, 'name') and get_json_attr(country_raw, 'stationcount') and \
|
||||
int(get_json_attr(country_raw, 'stationcount')) > MINIMUM_COUNT_COUNTRY:
|
||||
country_directories.append(generic.Directory(get_json_attr(country_raw, 'name'),
|
||||
get_json_attr(country_raw, 'stationcount')))
|
||||
if my_filter.chk_parameter('country', get_json_attr(country_raw, 'name')):
|
||||
country_directories.append(generic.Directory(get_json_attr(country_raw, 'name'),
|
||||
get_json_attr(country_raw, 'stationcount')))
|
||||
return country_directories
|
||||
|
||||
|
||||
|
@ -114,9 +115,10 @@ def get_language_directories():
|
|||
for language_raw in languages_raw:
|
||||
if get_json_attr(language_raw, 'name') and get_json_attr(language_raw, 'stationcount') and \
|
||||
int(get_json_attr(language_raw, 'stationcount')) > MINIMUM_COUNT_LANGUAGE:
|
||||
language_directories.append(generic.Directory(get_json_attr(language_raw, 'name'),
|
||||
get_json_attr(language_raw, 'stationcount'),
|
||||
get_json_attr(language_raw, 'name').title()))
|
||||
if my_filter.chk_parameter('languagecodes', get_json_attr(language_raw, 'iso_639')):
|
||||
language_directories.append(generic.Directory(get_json_attr(language_raw, 'name'),
|
||||
get_json_attr(language_raw, 'stationcount'),
|
||||
get_json_attr(language_raw, 'name').title()))
|
||||
return language_directories
|
||||
|
||||
|
||||
|
|
|
@ -14,36 +14,33 @@ class MyTestCase(unittest.TestCase):
|
|||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
def test_verify_values(self):
|
||||
assert my_filter.verify_value( None, None )
|
||||
assert my_filter.verify_value( '', '' )
|
||||
assert my_filter.verify_value( None, '' )
|
||||
assert my_filter.verify_value( 3, 3 )
|
||||
assert my_filter.verify_value( '3', 3 )
|
||||
assert my_filter.verify_value( '3', '3' )
|
||||
assert my_filter.verify_value( '3,4,5,6', '5' )
|
||||
|
||||
assert not my_filter.verify_value( '', None )
|
||||
assert not my_filter.verify_value( '', '3' )
|
||||
assert not my_filter.verify_value( 3, 4 )
|
||||
assert not my_filter.verify_value( '3', 4 )
|
||||
assert not my_filter.verify_value( '4', '3' )
|
||||
assert not my_filter.verify_value( '3,4,5,6', '9' )
|
||||
assert my_filter.verify_value(None, None)
|
||||
assert my_filter.verify_value('', '')
|
||||
assert my_filter.verify_value(None, '')
|
||||
assert my_filter.verify_value(3, 3)
|
||||
assert my_filter.verify_value('3', 3)
|
||||
assert my_filter.verify_value('3', '3')
|
||||
assert my_filter.verify_value('3,4,5,6', '5')
|
||||
|
||||
assert not my_filter.verify_value('', None)
|
||||
assert not my_filter.verify_value('', '3')
|
||||
assert not my_filter.verify_value(3, 4)
|
||||
assert not my_filter.verify_value('3', 4)
|
||||
assert not my_filter.verify_value('4', '3')
|
||||
assert not my_filter.verify_value('3,4,5,6', '9')
|
||||
|
||||
def test_init_filter(self):
|
||||
my_filter.init_filter()
|
||||
|
||||
filter.init_filter()
|
||||
|
||||
for elem in filter.filter_dir:
|
||||
for elem in my_filter.filter_dir:
|
||||
logging.warning("Name filtertype: %s", elem)
|
||||
filter_param = filter.filter_dir[elem]
|
||||
filter_param = my_filter.filter_dir[elem]
|
||||
if filter_param:
|
||||
for par in filter_param:
|
||||
logging.warning(" Name paramter: %s",par)
|
||||
logging.warning(" Name paramter: %s", par)
|
||||
else:
|
||||
logging.warning(" <empty list>")
|
||||
|
||||
|
||||
def test_valid_station(self):
|
||||
my_filter.init_filter()
|
||||
test_lines = generic.readlns_txt_file(generic.get_var_path()+"/test.json")
|
||||
|
@ -61,10 +58,22 @@ class MyTestCase(unittest.TestCase):
|
|||
my_filter.end_filter()
|
||||
|
||||
def test_life_popular_station(self):
|
||||
#hard test for filter
|
||||
# hard test for filter
|
||||
stations = radiobrowser.get_stations_by_votes(10000000)
|
||||
logging.info("Stations (%d)", len(stations))
|
||||
|
||||
def test_get_languages(self):
|
||||
result = radiobrowser.get_language_directories()
|
||||
assert len(result) == 3
|
||||
|
||||
def test_get_countries(self):
|
||||
result = radiobrowser.get_country_directories()
|
||||
assert len(result) == 4
|
||||
|
||||
def test_get_genre(self):
|
||||
result = radiobrowser.get_genre_directories()
|
||||
assert len(result) < 300
|
||||
|
||||
def test_recently_hit(self):
|
||||
|
||||
try:
|
||||
|
@ -76,24 +85,29 @@ class MyTestCase(unittest.TestCase):
|
|||
assert len(result) == 0
|
||||
|
||||
result = my_recentlystation.get_recently_stations_dictionary()
|
||||
assert result == None
|
||||
assert result is None
|
||||
|
||||
i = 0
|
||||
while i < 10:
|
||||
my_recentlystation.signal_station_selected('NAME '+ str(i),'http://dummy/'+ str(i), 'http://icon'+ str(i))
|
||||
my_recentlystation.signal_station_selected('NAME ' + str(i), 'http://dummy/' + str(i),
|
||||
'http://icon' + str(i))
|
||||
i = i+1
|
||||
|
||||
result = my_recentlystation.get_recently_stations_dictionary()
|
||||
assert my_recentlystation.directory_name()
|
||||
assert result[my_recentlystation.directory_name()]
|
||||
|
||||
my_recentlystation.signal_station_selected('Konverenz: Sport' , 'http://dummy/' + str(i), 'http://icon' + str(i))
|
||||
my_recentlystation.signal_station_selected('Konverenz: Sport' , 'http://dummy/' + str(i), 'http://icon' + str(i))
|
||||
my_recentlystation.signal_station_selected('Konverenz: Sport' , 'http://dummy/' + str(i), 'http://icon' + str(i))
|
||||
my_recentlystation.signal_station_selected('Konverenz: Sport', 'http://dummy/' + str(i),
|
||||
'http://icon' + str(i))
|
||||
my_recentlystation.signal_station_selected('Konverenz: Sport', 'http://dummy/' + str(i),
|
||||
'http://icon' + str(i))
|
||||
my_recentlystation.signal_station_selected('Konverenz: Sport', 'http://dummy/' + str(i),
|
||||
'http://icon' + str(i))
|
||||
|
||||
i = 6
|
||||
while i < 17:
|
||||
my_recentlystation.signal_station_selected('NAME '+ str(i),'http://dummy/'+ str(i), 'http://icon'+ str(i))
|
||||
my_recentlystation.signal_station_selected('NAME ' + str(i), 'http://dummy/' + str(i),
|
||||
'http://icon' + str(i))
|
||||
i = i+1
|
||||
|
||||
result = my_recentlystation.get_recently_stations_dictionary()
|
||||
|
@ -106,11 +120,13 @@ class MyTestCase(unittest.TestCase):
|
|||
while j < 6:
|
||||
i = 6
|
||||
while i < 9:
|
||||
my_recentlystation.signal_station_selected('NAME '+ str(i),'http://dummy/'+ str(i), 'http://icon'+ str(i))
|
||||
my_recentlystation.signal_station_selected('NAME ' + str(i), 'http://dummy/' + str(i),
|
||||
'http://icon' + str(i))
|
||||
i = i+1
|
||||
j = j+1
|
||||
result = my_recentlystation.get_stations_by_vote()
|
||||
assert len(result) == 5
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Reference in a new issue