-
-
Save userid/9d9dfc432f0fed0d1e1b722f70c2e56f to your computer and use it in GitHub Desktop.
斗鱼2018新api,直播流URL提取
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import re | |
import requests | |
import argparse | |
import time | |
import hashlib | |
import json | |
def get_api(url,rate): | |
url = re.sub(r'[\w.]*douyu.com','m.douyu.com',url) | |
html = requests.get(url) | |
room_id_patt = r'room_id\s*:\s*(\d+),' | |
room_id = re.search(room_id_patt, html.text).group(1) | |
api_url = "http://www.douyutv.com/api/v1/" | |
args = "room/%s?aid=wp&client_sys=wp&time=%d" % (room_id, int(time.time())) | |
auth_md5 = (args + "zNzMV1y4EMxOHS6I5WKm").encode("utf-8") | |
auth_str = hashlib.md5(auth_md5).hexdigest() | |
json_request_url = "%s%s&auth=%s" % (api_url, args, auth_str) | |
content = requests.get(json_request_url) | |
json_content = json.loads(content.text) | |
data = json_content['data'] | |
show_status = data.get('show_status') | |
if show_status is not "1": | |
raise ValueError("Offline!!") | |
other_bit = data.get('rtmp_multi_bitrate') | |
if rate == "1": | |
real_url = data.get('rtmp_url') + '/' + other_bit.get('middle') | |
elif rate == "2": | |
real_url = data.get('rtmp_url') + '/' + other_bit.get('middle2') | |
else: | |
real_url = data.get('rtmp_url') + '/' + data.get('rtmp_live') | |
return(real_url) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('url') | |
parser.add_argument('ratio',nargs='?',default='3') | |
args = parser.parse_args() | |
rid = args.url | |
rate = args.ratio | |
flv_url = get_api(rid,rate) | |
print (flv_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment