snapchat

package
v0.0.0-...-b867611 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package snapchat is the library behind the snap command line: the HTTP client, block detection, and the typed data models for story.snapchat.com and www.snapchat.com.

Snapchat is Tier C (anti-bot). Requests from datacenter IPs usually receive a Cloudflare challenge page (HTTP 403 or 200 with a JS interstitial) instead of real data. The client detects all known block patterns and returns errs.Blocked so callers can exit with code 5.

Index

Constants

View Source
const (
	Host      = "snapchat.com"
	BaseURL   = "https://www.snapchat.com"
	StoryBase = "https://story.snapchat.com"
)

Host and base URLs.

View Source
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " +
	"AppleWebKit/537.36 (KHTML, like Gecko) " +
	"Chrome/124.0.0.0 Safari/537.36"

DefaultUserAgent mimics a real desktop Chrome browser on macOS.

Variables

This section is empty.

Functions

func IsBlocked

func IsBlocked(status int, body []byte, h http.Header) bool

IsBlocked reports whether the response signals a Cloudflare/CDN bot block.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a rate-limited HTTP client for Snapchat public endpoints.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url with pacing and retries (exported for tests).

func (*Client) GetStory

func (c *Client) GetStory(ctx context.Context, username string) (*Story, error)

GetStory fetches the public story metadata for username.

func (*Client) Spotlight

func (c *Client) Spotlight(ctx context.Context, limit int) ([]*SpotlightVideo, error)

Spotlight fetches trending Spotlight videos. Returns up to limit records.

type Config

type Config struct {
	BaseURL   string
	StoryBase string
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds tunable parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns production-ready defaults.

type Domain

type Domain struct{}

Domain is the Snapchat driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify implements the URI resolver interface.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and binary identity.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and all operations onto app.

type SpotlightVideo

type SpotlightVideo struct {
	ID        string `json:"id"`
	Title     string `json:"title"`
	Author    string `json:"author"`
	ViewCount int64  `json:"view_count"`
	DurationS int    `json:"duration_s"`
	Thumbnail string `json:"thumbnail"`
	URL       string `json:"url"`
}

SpotlightVideo is one trending Spotlight video record.

type Story

type Story struct {
	Username    string `json:"username"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Thumbnail   string `json:"thumbnail"`
	MediaCount  int    `json:"media_count"`
	URL         string `json:"url"`
}

Story is one public Snapchat story record.

func ParseStory

func ParseStory(body []byte, username string) (*Story, error)

ParseStory extracts Story fields from the og: meta tags in body (exported for tests).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL