瀏覽代碼

Implemented clickvote

Canuma 3 年之前
父節點
當前提交
62d33d2ce6
共有 2 個文件被更改,包括 13 次插入2 次删除
  1. 8 0
      ycast/radiobrowser.py
  2. 5 2
      ycast/server.py

+ 8 - 0
ycast/radiobrowser.py

@@ -155,3 +155,11 @@ def get_stations_by_votes(limit=DEFAULT_STATION_LIMIT):
         if SHOW_BROKEN_STATIONS or get_json_attr(station_json, 'lastcheckok') == 1:
             stations.append(Station(station_json))
     return stations
+
+
+def click_vote(uid):
+    clickvote_json = request('url/' + str(uid))
+    if clickvote_json:
+        logging.debug("radio-browser replied: %s", get_json_attr(clickvote_json, 'message'))
+    else:
+        logging.error('clickvote did not work')

+ 5 - 2
ycast/server.py

@@ -24,6 +24,7 @@ PATH_RADIOBROWSER_POPULAR = 'popular'
 
 station_tracking = False
 my_stations_enabled = False
+enable_clickvote = False
 app = Flask(__name__)
 
 
@@ -111,10 +112,12 @@ def get_station_by_id(stationid, additional_info=False):
     return None
 
 
-def vtuner_redirect(url):
+def vtuner_redirect(url, stationid):
     if request and request.host and not re.search("^[A-Za-z0-9]+\.vtuner\.com$", request.host):
         logging.warning("You are not accessing a YCast redirect with a whitelisted host url (*.vtuner.com). "
                         "Some AVRs have problems with this. The requested host was: %s", request.host)
+        if enable_clickvote:
+            radiobrowser.click_vote(generic.get_stationid_without_prefix(stationid))
     return redirect(url, code=302)
 
 
@@ -261,7 +264,7 @@ def get_stream_url():
         logging.error("Could not get station with id '%s'", stationid)
         abort(404)
     logging.debug("Station with ID '%s' requested", station.id)
-    return vtuner_redirect(station.url)
+    return vtuner_redirect(station.url, station.id)
 
 
 @app.route('/' + PATH_ROOT + '/' + PATH_STATION,