from music_assistant_models.media_items.media_item import RecommendationFolder
from music_assistant_models.streamdetails import MultiPartPath, StreamDetails
+from music_assistant.constants import PLAYBACK_REPORT_INTERVAL_SECONDS
from music_assistant.models.music_provider import MusicProvider
from music_assistant.providers.audiobookshelf.parsers import (
parse_audiobook,
async with self.create_session_lock:
# check for an available open session
if session_helper := self.sessions.get(mass_item_id):
+ # reset here, as this is our "time listened".
+ session_helper.last_sync_time = time.time()
with suppress(AbsSessionNotFoundError):
return await self._client.get_open_session(
session_id=session_helper.abs_session_id
# this method is called _before_ get_stream_details, so the playback session
# is created here.
session = await self._get_playback_session(mass_item_id=item_id)
- finished = session.current_time > session.duration - 30
+ finished = session.current_time > session.duration - PLAYBACK_REPORT_INTERVAL_SECONDS
self.logger.debug("Resume position: obtained.")
return finished, int(session.current_time * 1000)
async def _update_by_session(session_helper: SessionHelper, duration: int) -> bool:
now = time.time()
+ time_listened = now - session_helper.last_sync_time
+ if time_listened > PLAYBACK_REPORT_INTERVAL_SECONDS + 3:
+ # See player_queues controller, we get an update every 30s, and immediately on pause
+ # or play.
+ # We reset above 33, as this indicates a trigger after a longer absence and should
+ # not count into abs' statistics
+ self.logger.debug("Resetting time_listened due to longer absence.")
+ time_listened = 0.0
try:
await self._client.sync_open_session(
session_id=session_helper.abs_session_id,
parameters=SyncOpenSessionParameters(
current_time=position,
- time_listened=now - session_helper.last_sync_time,
+ time_listened=time_listened,
duration=duration,
),
)
if media_item is None or not isinstance(media_item, PodcastEpisode):
return
- if fully_played and position < media_item.duration - 30:
+ if fully_played and position < media_item.duration - PLAYBACK_REPORT_INTERVAL_SECONDS:
# faulty position update
# occurs sometimes, if a player disconnects unexpectedly, or reports
# a false position - seen this for MC players, but not for sendspin
if media_item is None or not isinstance(media_item, Audiobook):
return
- if fully_played and position < media_item.duration - 30:
+ if fully_played and position < media_item.duration - PLAYBACK_REPORT_INTERVAL_SECONDS:
# faulty position update, see above
return
if not self.progress_guard.guard_ok_abs(progress):
continue
if progress.current_time is not None:
- if int(progress.current_time) != 0 and not progress.current_time >= 30:
+ if (
+ int(progress.current_time) != 0
+ and not progress.current_time >= PLAYBACK_REPORT_INTERVAL_SECONDS
+ ):
# same as mass default, only > 30s
continue
if progress.library_item_id not in known_ids:
)
if mass_audiobook is None:
return
- if int(progress.current_time) == 0:
+ if int(progress.current_time) == 0 and not progress.is_finished:
await self.mass.music.mark_item_unplayed(mass_audiobook)
else:
await self.mass.music.mark_item_played(
mass_episode = await self.get_podcast_episode(_episode_id, add_progress=False)
except MediaNotFoundError:
return
- if int(progress.current_time) == 0:
+ if int(progress.current_time) == 0 and not progress.is_finished:
await self.mass.music.mark_item_unplayed(mass_episode)
else:
await self.mass.music.mark_item_played(