-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathvinhlongtv.py
More file actions
73 lines (60 loc) · 2.01 KB
/
Copy pathvinhlongtv.py
File metadata and controls
73 lines (60 loc) · 2.01 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
"""
$description Vietnamese live TV channels from THVL, including THVL1, THVL2, THVL3 and THVL4.
$url thvli.vn
$type live
$metadata id
$metadata title
$region Vietnam
"""
import re
from datetime import datetime, timezone
from hashlib import md5
from streamlink.logger import getLogger
from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream
log = getLogger(__name__)
@pluginmatcher(
re.compile(r"https?://(?:www\.)?thvli\.vn/live/(?P<channel>[^/]+)"),
)
class VinhLongTV(Plugin):
_API_URL = "https://api.thvli.vn/backend/cm/get_detail/{channel}/"
_API_KEY_DATE = "Kh0ngDuLieu"
_API_KEY_TIME = "C0R0i"
_API_KEY_SECRET = "Kh0aAnT0an"
def _get_headers(self):
now = datetime.now(tz=timezone.utc)
date = now.strftime("%Y%m%d")
time = now.strftime("%H%M%S")
dtstr = f"{date}{time}"
dthash = md5(dtstr.encode()).hexdigest()
key_value = f"{dthash[:3]}{dthash[-3:]}"
key_access = f"{self._API_KEY_DATE}{date}{self._API_KEY_TIME}{time}{self._API_KEY_SECRET}{key_value}"
return {
"X-SFD-Date": dtstr,
"X-SFD-Key": md5(key_access.encode()).hexdigest(),
}
def _get_streams(self):
channel = self.match.group("channel")
params = {"timezone": "UTC"}
headers = self._get_headers()
self.id, self.title, hls_url = self.session.http.get(
self._API_URL.format(channel=channel),
params=params,
headers=headers,
schema=validate.Schema(
validate.parse_json(),
{
"id": str,
"title": str,
"link_play": str,
},
validate.union_get(
"id",
"title",
"link_play",
),
),
)
return HLSStream.parse_variant_playlist(self.session, hls_url)
__plugin__ = VinhLongTV