Thomas Hanika 3 年之前
父节点
当前提交
a490e13b99
共有 5 个文件被更改,包括 23 次插入23 次删除
  1. 2 8
      ycast/generic.py
  2. 12 6
      ycast/my_recentlystation.py
  3. 3 3
      ycast/my_stations.py
  4. 2 2
      ycast/radiobrowser.py
  5. 4 4
      ycast/server.py

+ 2 - 8
ycast/generic.py

@@ -34,13 +34,6 @@ def get_stationid_prefix(uid):
     return uid[:2]
     return uid[:2]
 
 
 
 
-def get_stationid_without_prefix(uid):
-    if len(uid) < 4:
-        logging.error("Could not extract stationid (Invalid station id length)")
-        return None
-    return uid[3:]
-
-
 def get_cache_path(cache_name):
 def get_cache_path(cache_name):
     cache_path = CACHE_PATH + '/' + cache_name
     cache_path = CACHE_PATH + '/' + cache_name
     try:
     try:
@@ -52,6 +45,7 @@ def get_cache_path(cache_name):
         return None
         return None
     return cache_path
     return cache_path
 
 
+
 def get_checksum(feed, charlimit=12):
 def get_checksum(feed, charlimit=12):
     hash_feed = feed.encode()
     hash_feed = feed.encode()
     hash_object = hashlib.md5(hash_feed)
     hash_object = hashlib.md5(hash_feed)
@@ -60,4 +54,4 @@ def get_checksum(feed, charlimit=12):
     for i, b in enumerate(digest[8:]):
     for i, b in enumerate(digest[8:]):
         xor_fold[i] ^= b
         xor_fold[i] ^= b
     digest_xor_fold = ''.join(format(x, '02x') for x in bytes(xor_fold))
     digest_xor_fold = ''.join(format(x, '02x') for x in bytes(xor_fold))
-    return digest_xor_fold[:charlimit]
+    return str(digest_xor_fold[:charlimit]).upper()

+ 12 - 6
ycast/my_recentlystation.py

@@ -8,28 +8,32 @@ MAX_ENTRIES = 15
 
 
 config_file = VAR_PATH + '/recently.yml'
 config_file = VAR_PATH + '/recently.yml'
 
 
-def signalStationSelected(name,url,icon):
-    logging.debug("  %s:%s|%s",name,url,icon)
+
+def signal_station_selected(name, url, icon):
+    logging.debug("  %s:%s|%s", name, url, icon)
     list_heared_stations = get_stations_list()
     list_heared_stations = get_stations_list()
-    if len(list_heared_stations) == 0 :
+    if len(list_heared_stations) == 0:
         list_heared_stations.append("recently used:\n")
         list_heared_stations.append("recently used:\n")
+    # make name yaml - like
+    name = name.replace(":", " -")
 
 
     for line in list_heared_stations:
     for line in list_heared_stations:
-        elements = line.split(':')
+        elements = line.split(': ')
         if elements[0] == '  '+name:
         if elements[0] == '  '+name:
             list_heared_stations.remove(line)
             list_heared_stations.remove(line)
-            logging.debug("Name '%s' exists and deleted",name)
+            logging.debug("Name '%s' exists and deleted", name)
     piped_icon = ''
     piped_icon = ''
     if icon and len(icon) > 0:
     if icon and len(icon) > 0:
         piped_icon = '|' + icon
         piped_icon = '|' + icon
 
 
-    list_heared_stations.insert(1,'  '+name+': '+url+piped_icon+'\n')
+    list_heared_stations.insert(1, '  '+name+': '+url+piped_icon+'\n')
     if len(list_heared_stations) > MAX_ENTRIES+1:
     if len(list_heared_stations) > MAX_ENTRIES+1:
         # remove last (oldest) entry
         # remove last (oldest) entry
         list_heared_stations.pop()
         list_heared_stations.pop()
 
 
     set_stations_yaml(list_heared_stations)
     set_stations_yaml(list_heared_stations)
 
 
+
 def set_stations_yaml(heared_stations):
 def set_stations_yaml(heared_stations):
     try:
     try:
         os.makedirs(VAR_PATH)
         os.makedirs(VAR_PATH)
@@ -47,6 +51,7 @@ def set_stations_yaml(heared_stations):
     except Exception as ex:
     except Exception as ex:
         logging.error("File not written '%s': %s", config_file, ex)
         logging.error("File not written '%s': %s", config_file, ex)
 
 
+
 def get_stations_list():
 def get_stations_list():
     try:
     try:
         with open(config_file, 'r') as f:
         with open(config_file, 'r') as f:
@@ -59,6 +64,7 @@ def get_stations_list():
         return []
         return []
     return heared_stations
     return heared_stations
 
 
+
 def get_recently_stations_yaml():
 def get_recently_stations_yaml():
     try:
     try:
         with open(config_file, 'r') as f:
         with open(config_file, 'r') as f:

+ 3 - 3
ycast/my_stations.py

@@ -31,12 +31,12 @@ def set_config(config):
         return False
         return False
 
 
 
 
-def get_station_by_id(uid):
+def get_station_by_id(vtune_id):
     my_stations_yaml = get_stations_yaml()
     my_stations_yaml = get_stations_yaml()
     if my_stations_yaml:
     if my_stations_yaml:
         for category in my_stations_yaml:
         for category in my_stations_yaml:
             for station in get_stations_by_category(category):
             for station in get_stations_by_category(category):
-                if uid == generic.get_stationid_without_prefix(station.id):
+                if vtune_id == station.id:
                     return station
                     return station
     return None
     return None
 
 
@@ -82,6 +82,6 @@ def get_stations_by_category(category):
             station_icon = None
             station_icon = None
             if len(url_list) > 1:
             if len(url_list) > 1:
                 station_icon = url_list[1]
                 station_icon = url_list[1]
-            station_id = str(generic.get_checksum(station_name + station_url)).upper()
+            station_id = generic.get_checksum(station_name + station_url)
             stations.append(Station(station_id, station_name, station_url, category, station_icon))
             stations.append(Station(station_id, station_name, station_url, category, station_icon))
     return stations
     return stations

+ 2 - 2
ycast/radiobrowser.py

@@ -28,7 +28,7 @@ def get_json_attr(json, attr):
 class Station:
 class Station:
     def __init__(self, station_json):
     def __init__(self, station_json):
         self.stationuuid = get_json_attr(station_json, 'stationuuid')
         self.stationuuid = get_json_attr(station_json, 'stationuuid')
-        self.id = generic.get_checksum(self.stationuuid)
+        self.id = generic.generate_stationid_with_prefix(generic.get_checksum(self.stationuuid), ID_PREFIX)
         self.name = get_json_attr(station_json, 'name')
         self.name = get_json_attr(station_json, 'name')
         self.url = get_json_attr(station_json, 'url')
         self.url = get_json_attr(station_json, 'url')
         self.icon = get_json_attr(station_json, 'favicon')
         self.icon = get_json_attr(station_json, 'favicon')
@@ -40,7 +40,7 @@ class Station:
         self.bitrate = get_json_attr(station_json, 'bitrate')
         self.bitrate = get_json_attr(station_json, 'bitrate')
 
 
     def to_vtuner(self):
     def to_vtuner(self):
-        return vtuner.Station(generic.generate_stationid_with_prefix(self.id, ID_PREFIX), self.name,
+        return vtuner.Station(self.id, self.name,
                               ', '.join(self.tags), self.url, self.icon,
                               ', '.join(self.tags), self.url, self.icon,
                               self.tags[0], self.countrycode, self.codec, self.bitrate, None)
                               self.tags[0], self.countrycode, self.codec, self.bitrate, None)
 
 

+ 4 - 4
ycast/server.py

@@ -8,7 +8,7 @@ import ycast.radiobrowser as radiobrowser
 import ycast.my_stations as my_stations
 import ycast.my_stations as my_stations
 import ycast.generic as generic
 import ycast.generic as generic
 import ycast.station_icons as station_icons
 import ycast.station_icons as station_icons
-from ycast.my_recentlystation import signalStationSelected
+from ycast.my_recentlystation import signal_station_selected
 
 
 PATH_ROOT = 'ycast'
 PATH_ROOT = 'ycast'
 PATH_PLAY = 'play'
 PATH_PLAY = 'play'
@@ -102,9 +102,9 @@ def get_paged_elements(items, requestargs):
 def get_station_by_id(stationid, additional_info=False):
 def get_station_by_id(stationid, additional_info=False):
     station_id_prefix = generic.get_stationid_prefix(stationid)
     station_id_prefix = generic.get_stationid_prefix(stationid)
     if station_id_prefix == my_stations.ID_PREFIX:
     if station_id_prefix == my_stations.ID_PREFIX:
-        return my_stations.get_station_by_id(generic.get_stationid_without_prefix(stationid))
+        return my_stations.get_station_by_id(stationid)
     elif station_id_prefix == radiobrowser.ID_PREFIX:
     elif station_id_prefix == radiobrowser.ID_PREFIX:
-        station = radiobrowser.get_station_by_id(generic.get_stationid_without_prefix(stationid))
+        station = radiobrowser.get_station_by_id(stationid)
         if additional_info:
         if additional_info:
             station.get_playable_url()
             station.get_playable_url()
         return station
         return station
@@ -299,7 +299,7 @@ def get_station_icon():
     if not station:
     if not station:
         logging.error("Could not get station with id '%s'", stationid)
         logging.error("Could not get station with id '%s'", stationid)
         abort(404)
         abort(404)
-    signalStationSelected(station.name,station.url,station.icon)
+    signal_station_selected(station.name, station.url, station.icon)
     if not hasattr(station, 'icon') or not station.icon:
     if not hasattr(station, 'icon') or not station.icon:
         logging.warning("No icon information found for station with id '%s'", stationid)
         logging.warning("No icon information found for station with id '%s'", stationid)
         abort(404)
         abort(404)