ig

package module
v0.0.0-...-eb159b1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 9 Imported by: 0

README

go-ig

Go Reference Build

Instagram client for extracting basic data.

It works by download HTML page of the profile and extracting data from script tag.

NOTE: this provides only a small amount of data and is not reliable since it depends on what initial HTML does Instagram serve.

Install

go get -u github.com/sewiti/go-ig

Example

package main

import (
	"context"
	"fmt"

	"github.com/sewiti/go-ig"
)

func main() {
	const username = "instagram"
	profile, posts, err := ig.Get(context.Background(), username)
	if err != nil {
		panic(err)
	}
	fmt.Printf("extracted %d %s's posts", len(posts), profile.Identifier.Value)
	// Output:
	// extracted 9 instagram's posts
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractData

func ExtractData(root *html.Node) []string

func Get

func Get(ctx context.Context, username string) (*Profile, []Post, error)

func ParseHTML

func ParseHTML(r io.Reader) (*Profile, []Post, error)

Types

type Comment

type Comment struct {
	Type                 string                `json:"@type"`
	Text                 string                `json:"text"`
	Author               User                  `json:"author"`
	DateCreated          time.Time             `json:"dateCreated"`
	InteractionStatistic *InteractionStatistic `json:"interactionStatistic"`
}

type Entity

type Entity struct {
	Type string `json:"@type"`
	ID   string `json:"@id"`
}

type Identifier

type Identifier struct {
	Type       string `json:"@type"`
	PropertyID string `json:"propertyID"`
	Value      string `json:"value"`
}

type Image

type Image struct {
	Type                 string `json:"@type"`
	Caption              string `json:"caption"`
	RepresentativeOfPage string `json:"representativeOfPage"`
	Height               string `json:"height"`
	Width                string `json:"width"`
	URL                  string `json:"url"`
}

type InteractionStatistic

type InteractionStatistic struct {
	Type                 string `json:"@type"`
	InteractionType      string `json:"interactionType"`
	UserInteractionCount int    `json:"userInteractionCount"`
}

type InteractionStatisticStr

type InteractionStatisticStr struct {
	Type                 string `json:"@type"`
	InteractionType      string `json:"interactionType"`
	UserInteractionCount string `json:"userInteractionCount"`
}

type Location

type Location struct {
	Type             string `json:"@type"`
	Name             string `json:"name"`
	MainEntityOfPage Entity `json:"mainEntityOfPage"`
}

type Post

type Post struct {
	ArticleBody          string                 `json:"articleBody"`
	Author               User                   `json:"author"`
	Comment              Comment                `json:"comment"`
	CommentCount         string                 `json:"commentCount"`
	ContentLocation      *Location              `json:"contentLocation"`
	Context              string                 `json:"@context"`
	DateCreated          time.Time              `json:"dateCreated"`
	DateModified         time.Time              `json:"dateModified"`
	Headline             string                 `json:"headline"`
	Identifier           Identifier             `json:"identifier"`
	Image                []Image                `json:"image"`
	InteractionStatistic []InteractionStatistic `json:"interactionStatistic"`
	MainEntityOfPage     Entity                 `json:"mainEntityOfPage"`
	Type                 string                 `json:"@type"`
	URL                  string                 `json:"url"`
	Video                []Video                `json:"video"`
}

type Profile

type Profile struct {
	Context              string                    `json:"@context"`
	Type                 string                    `json:"@type"`
	Description          string                    `json:"description"`
	Author               User                      `json:"author"`
	MainEntityOfPage     Entity                    `json:"mainEntityOfPage"`
	Identifier           Identifier                `json:"identifier"`
	InteractionStatistic []InteractionStatisticStr `json:"interactionStatistic"`
}

type User

type User struct {
	Type                 string                `json:"@type"`
	Identifier           *Identifier           `json:"identifier"`
	Image                string                `json:"image"`
	Name                 string                `json:"name"`
	AlternateName        string                `json:"alternateName"`
	SameAs               string                `json:"sameAs"`
	URL                  string                `json:"url"`
	InteractionStatistic *InteractionStatistic `json:"interactionStatistic"`
}

type Video

type Video struct {
	Type                 string                 `json:"@type"`
	UploadDate           time.Time              `json:"uploadDate"`
	Description          string                 `json:"description"`
	Name                 string                 `json:"name"`
	Caption              string                 `json:"caption"`
	Height               string                 `json:"height"`
	Width                string                 `json:"width"`
	ContentURL           string                 `json:"contentUrl"`
	ThumbnailURL         string                 `json:"thumbnailUrl"`
	Genre                []json.RawMessage      `json:"genre"`    // TODO
	Keywords             []json.RawMessage      `json:"keywords"` // TODO
	InteractionStatistic []InteractionStatistic `json:"interationStatistic"`
	Creator              User                   `json:"creator"`
	Comment              []Comment              `json:"comment"`
	CommentCount         string                 `json:"commentCount"`
	IsFamilyFriendly     bool                   `json:"isFamilyFriendly"`
	Mentions             []User                 `json:"mentions"`
	InLanguage           string                 `json:"inLanguage"`
	Duration             string                 `json:"duration"`
	EmbeddedTextCaption  string                 `json:"embeddedTextCaption"`
	Transcript           string                 `json:"transcript"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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