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

Include item ID in stop playback reporting payload #103

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

v1.0.3
---------------------------------------

- Include item ID in stop playback reporting payload

v1.0.2
---------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion mopidy_jellyfin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mopidy import config, ext


__version__ = '1.0.2'
__version__ = '1.0.3'

logger = logging.getLogger(__name__)

Expand Down
19 changes: 13 additions & 6 deletions mopidy_jellyfin/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, config, core):
self.reporting_thread = threading.Thread(target=self._check_status)
# Kill thread immediately on program exit
self.reporting_thread.daemon = True
self.current_track_id = ''

def on_start(self):
# Start the websocket client and reporting thread
Expand Down Expand Up @@ -85,11 +86,13 @@ def _playback_state_changed(self, data):
self._start_playback(data)
elif new_state == 'stopped':
self._stop_playback()
self.current_track_id = ''

def _stop_playback(self):
# Report to Jellyfin that playback has stopped
data = self._create_progress_payload()
self.wsc.http.post(
'{}/Sessions/Playing/Stopped'.format(self.hostname))
'{}/Sessions/Playing/Stopped'.format(self.hostname), data)

def _start_playback(self, data):
# Report to Jellyfin that playback has started
Expand Down Expand Up @@ -124,10 +127,12 @@ def _create_progress_payload(self):
# Build the json payload sent to the server for playback reporting

session_id = self._get_session_id()
track = self.core.playback.get_current_track().get()
new_item_id = ''

if session_id and track:
item_id = track.uri.split(':')[-1]
if session_id:
track = self.core.playback.get_current_track().get()
if track:
new_item_id = track.uri.split(':')[-1]
mute_state = self.core.mixer.get_mute().get()
volume = self.core.mixer.get_volume().get()
play_time = self.core.playback.get_time_position().get() * 10000
Expand Down Expand Up @@ -158,12 +163,14 @@ def _create_progress_payload(self):
"PositionTicks": play_time,
"PlayMethod": "DirectPlay",
"PlaySessionId": session_id,
"MediaSourceId": item_id,
"MediaSourceId": self.current_track_id or new_item_id,
"CanSeek": True,
"ItemId": item_id,
"ItemId": self.current_track_id or new_item_id,
"NowPlayingQueue": now_playing_queue,
"PlaylistItemId": playlist_item_id,
}
if new_item_id:
self.current_track_id = new_item_id
else:
data = {}

Expand Down