示例#1
0
func (p *Parser) getLinkInfo(u string) *oembed.Info {
	pu, _ := url.Parse(u)

	if pu == nil {
		return nil
	}

	info := oembed.NewInfo()
	info.Type = "link"
	info.URL = u
	info.ProviderURL = "http://" + pu.Host
	info.ProviderName = pu.Host

	return info
}
示例#2
0
func (p *Parser) getImageInfo(u string, data []byte) *oembed.Info {
	pu, _ := url.Parse(u)

	if pu == nil {
		return nil
	}

	config, _, err := image.DecodeConfig(bytes.NewReader(data))

	info := oembed.NewInfo()
	info.Type = "photo"
	info.URL = u
	info.ProviderURL = "http://" + pu.Host
	info.ProviderName = pu.Host

	if err == nil {
		info.Width = uint64(config.Width)
		info.Height = uint64(config.Height)
	}

	return info
}