forked from Damianonymous/streamlink-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvnplayer.py
164 lines (143 loc) · 5.43 KB
/
tvnplayer.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import base64
import binascii
import time
from hashlib import sha1
from Crypto.Cipher import AES
from streamlink.plugin import Plugin
from streamlink.plugin.api import http, validate
from streamlink.stream import HTTPStream
platforms = [
{
'platform': 'ConnectedTV',
'terminal': 'Panasonic',
'authKey': '064fda5ab26dc1dd936f5c6e84b7d3c2',
'userAgent': 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
'apiVer': '3.1',
'encrypt': False
}, {
'platform': 'Mobile',
'terminal': 'Android',
'authKey': 'b4bc971840de63d105b3166403aa1bea',
'userAgent': 'Apache-HttpClient/UNAVAILABLE (java 1.4)',
'apiVer': '3.0',
'encrypt': True
}, {
'platform': 'ConnectedTV',
'terminal': 'Samsung2',
'authKey': '453198a80ccc99e8485794789292f061',
'userAgent': 'Mozilla/5.0 (SmartHub; SMART-TV; U; Linux/SmartTV; Maple2012) AppleWebKit/534.7 (KHTML, like Gecko) SmartTV Safari/534.7',
'api': '3.6',
'encrypt': True
}, {
'platform': 'Mobile',
'terminal': 'Android',
'authKey': 'b4bc971840de63d105b3166403aa1bea',
'userAgent': 'Apache-HttpClient/UNAVAILABLE (java 1.4)',
'api': '2.0',
'encrypt': True
}, {
'platform': 'Mobile',
'terminal': 'Android',
'authKey': '4dc7b4f711fb9f3d53919ef94c23890c',
'userAgent': 'Player/3.3.4 tablet Android/4.1.1 net/wifi',
'api': '3.1',
'encrypt': True
}
]
PLAYLIST_URL = "http://player.pl/api/?id={video_id}&platform={platform}&terminal={terminal}&format=json&v={api}&authKey={authkey}&type=episode&&m=getItem"
_url_re = re.compile(
r"^(?:https?:\/\/)?(?:www.)?player\.pl\/[^\"]+,(?P<video_id>[0-9]+).*")
_playlist_schema = validate.Schema(
{
"item": {
"videos": {
"main": {
"video_content": validate.all([
{
"profile_name": validate.text,
"url": validate.url(scheme=validate.any("http"))
}
])
}
}
}
},
validate.get("item"),
validate.get("videos"),
validate.get("main"),
validate.get("video_content")
)
QUALITY_MAP = {
u"Standard": "720p",
u"HD": "1080p",
u"SD": "640p",
u"Bardzo wysoka": "1080p",
u"Średnia": "720p",
u"Wysoka": "640p",
u"Niska": "512p",
u"Bardzo niska": "320p",
}
class TvnPlayer(Plugin):
@classmethod
def can_handle_url(cls, url):
return _url_re.match(url)
def _get_salt_and_token(self, url):
url = url.replace('http://redir.atmcdn.pl/http/', '')
SecretKey = 'AB9843DSAIUDHW87Y3874Q903409QEWA'
iv = 'ab5ef983454a21bd'
KeyStr = '0f12f35aa0c542e45926c43a39ee2a7b38ec2f26975c00a30e1292f7e137e120e5ae9d1cfe10dd682834e3754efc1733'
salt = sha1()
salt.update(os.urandom(16))
salt = salt.hexdigest()[:32]
tvncrypt = AES.new(SecretKey, AES.MODE_CBC, iv)
key = tvncrypt.decrypt(binascii.unhexlify(KeyStr))[:32]
expire = 3600000 + long(time.time() * 1000) - 946684800000
unencryptedToken = "name=%s&expire=%s\0" % (url, expire)
def pkcs5_pad(s): return s + (16 - len(s) % 16) * chr(16 - len(s) % 16)
def pkcs5_unpad(s): return s[0:-ord(s[-1])]
unencryptedToken = pkcs5_pad(unencryptedToken)
tvncrypt = AES.new(binascii.unhexlify(
key), AES.MODE_CBC, binascii.unhexlify(salt))
encryptedToken = tvncrypt.encrypt(unencryptedToken)
encryptedTokenHEX = binascii.hexlify(encryptedToken).upper()
return salt, encryptedTokenHEX
def _get_all_streams(self, video_content, encrypt):
for video in video_content:
url = video["url"]
quality = QUALITY_MAP[video["profile_name"]]
if encrypt:
salt, token = self._get_salt_and_token(url)
video_url = url + '?salt=%s&token=%s' % (salt, token)
else:
video_url = url
stream = HTTPStream(self.session, video_url)
yield quality, stream
def _check_platform(self, video_id, platform):
playlist = PLAYLIST_URL.format(video_id=video_id,
terminal=platform['terminal'],
platform=platform['platform'],
api=platform['apiVer'],
authkey=platform['authKey'])
self.logger.debug("PLAYLIST URL: " + playlist)
http.headers.update({"User-Agent": platform['userAgent']})
res = http.get(playlist)
try:
data = http.json(res, schema=_playlist_schema)
except Exception as ex:
self.logger.debug(ex.message)
return None
return self._get_all_streams(data, platform['encrypt'])
def _get_streams(self):
url_match = _url_re.match(self.url)
if url_match:
video_id = url_match.group("video_id")
for platform in platforms:
streams = self._check_platform(video_id, platform)
if streams:
return streams
return None
__plugin__ = TvnPlayer