forked from streamlink/streamlink
/
tv8.py
46 lines (32 loc) · 1.27 KB
/
tv8.py
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
"""
$description Turkish live TV channel owned by Acun Medya Group.
$url tv8.com.tr
$type live
"""
import logging
import re
from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream
from streamlink.stream.hls_filtered import FilteredHLSStreamReader, FilteredHLSStreamWriter
log = logging.getLogger(__name__)
class TV8HLSStreamWriter(FilteredHLSStreamWriter):
ad_re = re.compile(r"/ad/|/crea/")
def should_filter_sequence(self, sequence):
return self.ad_re.search(sequence.segment.uri) is not None or super().should_filter_sequence(sequence)
class TV8HLSStreamReader(FilteredHLSStreamReader):
__writer__ = TV8HLSStreamWriter
class TV8HLSStream(HLSStream):
__reader__ = TV8HLSStreamReader
@pluginmatcher(re.compile(
r"https?://www\.tv8\.com\.tr/canli-yayin"
))
class TV8(Plugin):
def _get_streams(self):
hls_url = self.session.http.get(self.url, schema=validate.Schema(
re.compile(r"""var\s+videoUrl\s*=\s*(?P<q>["'])(?P<hls_url>https?://.*?\.m3u8.*?)(?P=q)"""),
validate.any(None, validate.get("hls_url")),
))
if hls_url is not None:
return TV8HLSStream.parse_variant_playlist(self.session, hls_url)
__plugin__ = TV8