1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-07-30 21:32:14 +08:00

Compare commits

..

No commits in common. "4cb2edc05a2ce0a4f7dc24d3d08c4bf8b0434174" and "cd9e41e505b5d45262e85b33f7d2506564f0c436" have entirely different histories.

7 changed files with 64 additions and 101 deletions

View File

@ -9,23 +9,17 @@ import requests
class BiliBili: class BiliBili:
def __init__(self, rid): def __init__(self, rid):
"""
有些地址无法在PotPlayer播放建议换个播放器试试
Args:
rid:
"""
rid = rid rid = rid
self.header = { self.header = {
'User-Agent': 'Mozilla/5.0 (iPod; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, ' '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',
'like Gecko) CriOS/87.0.4280.163 Mobile/15E148 Safari/604.1',
} }
# 先获取直播状态和真实房间号 # 先获取直播状态和真实房间号
r_url = 'https://api.live.bilibili.com/room/v1/Room/room_init' r_url = 'https://api.live.bilibili.com/room/v1/Room/room_init'
param = { param = {
'id': rid 'id': rid
} }
with requests.Session() as self.s: with requests.Session() as s:
res = self.s.get(r_url, headers=self.header, params=param).json() res = s.get(r_url, headers=self.header, params=param).json()
if res['msg'] == '直播间不存在': if res['msg'] == '直播间不存在':
raise Exception(f'bilibili {rid} {res["msg"]}') raise Exception(f'bilibili {rid} {res["msg"]}')
live_status = res['data']['live_status'] live_status = res['data']['live_status']
@ -33,43 +27,46 @@ class BiliBili:
raise Exception(f'bilibili {rid} 未开播') raise Exception(f'bilibili {rid} 未开播')
self.real_room_id = res['data']['room_id'] self.real_room_id = res['data']['room_id']
def get_real_url(self, current_qn: int = 10000) -> dict: def get_real_url(self, current_qn: int = 10000) -> list:
url = 'https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo' url = 'https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo'
param = { param = {
'room_id': self.real_room_id, 'device': 'pc',
'platform': 'h5',
'scale': 0,
'build': '10000',
'protocol': '0,1', 'protocol': '0,1',
'format': '0,1,2', 'format': '0,1,2',
'codec': '0,1', 'codec': '0,1',
'qn': current_qn, 'room_id': self.real_room_id,
'platform': 'h5', 'qn': current_qn
'ptype': 8,
} }
res = self.s.get(url, headers=self.header, params=param).json() with requests.Session() as session:
stream_info = res['data']['playurl_info']['playurl']['stream'] res = session.get(url, headers=self.header, params=param)
qn_max = 0 res = res.json()
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'] stream_info = res['data']['playurl_info']['playurl']['stream']
qn_max = 0
stream_urls = {} for data in stream_info:
# flv流无法播放暂修改成获取hls格式的流 accept_qn = data['format'][0]['codec'][0]['accept_qn']
for data in stream_info: for qn in accept_qn:
format_name = data['format'][0]['format_name'] qn_max = qn if qn > qn_max else qn_max
if format_name == 'ts': if qn_max != current_qn:
base_url = data['format'][-1]['codec'][0]['base_url'] param['qn'] = qn_max
url_info = data['format'][-1]['codec'][0]['url_info'] res = session.get(url, headers=self.header, params=param)
for i, info in enumerate(url_info): res = res.json()
host = info['host'] stream_info = res['data']['playurl_info']['playurl']['stream']
extra = info['extra'] stream_url_list = []
stream_urls[f'线路{i + 1}'] = f'{host}{base_url}{extra}' for data in stream_info:
break format_name = data['format'][0]['format_name']
return stream_urls 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
def get_real_url(rid): def get_real_url(rid):

View File

@ -15,8 +15,7 @@ class FengBo:
def get_real_url(self): def get_real_url(self):
with requests.Session() as s: with requests.Session() as s:
res = s.get(f'https://external.fengbolive.com/cgi-bin/get_anchor_info_proxy.fcgi?anchorid={self.rid}') res = s.get('https://external.fengbolive.com/cgi-bin/get_anchor_info_proxy.fcgi?anchorid=' + str(self.rid)).json()
res = res.json()
if res['ret'] == 1: if res['ret'] == 1:
info = res['info'] info = res['info']
info = unquote(info, 'utf-8') info = unquote(info, 'utf-8')

View File

@ -21,7 +21,7 @@ class HongLe:
pass pass
tt = int(time.time() * 1000) tt = int(time.time() * 1000)
url = f'https://service.hongle.tv/v2/userw/login?_st1={tt}' url = 'https://service.hongle.tv/v2/userw/login?_st1={}'.format(tt)
data = { data = {
'_st1': tt, '_st1': tt,
'geetest_challenge': '7f4f6fd6257799c0bcac1f38c21c042dl0', 'geetest_challenge': '7f4f6fd6257799c0bcac1f38c21c042dl0',

View File

@ -7,7 +7,6 @@ import urllib.parse
import hashlib import hashlib
import time import time
def live(e): def live(e):
i, b = e.split('?') i, b = e.split('?')
r = i.split('/') r = i.split('/')

41
kuwo.py
View File

@ -1,44 +1,26 @@
# 酷我聚星直播http://jx.kuwo.cn/ # 酷我聚星直播http://jx.kuwo.cn/
import requests import requests
import re
class KuWo: class KuWo:
def __init__(self, rid): def __init__(self, rid):
self.rid = 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): def get_real_url(self):
res = self.s.get(f'https://jx.kuwo.cn/{self.rid}').text with requests.Session() as s:
roomid = re.search(r"roomId: '(\d*)'", res) res = s.get('https://zhiboserver.kuwo.cn/proxy.p?src=h5&cmd=enterroom&rid={}&videotype=1&auto=1'.format(self.rid))
if roomid: res = res.json()
self.rid = roomid.group(1)
else:
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: try:
url = res['data']['horizontal'][0]['httpshls'][0] livestatus = res['room']['livestatus']
except (KeyError, IndexError): except KeyError:
url = res['data']['vertical'][0]['httpshls'][0] raise Exception('房间号错误')
return url if livestatus == 2:
real_url = res['live']['url']
return real_url
else:
raise Exception('未开播')
def get_real_url(rid): def get_real_url(rid):
@ -53,3 +35,4 @@ def get_real_url(rid):
if __name__ == '__main__': if __name__ == '__main__':
r = input('输入酷我聚星直播房间号:\n') r = input('输入酷我聚星直播房间号:\n')
print(get_real_url(r)) print(get_real_url(r))

View File

@ -13,7 +13,7 @@ class LeHai:
self.rid = rid self.rid = rid
def get_real_url(self): def get_real_url(self):
url = f'https://service.lehaitv.com/v2/room/{self.rid}/media/advanceInfoRoom' url = 'https://service.lehaitv.com/v2/room/{}/enter'.format(self.rid)
params = { params = {
'_st1': int(time.time() * 1e3), '_st1': int(time.time() * 1e3),
'accessToken': 's7FUbTJ%2BjILrR7kicJUg8qr025ZVjd07DAnUQd8c7g%2Fo4OH9pdSX6w%3D%3D', 'accessToken': 's7FUbTJ%2BjILrR7kicJUg8qr025ZVjd07DAnUQd8c7g%2Fo4OH9pdSX6w%3D%3D',
@ -29,8 +29,9 @@ class LeHai:
res = res.json() res = res.json()
statuscode = res['status']['statuscode'] statuscode = res['status']['statuscode']
if statuscode == '0': if statuscode == '0':
if res['data']['live_status'] == 1: if res['data']['live_status'] == '1':
real_url = res['data']['medial_url_app_for_h264'] anchor, = res['data']['anchor']
real_url = anchor['media_url']
return real_url return real_url
else: else:
raise Exception('未开播') raise Exception('未开播')

36
pps.py
View File

@ -9,36 +9,20 @@ class PPS:
def __init__(self, rid): def __init__(self, rid):
self.rid = rid self.rid = rid
self.BASE_URL = 'https://m-x.pps.tv/api/stream/getH5'
self.s = requests.Session()
def get_real_url(self): 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: try:
res = self.s.get(f'https://m-x.pps.tv/room/{self.rid}', headers=headers).text response = requests.get('http://m-x.pps.tv/room/' + str(self.rid)).text
anchor_id = re.findall(r'anchor_id":"(\d*)', res)[0] anchor_id = re.findall(r'anchor_id":(\d*),"online_uid', response)[0]
params = { tt = int(time.time() * 1000)
'qd_tm': tt, 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)
'typeId': 1, headers = {
'platform': 7, 'Content-Type': 'application/x-www-form-urlencoded',
'vid': 0, 'Referer': 'http://m-x.pps.tv/'
'qd_vip': 0,
'qd_uid': anchor_id,
'qd_ip': '114.114.114.114',
'qd_vipres': 0,
'qd_src': 'h5_xiu',
'qd_tvid': 0,
'callback': '',
} }
res = self.s.get(self.BASE_URL, headers=headers, params=params).text response = requests.get(url=url, headers=headers).text
real_url = re.findall(r'"hls":"(.*)","rate_list', res)[0] real_url = re.findall(r'"hls":"(.*)","rate_list', response)[0]
except Exception: except:
raise Exception('直播间不存在或未开播') raise Exception('直播间不存在或未开播')
return real_url return real_url