dyatl

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: MIT Imports: 16 Imported by: 0

README

example workflow name codecov

Takes title and og:image from any page:

c := dyatl.Client()
result, err := c.Preview("https://meduza.io/shapito/2020/12/29/kazhduyu-zimu-v-rossii-edyat-zamerzshiy-doshirak-ved-chem-esche-zanyatsya-v-yakutske-ili-novosibirske")
if err != nil {
    panic(err)
}

fmt.Println("Title:", c.Title)
fmt.Println("ThumbnailUrl:", c.ThumbnailUrl)

Special cases like YouTube:

c := dyatl.Client()
result, err := c.Preview("https://www.youtube.com/watch?v=eLAHSRmFFzE")
if err != nil {
    panic(err)
}

fmt.Println("Title:", c.Title)
fmt.Println("ThumbnailUrl:", c.ThumbnailUrl)
fmt.Println("YoutubeId:", c.YoutubeId)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotHttpUrl      = errors.New("not http url")
	PreviewNotFound = errors.New("preview not found")
)
View Source
var (
	Unauthorized = errors.New("Unauthorized")
	BadRequest   = errors.New("Bad Request")
)
View Source
var DefaultDNS = "8.8.8.8:53"

Functions

func IsTimeout

func IsTimeout(err error) bool

func YoutubeIdFromUrl

func YoutubeIdFromUrl(u *url.URL) string

Types

type CheckedURL

type CheckedURL struct {
	*url.URL
	// contains filtered or unexported fields
}

func NewCheckedURL

func NewCheckedURL(s string) *CheckedURL

func (CheckedURL) HostAvailable

func (u CheckedURL) HostAvailable() bool

func (CheckedURL) LooksCorrect

func (u CheckedURL) LooksCorrect() bool

type Client

type Client struct {
	http.Client
	UserAgent      string
	AcceptLanguage string
}

func NewClient

func NewClient() Client

func (Client) Get

func (c Client) Get(url string) (*http.Response, error)

func (Client) GetYoutubeData

func (c Client) GetYoutubeData(id string) (YoutubeData, error)

func (Client) Preview

func (c Client) Preview(link string) (Preview, error)

type Preview

type Preview struct {
	Title        string
	ThumbnailUrl string
	YoutubeId    string
}

type YoutubeData

type YoutubeData struct {
	Type    string `json:"type"`
	Version string `json:"version"`

	Title      string `json:"title"`
	AuthorName string `json:"author_name"`
	AuthorUrl  string `json:"author_url"`

	Html   string `json:"html"`
	Width  int    `json:"width"`
	Height int    `json:"height"`

	ProviderName string `json:"provider_name"`
	ProviderUrl  string `json:"provider_url"`

	ThumbnailUrl    string `json:"thumbnail_url"`
	ThumbnailHeight int    `json:"thumbnail_height"`
	ThumbnailWidth  int    `json:"thumbnail_width"`
}

Jump to

Keyboard shortcuts

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