MM-31171 Fork OpenGraph library to handle bad HTML from YouTube (#16528)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
599e8f67e6
Коммит
1367418e3c
2
go.mod
2
go.mod
@@ -139,3 +139,5 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/NYTimes/gziphandler v1.1.1 => github.com/agnivade/gziphandler v1.1.2-0.20200815170021-7481835cb745
|
replace github.com/NYTimes/gziphandler v1.1.1 => github.com/agnivade/gziphandler v1.1.2-0.20200815170021-7481835cb745
|
||||||
|
|
||||||
|
replace github.com/dyatlov/go-opengraph => github.com/hmhealey/go-opengraph v0.0.0-20201209151214-f2d823730dba
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -413,6 +413,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
|
|||||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo=
|
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo=
|
||||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||||
|
github.com/hmhealey/go-opengraph v0.0.0-20201209151214-f2d823730dba h1:2vMJwzNFzJcB6OSIZWNcjTGn4fWDcZTDv3DNPWL/OrA=
|
||||||
|
github.com/hmhealey/go-opengraph v0.0.0-20201209151214-f2d823730dba/go.mod h1:IRzuuhgRxsskfZk1qE3U0gStYsrnZR3wPpntC5Dkv5g=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||||
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428 h1:Mo9W14pwbO9VfRe+ygqZ8dFbPpoIK1HFrG/zjTuQ+nc=
|
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428 h1:Mo9W14pwbO9VfRe+ygqZ8dFbPpoIK1HFrG/zjTuQ+nc=
|
||||||
|
|||||||
15
vendor/github.com/dyatlov/go-opengraph/opengraph/opengraph.go
сгенерированный
поставляемый
15
vendor/github.com/dyatlov/go-opengraph/opengraph/opengraph.go
сгенерированный
поставляемый
@@ -17,7 +17,7 @@ type Image struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Width uint64 `json:"width"`
|
Width uint64 `json:"width"`
|
||||||
Height uint64 `json:"height"`
|
Height uint64 `json:"height"`
|
||||||
draft bool `json:"-"`
|
draft bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Video defines Open Graph Video type
|
// Video defines Open Graph Video type
|
||||||
@@ -27,7 +27,7 @@ type Video struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Width uint64 `json:"width"`
|
Width uint64 `json:"width"`
|
||||||
Height uint64 `json:"height"`
|
Height uint64 `json:"height"`
|
||||||
draft bool `json:"-"`
|
draft bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Audio defines Open Graph Audio Type
|
// Audio defines Open Graph Audio Type
|
||||||
@@ -35,7 +35,7 @@ type Audio struct {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
SecureURL string `json:"secure_url"`
|
SecureURL string `json:"secure_url"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
draft bool `json:"-"`
|
draft bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Article contain Open Graph Article structure
|
// Article contain Open Graph Article structure
|
||||||
@@ -119,9 +119,6 @@ func (og *OpenGraph) ProcessHTML(buffer io.Reader) error {
|
|||||||
return z.Err()
|
return z.Err()
|
||||||
case html.StartTagToken, html.SelfClosingTagToken, html.EndTagToken:
|
case html.StartTagToken, html.SelfClosingTagToken, html.EndTagToken:
|
||||||
name, hasAttr := z.TagName()
|
name, hasAttr := z.TagName()
|
||||||
if atom.Lookup(name) == atom.Body {
|
|
||||||
return nil // OpenGraph is only in head, so we don't need body
|
|
||||||
}
|
|
||||||
if atom.Lookup(name) != atom.Meta || !hasAttr {
|
if atom.Lookup(name) != atom.Meta || !hasAttr {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -185,7 +182,7 @@ func (og *OpenGraph) ProcessMeta(metaAttrs map[string]string) {
|
|||||||
case "og:locale:alternate":
|
case "og:locale:alternate":
|
||||||
og.LocalesAlternate = append(og.LocalesAlternate, metaAttrs["content"])
|
og.LocalesAlternate = append(og.LocalesAlternate, metaAttrs["content"])
|
||||||
case "og:audio":
|
case "og:audio":
|
||||||
if len(og.Audios)>0 && og.Audios[len(og.Audios)-1].draft {
|
if len(og.Audios) > 0 && og.Audios[len(og.Audios)-1].draft {
|
||||||
og.Audios[len(og.Audios)-1].URL = metaAttrs["content"]
|
og.Audios[len(og.Audios)-1].URL = metaAttrs["content"]
|
||||||
og.Audios[len(og.Audios)-1].draft = false
|
og.Audios[len(og.Audios)-1].draft = false
|
||||||
} else {
|
} else {
|
||||||
@@ -198,7 +195,7 @@ func (og *OpenGraph) ProcessMeta(metaAttrs map[string]string) {
|
|||||||
og.ensureHasAudio()
|
og.ensureHasAudio()
|
||||||
og.Audios[len(og.Audios)-1].Type = metaAttrs["content"]
|
og.Audios[len(og.Audios)-1].Type = metaAttrs["content"]
|
||||||
case "og:image":
|
case "og:image":
|
||||||
if len(og.Images)>0 && og.Images[len(og.Images)-1].draft {
|
if len(og.Images) > 0 && og.Images[len(og.Images)-1].draft {
|
||||||
og.Images[len(og.Images)-1].URL = metaAttrs["content"]
|
og.Images[len(og.Images)-1].URL = metaAttrs["content"]
|
||||||
og.Images[len(og.Images)-1].draft = false
|
og.Images[len(og.Images)-1].draft = false
|
||||||
} else {
|
} else {
|
||||||
@@ -226,7 +223,7 @@ func (og *OpenGraph) ProcessMeta(metaAttrs map[string]string) {
|
|||||||
og.Images[len(og.Images)-1].Height = h
|
og.Images[len(og.Images)-1].Height = h
|
||||||
}
|
}
|
||||||
case "og:video":
|
case "og:video":
|
||||||
if len(og.Videos)>0 && og.Videos[len(og.Videos)-1].draft {
|
if len(og.Videos) > 0 && og.Videos[len(og.Videos)-1].draft {
|
||||||
og.Videos[len(og.Videos)-1].URL = metaAttrs["content"]
|
og.Videos[len(og.Videos)-1].URL = metaAttrs["content"]
|
||||||
og.Videos[len(og.Videos)-1].draft = false
|
og.Videos[len(og.Videos)-1].draft = false
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
3
vendor/modules.txt
поставляемый
3
vendor/modules.txt
поставляемый
@@ -176,7 +176,7 @@ github.com/dsnet/compress/bzip2/internal/sais
|
|||||||
github.com/dsnet/compress/internal
|
github.com/dsnet/compress/internal
|
||||||
github.com/dsnet/compress/internal/errors
|
github.com/dsnet/compress/internal/errors
|
||||||
github.com/dsnet/compress/internal/prefix
|
github.com/dsnet/compress/internal/prefix
|
||||||
# github.com/dyatlov/go-opengraph v0.0.0-20180429202543-816b6608b3c8
|
# github.com/dyatlov/go-opengraph v0.0.0-20180429202543-816b6608b3c8 => github.com/hmhealey/go-opengraph v0.0.0-20201209151214-f2d823730dba
|
||||||
## explicit
|
## explicit
|
||||||
github.com/dyatlov/go-opengraph/opengraph
|
github.com/dyatlov/go-opengraph/opengraph
|
||||||
# github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c
|
# github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c
|
||||||
@@ -919,3 +919,4 @@ willnorris.com/go/gifresize
|
|||||||
## explicit
|
## explicit
|
||||||
willnorris.com/go/imageproxy
|
willnorris.com/go/imageproxy
|
||||||
willnorris.com/go/imageproxy/third_party/http
|
willnorris.com/go/imageproxy/third_party/http
|
||||||
|
# github.com/dyatlov/go-opengraph => github.com/hmhealey/go-opengraph v0.0.0-20201209151214-f2d823730dba
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user