MCPcopy
hub / github.com/Jack-Cherish/python-spider / DouYin

Class DouYin

douyin.py:6–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import requests, json, time, re, os, sys, time
5
6class DouYin(object):
7 def __init__(self):
8 """
9 抖音App视频下载
10 """
11 #SSL认证
12 pass
13
14 def get_video_urls(self, user_id):
15 """
16 获得视频播放地址
17 Parameters:
18 nickname:查询的用户名
19 Returns:
20 video_names: 视频名字列表
21 video_urls: 视频链接列表
22 aweme_count: 视频数量
23 """
24 video_names = []
25 video_urls = []
26 unique_id = ''
27 while unique_id != user_id:
28 search_url = 'https://api.amemv.com/aweme/v1/discover/search/?cursor=0&keyword=%s&count=10&type=1&retry_type=no_retry&iid=17900846586&device_id=34692364855&ac=wifi&channel=xiaomi&aid=1128&app_name=aweme&version_code=162&version_name=1.6.2&device_platform=android&ssmix=a&device_type=MI+5&device_brand=Xiaomi&os_api=24&os_version=7.0&uuid=861945034132187&openudid=dc451556fc0eeadb&manifest_version_code=162&resolution=1080*1920&dpi=480&update_version_code=1622' % user_id
29 req = requests.get(url = search_url, verify = False)
30 html = json.loads(req.text)
31 aweme_count = html['user_list'][0]['user_info']['aweme_count']
32 uid = html['user_list'][0]['user_info']['uid']
33 nickname = html['user_list'][0]['user_info']['nickname']
34 unique_id = html['user_list'][0]['user_info']['unique_id']
35 user_url = 'https://www.douyin.com/aweme/v1/aweme/post/?user_id=%s&max_cursor=0&count=%s' % (uid, aweme_count)
36 req = requests.get(url = user_url, verify = False)
37 html = json.loads(req.text)
38 i = 1
39 for each in html['aweme_list']:
40 share_desc = each['share_info']['share_desc']
41 if '抖音-原创音乐短视频社区' == share_desc:
42 video_names.append(str(i) + '.mp4')
43 i += 1
44 else:
45 video_names.append(share_desc + '.mp4')
46 video_urls.append(each['share_info']['share_url'])
47
48 return video_names, video_urls, nickname
49
50 def get_download_url(self, video_url):
51 """
52 获得视频播放地址
53 Parameters:
54 video_url:视频播放地址
55 Returns:
56 download_url: 视频下载地址
57 """
58 req = requests.get(url = video_url, verify = False)
59 bf = BeautifulSoup(req.text, 'lxml')
60 script = bf.find_all('script')[-1]
61 video_url_js = re.findall('var data = \[(.+)\];', str(script))[0]
62 video_html = json.loads(video_url_js)
63 download_url = video_html['video']['play_addr']['url_list'][0]

Callers 1

douyin.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected