-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsbscokr.py
More file actions
110 lines (96 loc) · 3.27 KB
/
Copy pathsbscokr.py
File metadata and controls
110 lines (96 loc) · 3.27 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
$description Live TV channels from SBS, a South Korean public broadcaster.
$url www.sbs.co.kr/live
$type live
$metadata id
$metadata author
$metadata title
$region South Korea
"""
import argparse
import re
from streamlink.logger import getLogger
from streamlink.plugin import Plugin, pluginargument, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream
log = getLogger(__name__)
@pluginmatcher(
re.compile(r"https?://www\.sbs\.co\.kr/live/(?P<channel>[^/?]+)"),
)
@pluginargument(
"id",
help=argparse.SUPPRESS,
)
class SBScokr(Plugin):
_URL_API_CHANNELS = "https://static.apis.sbs.co.kr/play-api/1.0/onair{virtual}/channels"
_URL_API_CHANNEL = "https://apis.sbs.co.kr/play-api/1.0/onair{virtual}/channel/{channel}"
def _get_streams(self):
channel = self.match["channel"]
for virtual in ("", "/virtual"):
channels = self.session.http.get(
self._URL_API_CHANNELS.format(virtual=virtual),
schema=validate.Schema(
validate.parse_json(),
{
"list": [
{
"channelid": str,
},
],
},
validate.get("list"),
validate.map(lambda item: item["channelid"]),
),
)
if channel in channels:
break
else:
return
info, hls_url = self.session.http.get(
self._URL_API_CHANNEL.format(virtual=virtual, channel=channel),
params={
"v_type": "2",
"platform": "pcweb",
"protocol": "hls",
"jwt-token": "",
"ssl": "Y",
"rscuse": "",
},
schema=validate.Schema(
validate.parse_json(),
{
"onair": {
"info": {
"channelid": str,
"channelname": str,
"title": str,
"onair_yn": str,
"overseas_yn": str,
"overseas_text": str,
},
"source": {
"mediasource": {
validate.optional("mediaurl"): validate.url(path=validate.endswith(".m3u8")),
},
},
},
},
validate.get("onair"),
validate.union_get(
"info",
("source", "mediasource", "mediaurl"),
),
),
)
if info["overseas_yn"] != "Y":
log.error(f"Geo-restricted content: {info['overseas_text']}")
return
if info["onair_yn"] != "Y":
log.error("This channel is currently unavailable")
return
self.id = info["channelid"]
self.author = info["channelname"]
self.title = info["title"]
if hls_url:
return HLSStream.parse_variant_playlist(self.session, hls_url)
__plugin__ = SBScokr