-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathstripchat.py
57 lines (45 loc) · 2.06 KB
/
stripchat.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
import re
from streamlink.plugin import Plugin
from streamlink.plugin.api import validate
from streamlink.stream import HLSStream
_url_re = re.compile(r"https?://(\w+\.)?stripchat\.com/(?P<username>[a-zA-Z0-9_-]+)")
_post_schema = validate.Schema(
{
"cam": validate.Schema({
'streamName' : validate.text,
'viewServers': validate.Schema({'flashphoner-hls': validate.text})
}),
"user": validate.Schema({
'user' : validate.Schema({
'status' : validate.text,
'isLive' : bool
})
})
}
)
class Stripchat(Plugin):
@classmethod
def can_handle_url(cls, url):
return _url_re.match(url)
def _get_streams(self):
match = _url_re.match(self.url)
username = match.group("username")
api_call = "https://stripchat.com/api/front/v2/models/username/{0}/cam".format(username)
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"X-Requested-With": "XMLHttpRequest",
"Referer": self.url,
}
res = self.session.http.get(api_call, headers=headers)
data = self.session.http.json(res, schema=_post_schema)
server = "https://b-{0}.doppiocdn.com/hls/{1}/master_{1}.m3u8".format(data["cam"]["viewServers"]["flashphoner-hls"],data["cam"]["streamName"])
server0 = "https://b-{0}.doppiocdn.com/hls/{1}/{1}.m3u8".format(data["cam"]["viewServers"]["flashphoner-hls"],data["cam"]["streamName"])
self.logger.info("Stream status: {0}".format(data["user"]["user"]["status"]))
if (data["user"]["user"]["isLive"] is True and data["user"]["user"]["status"] == "public" and server):
try:
for s in HLSStream.parse_variant_playlist(self.session,server,headers={'Referer': self.url}).items():
yield s
except IOError as err:
stream = HLSStream(self.session, server0)
yield "Auto", stream
__plugin__ = Stripchat