import re
import shutil
import subprocess

import pytest


@pytest.mark.live
def test_dokustreams_embed_url_via_curl():
    if shutil.which('curl') is None:
        pytest.skip('curl not available')

    url = 'https://doku-streams.com/verbrechen/deutsche-im-knast-japan-und-die-disziplin/'
    result = subprocess.run(
        ['curl', '-L', '-s', '--compressed', url],
        check=False,
        capture_output=True,
        text=False,
    )
    assert result.returncode == 0
    html = result.stdout.decode('utf-8', errors='ignore')
    assert html

    iframe_match = re.search(r'<iframe[^>]+src="([^"]+)"', html, re.IGNORECASE)
    if iframe_match is None:
        iframe_match = re.search(r'"embedUrl"\s*:\s*"([^"]+)"', html)
    assert iframe_match is not None

    src = iframe_match.group(1)
    assert 'youtube' in src or 'vimeo' in src
