forked from streamlink/streamlink
/
onetv.py
65 lines (53 loc) · 1.81 KB
/
onetv.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""
$description A state/privately owned Russian live TV channel.
$url 1tv.ru
$type live
$region Russia
"""
import logging
import random
import re
from streamlink.compat import unquote
from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream
from streamlink.utils.url import update_qsd
log = logging.getLogger(__name__)
@pluginmatcher(re.compile(
r"https?://(?:www\.)?1tv\.ru/live"
))
@pluginmatcher(re.compile(
r"https?://static\.1tv\.ru/eump/(?:embeds|pages)/1tv_live(?:_orbit-plus-4)?\.html"
))
class OneTV(Plugin):
def _get_streams(self):
if "orbit-plus-4" in self.url:
channel = "1tv-orbit-plus-4"
self.title = u"Первый канал HD (+4)"
else:
channel = "1tvch"
self.title = u"Первый канал HD"
url = self.session.http.get(
"https://stream.1tv.ru/api/playlist/{0}_as_array.json".format(channel),
data={"r": random.randint(1, 100000)},
schema=validate.Schema(
validate.parse_json(),
{"hls": [validate.url()]},
validate.get(("hls", 0)),
))
if not url:
return
log.debug("{0}".format(url))
if "georestrictions" in url:
log.error("Stream is geo-restricted")
return
hls_session = self.session.http.get(
"https://stream.1tv.ru/get_hls_session",
schema=validate.Schema(
validate.parse_json(),
{"s": validate.transform(unquote)},
))
url = update_qsd(url, qsd=hls_session, safe="/:")
return HLSStream.parse_variant_playlist(self.session, url, name_fmt="{pixels}_{bitrate}")
__plugin__ = OneTV