douyu.py
#-*- coding:utf-8 -*-
import requests
import re,sys
import execjs
import time
import hashlib
def get_tt():
tt1 = str(int(time.time()))
tt2 = str(int((time.time() * 1000)))
today = time.strftime('%Y%m%d', time.localtime())
return tt1, tt2, today
def get_homejs(rid):
room_url = 'https://m.douyu.com/' + rid
response = requests.get(url=room_url)
pattern_real_rid = r'"rid":(\d{1,7})'
real_rid = re.findall(pattern_real_rid, response.text, re.I)[0]
if real_rid != rid:
room_url = 'https://m.douyu.com/' + real_rid
response = requests.get(url=room_url)
homejs = ''
pattern = r'(function ub9.*)[\s\S](var.*)'
result = re.findall(pattern, response.text, re.I)
str1 = re.sub(r'eval.*;}', 'strc;}', result[0][0])
homejs = str1 + result[0][1]
return homejs, real_rid
def get_sign(rid, post_v, tt, ub9):
docjs = execjs.compile(ub9)
res2 = docjs.call('ub98484234')
str3 = re.sub(r'\(function[\s\S]*toString\(\)', '\'', res2)
md5rb = hashlib.md5((rid + '10000000000000000000000000001501' + tt + '2501' +
post_v).encode('utf-8')).hexdigest()
str4 = 'function get_sign(){var rb=\'' + md5rb + str3
str5 = re.sub(r'return rt;}[\s\S]*','return re;};', str4)
str6 = re.sub(r'"v=.*&sign="\+', '', str5)
docjs1 = execjs.compile(str6)
sign = docjs1.call(
'get_sign', rid, '10000000000000000000000000001501', tt)
return sign
def mix_room(rid):
result1 = 'PKing'
return result1
def get_pre_url(rid, tt):
request_url = 'https://playweb.douyucdn.cn/lapi/live/hlsH5Preview/' + rid
post_data = {
'rid': rid,
'did': '10000000000000000000000000001501'
}
auth = hashlib.md5((rid + str(tt)).encode('utf-8')).hexdigest()
header = {
'content-type': 'application/x-www-form-urlencoded',
'rid': rid,
'time': tt,
'auth': auth
}
response = requests.post(url=request_url, headers=header, data=post_data)
response = response.json()
pre_url = ''
if response.get('error') == 0:
real_url = (response.get('data')).get('rtmp_live')
if 'mix=1' in real_url:
pre_url = mix_room(rid)
else:
pattern1 = r'^[0-9a-zA-Z]*'
pre_url = re.search(pattern1, real_url, re.I).group()
return pre_url
def get_sign_url(post_v, rid, tt, ub9):
sign = get_sign(rid, post_v, tt, ub9)
request_url = 'https://m.douyu.com/api/room/ratestream'
post_data = {
'v': '2501' + post_v,
'did': '10000000000000000000000000001501',
'tt': tt,
'sign': sign,
'ver': '219032101',
'rid': rid,
'rate': '-1'
}
header = {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36'
}
response = requests.post(url=request_url, headers=header, data=post_data).json()
if response.get('code') == 0:
real_url = (response.get('data')).get('url')
if 'mix=1' in real_url:
result1 = mix_room(rid)
else:
pattern1 = r'live/(\d{1,8}[0-9a-zA-Z]+)_?[\d]{0,4}/playlist'
result1 = re.findall(pattern1, real_url, re.I)[0]
else:
result1 = 0
return result1
def get_real_url(rid):
rid = str(rid)
tt = get_tt()
url = get_pre_url(rid, tt[1])
if url:
return "http://tx2play1.douyucdn.cn/live/" + url + ".flv?uuid="
else:
result = get_homejs(rid)
real_rid = result[1]
homejs = result[0]
real_url = get_sign_url(tt[2], real_rid, tt[0], homejs)
if real_url != 0:
real_url = "http://tx2play1.douyucdn.cn/live/" + real_url + ".flv?uuid="
else:
real_url = '未开播'
return real_url
def get_url_from_js(rid):
# 从播放页源代码中直接匹配地址
header = {
'Content-Type': 'application/x-www-form-urlencoded'
}
try:
response = requests.get('https://www.douyu.com/{}'.format(rid), headers=header).text
real_url = re.findall(r'live/({}[\d\w]*?)_'.format(rid), response)[0]
except:
real_url = '直播间未开播或不存在'
return "http://tx2play1.douyucdn.cn/live/" + real_url + ".flv?uuid="
#rid = str(input('请输入斗鱼数字房间号:\n'))
def main(rid):
real_url = get_real_url(rid)
return real_url
main(rid="607575")
main(rid="2132902")
main(rid="579963")
get_douyu_url.py
# -*- coding: utf-8 -*-
from douyu import main
import requests
import re,sys
reload(sys)
sys.setdefaultencoding("utf-8")
url="https://www.douyu.com/g_LOL"
header={
"accept":" text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'
}
req=requests.get(url)#获取响应
con=req.content
pattern = re.compile(r'"room_id":"(\d+)",.*?,"nickname":"(.*?)","icon":"(.*?)",')
match =re.findall(pattern , con)
f=open(r'インタネットs.txt'.decode("utf-8"),'w')
for li in match:
#print li[1].decode("utf-8")+",https://www.douyu.com/"+li[0]+" pic:"+li[2]
print li[1].decode("utf-8")+","+main(li[0])
f.write(li[1].decode("utf-8")+","+main(li[0])+"\n")
f.close()
イTatari 윈 네코ッ스위트 s.txt
심바 IMB 다이애나 다이애나, HTTP :? //Tx2play1.douyucdn.cn/live/3487376r1D1fzmm6.flv UUID =
ShinyRuoの, HTTP : //tx2play1.douyucdn.cn/live/13703ro4JBwp1Bne.flv UUID =
새끼 돼지 슈퍼 원수 동성, HTTP : //tx2play1.douyucdn.cn/live/168000rsNmkOeEHj.flv UUID =이
아기 공 ouo, HTTP :? //tx2play1.douyucdn.cn/live/5974716rkBzoDGWh.flv UUID =
잎 노트, http://tx2play1.douyucdn.cn/live/12313rjVSeVyskva.flv?uuid=
사우스 다이애나 큰 악마 아이, HTTP :? //tx2play1.douyucdn.cn/live/5526219rEx8vP6zB.flv UUID =
게으른 고양이 QAQ은 http : / /tx2play1.douyucdn.cn/live/577224rhfzd1IVRR.flv?uuid=
김 진구 끈적 거리는 doinb, HTTP : //tx2play1.douyucdn.cn/live/252140r5BMWiDCGK.flv UUID =
년 칼 자매 QAQ은 http : // tx2play1.douyucdn.cn/live/5132911roE44q4jf.flv?uuid=
오브 워크래프트 내리고, HTTP : //tx2play1.douyucdn.cn/live/262537reZ88fqH2q.flv UUID =?
그래픽 통신 I, HTTP :? UUID = //tx2play1.douyucdn.cn/live/210398rCKVxHi72Q.flv
ZZC 아오 양, HTTP :? //Tx2play1.douyucdn.cn/live/666743rZ73OM62TF.flv UUID =
밤 다이애나 살인 카미카제 은 http : //tx2play1.douyucdn.cn/live/217785rEzODyfTBm.flv UUID =
Nuoxia 지원, HTTP : //tx2play1.douyucdn.cn/live/8932rQE8XMa61dU0.flv UUID =?
다이애나, HTTP aleng 감기 : // tx2play1.douyucdn.cn/live/520rHYUEOg3jqYzk.flv?uuid=
헛되이 작은 그것을 각성, HTTP :? //tx2play1.douyucdn.cn/live/5324613r7VsJEaS8.flv UUID =
스러운 얼굴 케이크를 HTTP : //tx2play1.douyucdn ? .CN / 라이브 / 266055rWTCMD5Egt.flv UUID =
첫 번째 창 S, HTTP :? //tx2play1.douyucdn.cn/live/593392rj4WvDD3yn.flv UUID = 돌 루트 페이지
// tx2play1 : 2 번 호출되지 저우 Shuyi, HTTP. douyucdn.cn/live/290935rjVxzK8wr8.flv?uuid=
//tx2play1.douyucdn.cn/live/4496475rUSl3A61C.flv UUID = 천 개 단어의 아 크리 딘, HTTP하지?
어디 얼음, HTTP :? //Tx2play1.douyucdn.cn/live/17349rcZgVsrYUDF.flv UUID =
캐년 킬 하나님 간장, HTTP :? //Tx2play1.douyucdn.cn/live/6717704rLtJSW9ea.flv UUID =
하나님의 메인 홀 슈 노래 둥팅 호, HTTP : //tx2play1.douyucdn.cn/live/138243rFTYzMUEcQ.flv UUID =
대한 진 케시, 같은 HTTP :? //tx2play1.douyucdn.cn/live/544865rcia0F1sCa.flv UUID =
14 레빈은 http : //tx2play1.douyucdn.cn/live/2016309r2SksIKcc.flv?uuid=
희 보아, HTTP :? UUID = //tx2play1.douyucdn.cn/live/838936rHWLXJM1AC.flv
년 블라인드 왕은 http : //tx2play1.douyucdn .CN / 라이브 / 12118rNSZenbNNAF.flv UUID =?
T1 다이애나 JK 특별한 걱정은 http : //tx2play1.douyucdn.cn/live/534183rWTAULgCXv.flv UUID =
빛 다이애나, HTTP 웨이브 : //tx2play1.douyucdn.cn/live /600290rJNcnntP0X.flv?uuid=
불멸의 형제 다이애나, HTTP : //tx2play1.douyucdn.cn/live/787579r0NPV4KmRZ.flv UUID =?