def favorite(user_id, user_name=None): print("正在拉取", user_name if user_name else user_id, '喜欢的抖音视频...') # 组装数据 params = getParams(user_id) favorite_video_list = [] max_cursor = None while True: if max_cursor: params['max_cursor'] = str(max_cursor) # 请求数据 result = fetch(URL.favorite_url(), headers=common_headers, params=params, verify=False) #修改全局变量的值 aweme_list = result.get('aweme_list') if aweme_list != None and len(aweme_list) != 0: favorite_video_list.extend(aweme_list) if result.get('has_more') != 1: break else: max_cursor = result.get('max_cursor') print(user_name if user_name else user_id, '喜欢的抖音视频拉取完成') videos = [] for item in favorite_video_list: video = data_to_video(item) videos.append(video) return videos
def billboard(): result = fetch(URL.billboard(), headers=common_headers, verify=False) aweme_list = result.get('aweme_list') videos = [] for item in aweme_list: # 视频列表有4个视频地址,前两个web可以打开,后面两个只能用手机或者模拟器打开 video = data_to_video(item.get('aweme_info', {})) videos.append(video) return videos
def hotSearchWord(): result = fetch(URL.hot_search_word(), headers=common_headers, verify=False) word_list = result.get('data').get('word_list') words = [] for item in word_list: # 热门词 word = data_to_word(item) words.append(word) return words
def get_aweme_list(): user_video_list = [] url = 'https://aweme.snssdk.com/aweme/v1/challenge/aweme/?iid=30373511894&device_id=35781128184&os_api=18&app_name=aweme&channel=App%20Store&idfa=811A8841-030F-4AEA-B934-C2A56489C32D&device_platform=iphone&build_number=17805&vid=A4BB3AF4-7981-4805-995B-78419881DC11&openudid=99bf2b608173e21cefd562496d2cf21fa8eba580&device_type=iPhone7,2&app_version=1.7.8&version_code=1.7.8&os_version=11.3&screen_width=750&aid=1128&ac=WIFI&ch_id=1574030716416014&count=21&cursor=0&pull_type=2&query_type=0&type=5&mas=001469ed4a7a3f61de046e21c8c7ae8bcb64a983471da18ec0c8d1&as=a1c5206d9e676a38ee4960&ts=1524500606' offset, count = 0, 0 while True: # define cursor result = fetch(url, headers=person_post_headers, verify=False) print(result) if result.get('has_more') != 1: break
def get_music_urls(mc_id): musics = [] result = fetch(URL.music_collection_list(mc_id), headers=common_headers, verify=False) music_list = result.get('music_list', []) for item in music_list: music = data_collection_to_music(item) musics.append(music) return musics
def music_collection(): result = fetch(URL.music_collection_url(), headers=common_headers, verify=False) mc_list = result.get('mc_list', []) collection_list = [] for mc in mc_list: mc_id = mc['id'] mc_name = mc['mc_name'] print('正在拉取', mc_name, '...') mc_musics = get_music_urls(mc_id) musicCollection = MusicCollection( mc_id=mc_id, mc_name=mc_name, mc_musics=mc_musics) if id else None collection_list.append(musicCollection) print(mc_name, '拉取完毕') return collection_list
def category(maxCursor=50): """ get trend result :return: """ offset = 0 # 单个例子测试 # query['cursor'] = str(offset) # result = fetch(URL.category_list(), headers=common_headers, params=query, verify=False) # category_list = result.get('category_list') # datetime = parse_datetime(result.get('extra', {}).get('now')) # final = [] # for item in category_list: # # process per category # if item.get('desc') == '热门话题': # print('===热门话题') # final.append(data_to_topic(item)) # if item.get('desc') == '热门音乐': # print('===热门音乐') # final.append(data_to_music(item.get('music_info', {}))) # return final # 获取所有的 while True: query['cursor'] = str(offset) result = fetch(URL.category_list(), headers=common_headers, params=query, verify=False) category_list = result.get('category_list') datetime = parse_datetime(result.get('extra', {}).get('now')) final = [] for item in category_list: # process per category if item.get('desc') == '热门话题': final.append(data_to_topic(item)) if item.get('desc') == '热门音乐': final.append(data_to_music(item.get('music_info', {}))) if result.get('has_more') != 1: break else: if offset > maxCursor: # 不想拉取很多可以设置这个参数 break offset = result.get('cursor') return final
def get_aweme_list(queryParams): user_video_list = [] max_cursor = 0 while True: if max_cursor: queryParams['max_cursor'] = str(max_cursor) result = fetch(URL.person_post_url(), headers=person_post_headers, params=queryParams, verify=False) aweme_list = result.get('aweme_list', []) if aweme_list != None and len(aweme_list) != 0: user_video_list.extend(aweme_list) if result.get('has_more') != 1: break else: max_cursor = result.get('max_cursor') return user_video_list