From 779aa876362b18a25884595297dbe553713d90ac Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 20 Aug 2024 04:57:31 +0000 Subject: [PATCH 1/5] fix typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a50212c..c3a4663 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,12 @@ A self-hosted private and anonymous [metasearch engine](https://en.wikipedia.org ## Comparison to other search engines -| Feature | Whoogle | Araa-Search | LibreY | 4get | *Warp* | +| Feature | Whoogle [1] | Araa-Search | LibreY | 4get | *Warp* | | :----------------------------------- | ------------------ | ------------------------- | ------------------------ | ------------------------ | ---------------------------------------------------- | | Works without JavaScript | ✅ | ✅ | ✅ | ✅ | ✅ | | Music search | ❓ | ❌ | ❌ | ✅ | ✅ | | Torrent search | ❌ | ✅ | ✅ | ❌ | ✅ | -| API | ❌ | ✅ | ✅ | ✅ | ✅ | +| API | ❌ | ✅ | ❓ [2] | ✅ | ✅ | | Scalable | ❌ | ❌ | ❌ | ❌ | ✅ | | Not Resource Hungry | ❓ Moderate | ❌ Very resource hungry | ❌ Moderate 200-400mb~ | ❌ Moderate 200-400mb~ | ✅ about 15-20MiB at idle, 17-22MiB when searching | | Dynamic Page Loading | ❓ Not specified | ❌ | ❌ | ❌ | ✅ | From 3b4b9ee83a04d9efe8215429bbd864d93ce136a8 Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 20 Aug 2024 18:40:04 +0200 Subject: [PATCH 2/5] revert img proxy for video --- video.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 video.go diff --git a/video.go b/video.go old mode 100755 new mode 100644 index 1633853..ccda543 --- a/video.go +++ b/video.go @@ -206,7 +206,7 @@ func fetchVideoResults(query, safe, lang string, page int) []VideoResult { Views: formatViews(item.Views), Creator: item.UploaderName, Publisher: "Piped", - Image: fmt.Sprintf("/img_proxy?url=%s", url.QueryEscape(item.Thumbnail)), + Image: item.Thumbnail, //fmt.Sprintf("/img_proxy?url=%s", url.QueryEscape(item.Thumbnail)), // Using image proxy is not working, but its not needed here as piped is proxy anyway Duration: formatDuration(item.Duration), }) } From a7e1ef812e2d0b88949b8b90aa8d524f866bf60b Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 21 Aug 2024 11:08:37 +0200 Subject: [PATCH 3/5] fix user setting expiring immediately --- user-settings.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/user-settings.go b/user-settings.go index 9b7b5ee..8056287 100755 --- a/user-settings.go +++ b/user-settings.go @@ -3,6 +3,7 @@ package main import ( "html/template" "net/http" + "time" ) type UserSettings struct { @@ -39,10 +40,13 @@ func loadUserSettings(r *http.Request) UserSettings { } func saveUserSettings(w http.ResponseWriter, settings UserSettings) { + expiration := time.Now().Add(90 * 24 * time.Hour) // 90 days from now + http.SetCookie(w, &http.Cookie{ Name: "theme", Value: settings.Theme, Path: "/", + Expires: expiration, // Expiration time needs to be set otherwise it will expire immediately Secure: true, // Ensure cookie is sent over HTTPS only SameSite: http.SameSiteNoneMode, // Set SameSite to None }) @@ -50,6 +54,7 @@ func saveUserSettings(w http.ResponseWriter, settings UserSettings) { Name: "language", Value: settings.Language, Path: "/", + Expires: expiration, Secure: true, // Ensure cookie is sent over HTTPS only SameSite: http.SameSiteNoneMode, // Set SameSite to None }) @@ -57,6 +62,7 @@ func saveUserSettings(w http.ResponseWriter, settings UserSettings) { Name: "safe", Value: settings.SafeSearch, Path: "/", + Expires: expiration, Secure: true, // Ensure cookie is sent over HTTPS only SameSite: http.SameSiteNoneMode, // Set SameSite to None }) From 32e94d1c2f6d22bb8783867a660b754f2bcf24eb Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 21 Aug 2024 12:01:19 +0200 Subject: [PATCH 4/5] change cookies from any site to strict --- user-settings.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/user-settings.go b/user-settings.go index 8056287..83fee6c 100755 --- a/user-settings.go +++ b/user-settings.go @@ -46,25 +46,25 @@ func saveUserSettings(w http.ResponseWriter, settings UserSettings) { Name: "theme", Value: settings.Theme, Path: "/", - Expires: expiration, // Expiration time needs to be set otherwise it will expire immediately - Secure: true, // Ensure cookie is sent over HTTPS only - SameSite: http.SameSiteNoneMode, // Set SameSite to None + Expires: expiration, // Expiration time needs to be set otherwise it will expire immediately + Secure: true, // Ensure cookie is sent over HTTPS only + SameSite: http.SameSiteStrictMode, }) http.SetCookie(w, &http.Cookie{ Name: "language", Value: settings.Language, Path: "/", Expires: expiration, - Secure: true, // Ensure cookie is sent over HTTPS only - SameSite: http.SameSiteNoneMode, // Set SameSite to None + Secure: true, + SameSite: http.SameSiteStrictMode, }) http.SetCookie(w, &http.Cookie{ Name: "safe", Value: settings.SafeSearch, Path: "/", Expires: expiration, - Secure: true, // Ensure cookie is sent over HTTPS only - SameSite: http.SameSiteNoneMode, // Set SameSite to None + Secure: true, + SameSite: http.SameSiteStrictMode, }) printDebug("settings saved: %v", settings) From 25fb33a7259b01026eb2f6143f64aaf1cefcbef8 Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 21 Aug 2024 12:30:03 +0200 Subject: [PATCH 5/5] retrive more images from bing --- images-bing.go | 52 +++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/images-bing.go b/images-bing.go index a9f8717..d6e37c5 100644 --- a/images-bing.go +++ b/images-bing.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "net/http" "net/url" @@ -36,45 +37,52 @@ func PerformBingImageSearch(query, safe, lang string, page int) ([]ImageSearchRe // Extract data using goquery var results []ImageSearchResult - doc.Find(".imgpt").Each(func(i int, s *goquery.Selection) { + doc.Find(".iusc").Each(func(i int, s *goquery.Selection) { + // Extract image source imgTag := s.Find("img") imgSrc, exists := imgTag.Attr("src") if !exists { - return + imgSrc, exists = imgTag.Attr("data-src") + if !exists { + return + } } - title, _ := imgTag.Attr("alt") + // 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")) - // Extract the original image URL from the `mediaurl` parameter in the link - pageLink, exists := s.Find("a.iusc").Attr("href") - mediaURL := "" - if exists { - if u, err := url.Parse(pageLink); err == nil { - if mediaURLParam := u.Query().Get("mediaurl"); mediaURLParam != "" { - mediaURL, _ = url.QueryUnescape(mediaURLParam) - } - } + // Extract the m parameter (JSON-encoded image metadata) + metadata, exists := s.Attr("m") + if !exists { + return } - results = append(results, ImageSearchResult{ - Thumbnail: imgSrc, - Title: strings.TrimSpace(title), - Media: imgSrc, - Width: width, - Height: height, - Source: mediaURL, // Original image URL - ThumbProxy: imgSrc, - }) + // Parse the metadata to get the media URL (the original image source) + var data map[string]interface{} + if err := json.Unmarshal([]byte(metadata), &data); err == nil { + mediaURL, ok := data["murl"].(string) + if ok { + results = append(results, ImageSearchResult{ + Thumbnail: imgSrc, + Title: strings.TrimSpace(title), + Media: mediaURL, + Width: width, + Height: height, + Source: mediaURL, + ThumbProxy: imgSrc, + }) + } + } }) duration := time.Since(startTime) // Check if the number of results is one or less - if len(results) <= 1 { + if len(results) == 0 { return nil, duration, fmt.Errorf("no images found") }