-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Now playing invoked when necessary - Code cleanup and refactoring
- Loading branch information
Showing
9 changed files
with
334 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.env | ||
upnp_scrobbler/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.