瀏覽代碼

Merge f2fffcedce4d8a44ab80410bdaa196a21890a163 into f349a2686c336420b8e2dc4c9a2a9fc12dd4e358

Jakub Janeczko 3 年之前
父節點
當前提交
ae197814fa
共有 2 個文件被更改,包括 23 次插入11 次删除
  1. 8 3
      ycast/server.py
  2. 15 8
      ycast/vtuner.py

+ 8 - 3
ycast/server.py

@@ -105,7 +105,7 @@ def get_station_by_id(stationid, additional_info=False):
         return my_stations.get_station_by_id(generic.get_stationid_without_prefix(stationid))
     elif station_id_prefix == radiobrowser.ID_PREFIX:
         station = radiobrowser.get_station_by_id(generic.get_stationid_without_prefix(stationid))
-        if additional_info:
+        if station and additional_info:
             station.get_playable_url()
         return station
     return None
@@ -123,7 +123,7 @@ def vtuner_redirect(url):
 def upstream(path):
     if request.args.get('token') == '0':
         return vtuner.get_init_token()
-    if request.args.get('search'):
+    if request.args.get('search') or request.args.get('Search'):
         return station_search()
     if 'statxml.asp' in path and request.args.get('id'):
         return get_station_info()
@@ -238,15 +238,20 @@ def radiobrowser_popular():
            methods=['GET', 'POST'])
 def station_search():
     query = request.args.get('search')
+    if not query:
+        query = request.args.get('Search')
     if not query or len(query) < 3:
         page = vtuner.Page()
         page.add(vtuner.Display("Search query too short"))
         page.set_count(1)
         return page.to_string()
+    station = get_station_by_id(query, additional_info=(not station_tracking))
+    if station:
+        stations = [station]
     else:
         # TODO: we also need to include 'my station' elements
         stations = radiobrowser.search(query)
-        return get_stations_page(stations, request).to_string()
+    return get_stations_page(stations, request).to_string()
 
 
 @app.route('/' + PATH_ROOT + '/' + PATH_PLAY,

+ 15 - 8
ycast/vtuner.py

@@ -131,14 +131,21 @@ class Station:
         ET.SubElement(item, 'StationName').text = self.name
         if self.trackurl:
             ET.SubElement(item, 'StationUrl').text = self.trackurl
-        else:
+        elif self.url:
             ET.SubElement(item, 'StationUrl').text = self.url
-        ET.SubElement(item, 'StationDesc').text = self.description
-        ET.SubElement(item, 'Logo').text = self.icon
-        ET.SubElement(item, 'StationFormat').text = self.genre
-        ET.SubElement(item, 'StationLocation').text = self.location
-        ET.SubElement(item, 'StationBandWidth').text = str(self.bitrate)
-        ET.SubElement(item, 'StationMime').text = self.mime
+        if self.description:
+            ET.SubElement(item, 'StationDesc').text = self.description
+        if self.icon:
+            ET.SubElement(item, 'Logo').text = self.icon
+        if self.genre:
+            ET.SubElement(item, 'StationFormat').text = self.genre
+        if self.location:
+            ET.SubElement(item, 'StationLocation').text = self.location
+        if self.bitrate:
+            ET.SubElement(item, 'StationBandWidth').text = str(self.bitrate)
+        if self.mime:
+            ET.SubElement(item, 'StationMime').text = self.mime
         ET.SubElement(item, 'Relia').text = '3'
-        ET.SubElement(item, 'Bookmark').text = self.bookmark
+        if self.bookmark:
+            ET.SubElement(item, 'Bookmark').text = self.bookmark
         return item