fixed quant images, and changed lang code from "lang_en" to "en"
This commit is contained in:
parent
0019202571
commit
a5221039f4
3 changed files with 112 additions and 51 deletions
|
@ -24,6 +24,64 @@ type QwantAPIResponse struct {
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConvertToQwantLocale(langCode string) string {
|
||||||
|
langMap := map[string]string{
|
||||||
|
"en": "en_us", // English
|
||||||
|
"af": "en_us", // Afrikaans (no direct match, default to English)
|
||||||
|
"ar": "ar", // Arabic
|
||||||
|
"hy": "en_us", // Armenian (no direct match, default to English)
|
||||||
|
"be": "en_us", // Belarusian (no direct match, default to English)
|
||||||
|
"bg": "bg_bg", // Bulgarian
|
||||||
|
"ca": "ca_es", // Catalan
|
||||||
|
"zh-CN": "zh_cn", // Chinese Simplified
|
||||||
|
"zh-TW": "zh_hk", // Chinese Traditional
|
||||||
|
"hr": "en_us", // Croatian (no direct match, default to English)
|
||||||
|
"cs": "cs_cz", // Czech
|
||||||
|
"da": "da_dk", // Danish
|
||||||
|
"nl": "nl_nl", // Dutch
|
||||||
|
"eo": "en_us", // Esperanto (no direct match, default to English)
|
||||||
|
"et": "et_ee", // Estonian
|
||||||
|
"tl": "en_us", // Tagalog (no direct match, default to English)
|
||||||
|
"fi": "fi_fi", // Finnish
|
||||||
|
"fr": "fr_fr", // French
|
||||||
|
"de": "de_de", // German
|
||||||
|
"el": "el_gr", // Greek
|
||||||
|
"iw": "he_il", // Hebrew
|
||||||
|
"hi": "en_us", // Hindi (no direct match, default to English)
|
||||||
|
"hu": "hu_hu", // Hungarian
|
||||||
|
"is": "en_us", // Icelandic (no direct match, default to English)
|
||||||
|
"id": "en_us", // Indonesian (no direct match, default to English)
|
||||||
|
"it": "it_it", // Italian
|
||||||
|
"ja": "ja_jp", // Japanese
|
||||||
|
"ko": "ko_kr", // Korean
|
||||||
|
"lv": "en_us", // Latvian (no direct match, default to English)
|
||||||
|
"lt": "en_us", // Lithuanian (no direct match, default to English)
|
||||||
|
"no": "nb_no", // Norwegian
|
||||||
|
"fa": "en_us", // Persian (no direct match, default to English)
|
||||||
|
"pl": "pl_pl", // Polish
|
||||||
|
"pt": "pt_pt", // Portuguese
|
||||||
|
"ro": "ro_ro", // Romanian
|
||||||
|
"ru": "ru_ru", // Russian
|
||||||
|
"sr": "en_us", // Serbian (no direct match, default to English)
|
||||||
|
"sk": "en_us", // Slovak (no direct match, default to English)
|
||||||
|
"sl": "en_us", // Slovenian (no direct match, default to English)
|
||||||
|
"es": "es_es", // Spanish
|
||||||
|
"sw": "en_us", // Swahili (no direct match, default to English)
|
||||||
|
"sv": "sv_se", // Swedish
|
||||||
|
"th": "th_th", // Thai
|
||||||
|
"tr": "tr_tr", // Turkish
|
||||||
|
"uk": "en_us", // Ukrainian (no direct match, default to English)
|
||||||
|
"vi": "en_us", // Vietnamese (no direct match, default to English)
|
||||||
|
"": "en_us", // Default to English if no language is provided
|
||||||
|
}
|
||||||
|
|
||||||
|
if qwantLocale, exists := langMap[langCode]; exists {
|
||||||
|
return qwantLocale
|
||||||
|
}
|
||||||
|
printWarn("Qwant locale code missing: %v, defaulting to: en_us", langCode)
|
||||||
|
return "en_us" // Default fallback
|
||||||
|
}
|
||||||
|
|
||||||
// PerformQwantImageSearch performs an image search on Qwant and returns the results.
|
// PerformQwantImageSearch performs an image search on Qwant and returns the results.
|
||||||
func PerformQwantImageSearch(query, safe, lang string, page int) ([]ImageSearchResult, time.Duration, error) {
|
func PerformQwantImageSearch(query, safe, lang string, page int) ([]ImageSearchResult, time.Duration, error) {
|
||||||
startTime := time.Now() // Start the timer
|
startTime := time.Now() // Start the timer
|
||||||
|
@ -36,13 +94,16 @@ func PerformQwantImageSearch(query, safe, lang string, page int) ([]ImageSearchR
|
||||||
offset = (page - 1) * resultsPerPage
|
offset = (page - 1) * resultsPerPage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure count + offset is within acceptable limits
|
||||||
|
if offset+resultsPerPage > 250 {
|
||||||
|
return nil, 0, fmt.Errorf("count + offset must be lower than 250 for quant")
|
||||||
|
}
|
||||||
|
|
||||||
if safe == "" {
|
if safe == "" {
|
||||||
safe = "0"
|
safe = "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
if lang == "" {
|
lang = ConvertToQwantLocale(lang)
|
||||||
lang = "en_CA"
|
|
||||||
}
|
|
||||||
|
|
||||||
apiURL := fmt.Sprintf("https://api.qwant.com/v3/search/images?t=images&q=%s&count=%d&locale=%s&offset=%d&device=desktop&tgp=2&safesearch=%s",
|
apiURL := fmt.Sprintf("https://api.qwant.com/v3/search/images?t=images&q=%s&count=%d&locale=%s&offset=%d&device=desktop&tgp=2&safesearch=%s",
|
||||||
url.QueryEscape(query),
|
url.QueryEscape(query),
|
||||||
|
@ -87,7 +148,7 @@ func PerformQwantImageSearch(query, safe, lang string, page int) ([]ImageSearchR
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Media: item.Media,
|
Media: item.Media,
|
||||||
Source: item.Url,
|
Source: item.Url,
|
||||||
ThumbProxy: "/img_proxy?url=" + url.QueryEscape(item.Media),
|
ThumbProxy: "/img_proxy?url=" + url.QueryEscape(item.Media), // New proxy not exactly working as intended
|
||||||
Width: item.Width,
|
Width: item.Width,
|
||||||
Height: item.Height,
|
Height: item.Height,
|
||||||
})
|
})
|
||||||
|
|
92
main.go
92
main.go
|
@ -18,52 +18,52 @@ var settings UserSettings
|
||||||
|
|
||||||
var languageOptions = []LanguageOption{
|
var languageOptions = []LanguageOption{
|
||||||
{Code: "", Name: "Any Language"},
|
{Code: "", Name: "Any Language"},
|
||||||
{Code: "lang_en", Name: "English"},
|
{Code: "en", Name: "English"},
|
||||||
{Code: "lang_af", Name: "Afrikaans"},
|
{Code: "af", Name: "Afrikaans"},
|
||||||
{Code: "lang_ar", Name: "العربية (Arabic)"},
|
{Code: "ar", Name: "العربية (Arabic)"},
|
||||||
{Code: "lang_hy", Name: "Հայերեն (Armenian)"},
|
{Code: "hy", Name: "Հայերեն (Armenian)"},
|
||||||
{Code: "lang_be", Name: "Беларуская (Belarusian)"},
|
{Code: "be", Name: "Беларуская (Belarusian)"},
|
||||||
{Code: "lang_bg", Name: "български (Bulgarian)"},
|
{Code: "bg", Name: "български (Bulgarian)"},
|
||||||
{Code: "lang_ca", Name: "Català (Catalan)"},
|
{Code: "ca", Name: "Català (Catalan)"},
|
||||||
{Code: "lang_zh-CN", Name: "中文 (简体) (Chinese Simplified)"},
|
{Code: "zh-CN", Name: "中文 (简体) (Chinese Simplified)"},
|
||||||
{Code: "lang_zh-TW", Name: "中文 (繁體) (Chinese Traditional)"},
|
{Code: "zh-TW", Name: "中文 (繁體) (Chinese Traditional)"},
|
||||||
{Code: "lang_hr", Name: "Hrvatski (Croatian)"},
|
{Code: "hr", Name: "Hrvatski (Croatian)"},
|
||||||
{Code: "lang_cs", Name: "Čeština (Czech)"},
|
{Code: "cs", Name: "Čeština (Czech)"},
|
||||||
{Code: "lang_da", Name: "Dansk (Danish)"},
|
{Code: "da", Name: "Dansk (Danish)"},
|
||||||
{Code: "lang_nl", Name: "Nederlands (Dutch)"},
|
{Code: "nl", Name: "Nederlands (Dutch)"},
|
||||||
{Code: "lang_eo", Name: "Esperanto"},
|
{Code: "eo", Name: "Esperanto"},
|
||||||
{Code: "lang_et", Name: "Eesti (Estonian)"},
|
{Code: "et", Name: "Eesti (Estonian)"},
|
||||||
{Code: "lang_tl", Name: "Filipino (Tagalog)"},
|
{Code: "tl", Name: "Filipino (Tagalog)"},
|
||||||
{Code: "lang_fi", Name: "Suomi (Finnish)"},
|
{Code: "fi", Name: "Suomi (Finnish)"},
|
||||||
{Code: "lang_fr", Name: "Français (French)"},
|
{Code: "fr", Name: "Français (French)"},
|
||||||
{Code: "lang_de", Name: "Deutsch (German)"},
|
{Code: "de", Name: "Deutsch (German)"},
|
||||||
{Code: "lang_el", Name: "Ελληνικά (Greek)"},
|
{Code: "el", Name: "Ελληνικά (Greek)"},
|
||||||
{Code: "lang_iw", Name: "עברית (Hebrew)"},
|
{Code: "iw", Name: "עברית (Hebrew)"},
|
||||||
{Code: "lang_hi", Name: "हिन्दी (Hindi)"},
|
{Code: "hi", Name: "हिन्दी (Hindi)"},
|
||||||
{Code: "lang_hu", Name: "magyar (Hungarian)"},
|
{Code: "hu", Name: "magyar (Hungarian)"},
|
||||||
{Code: "lang_is", Name: "íslenska (Icelandic)"},
|
{Code: "is", Name: "íslenska (Icelandic)"},
|
||||||
{Code: "lang_id", Name: "Bahasa Indonesia (Indonesian)"},
|
{Code: "id", Name: "Bahasa Indonesia (Indonesian)"},
|
||||||
{Code: "lang_it", Name: "italiano (Italian)"},
|
{Code: "it", Name: "italiano (Italian)"},
|
||||||
{Code: "lang_ja", Name: "日本語 (Japanese)"},
|
{Code: "ja", Name: "日本語 (Japanese)"},
|
||||||
{Code: "lang_ko", Name: "한국어 (Korean)"},
|
{Code: "ko", Name: "한국어 (Korean)"},
|
||||||
{Code: "lang_lv", Name: "latviešu (Latvian)"},
|
{Code: "lv", Name: "latviešu (Latvian)"},
|
||||||
{Code: "lang_lt", Name: "lietuvių (Lithuanian)"},
|
{Code: "lt", Name: "lietuvių (Lithuanian)"},
|
||||||
{Code: "lang_no", Name: "norsk (Norwegian)"},
|
{Code: "no", Name: "norsk (Norwegian)"},
|
||||||
{Code: "lang_fa", Name: "فارسی (Persian)"},
|
{Code: "fa", Name: "فارسی (Persian)"},
|
||||||
{Code: "lang_pl", Name: "polski (Polish)"},
|
{Code: "pl", Name: "polski (Polish)"},
|
||||||
{Code: "lang_pt", Name: "português (Portuguese)"},
|
{Code: "pt", Name: "português (Portuguese)"},
|
||||||
{Code: "lang_ro", Name: "română (Romanian)"},
|
{Code: "ro", Name: "română (Romanian)"},
|
||||||
{Code: "lang_ru", Name: "русский (Russian)"},
|
{Code: "ru", Name: "русский (Russian)"},
|
||||||
{Code: "lang_sr", Name: "српски (Serbian)"},
|
{Code: "sr", Name: "српски (Serbian)"},
|
||||||
{Code: "lang_sk", Name: "slovenčina (Slovak)"},
|
{Code: "sk", Name: "slovenčina (Slovak)"},
|
||||||
{Code: "lang_sl", Name: "slovenščina (Slovenian)"},
|
{Code: "sl", Name: "slovenščina (Slovenian)"},
|
||||||
{Code: "lang_es", Name: "español (Spanish)"},
|
{Code: "es", Name: "español (Spanish)"},
|
||||||
{Code: "lang_sw", Name: "Kiswahili (Swahili)"},
|
{Code: "sw", Name: "Kiswahili (Swahili)"},
|
||||||
{Code: "lang_sv", Name: "svenska (Swedish)"},
|
{Code: "sv", Name: "svenska (Swedish)"},
|
||||||
{Code: "lang_th", Name: "ไทย (Thai)"},
|
{Code: "th", Name: "ไทย (Thai)"},
|
||||||
{Code: "lang_tr", Name: "Türkçe (Turkish)"},
|
{Code: "tr", Name: "Türkçe (Turkish)"},
|
||||||
{Code: "lang_uk", Name: "українська (Ukrainian)"},
|
{Code: "uk", Name: "українська (Ukrainian)"},
|
||||||
{Code: "lang_vi", Name: "Tiếng Việt (Vietnamese)"},
|
{Code: "vi", Name: "Tiếng Việt (Vietnamese)"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSearch(w http.ResponseWriter, r *http.Request) {
|
func handleSearch(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ func buildSearchURL(query, safe, lang string, page, resultsPerPage int) string {
|
||||||
|
|
||||||
langParam := ""
|
langParam := ""
|
||||||
if lang != "" {
|
if lang != "" {
|
||||||
langParam = "&lr=" + lang
|
langParam = "&lr=lang_" + lang
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate random geolocation
|
// Generate random geolocation
|
||||||
|
|
Loading…
Add table
Reference in a new issue