Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
gieljnssns committed May 11, 2023
2 parents f6ceac3 + 311d6bd commit 22ab370
Show file tree
Hide file tree
Showing 39 changed files with 1,946 additions and 556 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pre-commit-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.6.0
with:
python-version: '3.10'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit autoupdate
run: pre-commit autoupdate
- name: Create Pull Request
uses: peter-evans/[email protected].0
uses: peter-evans/[email protected].1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-autoupdate
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/[email protected]
- name: Set up Python 3.10
uses: actions/setup-python@v4.5.0
uses: actions/setup-python@v4.6.0
with:
python-version: "3.10"
- name: Install build
Expand All @@ -21,7 +21,7 @@ jobs:
run: >-
python3 -m build
- name: Publish release to PyPI
uses: pypa/[email protected].5
uses: pypa/[email protected].6
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python
uses: actions/setup-python@v4.5.0
uses: actions/setup-python@v4.6.0
with:
python-version: "3.11"
- name: Install dependencies
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.5.0
uses: actions/setup-python@v4.6.0
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- --branch=main
- id: debug-statements
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.262'
rev: 'v0.0.265'
hooks:
- id: ruff
- repo: https://github.com/psf/black
Expand Down
34 changes: 18 additions & 16 deletions music_assistant/common/models/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
CONF_LOG_LEVEL,
CONF_OUTPUT_CHANNELS,
CONF_OUTPUT_CODEC,
CONF_VOLUME_NORMALISATION,
CONF_VOLUME_NORMALISATION_TARGET,
CONF_VOLUME_NORMALIZATION,
CONF_VOLUME_NORMALIZATION_TARGET,
SECURE_STRING_SUBSTITUTE,
)

Expand Down Expand Up @@ -116,12 +116,14 @@ def parse_value(
if expected_type == int and isinstance(value, float):
self.value = int(value)
return self.value
if expected_type == int and isinstance(value, str) and value.isnumeric():
self.value = int(value)
return self.value
if expected_type == float and isinstance(value, str) and value.isnumeric():
self.value = float(value)
return self.value
for val_type in (int, float):
# convert int/float from string
if expected_type == val_type and isinstance(value, str):
try:
self.value = val_type(value)
return self.value
except ValueError:
pass
if self.type in UI_ONLY:
self.value = self.default_value
return self.value
Expand Down Expand Up @@ -327,23 +329,23 @@ class PlayerConfig(Config):
advanced=True,
)

CONF_ENTRY_VOLUME_NORMALISATION = ConfigEntry(
key=CONF_VOLUME_NORMALISATION,
CONF_ENTRY_VOLUME_NORMALIZATION = ConfigEntry(
key=CONF_VOLUME_NORMALIZATION,
type=ConfigEntryType.BOOLEAN,
label="Enable volume normalization (EBU-R128 based)",
default_value=True,
description="Enable volume normalization based on the EBU-R128 "
"standard without affecting dynamic range",
)

CONF_ENTRY_VOLUME_NORMALISATION_TARGET = ConfigEntry(
key=CONF_VOLUME_NORMALISATION_TARGET,
CONF_ENTRY_VOLUME_NORMALIZATION_TARGET = ConfigEntry(
key=CONF_VOLUME_NORMALIZATION_TARGET,
type=ConfigEntryType.INTEGER,
range=(-30, 0),
default_value=-14,
label="Target level for volume normalisation",
label="Target level for volume normalization",
description="Adjust average (perceived) loudness to this target level, " "default is -14 LUFS",
depends_on=CONF_VOLUME_NORMALISATION,
depends_on=CONF_VOLUME_NORMALIZATION,
advanced=True,
)

Expand Down Expand Up @@ -407,9 +409,9 @@ class PlayerConfig(Config):
)

DEFAULT_PLAYER_CONFIG_ENTRIES = (
CONF_ENTRY_VOLUME_NORMALISATION,
CONF_ENTRY_VOLUME_NORMALIZATION,
CONF_ENTRY_FLOW_MODE,
CONF_ENTRY_VOLUME_NORMALISATION_TARGET,
CONF_ENTRY_VOLUME_NORMALIZATION_TARGET,
CONF_ENTRY_EQ_BASS,
CONF_ENTRY_EQ_MID,
CONF_ENTRY_EQ_TREBLE,
Expand Down
48 changes: 26 additions & 22 deletions music_assistant/common/models/media_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ def quality(self) -> int:
score += 1
return int(score)

def __hash__(self):
def __hash__(self) -> int:
"""Return custom hash."""
return hash((self.provider_domain, self.item_id))
return hash((self.provider_instance, self.item_id))

def __eq__(self, other: ProviderMapping) -> bool:
"""Check equality of two items."""
return self.provider_instance == other.provider_instance and self.item_id == other.item_id


@dataclass(frozen=True)
Expand All @@ -67,10 +71,14 @@ class MediaItemLink(DataClassDictMixin):
type: LinkType
url: str

def __hash__(self):
def __hash__(self) -> int:
"""Return custom hash."""
return hash(self.type)

def __eq__(self, other: MediaItemLink) -> bool:
"""Check equality of two items."""
return self.url == other.url


@dataclass(frozen=True)
class MediaItemImage(DataClassDictMixin):
Expand All @@ -82,9 +90,13 @@ class MediaItemImage(DataClassDictMixin):
# if the path is just a plain (remotely accessible) URL, set it to 'url'
provider: str = "url"

def __hash__(self):
def __hash__(self) -> int:
"""Return custom hash."""
return hash(self.type.value, self.path)
return hash((self.type.value, self.path))

def __eq__(self, other: MediaItemImage) -> bool:
"""Check equality of two items."""
return self.__hash__() == other.__hash__()


@dataclass(frozen=True)
Expand All @@ -96,10 +108,14 @@ class MediaItemChapter(DataClassDictMixin):
position_end: float | None = None
title: str | None = None

def __hash__(self):
def __hash__(self) -> int:
"""Return custom hash."""
return hash(self.chapter_id)

def __eq__(self, other: MediaItemChapter) -> bool:
"""Check equality of two items."""
return self.chapter_id == other.chapter_id


@dataclass
class MediaItemMetadata(DataClassDictMixin):
Expand Down Expand Up @@ -255,10 +271,6 @@ def add_provider_mapping(self, prov_mapping: ProviderMapping) -> None:
}
self.provider_mappings.add(prov_mapping)

def __hash__(self):
"""Return custom hash."""
return hash((self.media_type, self.provider, self.item_id))


@dataclass
class ItemMapping(DataClassDictMixin):
Expand All @@ -280,17 +292,17 @@ def from_item(cls, item: MediaItem):
result.available = item.available
return result

def __hash__(self):
"""Return custom hash."""
return hash((self.media_type, self.provider, self.item_id))

def __post_init__(self):
"""Call after init."""
if not self.uri:
self.uri = create_uri(self.media_type, self.provider, self.item_id)
if not self.sort_name:
self.sort_name = create_sort_name(self.name)

def __hash__(self) -> int:
"""Return custom hash."""
return hash((self.media_type.value, self.provider, self.item_id))


@dataclass
class Artist(MediaItem):
Expand All @@ -299,10 +311,6 @@ class Artist(MediaItem):
media_type: MediaType = MediaType.ARTIST
musicbrainz_id: str | None = None

def __hash__(self):
"""Return custom hash."""
return hash((self.provider, self.item_id))


@dataclass
class Album(MediaItem):
Expand All @@ -316,10 +324,6 @@ class Album(MediaItem):
barcode: set[str] = field(default_factory=set)
musicbrainz_id: str | None = None # release group id

def __hash__(self):
"""Return custom hash."""
return hash((self.provider, self.item_id))


@dataclass
class DbAlbum(Album):
Expand Down
8 changes: 3 additions & 5 deletions music_assistant/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pathlib
from typing import Final

__version__: Final[str] = "2.0.0b29"
__version__: Final[str] = "2.0.0b30"

SCHEMA_VERSION: Final[int] = 22

Expand Down Expand Up @@ -35,8 +35,8 @@
CONF_PATH: Final[str] = "path"
CONF_USERNAME: Final[str] = "username"
CONF_PASSWORD: Final[str] = "password"
CONF_VOLUME_NORMALISATION: Final[str] = "volume_normalisation"
CONF_VOLUME_NORMALISATION_TARGET: Final[str] = "volume_normalisation_target"
CONF_VOLUME_NORMALIZATION: Final[str] = "volume_normalization"
CONF_VOLUME_NORMALIZATION_TARGET: Final[str] = "volume_normalization_target"
CONF_MAX_SAMPLE_RATE: Final[str] = "max_sample_rate"
CONF_EQ_BASS: Final[str] = "eq_bass"
CONF_EQ_MID: Final[str] = "eq_mid"
Expand All @@ -51,8 +51,6 @@
# config default values
DEFAULT_HOST: Final[str] = "0.0.0.0"
DEFAULT_PORT: Final[int] = 8095
DEFAULT_DB_LIBRARY: Final[str] = "sqlite:///[storage_path]/library.db"
DEFAULT_DB_CACHE: Final[str] = "sqlite:///[storage_path]/cache.db"

# common db tables
DB_TABLE_TRACK_LOUDNESS: Final[str] = "track_loudness"
Expand Down
10 changes: 5 additions & 5 deletions music_assistant/server/controllers/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import functools
import json
import logging
import os
import time
from collections import OrderedDict
from collections.abc import Iterator, MutableMapping
from typing import TYPE_CHECKING, Any

from music_assistant.constants import (
CONF_DB_CACHE,
DB_TABLE_CACHE,
DB_TABLE_SETTINGS,
DEFAULT_DB_CACHE,
ROOT_LOGGER_NAME,
SCHEMA_VERSION,
)
Expand Down Expand Up @@ -43,6 +42,7 @@ async def setup(self) -> None:

async def close(self) -> None:
"""Cleanup on exit."""
await self.database.close()

async def get(self, cache_key: str, checksum: str | None = None, default=None):
"""Get object from cache and return the results.
Expand Down Expand Up @@ -120,9 +120,9 @@ async def auto_cleanup(self):

async def _setup_database(self):
"""Initialize database."""
db_url: str = self.mass.config.get(CONF_DB_CACHE, DEFAULT_DB_CACHE)
db_url = db_url.replace("[storage_path]", self.mass.storage_path)
self.database = DatabaseConnection(db_url)
db_path = os.path.join(self.mass.storage_path, "cache.db")
self.database = DatabaseConnection(db_path)
await self.database.setup()

# always create db tables if they don't exist to prevent errors trying to access them later
await self.__create_database_tables()
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/controllers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def save_player_config(
data=config,
)
# signal update to the player manager
with suppress(PlayerUnavailableError):
with suppress(PlayerUnavailableError, AttributeError):
player = self.mass.players.get(config.player_id)
player.enabled = config.enabled
self.mass.players.update(config.player_id, force_update=True)
Expand Down
Loading

0 comments on commit 22ab370

Please sign in to comment.