Fix artwork bug in Apple TV (#9415)

* Fix artwork bug in Apple TV

* Clean up some None checks
This commit is contained in:
Pierre Ståhl 2017-09-14 07:30:29 +02:00 committed by Paulus Schoutsen
parent c94b3a7bf9
commit ba5e8d133d

View File

@ -93,7 +93,7 @@ class AppleTvDevice(MediaPlayerDevice):
if not self._power.turned_on: if not self._power.turned_on:
return STATE_OFF return STATE_OFF
if self._playing is not None: if self._playing:
from pyatv import const from pyatv import const
state = self._playing.play_state state = self._playing.play_state
if state == const.PLAY_STATE_NO_MEDIA or \ if state == const.PLAY_STATE_NO_MEDIA or \
@ -131,7 +131,7 @@ class AppleTvDevice(MediaPlayerDevice):
@property @property
def media_content_type(self): def media_content_type(self):
"""Content type of current playing media.""" """Content type of current playing media."""
if self._playing is not None: if self._playing:
from pyatv import const from pyatv import const
media_type = self._playing.media_type media_type = self._playing.media_type
if media_type == const.MEDIA_TYPE_VIDEO: if media_type == const.MEDIA_TYPE_VIDEO:
@ -144,13 +144,13 @@ class AppleTvDevice(MediaPlayerDevice):
@property @property
def media_duration(self): def media_duration(self):
"""Duration of current playing media in seconds.""" """Duration of current playing media in seconds."""
if self._playing is not None: if self._playing:
return self._playing.total_time return self._playing.total_time
@property @property
def media_position(self): def media_position(self):
"""Position of current playing media in seconds.""" """Position of current playing media in seconds."""
if self._playing is not None: if self._playing:
return self._playing.position return self._playing.position
@property @property
@ -168,18 +168,23 @@ class AppleTvDevice(MediaPlayerDevice):
@property @property
def media_image_hash(self): def media_image_hash(self):
"""Hash value for media image.""" """Hash value for media image."""
if self._playing is not None and self.state != STATE_IDLE: state = self.state
if self._playing and state not in [STATE_OFF, STATE_IDLE]:
return self._playing.hash return self._playing.hash
@asyncio.coroutine @asyncio.coroutine
def async_get_media_image(self): def async_get_media_image(self):
"""Fetch media image of current playing image.""" """Fetch media image of current playing image."""
state = self.state
if self._playing and state not in [STATE_OFF, STATE_IDLE]:
return (yield from self.atv.metadata.artwork()), 'image/png' return (yield from self.atv.metadata.artwork()), 'image/png'
return None, None
@property @property
def media_title(self): def media_title(self):
"""Title of current playing media.""" """Title of current playing media."""
if self._playing is not None: if self._playing:
if self.state == STATE_IDLE: if self.state == STATE_IDLE:
return 'Nothing playing' return 'Nothing playing'
title = self._playing.title title = self._playing.title
@ -215,7 +220,7 @@ class AppleTvDevice(MediaPlayerDevice):
This method must be run in the event loop and returns a coroutine. This method must be run in the event loop and returns a coroutine.
""" """
if self._playing is not None: if self._playing:
state = self.state state = self.state
if state == STATE_PAUSED: if state == STATE_PAUSED:
return self.atv.remote_control.play() return self.atv.remote_control.play()
@ -227,7 +232,7 @@ class AppleTvDevice(MediaPlayerDevice):
This method must be run in the event loop and returns a coroutine. This method must be run in the event loop and returns a coroutine.
""" """
if self._playing is not None: if self._playing:
return self.atv.remote_control.play() return self.atv.remote_control.play()
def async_media_stop(self): def async_media_stop(self):
@ -235,7 +240,7 @@ class AppleTvDevice(MediaPlayerDevice):
This method must be run in the event loop and returns a coroutine. This method must be run in the event loop and returns a coroutine.
""" """
if self._playing is not None: if self._playing:
return self.atv.remote_control.stop() return self.atv.remote_control.stop()
def async_media_pause(self): def async_media_pause(self):
@ -243,7 +248,7 @@ class AppleTvDevice(MediaPlayerDevice):
This method must be run in the event loop and returns a coroutine. This method must be run in the event loop and returns a coroutine.
""" """
if self._playing is not None: if self._playing:
return self.atv.remote_control.pause() return self.atv.remote_control.pause()
def async_media_next_track(self): def async_media_next_track(self):
@ -251,7 +256,7 @@ class AppleTvDevice(MediaPlayerDevice):
This method must be run in the event loop and returns a coroutine. This method must be run in the event loop and returns a coroutine.
""" """
if self._playing is not None: if self._playing:
return self.atv.remote_control.next() return self.atv.remote_control.next()
def async_media_previous_track(self): def async_media_previous_track(self):
@ -259,7 +264,7 @@ class AppleTvDevice(MediaPlayerDevice):
This method must be run in the event loop and returns a coroutine. This method must be run in the event loop and returns a coroutine.
""" """
if self._playing is not None: if self._playing:
return self.atv.remote_control.previous() return self.atv.remote_control.previous()
def async_media_seek(self, position): def async_media_seek(self, position):
@ -267,5 +272,5 @@ class AppleTvDevice(MediaPlayerDevice):
This method must be run in the event loop and returns a coroutine. This method must be run in the event loop and returns a coroutine.
""" """
if self._playing is not None: if self._playing:
return self.atv.remote_control.set_position(position) return self.atv.remote_control.set_position(position)