1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
package services
import (
"errors"
"math/rand"
"regexp"
"strings"
)
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
Pattern: regexp.MustCompile(`reddit\.com|libreddit|redlib|teddit`),
Targets: []string{"libreddit", "redlib", "teddit"},
},
{
// Google Search
Pattern: regexp.MustCompile(`google\.com|whoogle|searx|searxng`),
Targets: []string{"whoogle", "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
Pattern: regexp.MustCompile(`translate\.google\.com|lingva|simplytranslate`),
Targets: []string{"lingva", "simplytranslate"},
},
{
// TikTok
Pattern: regexp.MustCompile(`tiktok\.com|proxitok`),
Targets: []string{"proxitok"},
},
{
// Fandom
Pattern: regexp.MustCompile(`.*fandom\.com|breezewiki`),
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"},
},
{
// Genius
Pattern: regexp.MustCompile(`genius\.com|dumb`),
Targets: []string{"dumb"},
},
{
// 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"},
},
{
// Tent
// Note: This is a Bandcamp alternative, but the endpoints are
// completely different than Bandcamp, so 1-to-1 mapping of URLs
// is not possible without some additional work
Pattern: regexp.MustCompile("tent"),
Targets: []string{"tent"},
},
}
func MatchRequest(service string) (string, error) {
for _, mapping := range regexMap {
hasMatch := mapping.Pattern.MatchString(service)
if !hasMatch {
continue
}
if !strings.Contains(service, ".") {
return service, nil
}
index := rand.Intn(len(mapping.Targets))
value := mapping.Targets[index]
return value, nil
}
return "", errors.New("no match found")
}
|