Skip to content

Commit

Permalink
Revamped
Browse files Browse the repository at this point in the history
- Now playing invoked when necessary
- Code cleanup and refactoring
  • Loading branch information
GioF71 committed Dec 18, 2024
1 parent 7aeb8cd commit de00b07
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 258 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
upnp_scrobbler/__pycache__
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Start the container with the following:

DATE|DESCRIPTION
:---|:---
2024-12-18|Now playing is executed when appropriate only
2024-12-18|Code refactored
2024-12-11|Log host ip
2024-12-10|Add debug logging, to be refined
2024-11-29|Improved general reliability and management of duration
Expand Down
31 changes: 31 additions & 0 deletions upnp_scrobbler/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import constants


def get_bool_config(env_key: str, default_value: bool) -> bool:
cfg: str = os.getenv(env_key)
if not cfg: return default_value
return cfg.upper() == 'Y' or cfg.upper() == 'YES'


def get_dump_upnp_data() -> bool:
return get_bool_config(
env_key="DUMP_UPNP_DATA",
default_value=constants.DEFAULT_DUMP_UPNP_DATA)


def get_duration_threshold() -> int:
duration_cfg: str = os.getenv("DURATION_THRESHOLD")
if not duration_cfg: return constants.DEFAULT_DURATION_THRESHOLD
return int(duration_cfg)


def get_minimum_delta() -> float:
# not currently configurable
return constants.DEFAULT_MINIMUM_DELTA


def get_enable_now_playing() -> bool:
return get_bool_config(
env_key="ENABLE_NOW_PLAYING",
default_value=constants.DEFAULT_ENABLE_NOW_PLAYING)
6 changes: 6 additions & 0 deletions upnp_scrobbler/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEFAULT_DURATION_THRESHOLD: int = 240
DEFAULT_DUMP_UPNP_DATA: bool = False
DEFAULT_ENABLE_NOW_PLAYING: bool = True

# we accept new scrobbles for the same song after (seconds) ...
DEFAULT_MINIMUM_DELTA: float = 10.0
8 changes: 8 additions & 0 deletions upnp_scrobbler/event_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import Enum


class EventName(Enum):
TRANSPORT_STATE = "TransportState"
CURRENT_PLAY_MODE = "CurrentPlayMode"
CURRENT_TRACK_META_DATA = "CurrentTrackMetaData"
AV_TRANSPORT_URI_META_DATA = "AVTransportURIMetaData"
18 changes: 18 additions & 0 deletions upnp_scrobbler/player_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from enum import Enum


class PlayerState(Enum):
UNKNOWN = ""
PLAYING = "PLAYING"
PAUSED_PLAYBACK = "PAUSED_PLAYBACK"
STOPPED = "STOPPED"
TRANSITIONING = "TRANSITIONING"


def get_player_state(transport_state: str) -> PlayerState:
for _, member in PlayerState.__members__.items():
if transport_state == member.value:
print(f"get_player_state {transport_state} -> {member.value}")
return member
print(f"get_player_state state for {transport_state} not found")
return PlayerState.UNKNOWN
Loading

0 comments on commit de00b07

Please sign in to comment.