Skip to content

Commit

Permalink
Updates to latest sxm versions
Browse files Browse the repository at this point in the history
  • Loading branch information
AngellusMortis committed Jul 23, 2021
1 parent 6e72529 commit 6266e1b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 29 deletions.
14 changes: 10 additions & 4 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@
History
=======

0.2.3 (2021-08-17)
0.2.4 (2021-07-23)
------------------

* Adds args from latest `sxm`
* Improves performance on `PlayerState.get_channel`

0.2.3 (2021-07-17)
------------------

* Adds env var for `CLIPlayer` `channel-id`: `SXM_CLI_CHANNEL_ID`
* Adds env var for `CLIPlayer` `filename`: `SXM_CLI_FILENAME`

0.2.2 (2021-08-17)
0.2.2 (2021-07-17)
------------------

* Adds env var for `player_class`: `SXM_PLAYER_CLASS`

0.2.1 (2021-08-17)
0.2.1 (2021-07-17)
------------------

* Adds missing py.typed to add stubs
* Renames `queue.Event` enum to `queue.EventTypes`

0.2.0 (2021-08-15)
0.2.0 (2021-07-15)
------------------

* Replaces setuptools with filt
Expand Down
21 changes: 11 additions & 10 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ aiohttp==3.7.4.post0
# via sxm
alabaster==0.7.12
# via sphinx
anyio==3.2.1
anyio==3.3.0
# via httpcore
appdirs==1.4.4
# via black
astroid==2.6.2
astroid==2.6.5
# via pylint
async-timeout==3.0.1
# via aiohttp
Expand Down Expand Up @@ -174,11 +174,11 @@ packaging==21.0
# tox
parso==0.8.2
# via jedi
pathspec==0.8.1
pathspec==0.9.0
# via black
pbr==5.6.0
# via stevedore
pep517==0.10.0
pep517==0.11.0
# via pip-tools
pexpect==4.8.0
# via ipython
Expand Down Expand Up @@ -217,7 +217,7 @@ pygments==2.9.0
# ipython
# rich
# sphinx
pylint==2.9.3
pylint==2.9.5
# via sxm_player (pyproject.toml)
pymongo[srv,tls]==3.11.4
# via snooty-lextudio
Expand Down Expand Up @@ -298,13 +298,13 @@ sphinxcontrib-qthelp==1.0.3
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
# via sphinx
sqlalchemy==1.4.21
sqlalchemy==1.4.22
# via sxm_player (pyproject.toml)
sqlalchemy-stubs==0.4
# via sxm_player (pyproject.toml)
stevedore==3.3.0
# via bandit
sxm==0.2.5
sxm==0.2.7
# via sxm_player (pyproject.toml)
tenacity==8.0.1
# via sxm
Expand All @@ -315,15 +315,16 @@ toml==0.10.2
# flit
# flit-core
# mypy
# pep517
# pylint
# pyproject-flake8
# pytest
# pytest-cov
# snooty-lextudio
# tox
tomli==1.0.4
# via black
tomli==1.1.0
# via
# black
# pep517
tox==3.24.0
# via sxm_player (pyproject.toml)
traitlets==5.0.5
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ requires=[
'pydantic',
'pyyaml',
'sqlalchemy',
'sxm>=0.2.5',
'sxm>=0.2.7',
'typer',
]

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
aiohttp==3.7.4.post0
# via sxm
anyio==3.2.1
anyio==3.3.0
# via httpcore
async-timeout==3.0.1
# via aiohttp
Expand Down Expand Up @@ -86,9 +86,9 @@ sniffio==1.2.0
# anyio
# httpcore
# httpx
sqlalchemy==1.4.21
sqlalchemy==1.4.22
# via sxm_player (pyproject.toml)
sxm==0.2.5
sxm==0.2.7
# via sxm_player (pyproject.toml)
tenacity==8.0.1
# via sxm
Expand Down
2 changes: 1 addition & 1 deletion sxm_player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = """Christopher Bailey"""
__email__ = "[email protected]"
__version__ = "0.2.3"
__version__ = "0.2.4"
4 changes: 4 additions & 0 deletions sxm_player/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
OPTION_HOST,
OPTION_PASSWORD,
OPTION_PORT,
OPTION_PRECACHE,
OPTION_QUALITY,
OPTION_REGION,
OPTION_USERNAME,
Expand Down Expand Up @@ -88,6 +89,7 @@ def main(
host: str = OPTION_HOST,
output_folder: Optional[Path] = OPTION_OUTPUT_FOLDER,
reset_songs: bool = OPTION_RESET_SONGS,
precache: bool = OPTION_PRECACHE,
player_class: Optional[str] = ARG_PLAYER_CLASS,
):
"""Command line interface for sxm-player"""
Expand Down Expand Up @@ -132,6 +134,7 @@ def spawn_sxm_worker(
password: str,
region: RegionChoice,
quality: QualitySize,
precache: bool,
**kwargs,
):
runner.create_worker(
Expand All @@ -143,6 +146,7 @@ def spawn_sxm_worker(
password=password,
region=region,
quality=quality,
precache=precache,
)


Expand Down
23 changes: 14 additions & 9 deletions sxm_player/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import time
from datetime import datetime, timedelta, timezone
from typing import List, Optional, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union

from pydantic import BaseModel, PrivateAttr # pylint: disable=no-name-in-module
from sqlalchemy import Column, DateTime, String
Expand Down Expand Up @@ -156,6 +156,8 @@ class PlayerState(BaseModel):
_start_time: Optional[datetime] = PrivateAttr(None)
_time_offset: Optional[timedelta] = PrivateAttr(None)

_channels_lookup_cache: Dict[str, XMChannel] = PrivateAttr({})

@property
def stream_data(self) -> Tuple[Optional[str], Optional[str]]:
return (self.stream_channel, self.stream_url)
Expand All @@ -182,6 +184,7 @@ def update_channels(self, value: Optional[List[dict]]) -> None:
"""

self._channels = None
self._channels_lookup_cache = {}
self._raw_channels = value

if self._raw_channels is None:
Expand Down Expand Up @@ -307,11 +310,13 @@ def get_channel(self, name: str) -> Optional[XMChannel]:
"""Returns channel from list of `channels` with given name"""

name = name.lower()
for channel in self.channels:
if (
channel.name.lower() == name
or channel.id.lower() == name
or str(channel.channel_number) == name
):
return channel
return None
if name not in self._channels_lookup_cache:
for channel in self.channels:
if (
channel.name.lower() == name
or channel.id.lower() == name
or str(channel.channel_number) == name
):
self._channels_lookup_cache[name] = channel
break
return self._channels_lookup_cache.get(name)
8 changes: 7 additions & 1 deletion sxm_player/workers/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ServerWorker(InterruptableWorker):

_ip: str
_port: int
_precache: bool
sxm: SXMClient

def __init__(
Expand All @@ -28,13 +29,15 @@ def __init__(
password: str,
region: RegionChoice,
quality: QualitySize,
precache: bool,
*args,
**kwargs,
):
super().__init__(*args, **kwargs)

self._port = port
self._ip = ip
self._precache = precache

self.sxm = SXMClient(
username=username,
Expand Down Expand Up @@ -71,7 +74,10 @@ def run(self) -> None:
request_logger.info = request_logger.debug # type: ignore

app = web.Application()
app.router.add_get("/{_:.*}", make_http_handler(self.sxm.async_client))
app.router.add_get(
"/{_:.*}",
make_http_handler(self.sxm.async_client, cache_aac_chunks=self._precache),
)
try:
self._log.info(f"{self.name} has started on http://{self._ip}:{self._port}")
web.run_app(
Expand Down

0 comments on commit 6266e1b

Please sign in to comment.