<commit_before>import re

from streamlink.plugin import Plugin
from streamlink.plugin.api import http, useragents
from streamlink.stream import HLSStream, RTMPStream, HTTPStream

API_URL = "https://api-dsa.17app.co/api/v1/liveStreams/getLiveStreamInfo"

_url_re = re.compile(r"https://17.live/live/(?P<channel>[^/&?]+)")
_status_re = re.compile(r'\\"closeBy\\":\\"\\"')
_rtmp_re = re.compile(r'\\"url\\"\s*:\s*\\"(.+?)\\"')


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

    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")

        http.headers.update({'User-Agent': useragents.CHROME})

        payload = '{"liveStreamID": "%s"}' % (channel)
        res = http.post(API_URL, data=payload)
        status = _status_re.search(res.text)
        if not status:
            self.logger.info("Stream currently unavailable.")
            return

        http_url = _rtmp_re.search(res.text).group(1)
        http_url = http_url.replace("http:", "https:")
        yield "live", HTTPStream(self.session, http_url)

        if 'pull-rtmp' in http_url:
            url = http_url.replace("https:", "rtmp:").replace(".flv", "")
            stream = RTMPStream(self.session, {
                "rtmp": url,
                "live": True
            })
            yield "live", stream

        if 'wansu-' in http_url:
            url = http_url.replace(".flv", "/playlist.m3u8")
            for stream in HLSStream.parse_variant_playlist(self.session, url).items():
                yield stream
        else:
            url = http_url.replace(".flv", ".m3u8")
            yield "live", HLSStream(self.session, url)


__plugin__ = App17<commit_msg>[app17] Fix HLS URL (#1600)<commit_after>import re

from streamlink.plugin import Plugin
from streamlink.plugin.api import http, useragents
from streamlink.stream import HLSStream, RTMPStream, HTTPStream

API_URL = "https://api-dsa.17app.co/api/v1/liveStreams/getLiveStreamInfo"

_url_re = re.compile(r"https://17.live/live/(?P<channel>[^/&?]+)")
_status_re = re.compile(r'\\"closeBy\\":\\"\\"')
_rtmp_re = re.compile(r'\\"url\\"\s*:\s*\\"(.+?)\\"')


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

    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")

        http.headers.update({'User-Agent': useragents.CHROME})

        payload = '{"liveStreamID": "%s"}' % (channel)
        res = http.post(API_URL, data=payload)
        status = _status_re.search(res.text)
        if not status:
            self.logger.info("Stream currently unavailable.")
            return

        http_url = _rtmp_re.search(res.text).group(1)
        http_url = http_url.replace("http:", "https:")
        yield "live", HTTPStream(self.session, http_url)

        if 'pull-rtmp' in http_url:
            url = http_url.replace("https:", "rtmp:").replace(".flv", "")
            stream = RTMPStream(self.session, {
                "rtmp": url,
                "live": True
            })
            yield "live", stream

        if 'wansu-' in http_url:
            url = http_url.replace(".flv", "/playlist.m3u8")
            for stream in HLSStream.parse_variant_playlist(self.session, url).items():
                yield stream
        else:
            url = http_url.replace("live-hdl", "live-hls").replace(".flv", ".m3u8")
            yield "live", HLSStream(self.session, url)


__plugin__ = App17
{'fraction_non_alphanumeric': 0.15897580191333707, 'fraction_numerical': 0.009566685424873381, 'mean_word_length': 2.4750733137829912, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '6415665', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1167, 'n_words': 216}