Overview
TikTok Miner’s YouTube integration uses Apify’s YouTube scraper to collect channel information, video statistics, and engagement metrics. This integration provides access to YouTube data without requiring official API quota management.How It Works
The YouTube integration operates through theActorManager class:
- Channel Scraping: Collects channel information, subscriber counts, and video details
- Video Analysis: Retrieves video metrics including views, likes, and comments
- Search & Discovery: Finds channels and videos by keywords
- Data Transformation: Converts raw YouTube data into unified format
Architecture
- Actor Manager:
lib/apify/actor-manager.ts - Transformers:
lib/apify/transformers.ts - Configuration:
lib/apify/config.ts - Database Schema:
prisma/schema.prisma(YoutubeMetrics model)
Configuration
Environment Variables
Service Setup
Data Collection
Channel Metrics
TheYoutubeMetrics table stores:
| Field | Type | Description |
|---|---|---|
channelId | String | YouTube channel ID (unique) |
channelName | String | Channel display name |
channelUrl | String | Channel URL |
subscriberCount | Int | Total subscribers |
videoCount | Int | Total videos published |
viewCount | BigInt | Total channel views |
averageViews | Int | Average views per video |
averageLikes | Int | Average likes per video |
averageComments | Int | Average comments per video |
engagementRate | Float | Calculated engagement rate (%) |
country | String | Channel country |
customUrl | String | Custom channel URL |
publishedAt | DateTime | Channel creation date |
uploadsPlaylistId | String | Uploads playlist ID |
dailyViewGrowth | Float | Daily view growth rate |
dailySubGrowth | Float | Daily subscriber growth rate |
Data Model
Usage Examples
- Scrape Channel
- Calculate Engagement
- Search Videos
- Store in Database
Rate Limits & Quotas
Apify Limits
- Free Tier: $5 in free credits monthly
- Personal Plan: Starting at $49/month
- Default Timeout: 600 seconds (10 minutes) - YouTube scraping is intensive
- Memory: 1024 MB recommended for channel scraping
- Concurrent Runs: Based on subscription tier
YouTube Scraper Configuration
Cost Optimization
Advanced Features
Scrape Video Comments
Monitor Growth Over Time
Error Handling
Data Validation
TheYoutubeTransformer ensures data quality:
- Channel ID format validation
- URL normalization
- Description HTML stripping
- BigInt handling for view counts
- Date parsing and validation
- Numeric type coercion
Monitoring
Track Data Quality
Set Up Alerts
Best Practices
Limitations
- Private Videos: Cannot scrape unlisted or private videos
- Age-Restricted Content: Limited access without authentication
- Subscriber Counts: Large channels show approximated counts (e.g., “1M”)
- Live Streams: Real-time data may not be accurate
- Shorts: Limited metadata compared to regular videos
- Analytics Data: Revenue and detailed analytics require YouTube API
- Historical Data: Cannot access deleted videos or historical metrics
Troubleshooting
Common Issues
| Issue | Solution |
|---|---|
| ”Channel not found” | Verify URL format; channel may be terminated |
| ”Timeout exceeded” | Increase timeout or reduce maxItems |
| ”Invalid channel URL” | Use format: https://www.youtube.com/@channelname or /channel/ID |
| ”No videos found” | Channel may have no public videos |
| ”Memory limit exceeded” | Increase memoryMbytes to 1024 or higher |
Debug Mode
Comparison: YouTube API vs Apify Scraper
| Feature | YouTube API | Apify Scraper |
|---|---|---|
| Setup | Requires Google Cloud project & API key | Only Apify API key |
| Quota | 10,000 units/day (strict) | Based on Apify credits |
| Cost | Free tier limited, paid after quota | Pay per compute unit |
| Data Freshness | Real-time | Near real-time (slight delay) |
| Rate Limits | Very strict | Flexible with proxies |
| Private Data | Requires OAuth | Not available |
| Ease of Use | Complex quota management | Simple, no quotas |