mirror of
https://github.com/wbt5/real-url.git
synced 2025-07-29 21:00:30 +08:00
Compare commits
7 Commits
cd9e41e505
...
4cb2edc05a
Author | SHA1 | Date | |
---|---|---|---|
|
4cb2edc05a | ||
|
8a6766681b | ||
|
5bcf800f6e | ||
|
a3865d88c7 | ||
|
e6bfbb58e2 | ||
|
8ee49c50a0 | ||
|
9a2d70f701 |
75
bilibili.py
75
bilibili.py
@ -9,17 +9,23 @@ import requests
|
||||
class BiliBili:
|
||||
|
||||
def __init__(self, rid):
|
||||
"""
|
||||
有些地址无法在PotPlayer播放,建议换个播放器试试
|
||||
Args:
|
||||
rid:
|
||||
"""
|
||||
rid = rid
|
||||
self.header = {
|
||||
'User-Agent': 'Mozilla/5.0 (iPod; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.163 Mobile/15E148 Safari/604.1',
|
||||
'User-Agent': 'Mozilla/5.0 (iPod; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, '
|
||||
'like Gecko) CriOS/87.0.4280.163 Mobile/15E148 Safari/604.1',
|
||||
}
|
||||
# 先获取直播状态和真实房间号
|
||||
r_url = 'https://api.live.bilibili.com/room/v1/Room/room_init'
|
||||
param = {
|
||||
'id': rid
|
||||
}
|
||||
with requests.Session() as s:
|
||||
res = s.get(r_url, headers=self.header, params=param).json()
|
||||
with requests.Session() as self.s:
|
||||
res = self.s.get(r_url, headers=self.header, params=param).json()
|
||||
if res['msg'] == '直播间不存在':
|
||||
raise Exception(f'bilibili {rid} {res["msg"]}')
|
||||
live_status = res['data']['live_status']
|
||||
@ -27,46 +33,43 @@ class BiliBili:
|
||||
raise Exception(f'bilibili {rid} 未开播')
|
||||
self.real_room_id = res['data']['room_id']
|
||||
|
||||
def get_real_url(self, current_qn: int = 10000) -> list:
|
||||
def get_real_url(self, current_qn: int = 10000) -> dict:
|
||||
url = 'https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo'
|
||||
param = {
|
||||
'device': 'pc',
|
||||
'platform': 'h5',
|
||||
'scale': 0,
|
||||
'build': '10000',
|
||||
'room_id': self.real_room_id,
|
||||
'protocol': '0,1',
|
||||
'format': '0,1,2',
|
||||
'codec': '0,1',
|
||||
'room_id': self.real_room_id,
|
||||
'qn': current_qn
|
||||
'qn': current_qn,
|
||||
'platform': 'h5',
|
||||
'ptype': 8,
|
||||
}
|
||||
with requests.Session() as session:
|
||||
res = session.get(url, headers=self.header, params=param)
|
||||
res = res.json()
|
||||
res = self.s.get(url, headers=self.header, params=param).json()
|
||||
stream_info = res['data']['playurl_info']['playurl']['stream']
|
||||
qn_max = 0
|
||||
|
||||
for data in stream_info:
|
||||
accept_qn = data['format'][0]['codec'][0]['accept_qn']
|
||||
for qn in accept_qn:
|
||||
qn_max = qn if qn > qn_max else qn_max
|
||||
if qn_max != current_qn:
|
||||
param['qn'] = qn_max
|
||||
res = self.s.get(url, headers=self.header, params=param).json()
|
||||
stream_info = res['data']['playurl_info']['playurl']['stream']
|
||||
qn_max = 0
|
||||
for data in stream_info:
|
||||
accept_qn = data['format'][0]['codec'][0]['accept_qn']
|
||||
for qn in accept_qn:
|
||||
qn_max = qn if qn > qn_max else qn_max
|
||||
if qn_max != current_qn:
|
||||
param['qn'] = qn_max
|
||||
res = session.get(url, headers=self.header, params=param)
|
||||
res = res.json()
|
||||
stream_info = res['data']['playurl_info']['playurl']['stream']
|
||||
stream_url_list = []
|
||||
for data in stream_info:
|
||||
format_name = data['format'][0]['format_name']
|
||||
if format_name == 'flv':
|
||||
base_url = data['format'][0]['codec'][0]['base_url']
|
||||
url_info = data['format'][0]['codec'][0]['url_info']
|
||||
for info in url_info:
|
||||
host = info['host']
|
||||
extra = info['extra']
|
||||
# print(host + base_url + extra)
|
||||
stream_url_list.append(host + base_url + extra)
|
||||
break
|
||||
return stream_url_list
|
||||
|
||||
stream_urls = {}
|
||||
# flv流无法播放,暂修改成获取hls格式的流,
|
||||
for data in stream_info:
|
||||
format_name = data['format'][0]['format_name']
|
||||
if format_name == 'ts':
|
||||
base_url = data['format'][-1]['codec'][0]['base_url']
|
||||
url_info = data['format'][-1]['codec'][0]['url_info']
|
||||
for i, info in enumerate(url_info):
|
||||
host = info['host']
|
||||
extra = info['extra']
|
||||
stream_urls[f'线路{i + 1}'] = f'{host}{base_url}{extra}'
|
||||
break
|
||||
return stream_urls
|
||||
|
||||
|
||||
def get_real_url(rid):
|
||||
|
@ -15,7 +15,8 @@ class FengBo:
|
||||
|
||||
def get_real_url(self):
|
||||
with requests.Session() as s:
|
||||
res = s.get('https://external.fengbolive.com/cgi-bin/get_anchor_info_proxy.fcgi?anchorid=' + str(self.rid)).json()
|
||||
res = s.get(f'https://external.fengbolive.com/cgi-bin/get_anchor_info_proxy.fcgi?anchorid={self.rid}')
|
||||
res = res.json()
|
||||
if res['ret'] == 1:
|
||||
info = res['info']
|
||||
info = unquote(info, 'utf-8')
|
||||
|
@ -21,7 +21,7 @@ class HongLe:
|
||||
pass
|
||||
|
||||
tt = int(time.time() * 1000)
|
||||
url = 'https://service.hongle.tv/v2/userw/login?_st1={}'.format(tt)
|
||||
url = f'https://service.hongle.tv/v2/userw/login?_st1={tt}'
|
||||
data = {
|
||||
'_st1': tt,
|
||||
'geetest_challenge': '7f4f6fd6257799c0bcac1f38c21c042dl0',
|
||||
|
1
huya.py
1
huya.py
@ -7,6 +7,7 @@ import urllib.parse
|
||||
import hashlib
|
||||
import time
|
||||
|
||||
|
||||
def live(e):
|
||||
i, b = e.split('?')
|
||||
r = i.split('/')
|
||||
|
41
kuwo.py
41
kuwo.py
@ -1,26 +1,44 @@
|
||||
# 酷我聚星直播:http://jx.kuwo.cn/
|
||||
|
||||
import requests
|
||||
import re
|
||||
|
||||
|
||||
class KuWo:
|
||||
|
||||
def __init__(self, rid):
|
||||
self.rid = rid
|
||||
self.BASE_URL = 'https://jxm0.kuwo.cn/video/mo/live/pull/h5/v3/streamaddr'
|
||||
self.s = requests.Session()
|
||||
|
||||
def get_real_url(self):
|
||||
with requests.Session() as s:
|
||||
res = s.get('https://zhiboserver.kuwo.cn/proxy.p?src=h5&cmd=enterroom&rid={}&videotype=1&auto=1'.format(self.rid))
|
||||
res = res.json()
|
||||
try:
|
||||
livestatus = res['room']['livestatus']
|
||||
except KeyError:
|
||||
raise Exception('房间号错误')
|
||||
if livestatus == 2:
|
||||
real_url = res['live']['url']
|
||||
return real_url
|
||||
res = self.s.get(f'https://jx.kuwo.cn/{self.rid}').text
|
||||
roomid = re.search(r"roomId: '(\d*)'", res)
|
||||
if roomid:
|
||||
self.rid = roomid.group(1)
|
||||
else:
|
||||
raise Exception('未开播')
|
||||
raise Exception('未开播或房间号错误')
|
||||
params = {
|
||||
'std_bid': 1,
|
||||
'roomId': self.rid,
|
||||
'platform': 405,
|
||||
'version': 1000,
|
||||
'streamType': '3-6',
|
||||
'liveType': 1,
|
||||
'ch': 'fx',
|
||||
'ua': 'fx-mobile-h5',
|
||||
'kugouId': 0,
|
||||
'layout': 1,
|
||||
'videoAppId': 10011,
|
||||
}
|
||||
res = self.s.get(self.BASE_URL, params=params).json()
|
||||
if res['data']['sid'] == -1:
|
||||
raise Exception('未开播或房间号错误')
|
||||
try:
|
||||
url = res['data']['horizontal'][0]['httpshls'][0]
|
||||
except (KeyError, IndexError):
|
||||
url = res['data']['vertical'][0]['httpshls'][0]
|
||||
return url
|
||||
|
||||
|
||||
def get_real_url(rid):
|
||||
@ -35,4 +53,3 @@ def get_real_url(rid):
|
||||
if __name__ == '__main__':
|
||||
r = input('输入酷我聚星直播房间号:\n')
|
||||
print(get_real_url(r))
|
||||
|
||||
|
7
lehai.py
7
lehai.py
@ -13,7 +13,7 @@ class LeHai:
|
||||
self.rid = rid
|
||||
|
||||
def get_real_url(self):
|
||||
url = 'https://service.lehaitv.com/v2/room/{}/enter'.format(self.rid)
|
||||
url = f'https://service.lehaitv.com/v2/room/{self.rid}/media/advanceInfoRoom'
|
||||
params = {
|
||||
'_st1': int(time.time() * 1e3),
|
||||
'accessToken': 's7FUbTJ%2BjILrR7kicJUg8qr025ZVjd07DAnUQd8c7g%2Fo4OH9pdSX6w%3D%3D',
|
||||
@ -29,9 +29,8 @@ class LeHai:
|
||||
res = res.json()
|
||||
statuscode = res['status']['statuscode']
|
||||
if statuscode == '0':
|
||||
if res['data']['live_status'] == '1':
|
||||
anchor, = res['data']['anchor']
|
||||
real_url = anchor['media_url']
|
||||
if res['data']['live_status'] == 1:
|
||||
real_url = res['data']['medial_url_app_for_h264']
|
||||
return real_url
|
||||
else:
|
||||
raise Exception('未开播')
|
||||
|
36
pps.py
36
pps.py
@ -9,20 +9,36 @@ class PPS:
|
||||
|
||||
def __init__(self, rid):
|
||||
self.rid = rid
|
||||
self.BASE_URL = 'https://m-x.pps.tv/api/stream/getH5'
|
||||
self.s = requests.Session()
|
||||
|
||||
def get_real_url(self):
|
||||
headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, '
|
||||
'like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
|
||||
'Referer': 'https://m-x.pps.tv/'
|
||||
}
|
||||
tt = int(time.time() * 1000)
|
||||
try:
|
||||
response = requests.get('http://m-x.pps.tv/room/' + str(self.rid)).text
|
||||
anchor_id = re.findall(r'anchor_id":(\d*),"online_uid', response)[0]
|
||||
tt = int(time.time() * 1000)
|
||||
url = 'http://m-x.pps.tv/api/stream/getH5?qd_tm={}&typeId=1&platform=7&vid=0&qd_vip=0&qd_uid={}&qd_ip=114.114.114.114&qd_vipres=0&qd_src=h5_xiu&qd_tvid=0&callback='.format(tt, anchor_id)
|
||||
headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Referer': 'http://m-x.pps.tv/'
|
||||
res = self.s.get(f'https://m-x.pps.tv/room/{self.rid}', headers=headers).text
|
||||
anchor_id = re.findall(r'anchor_id":"(\d*)', res)[0]
|
||||
params = {
|
||||
'qd_tm': tt,
|
||||
'typeId': 1,
|
||||
'platform': 7,
|
||||
'vid': 0,
|
||||
'qd_vip': 0,
|
||||
'qd_uid': anchor_id,
|
||||
'qd_ip': '114.114.114.114',
|
||||
'qd_vipres': 0,
|
||||
'qd_src': 'h5_xiu',
|
||||
'qd_tvid': 0,
|
||||
'callback': '',
|
||||
}
|
||||
response = requests.get(url=url, headers=headers).text
|
||||
real_url = re.findall(r'"hls":"(.*)","rate_list', response)[0]
|
||||
except:
|
||||
res = self.s.get(self.BASE_URL, headers=headers, params=params).text
|
||||
real_url = re.findall(r'"hls":"(.*)","rate_list', res)[0]
|
||||
except Exception:
|
||||
raise Exception('直播间不存在或未开播')
|
||||
return real_url
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user