Skip to content

Commit

Permalink
Update episode metadata before playing next
Browse files Browse the repository at this point in the history
This PR includes:
- Mark the current episode as watched
- Reset resume position of the next episode before playing
- Extend jsonrpc to support JSONRPC batch mode
  • Loading branch information
dagwieers committed Dec 13, 2019
1 parent f18864b commit 53edfd2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
18 changes: 15 additions & 3 deletions resources/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ def addon_data_received(self, data, encoding='base64'):
self.encoding = encoding

@staticmethod
def play_kodi_item(episode):
jsonrpc(method='Player.Open', id=0, params=dict(item=dict(episodeid=episode.get('episodeid'))))
def play_kodi_item(episode, current_episodeid):
''' Play the next local episode '''
# Reset resume_time for next episode so we force starting from the beginning
# jsonrpc(dict(method='VideoLibrary.SetEpisodeDetails', params=dict(episodeid=episode.get('episodeid'), resume=dict(position=0))))

# Play the next episode
jsonrpc(dict(method='Player.Open', params=dict(item=dict(episodeid=episode.get('episodeid')))))

# If we do this too quickly, it won't be effective :-(
sleep(200)

# Mark the current episode as watched and reset position (Cannot run in batch)
jsonrpc(dict(method='VideoLibrary.SetEpisodeDetails', params=dict(episodeid=current_episodeid, playcount=1, resume=dict(position=0))))

def get_next_in_playlist(self, position):
result = jsonrpc(method='Playlist.GetItems', params=dict(
Expand Down Expand Up @@ -76,7 +87,8 @@ def handle_addon_lookup_of_current_episode(self):
return self.data.get('current_episode')

def notification_time(self, total_time=None):
# Alway use metadata, when available
''' Determine the best notification time to use '''
# Always use metadata, when available
if self.data.get('notification_time'):
return int(self.data.get('notification_time'))

Expand Down
2 changes: 1 addition & 1 deletion resources/lib/playbackmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def launch_popup(self, episode, playlist_item):
elif self.api.has_addon_data():
self.api.play_addon_item()
else:
self.api.play_kodi_item(episode)
self.api.play_kodi_item(episode, self.state.current_episode_id)

def show_popup_and_wait(self, episode, next_up_page, still_watching_page):
try:
Expand Down
23 changes: 19 additions & 4 deletions resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,26 @@ def calculate_progress_steps(period):
return (100.0 / int(period)) / 10


def jsonrpc(**kwargs):
def jsonrpc(*args, **kwargs):
''' Perform JSONRPC calls '''
if 'id' not in kwargs:
kwargs.update(id=1)
if 'jsonrpc' not in kwargs:
# We do not accept both args and kwargs
if args and kwargs:
log('ERROR: Wrong use of jsonrpc()')
return None

# Process a list of actions
if args:
for (idx, cmd) in enumerate(args):
if cmd.get('id') is None:
cmd.update(id=idx)
if cmd.get('jsonrpc') is None:
cmd.update(jsonrpc='2.0')
return json.loads(executeJSONRPC(json.dumps(args)))

# Process a single action
if kwargs.get('id') is None:
kwargs.update(id=0)
if kwargs.get('jsonrpc') is None:
kwargs.update(jsonrpc='2.0')
return json.loads(executeJSONRPC(json.dumps(kwargs)))

Expand Down

0 comments on commit 53edfd2

Please sign in to comment.