# Path: yledl/streamfilters.py
# class StreamFilters:
#     """Parameters for deciding which of potentially multiple available stream
#     versions to download.
#     """
#     latest_only = attr.ib(default=False)
#     maxbitrate = attr.ib(default=None)
#     maxheight = attr.ib(default=None)
#     enabled_backends = attr.ib(default=attr.Factory(
#         lambda: list(Backends.default_order)
#     ))


import pytest
from datetime import datetime
from utils import fetch_title, fetch_stream_url, fetch_episode_pages, \
    fetch_metadata
from yledl import StreamFilters


def test_areena_html5_stream_url():
    streamurl = fetch_stream_url('https://areena.yle.fi/1-787136')

    assert len(streamurl) == 1
    assert '/a.m3u8?' in streamurl[0]


def test_areena_html5_metadata():
    metadata = fetch_metadata('https://areena.yle.fi/1-787136')

    assert len(metadata) == 1
    flavors = metadata[0]['flavors']
    assert len(flavors) >= 5
    assert all(f.get('media_type') == 'video' for f in flavors)
    assert all('bitrate' in f and
               'height' in f and
               'width' in f
               for f in flavors)
    assert metadata[0]['duration_seconds'] == 907
    assert metadata[0]['region'] == 'World'
    assert metadata[0]['publish_timestamp'] == '2021-04-01T00:01:00+03:00'
    assert 'expired_timestamp' not in metadata[0]

# Path: yledl/streamfilters.py
# class StreamFilters:
#     """Parameters for deciding which of potentially multiple available stream
#     versions to download.
#     """
#     latest_only = attr.ib(default=False)
#     maxbitrate = attr.ib(default=None)
#     maxheight = attr.ib(default=None)
#     enabled_backends = attr.ib(default=attr.Factory(
#         lambda: list(Backends.default_order)
#     ))


# Path: tests/integration/test_areena_it.py
import pytest
from datetime import datetime
from utils import fetch_title, fetch_stream_url, fetch_episode_pages, \
    fetch_metadata
from yledl import StreamFilters



def test_areena_html5_stream_url():
    streamurl = fetch_stream_url('https://areena.yle.fi/1-787136')

    assert len(streamurl) == 1
    assert '/a.m3u8?' in streamurl[0]


def test_areena_html5_metadata():
    metadata = fetch_metadata('https://areena.yle.fi/1-787136')

    assert len(metadata) == 1
    flavors = metadata[0]['flavors']
    assert len(flavors) >= 5
    assert all(f.get('media_type') == 'video' for f in flavors)
    assert all('bitrate' in f and
               'height' in f and
               'width' in f
               for f in flavors)
    assert metadata[0]['duration_seconds'] == 907
    assert metadata[0]['region'] == 'World'
    assert metadata[0]['publish_timestamp'] == '2021-04-01T00:01:00+03:00'
    assert 'expired_timestamp' not in metadata[0]

    assert len(metadata[0]['description']) > 150