From 0ad879d32591377c4c28e772ed1474275a110ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20St=C3=A5hl?= Date: Thu, 15 Jun 2017 07:35:16 +0200 Subject: [PATCH] Remove port to play_url --- pyatv/airplay/player.py | 14 ++++++++------ pyatv/internal/apple_tv.py | 6 +++--- tests/test_airplay.py | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pyatv/airplay/player.py b/pyatv/airplay/player.py index 236724350..49e384dda 100644 --- a/pyatv/airplay/player.py +++ b/pyatv/airplay/player.py @@ -14,32 +14,34 @@ TIMEOUT = 10 +# TODO: Use net.HttpSession instead of ClientSession # pylint: disable=too-few-public-methods class AirPlayPlayer: """This class helps with playing media from an URL.""" - def __init__(self, loop, session, address): + def __init__(self, loop, session, address, port=7000): """Initialize a new AirPlay instance.""" self.loop = loop self.address = address self.session = session + self.port = port @asyncio.coroutine - def play_url(self, url, position=0, port=AIRPLAY_PORT): + def play_url(self, url, position=0): """Play media from an URL on the device.""" headers = {'User-Agent': 'MediaControl/1.0', 'Content-Type': 'text/parameters'} body = "Content-Location: {}\nStart-Position: {}\n\n".format( url, position) - address = self._url(port, 'play') + address = self._url(self.port, 'play') _LOGGER.debug('AirPlay %s to %s', url, address) resp = None try: resp = yield from self.session.post( address, headers=headers, data=body, timeout=TIMEOUT) - yield from self._wait_for_media_to_end(port) + yield from self._wait_for_media_to_end() finally: if resp is not None: resp.close() @@ -50,8 +52,8 @@ def _url(self, port, command): # Poll playback-info to find out if something is playing. It might take # some time until the media starts playing, give it 5 seconds (attempts) @asyncio.coroutine - def _wait_for_media_to_end(self, port): - address = self._url(port, 'playback-info') + def _wait_for_media_to_end(self): + address = self._url(self.port, 'playback-info') attempts = 5 video_started = False while True: diff --git a/pyatv/internal/apple_tv.py b/pyatv/internal/apple_tv.py index 9dd05d9b8..93abefc16 100644 --- a/pyatv/internal/apple_tv.py +++ b/pyatv/internal/apple_tv.py @@ -463,8 +463,7 @@ def play_url(self, url, **kwargs): yield from self.verify_authenticated() position = 0 if 'position' not in kwargs else int(kwargs['position']) - port = 7000 if 'port' not in kwargs else kwargs['port'] - return (yield from self.player.play_url(url, position, port)) + return (yield from self.player.play_url(url, position)) class AppleTVInternal(AppleTV): @@ -486,7 +485,8 @@ def __init__(self, loop, session, details): self._atv_metadata = MetadataInternal(self._apple_tv) self._atv_push_updater = PushUpdaterInternal(loop, self._apple_tv) - airplay_player = player.AirPlayPlayer(loop, session, details.address) + airplay_player = player.AirPlayPlayer( + loop, session, details.address, details.airplay_port) airplay_http = HttpSession( session, 'http://{0}:{1}/'.format( details.address, details.airplay_port)) diff --git a/tests/test_airplay.py b/tests/test_airplay.py index 454c035b7..3d33ebbfc 100644 --- a/tests/test_airplay.py +++ b/tests/test_airplay.py @@ -54,9 +54,9 @@ def test_play_video(self): self.usecase.airplay_playback_idle() session = ClientSession(loop=self.loop) - aplay = player.AirPlayPlayer(self.loop, session, '127.0.0.1') - yield from aplay.play_url( - STREAM, position=START_POSITION, port=self.app.port) + aplay = player.AirPlayPlayer( + self.loop, session, '127.0.0.1', port=self.app.port) + yield from aplay.play_url(STREAM, position=START_POSITION) self.assertEqual(self.fake_atv.last_airplay_url, STREAM) self.assertEqual(self.fake_atv.last_airplay_start, START_POSITION)