download form douyin's share link

This commit is contained in:
chs040701 2020-04-26 17:09:05 +08:00
parent 5a4eb06262
commit 0a1e949ba6

View File

@ -19,7 +19,9 @@ __all__ = ['douyin_download_by_url']
def douyin_download_by_url(url, **kwargs): def douyin_download_by_url(url, **kwargs):
page_content = get_content(url, headers=fake_headers) page_content = get_content(url, headers=fake_headers)
match_rule = re.compile(r'var data = \[(.*?)\];') match_rule = re.compile(r'var data = \[(.*?)\];')
video_info = json.loads(match_rule.findall(page_content)[0]) data = match_rule.findall(page_content)
if len(data) > 0:
video_info = json.loads([0])
video_url = video_info['video']['play_addr']['url_list'][0] video_url = video_info['video']['play_addr']['url_list'][0]
# fix: https://www.douyin.com/share/video/6553248251821165832 # fix: https://www.douyin.com/share/video/6553248251821165832
# if there is no title, use desc # if there is no title, use desc
@ -28,6 +30,12 @@ def douyin_download_by_url(url, **kwargs):
title = cha_list[0]['cha_name'] title = cha_list[0]['cha_name']
else: else:
title = video_info['desc'] title = video_info['desc']
else:
match_rule = re.compile(r'playAddr: "(.*?)"', re.S)
video_url = match_rule.findall(page_content)[0]
match_rule = re.compile(r'<p class="desc">(.*?)</p>', re.S)
title = match_rule.findall(page_content)[0].split('#')[0]
video_format = 'mp4' video_format = 'mp4'
size = url_size(video_url, faker=True) size = url_size(video_url, faker=True)
print_info( print_info(