Skip to content

Commit

Permalink
Mark (local) episode as watched when playing next
Browse files Browse the repository at this point in the history
This PR includes:
- Mark the current episode as watched
- Reset resume_time for next episode so it starts from beginning
  • Loading branch information
dagwieers committed Dec 13, 2019
1 parent f18864b commit 4d345ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 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
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 Expand Up @@ -163,7 +175,7 @@ def handle_kodi_lookup_of_current_episode(self, tvshowid, current_episode_id):

@staticmethod
def showtitle_to_id(title):
result = jsonrpc(method='VideoLibrary.GetTVShows', id='libTvShows', params=dict(properties=['title']))
result = jsonrpc(method='VideoLibrary.GetTVShows', params=dict(properties=['title']))

for tvshow in result.get('result', {}).get('tvshows', []):
if tvshow.get('label') == title:
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

0 comments on commit 4d345ba

Please sign in to comment.