"""
$description A privately owned Bulgarian live TV channel.
$url btvplus.bg
$type live
$region Bulgaria
"""

import logging
import re

from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream

log = logging.getLogger(__name__)


@pluginmatcher(re.compile(
    r"https?://(?:www\.)?btvplus\.bg/live/?"
))
class BTV(Plugin):
    URL_API = "https://btvplus.bg/lbin/v3/btvplus/player_config.php"

    def _get_streams(self):
        media_id = self.session.http.get(self.url, schema=validate.Schema(
            re.compile(r"media_id=(\d+)"),
            validate.any(None, validate.get(1)),
        ))
        if media_id is None:
            return

        stream_url = self.session.http.get(
            self.URL_API,
            params={
                "media_id": media_id,
            },
            schema=validate.Schema(
                validate.any(
                    validate.all(
                        validate.regex(re.compile(r"geo_blocked_stream")),
                        validate.get(0),
                    ),
                    validate.all(
                        validate.parse_json(),
                        {
                            "status": "ok",
                            "config": str,
                        },
                        validate.get("config"),
                        re.compile(r"src: \"(http.*?)\""),
                        validate.none_or_all(
                            validate.get(1),
                            validate.url(),
                        ),
                    ),
                ),
            ),
        )
        if not stream_url:
            return

        if stream_url == "geo_blocked_stream":
            log.error("The content is not available in your region")
            return

        return HLSStream.parse_variant_playlist(self.session, stream_url)


__plugin__ = BTV

@@ -1292,49 +1292,28 @@
    %22
-config%22: str,%0A                        %7D,%0A
+info%22: %7B%0A           
     
@@ -1321,34 +1321,39 @@
                 
-  
+%22file%22:
  validate.get(%22c
@@ -1350,79 +1350,43 @@
 ate.
-get(%22config%22),%0A                        re.compile(r%22src: %5C%22(http.*?)%5C%22%22
+url(path=validate.endswith(%22.m3u8%22)
 ),%0A 
@@ -1412,34 +1412,15 @@
     
-validate.none_or_all(%0A
     
+%7D,%0A
     
@@ -1443,29 +1443,11 @@
     
-validate.get(1),%0A    
+%7D,%0A
     
@@ -1479,39 +1479,28 @@
 ate.
-url(),%0A                        
+get((%22info%22, %22file%22)
 ),%0A 
@@ -1763,16 +1763,25 @@
  return 
+%7B%22live%22: 
 HLSStrea
@@ -1785,31 +1785,8 @@
 ream
-.parse_variant_playlist
 (sel
@@ -1807,16 +1807,17 @@
 eam_url)
+%7D
 %0A%0A%0A__plu

fix validation schema