File: test_filmon.py

package info (click to toggle)
streamlink 8.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,564 kB
  • sloc: python: 51,188; sh: 184; makefile: 152
file content (87 lines) | stat: -rw-r--r-- 3,725 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from __future__ import annotations

from datetime import datetime, timezone
from typing import TYPE_CHECKING
from unittest.mock import patch

import freezegun
import pytest

from streamlink.plugins.filmon import Filmon, FilmOnAPI, FilmOnHLS
from tests.plugins import PluginCanHandleUrl


if TYPE_CHECKING:
    from streamlink import Streamlink


class TestPluginCanHandleUrlFilmon(PluginCanHandleUrl):
    __plugin__ = Filmon

    should_match = [
        "http://www.filmon.tv/channel/grandstand-show",
        "http://www.filmon.tv/index/popout?channel_id=5510&quality=low",
        "http://www.filmon.tv/tv/channel/export?channel_id=5510&autoPlay=1",
        "http://www.filmon.tv/tv/channel/grandstand-show",
        "http://www.filmon.tv/tv/channel-4",
        "https://www.filmon.com/tv/bbc-news",
        "https://www.filmon.tv/tv/55",
        "http://www.filmon.tv/vod/view/10250-0-crime-boss",
        "http://www.filmon.tv/group/comedy",
    ]

    should_match_groups = [
        ("http://www.filmon.tv/channel/grandstand-show", (None, "grandstand-show", None)),
        ("http://www.filmon.tv/index/popout?channel_id=5510&quality=low", (None, "5510", None)),
        ("http://www.filmon.tv/tv/channel/export?channel_id=5510&autoPlay=1", (None, "5510", None)),
        ("http://www.filmon.tv/tv/channel/grandstand-show", (None, "grandstand-show", None)),
        ("https://www.filmon.com/tv/bbc-news", (None, "bbc-news", None)),
        ("https://www.filmon.com/tv/channel-4", (None, "channel-4", None)),
        ("https://www.filmon.tv/tv/55", (None, "55", None)),
        ("http://www.filmon.tv/group/comedy", ("group/", "comedy", None)),
        ("http://www.filmon.tv/vod/view/10250-0-crime-boss", (None, None, "10250-0-crime-boss")),
        ("http://www.filmon.tv/vod/view/10250-0-crime-boss/extra", (None, None, "10250-0-crime-boss")),
        ("http://www.filmon.tv/vod/view/10250-0-crime-boss?extra", (None, None, "10250-0-crime-boss")),
        ("http://www.filmon.tv/vod/view/10250-0-crime-boss&extra", (None, None, "10250-0-crime-boss")),
    ]


@pytest.fixture()
def filmonhls(session: Streamlink):
    with (
        freezegun.freeze_time("2000-01-01T00:00:00Z"),
        patch("streamlink.plugins.filmon.FilmOnHLS._get_stream_data", return_value=[]),
    ):
        api = FilmOnAPI(session)
        yield FilmOnHLS(session, "http://fake/one.m3u8", api=api, channel="test")


def test_filmonhls_to_url(filmonhls):
    filmonhls.watch_timeout = datetime(2000, 1, 1, 0, 0, 0, 0, timezone.utc).timestamp()
    assert filmonhls.to_url() == "http://fake/one.m3u8"


def test_filmonhls_to_url_updated(filmonhls):
    filmonhls.watch_timeout = datetime(1999, 12, 31, 23, 59, 59, 9999, timezone.utc).timestamp()

    filmonhls._get_stream_data.return_value = [
        ("high", "http://fake/two.m3u8", datetime(2000, 1, 1, 0, 0, 0, 0, timezone.utc).timestamp()),
    ]
    assert filmonhls.to_url() == "http://fake/two.m3u8"

    filmonhls.watch_timeout = datetime(1999, 12, 31, 23, 59, 59, 9999, timezone.utc).timestamp()
    filmonhls._get_stream_data.return_value = [
        ("high", "http://another-fake/three.m3u8", datetime(2000, 1, 1, 0, 0, 0, 0, timezone.utc).timestamp()),
    ]
    assert filmonhls.to_url() == "http://fake/three.m3u8"


def test_filmonhls_to_url_missing_quality(filmonhls):
    filmonhls.watch_timeout = datetime(1999, 12, 31, 23, 59, 59, 9999, timezone.utc).timestamp()

    filmonhls._get_stream_data.return_value = [
        ("low", "http://fake/two.m3u8", datetime(2000, 1, 1, 0, 0, 0, 0, timezone.utc).timestamp()),
    ]
    with pytest.raises(TypeError) as cm:
        filmonhls.to_url()
    assert str(cm.value) == "Stream has expired and cannot be translated to a URL"