Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjell Knudsen committed Dec 16, 2024
1 parent f297764 commit 41e2037
Show file tree
Hide file tree
Showing 14 changed files with 529 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Pipfile
/Pipfile.lock
/.flake8
/.envrc
39 changes: 19 additions & 20 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
import urllib.error
import urllib.parse
import urllib.request
from typing import Any
from typing import Any, Dict, List

import xbmc
import xbmcaddon
import xbmcgui
import xbmcplugin
import xbmcvfs

from resources.lib.languagecodes import LanguageCode

addonID: str = "plugin.audio.radiobrowser"
addon: xbmcaddon.Addon = xbmcaddon.Addon(id=addonID)

base_url: str = sys.argv[0]
addon_handle = int(sys.argv[1])
args: dict[str, Any] = urllib.parse.parse_qs(sys.argv[2][1:])
args: Dict[str, Any] = urllib.parse.parse_qs(sys.argv[2][1:])

xbmcplugin.setContent(addon_handle, "songs")

Expand All @@ -30,26 +29,26 @@

PAGE_LIMIT: int = 500

DEFAULT_ICON: dict[str, str] = {"icon": "DefaultFolder.png"}
DEFAULT_ICON: Dict[str, str] = {"icon": "DefaultFolder.png"}


class MyStations:
def __init__(self, my_stations: dict[str, Any]):
def __init__(self, my_stations: Dict[str, Any]):
self.stations = my_stations


MY_STATIONS: MyStations = MyStations({})


def get_radiobrowser_base_urls() -> list[str]:
def get_radiobrowser_base_urls() -> List[str]:
"""
Get all base urls of all currently available radiobrowser servers
Returns:
list: a list of strings
"""
hosts: list[str] = []
hosts: List[str] = []
# get all hosts from DNS
ips = socket.getaddrinfo("all.api.radio-browser.info", 80, 0, 0, socket.IPPROTO_TCP)
for ip_tuple in ips:
Expand All @@ -75,7 +74,7 @@ def LANGUAGE(id: int) -> str:
return addon.getLocalizedString(id)


def build_url(query: dict[str, int | str | bytes]):
def build_url(query: Dict[str, int | str | bytes]):
return base_url + "?" + urllib.parse.urlencode(query)


Expand Down Expand Up @@ -109,7 +108,7 @@ def addLink(stationuuid: str, name: str, url: str, favicon: str, bitrate: str):
)


def downloadFile(uri: str, param, url_parameter: dict[str, Any] = {}) -> bytes:
def downloadFile(uri: str, param, url_parameter: Dict[str, Any] = {}) -> bytes:
"""
Download file with the correct headers set
Expand Down Expand Up @@ -138,7 +137,7 @@ def downloadFile(uri: str, param, url_parameter: dict[str, Any] = {}) -> bytes:


def downloadApiFile(
path: str, param: dict[str, Any] | None, url_parameter: dict[str, str | int] = {}
path: str, param: Dict[str, Any] | None, url_parameter: Dict[str, str | int] = {}
) -> bytes:
"""
Download file with relative url from a random api server.
Expand Down Expand Up @@ -206,7 +205,7 @@ def delFromMyStations(stationuuid: str):


def createDirectoryItem(
urlArgs: dict[str, str | bytes | int], name: str, artArgs: dict[str, str]
urlArgs: Dict[str, str | bytes | int], name: str, artArgs: Dict[str, str]
):
localUrl = build_url(urlArgs)
li = xbmcgui.ListItem(name)
Expand Down Expand Up @@ -260,7 +259,7 @@ def buildMenu() -> None:
xbmcplugin.endOfDirectory(addon_handle)


def buildTagsList(args: dict[str, Any]) -> None:
def buildTagsList(args: Dict[str, Any]) -> None:
page = args.get("page")
if page is not None:
try:
Expand All @@ -270,7 +269,7 @@ def buildTagsList(args: dict[str, Any]) -> None:
else:
page = 0

url_parameter: dict[str, str | int] = {
url_parameter: Dict[str, str | int] = {
"limit": PAGE_LIMIT,
"offset": page * PAGE_LIMIT,
}
Expand Down Expand Up @@ -333,7 +332,7 @@ def buildCountriesList() -> None:
xbmcplugin.endOfDirectory(addon_handle)


def buildStatesList(args: dict[str, Any]) -> None:
def buildStatesList(args: Dict[str, Any]) -> None:
country = args["country"][0]
country = base64.b32decode(country)
country = country.decode("utf-8")
Expand Down Expand Up @@ -372,9 +371,9 @@ def buildStatesList(args: dict[str, Any]) -> None:
xbmcplugin.endOfDirectory(addon_handle)


def buildStationsSearch(args: dict[str, Any]) -> None:
def buildStationsSearch(args: Dict[str, Any]) -> None:
url = "/json/stations/search"
param: dict[str, Any] = {}
param: Dict[str, Any] = {}
if "url" in args:
url = args["url"][0]
else:
Expand All @@ -390,7 +389,7 @@ def buildStationsSearch(args: dict[str, Any]) -> None:
xbmcplugin.endOfDirectory(addon_handle)


def playStation(args: dict[str, Any]) -> None:
def playStation(args: Dict[str, Any]) -> None:
stationuuid = args["stationuuid"][0]
data = downloadApiFile("/json/url/" + str(stationuuid), None)
dataDecoded = json.loads(data)
Expand Down Expand Up @@ -426,7 +425,7 @@ def buildMyStations() -> None:
xbmcplugin.endOfDirectory(addon_handle)


def addStation(args: dict[str, Any]) -> None:
def addStation(args: Dict[str, Any]) -> None:
favicon = args["favicon"][0] if "favicon" in args else ""
addToMyStations(
args["stationuuid"][0],
Expand All @@ -437,7 +436,7 @@ def addStation(args: dict[str, Any]) -> None:
)


def deleteStation(args: dict[str, Any]) -> None:
def deleteStation(args: Dict[str, Any]) -> None:
delFromMyStations(args["stationuuid"][0])


Expand All @@ -461,7 +460,7 @@ def addCustomStation() -> None:
xbmc.executebuiltin("Container.Refresh(" + refresh_url + ")")


def router(mode: str | None, args: dict[str, Any]) -> None:
def router(mode: str | None, args: Dict[str, Any]) -> None:
if mode is None:
buildMenu()
elif mode == "tags":
Expand Down
File renamed without changes.
Loading

0 comments on commit 41e2037

Please sign in to comment.