1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-06-16 15:59:57 +08:00
zhibo-url/51lm.py
2021-11-13 13:54:32 +08:00

60 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 羚萌直播https://live.51lm.tv/programs/Hot
from urllib.parse import urlencode
import requests
import time
import hashlib
class LM:
def __init__(self, rid):
self.rid = rid
self.BASE_URL = 'https://www.51lm.tv/live/room/info/basic'
def get_real_url(self):
roominfo = {'programId': self.rid}
def g(d):
return hashlib.md5(f'{d}#{urlencode(roominfo)}#Ogvbm2ZiKE'.encode('utf-8')).hexdigest()
lminfo = {
'h': int(time.time()) * 1000,
'i': -246397986,
'o': 'iphone',
's': 'G_c17a64eff3f144a1a48d9f02e8d981c2',
't': 'H',
'v': '4.20.43',
'w': 'a710244508d3cc14f50d24e9fecc496a'
}
u = g(urlencode(lminfo))
lminfo = f'G={u}&{urlencode(lminfo)}'
with requests.Session() as s:
res = s.post(self.BASE_URL, json=roominfo, headers={'lminfo': lminfo}).json()
code = res['code']
if code == 200:
status = res['data']['isLiving']
if status == 'True':
real_url = res['data']['playUrl']
return real_url
else:
raise Exception('未开播')
elif code == -1:
raise Exception('输入错误')
elif code == 1201:
raise Exception('直播间不存在')
def get_real_url(rid):
try:
lm = LM(rid)
return lm.get_real_url()
except Exception as e:
print('Exception', e)
return False
if __name__ == '__main__':
r = input('输入羚萌直播房间号:\n')
print(get_real_url(r))