<commit_before>"""Play media on a device by sending an URL."""

import logging
import asyncio
import plistlib
from uuid import uuid4

from pyatv import exceptions


_LOGGER = logging.getLogger(__name__)

PLAY_RETRIES = 3
WAIT_RETRIES = 5
TIMEOUT = 10
HEADERS = {
    "User-Agent": "MediaControl/1.0",
    "Content-Type": "application/x-apple-binary-plist",
}


# pylint: disable=too-few-public-methods
class AirPlayPlayer:
    """This class helps with playing media from an URL."""

    def __init__(self, loop, http):
        """Initialize a new AirPlay instance."""
        self.loop = loop
        self.http = http

    async def play_url(self, url, position=0):
        """Play media from an URL on the device."""
        body = {
            "Content-Location": url,
            "Start-Position": position,
            "X-Apple-Session-ID": str(uuid4()),
        }

        retry = 0
        while retry < PLAY_RETRIES:
            _LOGGER.debug("Starting to play %s", url)

            # pylint: disable=no-member
            _, status = await self.http.post_data(
                "play",
                headers=HEADERS,
                data=plistlib.dumps(body, fmt=plistlib.FMT_BINARY),
                timeout=TIMEOUT,
            )
<commit_msg>airplay: Use default timeout for HTTP requests<commit_after>"""Play media on a device by sending an URL."""

import logging
import asyncio
import plistlib
from uuid import uuid4

from pyatv import exceptions


_LOGGER = logging.getLogger(__name__)

PLAY_RETRIES = 3
WAIT_RETRIES = 5
HEADERS = {
    "User-Agent": "MediaControl/1.0",
    "Content-Type": "application/x-apple-binary-plist",
}


# pylint: disable=too-few-public-methods
class AirPlayPlayer:
    """This class helps with playing media from an URL."""

    def __init__(self, loop, http):
        """Initialize a new AirPlay instance."""
        self.loop = loop
        self.http = http

    async def play_url(self, url, position=0):
        """Play media from an URL on the device."""
        body = {
            "Content-Location": url,
            "Start-Position": position,
            "X-Apple-Session-ID": str(uuid4()),
        }

        retry = 0
        while retry < PLAY_RETRIES:
            _LOGGER.debug("Starting to play %s", url)

            # pylint: disable=no-member
            _, status = await self.http.post_data(
                "play",
                headers=HEADERS,
                data=plistlib.dumps(body, fmt=plistlib.FMT_BINARY),
            )

{'fraction_non_alphanumeric': 0.11293552262715258, 'fraction_numerical': 0.007208650380456548, 'mean_word_length': 2.2315653298835705, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4857306', 'n_tokens_mistral': 766, 'n_tokens_neox': 736, 'n_words': 207}