def hot_search(): """ get 20 of the most popular searching videos in billboard :return:HotSearch """ result = get(hot_search_url, headers=headers) data = result.get('data', {}) date_time = parse_datetime(data.get('active_time')) word_list = data.get('word_list', []) data_lists = [{'hot_value': item.get('hot_value'), 'word': item.get('word')} for item in word_list] return HotSearch(data=data_lists, datetime=date_time)
def hot_stars(): """ get 20 of the most popular starts in billboard :return:HotStar """ result = get(url=hot_star_url, headers=headers) date_time = parse_datetime(result.get('active_time')) star_list = result.get('user_list', []) stars = [] for item in star_list: star = parse_to_star(item) stars.append(star) return HotStar(data=stars, datetime=date_time)
def hot_pe_top20(): """ get 20 of the most popular positive energy videos in billboard :return:HotPETopVideo """ result = get(hot_positive_energy_url, headers=headers) active_time = parse_datetime(result.get('active_time')) video_lists = result.get('aweme_list', []) videos = [] for item in video_lists: video = parse_to_video(item.get('aweme_info')) video.hot_value_count = item.get('hot_value') videos.append(video) return HotPETopVideo(data=videos, datetime=active_time)
def hot_music(): """ get 20 of the most popular musics in billboard :return:HotTopMusic """ result = get(url=hot_music_url, headers=headers) date_time = parse_datetime(result.get('active_time')) music_list = result.get('music_list', []) musics = [] for item in music_list: music = parse_to_music(item.get('music_info')) music.hot_value = item.get('hot_value') musics.append(music) return HotTopMusic(data=musics, datetime=date_time)
def videos(self, max=None): """ videos belongs to challenge :param max:videos number need :return:videos generator """ if not isinstance(max, int): raise RuntimeError("`max` param must be int") if max <= 0: raise RuntimeError("`max` param must >=1") from douyin_spider.utils.parse import parse_to_video music_video_params = { 'music_id': str(self.id), 'count': '9', 'cursor': '0', 'aid': '1128', 'screen_limit': '3', 'download_click_limit': '0', '_signature': generate_signature(str(self.id)), } count, cursor = 0, None while True: if cursor: music_video_params['cursor'] = str(cursor) # music_video_params['_signature'] = generate_signature( # str(self.id) + '9' + str(cursor)) result = get(share_music_base_url, params=music_video_params, headers=HEADERS) aweme_list = result.get('aweme_list', []) for item in aweme_list: count += 1 video = parse_to_video(item) yield video if max and count >= max: return if result.get('has_more'): cursor = result.get('cursor') else: break if count == 0: print(f"There is no video in this music {self.id}") print(f"video count:{count}")
def videos(self, max=None): """ videos belongs to challenge :param max:videos number need :return:videos generator """ print(f"<{type(self).__name__}<{self.nickname},{self.id}>>") if not isinstance(max, int): raise RuntimeError("`max` param must be int") if max <= 0: raise RuntimeError("`max` param must >=1") from douyin_spider.utils.parse import parse_to_video user_video_params = { 'user_id': str(self.id), 'count': '21', 'max_cursor': '0', 'aid': '1128', '_signature': generate_signature(str(self.id)), 'dytk': get_user_dytk_by_id(str(self.id)), } count, cursor = 0, None while True: if cursor: user_video_params['max_cursor'] = str(cursor) result = get(share_user_base_url, params=user_video_params, headers=HEADERS) aweme_list = result.get('aweme_list', []) for item in aweme_list: count += 1 video = parse_to_video(item) yield video if max and count >= max: return if result.get('has_more'): cursor = result.get('max_cursor') else: break if count == 0: print(f"There is no video in the user {self.id}") print(f"video count:{count}")
def videos(self, max=None): """ videos belongs to challenge :param max:videos number need :return:videos generator """ print(f"<{type(self).__name__}<{self.name},{self.id}>>") if not isinstance(max, int): raise RuntimeError("`max` param must be int") if max <= 0: raise RuntimeError("`max` param must >=1") from douyin_spider.utils.parse import parse_to_video challenge_video_params = { "ch_id": str(self.id), "count": "9", "cursor": "0", "aid": "1128", "screen_limit": "3", "download_click_limit": "0", "_signature": generate_signature(str(self.id) + '9' + '0'), } count, cursor = 0, None while True: if cursor: challenge_video_params['cursor'] = str(cursor) result = get(share_challenge_base_url, params=challenge_video_params, headers=HEADERS) aweme_list = result.get('aweme_list', []) for item in aweme_list: count += 1 video = parse_to_video(item) yield video if max and count >= max: return if result.get('has_more'): cursor = result.get('cursor') else: break if count == 0: print(f"There is no video in the challenge {self.id}") print(f"video count:{count}")