7.8 KiB
7.8 KiB
name, description, version, author, tags, skills, dependencies, inputs, outputs, config
| name | description | version | author | tags | skills | dependencies | inputs | outputs | config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TikTok Trends | Fetch top trending TikTok videos for a given country and generate an engagement report with optional video downloads. | 2 | pastilhas |
|
|
|
|
|
|
TikTok Trends
Fetch top trending TikTok videos for a given country and generate a comprehensive engagement report.
Overview
This task uses the Apify novi~fast-tiktok-scraper actor to fetch trending videos from TikTok for a specified country. It generates:
- Engagement metrics (total/average views, likes, shares, comments)
- Top hashtags found in trending content
- Popular sounds being used
- Creator analysis (who appears multiple times in trending)
- Complete video list with links and stats
Optionally downloads videos using yt-dlp for offline analysis.
Pre-execution Checks
-
Validate inputs:
api_tokenmust be provided (required)countrymust be a valid 2-letter country codelimitmust be between 1-100
-
Check dependencies:
- Verify script exists at
$OFFICER_USER_ROOT/../resources/scripts/apify/tiktok-trends.ts - Verify bun is installed
- If
download=true, verify yt-dlp is installed
- Verify script exists at
-
Test Apify token:
- Make a test call to
GET https://api.apify.com/v2/users/meto validate the token - Abort with clear error if token is invalid or account has no credits
- Make a test call to
Execution
Run the script with the following command:
bun "$OFFICER_USER_ROOT/../resources/scripts/apify/tiktok-trends.ts" \
--apikey "<api_token>" \
--country "<country>" \
--limit <limit> \
--output "<output_dir>" \
<download_flag>
Where:
<download_flag>is--downloadifdownload=true, otherwise omitted<output_dir>is a timestamped directory created inside$HOME/tiktok-trends/(the logged-in user's home directory)
Pipe output to log:
<command_above> 2>&1 | tee "<output_dir>/run.log"
Success Criteria
The task is considered successful when:
- Script exits with code 0
report-YYYY-MM-DD.mdexists and is non-emptyraw-YYYY-MM-DD.jsonexists and contains valid JSON array- (If download enabled)
videos/directory exists with at least one file
Error Handling
| Scenario | Action |
|---|---|
| Script exits non-zero | Check run.log for Apify/API errors. Common causes: invalid token, no credits, rate limits |
| Empty results | Report "No trending videos found" but mark as success if files were created |
| Partial results | Report success if at least 1 video returned, note the discrepancy |
| Timeout (>10 min) | Kill process, report timeout. Check Apify actor status in console |
| Download failures | Report which videos failed but mark task as success if main report generated |
Post-execution
After successful execution:
-
Verify outputs:
- Check all expected files exist
- Validate JSON is parseable
- If download enabled, count video files
-
Generate summary (
report.md):# TikTok Trends Run Summary ## Run Details - **Date**: YYYY-MM-DD - **Timestamp**: HH:MM:SS - **Apify Actor**: novi~fast-tiktok-scraper - **Country**: <country_name> (<country_code>) - **Requested**: <limit> videos - **Received**: <actual_count> videos - **Duration**: <X> minutes <Y> seconds ## Cost Analysis - **Apify Credits Used**: <cost> USD - **Cost per Video**: $<cost/actual_count> ## Key Findings - **Top Video**: @<creator> - <views> views <description_preview> URL: <url> - **Top Hashtag**: #<hashtag> (<count> occurrences) - **Top Sound**: <sound_name> (<count> uses) ## Output Files - `report-YYYY-MM-DD.md` (<size>) - Engagement report - `raw-YYYY-MM-DD.json` (<size>) - Raw API data - `run.log` (<size>) - Execution log - `videos/` (<count> files, <total_size>) - Downloaded videos (if enabled) ## Notes - <any_warnings_or_errors_from_log> -
Cleanup:
- Remove temporary files if any
- Report final status to user
Notes
- Rate limiting: The Apify actor may take 1-3 minutes depending on the limit
- Costs: Each run uses Apify compute units. Monitor usage at https://console.apify.com/billing
- Data freshness: Trends data is near real-time but may have slight delays
- Video downloads: Downloading many videos can take significant time and storage
- Country availability: Not all countries have sufficient trending data; some may return fewer results than requested