From dd0f39fcebfa79b37819df60e938b8fe8cf33138 Mon Sep 17 00:00:00 2001 From: ArtyIF Date: Tue, 30 Aug 2022 19:41:14 +0300 Subject: [PATCH] Added ability to vote for stations --- README.md | 2 +- addon.py | 3 ++ addon.xml | 2 +- resources/lib/gui.py | 90 ++++++++++++++++++++--------------------- resources/lib/routes.py | 9 +++++ resources/lib/server.py | 2 +- 6 files changed, 59 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 54eb537..519993f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This plugin is still in an early stage. Here's what it can do and what's planned - [x] Filter states by country - [x] Search stations by name and tags - [x] Add/remove stations to/from Saved Stations -- [ ] Vote for stations +- [x] Vote for stations - [ ] Localization: - - [ ] Of the main interface - - [ ] Of locations and countries diff --git a/addon.py b/addon.py index e5c13e0..6bd68ff 100644 --- a/addon.py +++ b/addon.py @@ -70,6 +70,9 @@ def main(): saved_stations.remove_saved_station(args["url"][0], "url") elif mode[0] == "custom_url": routes.open_custom_url(addon_handle) + elif mode[0] == "vote": + server.connect() + routes.vote_for_station(args["uuid"][0]) elif mode[0] == "results": server.connect() routes.perform_search( diff --git a/addon.xml b/addon.xml index 8b6405a..dacdfc8 100644 --- a/addon.xml +++ b/addon.xml @@ -1,4 +1,4 @@ - + diff --git a/resources/lib/gui.py b/resources/lib/gui.py index e377a22..e6b17e0 100644 --- a/resources/lib/gui.py +++ b/resources/lib/gui.py @@ -67,37 +67,41 @@ def station_item(station, number): li.setProperty("IsPlayable", "true") + context_menu_items = [] if resolved: if not saved_stations.is_in_saved_stations(station["stationuuid"], "uuid"): - li.addContextMenuItems( - [ - ( - "Add to Saved Stations", - "RunPlugin(%s)" - % utils.build_url( - { - "mode": "saved_station_add", - "uuid": station["stationuuid"], - } - ), - ) - ] + context_menu_items.append( + ( + "Add to Saved Stations", + "RunPlugin(%s)" + % utils.build_url( + { + "mode": "saved_station_add", + "uuid": station["stationuuid"], + } + ), + ) ) else: - li.addContextMenuItems( - [ - ( - "Remove from Saved Stations", - "RunPlugin(%s)" - % utils.build_url( - { - "mode": "saved_station_remove", - "uuid": station["stationuuid"], - } - ), - ) - ] + context_menu_items.append( + ( + "Remove from Saved Stations", + "RunPlugin(%s)" + % utils.build_url( + { + "mode": "saved_station_remove", + "uuid": station["stationuuid"], + } + ), + ) ) + context_menu_items.append( + ( + "Vote for Station", + "RunPlugin(%s)" + % utils.build_url({"mode": "vote", "uuid": station["stationuuid"]}), + ) + ) url = utils.build_url( { @@ -108,30 +112,24 @@ def station_item(station, number): ) else: if not saved_stations.is_in_saved_stations(station, "url"): - li.addContextMenuItems( - [ - ( - "Add to Saved Stations", - "RunPlugin(%s)" - % utils.build_url( - {"mode": "saved_station_add", "url": station} - ), - ) - ] + context_menu_items.append( + ( + "Add to Saved Stations", + "RunPlugin(%s)" + % utils.build_url({"mode": "saved_station_add", "url": station}), + ) ) else: - li.addContextMenuItems( - [ - ( - "Remove from Saved Stations", - "RunPlugin(%s)" - % utils.build_url( - {"mode": "saved_station_remove", "url": station} - ), - ) - ] + context_menu_items.append( + ( + "Remove from Saved Stations", + "RunPlugin(%s)" + % utils.build_url({"mode": "saved_station_remove", "url": station}), + ) ) url = utils.build_url({"mode": "listen", "url": station}) + + li.addContextMenuItems(context_menu_items) return (url, li, False) diff --git a/resources/lib/routes.py b/resources/lib/routes.py index 124f16d..af00cfb 100644 --- a/resources/lib/routes.py +++ b/resources/lib/routes.py @@ -380,6 +380,15 @@ def get_saved_station_stations(addon_handle): xbmcplugin.endOfDirectory(addon_handle) +def vote_for_station(uuid): + vote_result = server.post("/vote/" + uuid).json() + + if vote_result["ok"]: + xbmcgui.Dialog().notification("RadioBrowser²", "Voted for station successfully!") + else: + xbmcgui.Dialog().notification("RadioBrowser²", "Voting for station failed: " + vote_result["message"]) + + def play(addon_handle, path, uuid): li = xbmcgui.ListItem(path=path) if len(uuid) > 0: diff --git a/resources/lib/server.py b/resources/lib/server.py index 8f13855..6044b6d 100644 --- a/resources/lib/server.py +++ b/resources/lib/server.py @@ -2,7 +2,7 @@ import random import requests -headers = {"User-Agent": "RadioBrowser2/0.7.0"} +headers = {"User-Agent": "RadioBrowser2/0.8.0"} server_url = ""