2025-01-21 13:46:29 -07:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"math/rand"
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RegexMapping struct {
|
|
|
|
Pattern *regexp.Regexp
|
|
|
|
Targets []string
|
|
|
|
}
|
|
|
|
|
|
|
|
var regexMap = []RegexMapping{
|
|
|
|
{
|
|
|
|
// YouTube
|
|
|
|
Pattern: regexp.MustCompile(`youtu(\.be|be\.com)|invidious|piped`),
|
|
|
|
Targets: []string{"piped", "invidious"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Twitter / X
|
|
|
|
Pattern: regexp.MustCompile(`twitter\.com|x\.com|nitter`),
|
|
|
|
Targets: []string{"nitter"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Reddit
|
2025-02-25 10:07:25 -08:00
|
|
|
Pattern: regexp.MustCompile(`reddit\.com|libreddit|redlib|teddit`),
|
|
|
|
Targets: []string{"libreddit", "redlib", "teddit"},
|
2025-01-21 13:46:29 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Google Search
|
|
|
|
Pattern: regexp.MustCompile(`google\.com|whoogle|searx|searxng`),
|
|
|
|
Targets: []string{"whoogle", "searx", "searxng"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Instagram
|
|
|
|
Pattern: regexp.MustCompile(`instagram\.com|proxigram`),
|
|
|
|
Targets: []string{"proxigram"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Wikipedia
|
|
|
|
Pattern: regexp.MustCompile(`wikipedia\.org|wikiless`),
|
|
|
|
Targets: []string{"wikiless"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Medium
|
|
|
|
Pattern: regexp.MustCompile(`medium\.com|scribe`),
|
|
|
|
Targets: []string{"scribe"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Odysee
|
|
|
|
Pattern: regexp.MustCompile(`odysee\.com|librarian`),
|
|
|
|
Targets: []string{"librarian"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Imgur
|
|
|
|
Pattern: regexp.MustCompile(`imgur\.com|rimgo`),
|
|
|
|
Targets: []string{"rimgo"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Google Translate
|
2025-02-25 10:07:25 -08:00
|
|
|
Pattern: regexp.MustCompile(`translate\.google\.com|lingva|simplytranslate`),
|
|
|
|
Targets: []string{"lingva", "simplytranslate"},
|
2025-01-21 13:46:29 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// TikTok
|
|
|
|
Pattern: regexp.MustCompile(`tiktok\.com|proxitok`),
|
|
|
|
Targets: []string{"proxitok"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Fandom
|
2025-01-27 12:17:20 -07:00
|
|
|
Pattern: regexp.MustCompile(`.*fandom\.com|breezewiki`),
|
2025-01-21 13:46:29 -07:00
|
|
|
Targets: []string{"breezewiki"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// IMDB
|
|
|
|
Pattern: regexp.MustCompile(`imdb\.com|libremdb`),
|
|
|
|
Targets: []string{"libremdb"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Quora
|
|
|
|
Pattern: regexp.MustCompile(`quora\.com|quetre`),
|
|
|
|
Targets: []string{"quetre"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// GitHub
|
|
|
|
Pattern: regexp.MustCompile(`github\.com|gothub`),
|
|
|
|
Targets: []string{"gothub"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// StackOverflow
|
|
|
|
Pattern: regexp.MustCompile(`stackoverflow\.com|anonymousoverflow`),
|
|
|
|
Targets: []string{"anonymousoverflow"},
|
|
|
|
},
|
2025-02-25 10:07:25 -08:00
|
|
|
{
|
|
|
|
// Genius
|
|
|
|
Pattern: regexp.MustCompile(`genius\.com|dumb`),
|
|
|
|
Targets: []string{"dumb"},
|
|
|
|
},
|
2025-02-25 15:38:33 -07:00
|
|
|
{
|
|
|
|
// 4get
|
|
|
|
// Note: Could be used for redirecting other search engine
|
|
|
|
// requests, but would need special handling
|
|
|
|
Pattern: regexp.MustCompile("4get"),
|
|
|
|
Targets: []string{"4get"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// LibreY
|
|
|
|
// Note: Could be used for redirecting other search engine
|
|
|
|
// requests, but would need special handling
|
|
|
|
Pattern: regexp.MustCompile("librex|librey"),
|
|
|
|
Targets: []string{"librey"},
|
|
|
|
},
|
2025-01-21 13:46:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func MatchRequest(service string) (string, error) {
|
|
|
|
for _, mapping := range regexMap {
|
|
|
|
hasMatch := mapping.Pattern.MatchString(service)
|
|
|
|
if !hasMatch {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
index := rand.Intn(len(mapping.Targets))
|
|
|
|
value := mapping.Targets[index]
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", errors.New("no match found")
|
|
|
|
}
|