diff --git a/images-bing.go b/images-bing.go index bb2b8fb..2aa0fbf 100644 --- a/images-bing.go +++ b/images-bing.go @@ -49,9 +49,6 @@ func PerformBingImageSearch(query, safe, lang string, page int) ([]ImageSearchRe } } - // Extract the image title from `alt` attribute - title := imgTag.AttrOr("alt", "") - // Extract width and height if available width, _ := strconv.Atoi(imgTag.AttrOr("width", "0")) height, _ := strconv.Atoi(imgTag.AttrOr("height", "0")) @@ -62,31 +59,36 @@ func PerformBingImageSearch(query, safe, lang string, page int) ([]ImageSearchRe return } - // Parse the metadata to get the media URL (the original image source) + // Parse the metadata to get the media URL and title var data map[string]interface{} if err := json.Unmarshal([]byte(metadata), &data); err == nil { mediaURL, ok := data["murl"].(string) - if ok { - // Apply the image proxy - proxiedFullURL := "/imgproxy?url=" + mediaURL - proxiedThumbURL := "/imgproxy?url=" + imgSrc - results = append(results, ImageSearchResult{ - Thumb: imgSrc, - Title: strings.TrimSpace(title), - Full: imgSrc, - Source: mediaURL, - ProxyFull: proxiedFullURL, // Proxied full-size image URL - ProxyThumb: proxiedThumbURL, // Proxied thumbnail URL - Width: width, - Height: height, - }) + if !ok { + return } + + // Extract title from the metadata + title, _ := data["t"].(string) + + // Apply the image proxy + proxiedFullURL := "/imgproxy?url=" + mediaURL + proxiedThumbURL := "/imgproxy?url=" + imgSrc + results = append(results, ImageSearchResult{ + Thumb: imgSrc, + Title: strings.TrimSpace(title), + Full: imgSrc, + Source: mediaURL, + ProxyFull: proxiedFullURL, // Proxied full-size image URL + ProxyThumb: proxiedThumbURL, // Proxied thumbnail URL + Width: width, + Height: height, + }) } }) duration := time.Since(startTime) - // Check if the number of results is one or less + // Check if the number of results is zero if len(results) == 0 { return nil, duration, fmt.Errorf("no images found") }