-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathbongacams.py
103 lines (76 loc) · 3.28 KB
/
bongacams.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
import json
import re
import requests
from urllib.parse import urljoin, urlparse, urlunparse
from streamlink.exceptions import PluginError, NoStreamsError
from streamlink.plugin.api import validate, useragents
from streamlink.plugin import Plugin
from streamlink.stream import HLSStream
from streamlink.utils import update_scheme
CONST_HEADERS = {}
CONST_HEADERS['User-Agent'] = useragents.CHROME
CONST_HEADERS['X-Requested-With'] = 'XMLHttpRequest'
url_re = re.compile(r"(http(s)?://)?(\w{2}.)?(bongacams\d*?\.com)/([\w\d_-]+)")
schema = validate.Schema({
"status": "success"
})
class bongacams(Plugin):
@classmethod
def can_handle_url(self, url):
return url_re.match(url)
def _get_streams(self):
match = url_re.match(self.url)
LISTING_PATH = 'tools/listing_v3.php'
stream_page_scheme = 'https'
stream_page_domain = match.group(4)
model_name = match.group(5)
listing_url = urlunparse((stream_page_scheme, stream_page_domain, LISTING_PATH, '', '', ''))
# create http session and set headers
http_session = self.session.http
http_session.headers.update(CONST_HEADERS)
params = {
"livetab": None,
"online_only": True,
"offset": 0,
"model_search[display_name][text]": model_name,
"_online_filter": 0,
"can_pin_models": False,
"limit": 1
}
response = http_session.get(listing_url, params=params)
self.logger.debug(response.text)
if len(http_session.cookies) == 0:
raise PluginError("Can't get a cookies")
if response.status_code != 200:
self.logger.debug("response for {0}:\n{1}".format(response.request.url, response.text))
raise PluginError("unexpected status code for {0}: {1}".format(response.url, response.status_code))
http_session.close()
response = response.json()
schema.validate(response)
if not model_name.lower() in list([model['username'].lower() for model in response['models']]):
raise NoStreamsError(self.url)
if str(response['online_count']) == '0':
raise NoStreamsError(self.url)
esid = None
for model in response['models']:
if model['username'].lower() == model_name.lower():
#if model['room'] not in ('public', 'private', 'fullprivate'):
# raise NoStreamsError(self.url)
esid = model.get('esid')
model_name = model['username']
if not esid:
raise PluginError("unknown error, esid={0} for {1}.\nResponse: {2}".format(esid, model_name, response['models']))
hls_url = f'https://{esid}.bcvcdn.com/hls/stream_{model_name}/playlist.m3u8'
if hls_url:
self.logger.debug('HLS URL: {0}'.format(hls_url))
try:
for s in HLSStream.parse_variant_playlist(self.session, hls_url).items():
yield s
except Exception as e:
if '404' in str(e):
self.logger.debug(str(e))
self.logger.debug('Stream is currently offline/private/away')
else:
self.logger.error(str(e))
return
__plugin__ = bongacams