feat: Add stream URL generation and service URL retrieval for sounds in music player service
This commit is contained in:
@@ -167,6 +167,20 @@ class MusicPlayerService:
|
|||||||
# Fallback if request context is not available
|
# Fallback if request context is not available
|
||||||
return f"http://localhost:5000/api/sounds/{sound_type.lower()}/thumbnails/{thumbnail_filename}"
|
return f"http://localhost:5000/api/sounds/{sound_type.lower()}/thumbnails/{thumbnail_filename}"
|
||||||
|
|
||||||
|
def _build_stream_url(self, sound_type: str, filename: str) -> str:
|
||||||
|
"""Build absolute stream URL."""
|
||||||
|
try:
|
||||||
|
# Try to get base URL from current request context
|
||||||
|
if request:
|
||||||
|
base_url = request.url_root.rstrip("/")
|
||||||
|
else:
|
||||||
|
# Fallback to localhost if no request context
|
||||||
|
base_url = "http://localhost:5000"
|
||||||
|
return f"{base_url}/api/sounds/{sound_type.lower()}/audio/{filename}"
|
||||||
|
except Exception:
|
||||||
|
# Fallback if request context is not available
|
||||||
|
return f"http://localhost:5000/api/sounds/{sound_type.lower()}/audio/{filename}"
|
||||||
|
|
||||||
def _load_playlist_with_context(
|
def _load_playlist_with_context(
|
||||||
self, playlist, reload: bool = False
|
self, playlist, reload: bool = False
|
||||||
) -> bool:
|
) -> bool:
|
||||||
@@ -499,6 +513,12 @@ class MusicPlayerService:
|
|||||||
sound = current_playlist_sound.sound
|
sound = current_playlist_sound.sound
|
||||||
|
|
||||||
if sound:
|
if sound:
|
||||||
|
# Get the service URL from the associated stream
|
||||||
|
service_url = None
|
||||||
|
if sound.streams:
|
||||||
|
# Get the first stream's URL if available
|
||||||
|
service_url = sound.streams[0].url
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"id": sound.id,
|
"id": sound.id,
|
||||||
"title": sound.name,
|
"title": sound.name,
|
||||||
@@ -511,6 +531,8 @@ class MusicPlayerService:
|
|||||||
if sound.thumbnail
|
if sound.thumbnail
|
||||||
else None
|
else None
|
||||||
),
|
),
|
||||||
|
"file_url": self._build_stream_url(sound.type, sound.filename),
|
||||||
|
"service_url": service_url,
|
||||||
"type": sound.type,
|
"type": sound.type,
|
||||||
}
|
}
|
||||||
return None
|
return None
|
||||||
@@ -535,6 +557,12 @@ class MusicPlayerService:
|
|||||||
):
|
):
|
||||||
sound = playlist_sound.sound
|
sound = playlist_sound.sound
|
||||||
if sound:
|
if sound:
|
||||||
|
# Get the service URL from the associated stream
|
||||||
|
service_url = None
|
||||||
|
if sound.streams:
|
||||||
|
# Get the first stream's URL if available
|
||||||
|
service_url = sound.streams[0].url
|
||||||
|
|
||||||
tracks.append(
|
tracks.append(
|
||||||
{
|
{
|
||||||
"id": sound.id,
|
"id": sound.id,
|
||||||
@@ -548,6 +576,8 @@ class MusicPlayerService:
|
|||||||
if sound.thumbnail
|
if sound.thumbnail
|
||||||
else None
|
else None
|
||||||
),
|
),
|
||||||
|
"file_url": self._build_stream_url(sound.type, sound.filename),
|
||||||
|
"service_url": service_url,
|
||||||
"type": sound.type,
|
"type": sound.type,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user