def report_playback(self, report=True): ''' Report playback progress to emby server. Check if the user seek. ''' current_file = self.get_playing_file() if not self.is_playing_file(current_file): return item = self.get_file_info(current_file) if window('emby.external.bool'): return if not report: previous = item['CurrentPosition'] item['CurrentPosition'] = int(self.getTime()) if int(item['CurrentPosition']) == 1: return try: played = float(item['CurrentPosition'] * 10000000) / int( item['Runtime']) * 100 except ZeroDivisionError: # Runtime is 0. played = 0 if played > 2.0 and not self.up_next: self.up_next = True self.next_up() if (item['CurrentPosition'] - previous) < 30: return result = JSONRPC('Application.GetProperties').execute( {'properties': ["volume", "muted"]}) result = result.get('result', {}) item['Volume'] = result.get('volume') item['Muted'] = result.get('muted') item['CurrentPosition'] = int(self.getTime()) self.detect_audio_subs(item) data = { 'QueueableMediaTypes': "Video,Audio", 'CanSeek': True, 'ItemId': item['Id'], 'MediaSourceId': item['MediaSourceId'], 'PlayMethod': item['PlayMethod'], 'VolumeLevel': item['Volume'], 'PositionTicks': int(item['CurrentPosition'] * 10000000), 'IsPaused': item['Paused'], 'IsMuted': item['Muted'], 'PlaySessionId': item['PlaySessionId'], 'AudioStreamIndex': item['AudioStreamIndex'], 'SubtitleStreamIndex': item['SubtitleStreamIndex'] } item['Server']['api'].session_progress(data)
def set_item(self, file, item): ''' Set playback information. ''' try: item['Runtime'] = int(item['Runtime']) except (TypeError, ValueError): try: item['Runtime'] = int(self.getTotalTime()) LOG.info("Runtime is missing, Kodi runtime: %s" % item['Runtime']) except Exception: item['Runtime'] = 0 LOG.info("Runtime is missing, Using Zero") try: seektime = self.getTime() except Exception: # at this point we should be playing and if not then bail out return result = JSONRPC('Application.GetProperties').execute({'properties': ["volume", "muted"]}) result = result.get('result', {}) volume = result.get('volume') muted = result.get('muted') item.update({ 'File': file, 'CurrentPosition': item.get('CurrentPosition') or int(seektime), 'Muted': muted, 'Volume': volume, 'Server': Jellyfin(item['ServerId']).get_client(), 'Paused': False }) self.played[file] = item LOG.info("-->[ play/%s ] %s", item['Id'], item)
def get_volume(self): ''' Safe to replace in child class. Return volume and mute. ''' result = JSONRPC('Application.GetProperties').execute( {'properties': ["volume", "muted"]}) result = result.get('result', {}) volume = result.get('volume') muted = result.get('muted') return volume, muted
def get_current_streams(self): ''' Safe to replace in child class. Return audio stream, subtitle stream, subtitle bool. ''' params = { 'playerid': self.monitor.playlistid, 'properties': ["currentsubtitle", "currentaudiostream", "subtitleenabled"] } result = JSONRPC('Player.GetProperties').execute(params) result = result.get('result') try: # Audio tracks audio = result['currentaudiostream']['index'] except (KeyError, TypeError): audio = 0 try: # Subtitles tracks subs = result['currentsubtitle']['index'] except (KeyError, TypeError): subs = 0 try: # If subtitles are enabled subs_enabled = result['subtitleenabled'] except (KeyError, TypeError): subs_enabled = False return audio, subs, subs_enabled
def detect_audio_subs(self, item): params = { 'playerid': 1, 'properties': ["currentsubtitle", "currentaudiostream", "subtitleenabled"] } result = JSONRPC('Player.GetProperties').execute(params) result = result.get('result') try: # Audio tracks audio = result['currentaudiostream']['index'] except (KeyError, TypeError): audio = 0 try: # Subtitles tracks subs = result['currentsubtitle']['index'] except (KeyError, TypeError): subs = 0 try: # If subtitles are enabled subs_enabled = result['subtitleenabled'] except (KeyError, TypeError): subs_enabled = False item['AudioStreamIndex'] = audio + 1 if not subs_enabled or not len(self.getAvailableSubtitleStreams()): item['SubtitleStreamIndex'] = None return mapping = item['SubsMapping'] tracks = len(self.getAvailableAudioStreams()) if mapping: if str(subs) in mapping: item['SubtitleStreamIndex'] = mapping[str(subs)] else: item['SubtitleStreamIndex'] = subs - len(mapping) + tracks + 1 else: item['SubtitleStreamIndex'] = subs + tracks + 1
def get_grouped_set(): ''' Get if boxsets should be grouped ''' result = JSONRPC('Settings.GetSettingValue').execute( {'setting': "videolibrary.groupmoviesets"}) return result.get('result', {}).get('value', False)