/ clis / douyin / _shared / public-api.js
public-api.js
 1  import { browserFetch } from './browser-fetch.js';
 2  export async function fetchDouyinUserVideos(page, secUid, count) {
 3      const params = new URLSearchParams({
 4          sec_user_id: secUid,
 5          max_cursor: '0',
 6          count: String(count),
 7          aid: '6383',
 8      });
 9      const data = await browserFetch(page, 'GET', `https://www.douyin.com/aweme/v1/web/aweme/post/?${params.toString()}`, {
10          headers: { referer: 'https://www.douyin.com/' },
11      });
12      return data.aweme_list || [];
13  }
14  export async function fetchDouyinComments(page, awemeId, count) {
15      const params = new URLSearchParams({
16          aweme_id: awemeId,
17          count: String(count),
18          cursor: '0',
19          aid: '6383',
20      });
21      const data = await browserFetch(page, 'GET', `https://www.douyin.com/aweme/v1/web/comment/list/?${params.toString()}`, {
22          headers: { referer: 'https://www.douyin.com/' },
23      });
24      return (data.comments || []).slice(0, count).map((comment) => ({
25          text: comment.text || '',
26          digg_count: comment.digg_count ?? 0,
27          nickname: comment.user?.nickname || '',
28      }));
29  }