Explorar o código

5 recently stations added in first page (experimental)

Thomas Hanika %!s(int64=3) %!d(string=hai) anos
pai
achega
cdb1c932a6
Modificáronse 3 ficheiros con 30 adicións e 5 borrados
  1. 0 1
      ycast/generic.py
  2. 8 3
      ycast/my_recentlystation.py
  3. 22 1
      ycast/server.py

+ 0 - 1
ycast/generic.py

@@ -114,7 +114,6 @@ def writelns_txt_file(file_name, line_list):
     try:
         with open(file_name, 'w') as f:
             f.writelines(line_list)
-            logging.info("File written '%s'", file_name)
     except Exception as ex:
         logging.error("File not written '%s':\n    %s", file_name, ex)
 

+ 8 - 3
ycast/my_recentlystation.py

@@ -2,14 +2,15 @@ import logging
 from ycast import generic
 
 MAX_ENTRIES = 15
+DIRECTORY_NAME = "recently used"
+
 recently_file = generic.get_var_path() + '/recently.yml'
 
 
 def signal_station_selected(name, url, icon):
-    logging.debug("  %s:%s|%s", name, url, icon)
     list_heard_stations = get_stations_list()
     if len(list_heard_stations) == 0:
-        list_heard_stations.append("recently used:\n")
+        list_heard_stations.append(DIRECTORY_NAME + ":\n")
     # make name yaml - like
     name = name.replace(":", " -")
 
@@ -17,7 +18,6 @@ def signal_station_selected(name, url, icon):
         elements = line.split(': ')
         if elements[0] == '  '+name:
             list_heard_stations.remove(line)
-            logging.debug("Name '%s' exists and deleted", name)
     piped_icon = ''
     if icon and len(icon) > 0:
         piped_icon = '|' + icon
@@ -40,3 +40,8 @@ def get_stations_list():
 
 def get_recently_stations_yaml():
     return generic.read_yaml_file(recently_file)
+
+
+def directory_name():
+    dir = generic.read_yaml_file(recently_file)
+    return list(dir.keys())[0]

+ 22 - 1
ycast/server.py

@@ -8,6 +8,7 @@ import ycast.radiobrowser as radiobrowser
 import ycast.my_stations as my_stations
 import ycast.generic as generic
 import ycast.station_icons as station_icons
+from ycast import my_recentlystation
 from ycast.my_recentlystation import signal_station_selected
 
 PATH_ROOT = 'ycast'
@@ -122,7 +123,7 @@ def vtuner_redirect(url):
 @app.route('/setupapp/<path:path>',
            methods=['GET', 'POST'])
 def upstream(path):
-    logging.debug('**********************:  %s', request.url)
+    logging.debug('upstream **********************:  %s', request.url)
     if request.args.get('token') == '0':
         return vtuner.get_init_token()
     if request.args.get('search'):
@@ -152,6 +153,26 @@ def landing(path=''):
     if my_stations_enabled:
         page.add(vtuner.Directory('My Stations', url_for('my_stations_landing', _external=True),
                                   len(my_stations.get_category_directories())))
+
+        stations = my_stations.get_stations_by_category(my_recentlystation.directory_name())
+        if stations:
+# emulate Sp
+            page.add(vtuner.Directory(' ', url_for('my_stations_landing', _external=True),
+                                      len(my_stations.get_category_directories())))
+            count = 0
+            for station in stations:
+                vtuner_station = station.to_vtuner()
+                if station_tracking:
+                    vtuner_station.set_trackurl(
+                        request.host_url + PATH_ROOT + '/' + PATH_PLAY + '?id=' + vtuner_station.uid)
+                vtuner_station.icon = request.host_url + PATH_ROOT + '/' + PATH_ICON + '?id=' + vtuner_station.uid
+                page.add(vtuner_station)
+                count = count + 1
+                if count > 4:
+                    break
+
+        page.set_count(3)
+
     else:
         page.add(vtuner.Display("'My Stations' feature not configured."))
         page.set_count(1)