mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-11-08 05:03:52 -05:00
Fix track info with new format
This commit is contained in:
@@ -49,8 +49,8 @@ class OasisMiniMediaPlayerEntity(OasisMiniEntity, MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def media_duration(self) -> int | None:
|
def media_duration(self) -> int | None:
|
||||||
"""Duration of current playing media in seconds."""
|
"""Duration of current playing media in seconds."""
|
||||||
if (track := self.device.track) and "reduced_svg_content" in track:
|
if (track := self.device.track) and "reduced_svg_content_new" in track:
|
||||||
return track["reduced_svg_content"].get("1")
|
return track["reduced_svg_content_new"]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ class OasisMini:
|
|||||||
return None
|
return None
|
||||||
svg_content = decrypt_svg_content(svg_content)
|
svg_content = decrypt_svg_content(svg_content)
|
||||||
paths = svg_content.split("L")
|
paths = svg_content.split("L")
|
||||||
total = self.track.get("reduced_svg_content", {}).get("1", len(paths))
|
total = self.track.get("reduced_svg_content_new", 0) or len(paths)
|
||||||
percent = (100 * self.progress) / total
|
percent = (100 * self.progress) / total
|
||||||
return percent
|
return percent
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -41,7 +41,7 @@ def draw_svg(track: dict, progress: int, model_id: str) -> str | None:
|
|||||||
if progress is not None:
|
if progress is not None:
|
||||||
svg_content = decrypt_svg_content(svg_content)
|
svg_content = decrypt_svg_content(svg_content)
|
||||||
paths = svg_content.split("L")
|
paths = svg_content.split("L")
|
||||||
total = track.get("reduced_svg_content", {}).get(model_id, len(paths))
|
total = track.get("reduced_svg_content_new", 0) or len(paths)
|
||||||
percent = min((100 * progress) / total, 100)
|
percent = min((100 * progress) / total, 100)
|
||||||
progress = math.floor((percent / 100) * (len(paths) - 1))
|
progress = math.floor((percent / 100) * (len(paths) - 1))
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ from custom_components.oasis_mini.pyoasismini.const import TRACKS
|
|||||||
ACCESS_TOKEN = os.getenv("GROUNDED_TOKEN")
|
ACCESS_TOKEN = os.getenv("GROUNDED_TOKEN")
|
||||||
|
|
||||||
|
|
||||||
|
def get_author_name(data: dict) -> str:
|
||||||
|
"""Get author name from a dict."""
|
||||||
|
author = (data.get("author") or {}).get("user") or {}
|
||||||
|
return author.get("name") or author.get("nickname") or "Oasis Mini"
|
||||||
|
|
||||||
|
|
||||||
async def update_tracks() -> None:
|
async def update_tracks() -> None:
|
||||||
"""Update tracks."""
|
"""Update tracks."""
|
||||||
client = OasisMini("", ACCESS_TOKEN)
|
client = OasisMini("", ACCESS_TOKEN)
|
||||||
@@ -32,23 +38,22 @@ async def update_tracks() -> None:
|
|||||||
for result in filter(lambda d: d["public"], data):
|
for result in filter(lambda d: d["public"], data):
|
||||||
if (
|
if (
|
||||||
(track_id := result["id"]) not in TRACKS
|
(track_id := result["id"]) not in TRACKS
|
||||||
or result["name"] != TRACKS[track_id].get("name")
|
or any(
|
||||||
or result["image"] != TRACKS[track_id].get("image")
|
result[field] != TRACKS[track_id].get(field)
|
||||||
|
for field in ("name", "image", "png_image")
|
||||||
|
)
|
||||||
|
or TRACKS[track_id].get("author") != get_author_name(result)
|
||||||
):
|
):
|
||||||
print(f"Updating track {track_id}: {result["name"]}")
|
print(f"Updating track {track_id}: {result['name']}")
|
||||||
track_info = await client.async_cloud_get_track_info(int(track_id))
|
track_info = await client.async_cloud_get_track_info(int(track_id))
|
||||||
if not track_info:
|
if not track_info:
|
||||||
print("No track info")
|
print("No track info")
|
||||||
break
|
break
|
||||||
author = (result.get("author") or {}).get("user") or {}
|
result["author"] = get_author_name(result)
|
||||||
updated_tracks[track_id] = {
|
result["reduced_svg_content_new"] = track_info.get(
|
||||||
"id": track_id,
|
"reduced_svg_content_new"
|
||||||
"name": result["name"],
|
)
|
||||||
"author": author.get("name") or author.get("nickname") or "Oasis Mini",
|
updated_tracks[track_id] = result
|
||||||
"image": result["image"],
|
|
||||||
"clean_pattern": track_info.get("cleanPattern", {}).get("id"),
|
|
||||||
"reduced_svg_content": track_info.get("reduced_svg_content"),
|
|
||||||
}
|
|
||||||
await client.session.close()
|
await client.session.close()
|
||||||
|
|
||||||
if not updated_tracks:
|
if not updated_tracks:
|
||||||
|
|||||||
Reference in New Issue
Block a user