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

Commit

Permalink
v0.6.1
Browse files Browse the repository at this point in the history
Removed a lot of duplicate code
  • Loading branch information
ArtyIF committed Aug 29, 2022
1 parent 4a2dc6e commit 129740b
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 294 deletions.
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.6.0">
<addon id="plugin.audio.rbb" name="RadioBrowser²" provider-name="ArtyIF" version="0.6.1">
<requires>
<import addon="xbmc.python" version="3.0.0" />
<import addon="script.module.requests" version="2.27.1"/>
Expand Down
295 changes: 4 additions & 291 deletions resources/lib/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,7 @@ def get_stations(addon_handle, kind, page, orderby, reverse):

station_list = []
for station in response:
votes = [f"[B]{station['votes']} votes[/B]"]
# TODO: localize language and location. pycountry maybe?
language = station["language"].split(",")
language = [i.title() for i in language]

location = [station["state"], station["country"]]
tags = station["tags"].split(",")

cleaned_tags = [i for i in votes + language + location + tags if i]
genre = ", ".join(cleaned_tags)

if station["lastcheckok"] == 0:
genre = "[B]Offline![/B] " + genre

li = xbmcgui.ListItem(station["name"], genre)

li.setInfo(
"music",
{
"title": station["name"],
"tracknumber": (page * 50) + len(station_list) + 1,
"size": station["bitrate"],
"genre": genre,
},
)
li.setArt(
{
"thumb": station["favicon"],
"poster": station["favicon"],
"fanart": station["favicon"],
"landscape": station["favicon"],
"icon": station["favicon"],
}
)
li.setProperty("IsPlayable", "true")
url = utils.build_url(
{"mode": "listen", "url": station["url_resolved"], "uuid": station["stationuuid"]}
)
station_list.append((url, li, False))
station_list.append(utils.station_item(station, (page * 50) + len(station_list) + 1))

station_list.append(
utils.next_page_item(response, "stations", page, {"kind": kind})
Expand Down Expand Up @@ -149,223 +111,13 @@ def open_search_directory(addon_handle):


def open_stations_sort_directory(addon_handle, kind):
menu_list = []

li = xbmcgui.ListItem("Most Voted First")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "votes", "reverse": "true"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Least Voted First")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "votes", "reverse": "false"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Most Listeners First")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "clickcount", "reverse": "true"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Least Listeners First")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "clickcount", "reverse": "false"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Name (A-Z)")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "name", "reverse": "false"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Name (Z-A)")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "name", "reverse": "true"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Bitrate (highest first)")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "bitrate", "reverse": "true"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Bitrate (lowest and undefined first)")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "bitrate", "reverse": "false"}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Recently Changed (oldest first)")
url = utils.build_url(
{
"mode": "stations",
"kind": kind,
"orderby": "changetimestamp",
"reverse": "false",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Recently Changed (newest first)")
url = utils.build_url(
{
"mode": "stations",
"kind": kind,
"orderby": "changetimestamp",
"reverse": "true",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Random")
url = utils.build_url(
{"mode": "stations", "kind": kind, "orderby": "random", "reverse": "false"}
)
menu_list.append((url, li, True))

menu_list = utils.sort_menu("stations", {"kind": kind})
xbmcplugin.addDirectoryItems(addon_handle, menu_list)
xbmcplugin.endOfDirectory(addon_handle)


def open_search_sort_directory(addon_handle, kind, search_text):
menu_list = []

li = xbmcgui.ListItem("Most Voted First")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "votes",
"reverse": "true",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Least Voted First")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "votes",
"reverse": "false",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Most Listeners First")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "clickcount",
"reverse": "true",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Least Listeners First")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "clickcount",
"reverse": "false",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Name (A-Z)")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "name",
"reverse": "false",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Name (Z-A)")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "name",
"reverse": "true",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Bitrate (highest first)")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "bitrate",
"reverse": "true",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Bitrate (lowest and undefined first)")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "bitrate",
"reverse": "false",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Recently Changed (oldest first)")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "changetimestamp",
"reverse": "false",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Sort by Recently Changed (newest first)")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "changetimestamp",
"reverse": "true",
}
)
menu_list.append((url, li, True))

li = xbmcgui.ListItem("Random")
url = utils.build_url(
{
"mode": "results",
"kind": kind,
"search_text": search_text,
"orderby": "random",
"reverse": "false",
}
)
menu_list.append((url, li, True))

menu_list = utils.sort_menu("results", {"kind": kind, "search_text": search_text})
xbmcplugin.addDirectoryItems(addon_handle, menu_list)
xbmcplugin.endOfDirectory(addon_handle)

Expand Down Expand Up @@ -590,46 +342,7 @@ def perform_search(addon_handle, kind, search_text, orderby, reverse, page):

results_list = []
for station in response:
votes = [f"[B]{station['votes']} votes[/B]"]
# TODO: localize language and location. pycountry maybe?
language = station["language"].split(",")
language = [i.title() for i in language]

location = [station["state"], station["country"]]
tags = station["tags"].split(",")

cleaned_tags = [i for i in votes + language + location + tags if i]
genre = ", ".join(cleaned_tags)

if station["lastcheckok"] == 0:
genre = "[B]Offline![/B] " + genre

li = xbmcgui.ListItem(station["name"], genre)

li.setInfo(
"music",
{
"title": station["name"],
"tracknumber": (page * 50) + len(results_list) + 1,
"size": station["bitrate"],
"genre": genre,
"playcount": station["clickcount"],
},
)
li.setArt(
{
"thumb": station["favicon"],
"poster": station["favicon"],
"fanart": station["favicon"],
"landscape": station["favicon"],
"icon": station["favicon"],
}
)
li.setProperty("IsPlayable", "true")
url = utils.build_url(
{"mode": "listen", "url": station["url_resolved"], "uuid": station["stationuuid"]}
)
results_list.append((url, li, False))
results_list.append(utils.station_item(station, (page * 50) + len(results_list) + 1))

results_list.append(
utils.next_page_item(
Expand Down
3 changes: 1 addition & 2 deletions resources/lib/server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import socket
import random
import requests
import xbmcgui

headers = {"User-Agent": "RadioBrowser2/0.6.0"}
headers = {"User-Agent": "RadioBrowser2/0.6.1"}
server_url = ""


Expand Down
Loading

0 comments on commit 129740b

Please sign in to comment.