Documentation
¶
Overview ¶
Package parser implements the w_popularity YouTube adapter.
Strategy: direct HTML scraping of the YouTube channel pages. We fetch `https://www.youtube.com/@<handle>/about` (for the channel snapshot) and `https://www.youtube.com/@<handle>/videos` (for recent uploads) with a modern desktop User-Agent and Accept-Language: en. Each response embeds a `var ytInitialData = {...};` blob which carries everything we need.
We do NOT call any official YouTube Data API and we do NOT shell out to yt-dlp — that approach broke in late 2024 when YouTube migrated several channel pages to a new "pageHeaderRenderer"/"aboutChannelViewModel" shape in which yt-dlp's extractor returns nulls for follower / view / playlist counts.
The parser is tolerant of both the legacy `c4TabbedHeaderRenderer` shape and the newer `pageHeaderRenderer` + `aboutChannelViewModel` shape. It walks all string leaves in ytInitialData looking for patterns such as "29.6M subscribers", "123,020,785,579 views", "980 videos" — so it keeps working as long as YouTube renders those strings somewhere in the JSON.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
APIKey string // no-op, accepted for backwards compatibility
HTTPClient *http.Client
HTTPTimeout time.Duration
UserAgent string
}
Config controls runtime behaviour. All fields are optional.
- APIKey is kept for backwards compatibility with callers that wired it up for the old yt-dlp+API path. It is currently a no-op; the parser no longer talks to the YouTube Data API.
- HTTPClient overrides the default client (used by tests to inject an httptest.Server via a URL-rewriting RoundTripper).
- HTTPTimeout is the per-request budget when HTTPClient is not provided (default 30s).
- UserAgent overrides the default desktop UA used in outgoing requests.
type YouTubeParser ¶
type YouTubeParser struct {
// contains filtered or unexported fields
}
YouTubeParser is the shared.Parser implementation for YouTube.
func New ¶
func New(cfg Config) *YouTubeParser
New returns a parser configured per cfg. It does not touch the network at construction time.
func (*YouTubeParser) FetchChannel ¶
func (p *YouTubeParser) FetchChannel(ctx context.Context, handle string) (shared.ChannelSnapshot, error)
FetchChannel fetches /<handle>/about and pulls Followers, PostsCount, TotalViews and the canonical channel id out of the embedded ytInitialData.
func (*YouTubeParser) FetchRecentPosts ¶
func (p *YouTubeParser) FetchRecentPosts(ctx context.Context, handle string, since time.Time) ([]shared.PostSnapshot, error)
FetchRecentPosts fetches /<handle>/videos and pulls the most recent video entries out of the embedded ytInitialData. Posts older than `since` are dropped. Ordering is newest-first as returned by YouTube.
func (*YouTubeParser) Platform ¶
func (p *YouTubeParser) Platform() shared.Platform