def connect_to_apple_tv(details, loop, protocol=None, session=None):
service = _get_service_used_to_connect(details, protocol)<EOL>if session is None:<EOL><INDENT>session = ClientSession(loop=loop)<EOL><DEDENT>airplay = _setup_airplay(loop, session, details)<EOL>if service.protocol == PROTOCOL_DMAP:<EOL><INDENT>return DmapAppleTV(loop, session, details, airplay)<EOL><DEDENT>return MrpAppleTV(loop, session, details, airplay)<EOL>
Connect and logins to an Apple TV.