Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No scrobble #1903

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions music_assistant/providers/opensubsonic/sonic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ async def get_stream_details(
item.content_type,
)

self.mass.create_task(self._report_playback_started(item_id))
elif media_type == MediaType.PODCAST_EPISODE:
item = await self._get_podcast_episode(item_id)

Expand All @@ -760,13 +759,20 @@ async def get_stream_details(
item.id,
item.content_type,
)
self.mass.create_task(self._report_playback_started(item.id))
else:
msg = f"Unsupported media type encountered '{media_type}'"
raise UnsupportedFeaturedException(msg)

mime_type = item.content_type
if mime_type.endswith("mpeg"):
# For mp4 or m4a files, better to let ffmpeg detect the codec in use so mark them unknown
if mime_type.endswith("mp4"):
self.logger.warning(
"Due to the streaming method used by the subsonic API, M4A files "
"may fail. See provider documentation for more information."
)
mime_type = "?"
# For mp3 files, ffmpeg wants to be told 'mp3' instead of 'audio/mpeg'
elif mime_type.endswith("mpeg"):
mime_type = item.suffix

return StreamDetails(
Expand All @@ -780,10 +786,6 @@ async def get_stream_details(
duration=item.duration if item.duration else 0,
)

async def _report_playback_started(self, item_id: str) -> None:
self.logger.debug("scrobble for now playing called for %s", item_id)
await self._run_async(self._conn.scrobble, sid=item_id, submission=False)

async def on_played(
self,
media_type: MediaType,
Expand All @@ -804,8 +806,10 @@ async def on_played(
When fully_played is set to false and position is 0,
the user marked the item as unplayed in the UI.
"""
self.logger.debug("scrobble for listen count called for %s", item_id)
await self._run_async(self._conn.scrobble, sid=item_id, submission=True)
# Only scrobble completed plays
if fully_played:
self.logger.debug("scrobble for listen count called for %s", item_id)
await self._run_async(self._conn.scrobble, sid=item_id, submission=True)

async def get_audio_stream(
self, streamdetails: StreamDetails, seek_position: int = 0
Expand All @@ -827,7 +831,7 @@ def _streamer() -> None:
timeOffset=seek_position,
estimateContentLength=True,
) as stream:
for chunk in stream.iter_content(chunk_size=40960):
for chunk in stream.iter_content(chunk_size=4096):
asyncio.run_coroutine_threadsafe(
audio_buffer.put(chunk), self.mass.loop
).result()
Expand Down
Loading