Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Added ability to vote for stations
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyIF committed Aug 30, 2022
1 parent a0d0cdf commit dd0f39f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<addon id="plugin.audio.rbb" name="RadioBrowser²" provider-name="ArtyIF" version="0.7.0">
<addon id="plugin.audio.rbb" name="RadioBrowser²" provider-name="ArtyIF" version="0.8.0">
<requires>
<import addon="xbmc.python" version="3.0.0" />
<import addon="script.module.requests" version="2.27.1"/>
Expand Down
90 changes: 44 additions & 46 deletions resources/lib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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)


Expand Down
9 changes: 9 additions & 0 deletions resources/lib/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
import requests

headers = {"User-Agent": "RadioBrowser2/0.7.0"}
headers = {"User-Agent": "RadioBrowser2/0.8.0"}
server_url = ""


Expand Down

0 comments on commit dd0f39f

Please sign in to comment.