PlexKodiConnect/resources/lib/player.py

94 lines
2.7 KiB
Python
Raw Normal View History

2015-12-25 07:07:00 +11:00
# -*- coding: utf-8 -*-
###############################################################################
2017-12-10 00:35:08 +11:00
from logging import getLogger
import copy
2015-12-25 07:07:00 +11:00
2018-01-22 04:31:49 +11:00
from xbmc import Player
2015-12-25 07:07:00 +11:00
2018-01-22 04:31:49 +11:00
from downloadutils import DownloadUtils as DU
from plexbmchelper.subscribers import LOCKER
import playqueue as PQ
import variables as v
2017-05-18 04:22:16 +10:00
import state
2015-12-25 07:07:00 +11:00
###############################################################################
2015-12-25 07:07:00 +11:00
2017-12-10 00:35:08 +11:00
LOG = getLogger("PLEX." + __name__)
2016-09-02 03:41:55 +10:00
###############################################################################
2015-12-25 07:07:00 +11:00
2018-01-26 03:15:38 +11:00
@LOCKER.lockthis
def playback_cleanup():
"""
PKC cleanup after playback ends/is stopped
"""
LOG.debug('playback_cleanup called')
2018-01-26 03:15:38 +11:00
# We might have saved a transient token from a user flinging media via
# Companion (if we could not use the playqueue to store the token)
state.PLEX_TRANSIENT_TOKEN = None
for playerid in state.ACTIVE_PLAYERS:
status = state.PLAYER_STATES[playerid]
# Remember the last played item later
state.OLD_PLAYER_STATES[playerid] = copy.deepcopy(status)
2018-01-26 03:15:38 +11:00
# Stop transcoding
if status['playmethod'] == 'Transcode':
2018-02-04 00:05:18 +11:00
LOG.debug('Tell the PMS to stop transcoding')
2018-01-26 03:15:38 +11:00
DU().downloadUrl(
'{server}/video/:/transcode/universal/stop',
parameters={'session': v.PKC_MACHINE_IDENTIFIER})
# Reset the player's status
status = copy.deepcopy(state.PLAYSTATE)
2018-01-26 03:15:38 +11:00
# As all playback has halted, reset the players that have been active
state.ACTIVE_PLAYERS = []
2018-02-04 00:05:18 +11:00
LOG.debug('Finished PKC playback cleanup')
2018-01-26 03:15:38 +11:00
2017-12-10 00:35:08 +11:00
class PKC_Player(Player):
2015-12-25 07:07:00 +11:00
def __init__(self):
2017-12-10 00:35:08 +11:00
Player.__init__(self)
2017-12-09 05:43:06 +11:00
LOG.info("Started playback monitor.")
2015-12-25 07:07:00 +11:00
2016-02-17 19:13:37 +11:00
def onPlayBackStarted(self):
"""
2016-09-02 03:41:55 +10:00
Will be called when xbmc starts playing a file.
"""
2018-01-22 04:31:49 +11:00
pass
2015-12-25 07:07:00 +11:00
2016-02-21 10:21:39 +11:00
def onPlayBackPaused(self):
2018-01-22 04:31:49 +11:00
"""
Will be called when playback is paused
"""
pass
2015-12-25 07:07:00 +11:00
2016-02-21 10:21:39 +11:00
def onPlayBackResumed(self):
2018-01-22 04:31:49 +11:00
"""
Will be called when playback is resumed
"""
pass
2015-12-25 07:07:00 +11:00
2016-02-21 10:21:39 +11:00
def onPlayBackSeek(self, time, seekOffset):
2018-01-22 04:31:49 +11:00
"""
Will be called when user seeks to a certain time during playback
"""
pass
2016-02-21 10:21:39 +11:00
def onPlayBackStopped(self):
2018-01-22 04:31:49 +11:00
"""
Will be called when playback is stopped by the user
"""
2018-02-04 00:05:18 +11:00
LOG.debug("ONPLAYBACK_STOPPED")
if state.PKC_CAUSED_STOP is True:
state.PKC_CAUSED_STOP = False
LOG.debug('PKC caused this playback stop - ignoring')
else:
playback_cleanup()
2016-03-17 04:01:07 +11:00
2018-01-22 04:31:49 +11:00
def onPlayBackEnded(self):
"""
Will be called when playback ends due to the media file being finished
"""
2018-02-04 00:05:18 +11:00
LOG.debug("ONPLAYBACK_ENDED")
2018-01-26 03:15:38 +11:00
playback_cleanup()