This commit is contained in:
@@ -229,6 +229,9 @@ func (s *SearchService) enrichArtgrid(result SearchResult) SearchResult {
|
||||
if result.ThumbnailURL == "" || result.PreviewVideoURL == "" {
|
||||
html, err := s.fetchText(result.Link)
|
||||
if err == nil {
|
||||
if !isMatchingArtgridClipPage(html, clipID) {
|
||||
return result
|
||||
}
|
||||
result.Title = firstNonEmpty(
|
||||
cleanArtgridTitle(extractMetaContent(html, "og:title")),
|
||||
cleanArtgridTitle(extractMetaContent(html, "title")),
|
||||
@@ -756,6 +759,33 @@ func cleanArtgridDescription(description string) string {
|
||||
return strings.TrimSpace(description)
|
||||
}
|
||||
|
||||
func isMatchingArtgridClipPage(html, clipID string) bool {
|
||||
if clipID == "" {
|
||||
return false
|
||||
}
|
||||
ogURL := extractMetaContent(html, "og:url")
|
||||
canonical := extractCanonicalURL(html)
|
||||
lowerHTML := strings.ToLower(html)
|
||||
for _, candidate := range []string{ogURL, canonical} {
|
||||
if strings.Contains(candidate, clipID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if strings.Contains(lowerHTML, "main-clipvideo_"+clipID) || strings.Contains(lowerHTML, "/clip/"+clipID+"/") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func extractCanonicalURL(html string) string {
|
||||
pattern := regexp.MustCompile(`(?i)<link[^>]+rel=["']canonical["'][^>]+href=["']([^"']+)`)
|
||||
matches := pattern.FindStringSubmatch(html)
|
||||
if len(matches) == 2 {
|
||||
return htmlUnescape(matches[1])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func deriveEnvatoPreviewFromThumbnail(thumbnail string) string {
|
||||
candidate := htmlUnescape(strings.TrimSpace(thumbnail))
|
||||
if candidate == "" {
|
||||
|
||||
Reference in New Issue
Block a user