<commit_before>import re

from streamlink.plugin import Plugin
from streamlink.plugin.api import http, validate
from streamlink.stream import HLSStream

_url_re = re.compile(r"http(s)?://(www\.)?openrec.tv/(live|movie)/[^/?&]+")
_playlist_url_re = re.compile(r"data-file=\"(?P<url>[^\"]+)\"")
_schema = validate.Schema(
    validate.transform(_playlist_url_re.search),
    validate.any(
        None,
        validate.all(
            validate.get("url"),
            validate.url(
                scheme="http",
                path=validate.endswith(".m3u8")
            )
        )
    )
)


class OPENRECtv(Plugin):
    @classmethod
    def can_handle_url(self, url):
        return _url_re.match(url)

    def _get_streams(self):
        playlist_url = http.get(self.url, schema=_schema)
        if not playlist_url:
            return

        return HLSStream.parse_variant_playlist(self.session, playlist_url)


__plugin__ = OPENRECtv<commit_msg>plugins.openrectv: add source quality for openrectv<commit_after>import re

from streamlink.plugin import Plugin
from streamlink.plugin.api import http, validate
from streamlink.stream import HLSStream

_url_re = re.compile(r"http(s)?://(www\.)?openrec.tv/(live|movie)/[^/?&]+")
_playlist_url_re = re.compile(r"data-(source)?file=\"(?P<url>[^\"]+)\"")
_schema = validate.Schema(
    validate.transform(_playlist_url_re.findall),
    [
        validate.union({
            "isSource": validate.all(validate.get(0), validate.transform(lambda s: s == "source")),
            "url": validate.all(validate.get(1), validate.url(scheme="http",
                                                       path=validate.endswith(".m3u8")))
        })
    ]
)


class OPENRECtv(Plugin):
    @classmethod
    def can_handle_url(cls, url):
        return _url_re.match(url)

    @classmethod
    def stream_weight(cls, stream):
        if stream == "source":
            return 1080 + 1, "openrectv"
        return Plugin.stream_weight(stream)

    def _get_streams(self):
        playlists = http.get(self.url, schema=_schema)
        for playlist in playlists:
            for q, s in HLSStream.parse_variant_playlist(self.session, playlist["url"]).items():
                yield "source" if playlist["isSource"] else q, s


__plugin__ = OPENRECtv
{'fraction_non_alphanumeric': 0.13604549431321084, 'fraction_numerical': 0.004811898512685914, 'mean_word_length': 2.767710049423394, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3293680', 'n_tokens_mistral': 749, 'n_tokens_neox': 719, 'n_words': 133}