headless_engine/google/
endpoints.rs1use url::Url;
2
3pub struct GoogleEndpoints;
5
6impl GoogleEndpoints {
7 pub fn search(query: &str) -> String {
8 format!(
9 "https://www.google.com/search?q={}",
10 urlencoding::encode(query)
11 )
12 }
13
14 pub fn web_search(query: &str) -> String {
15 format!(
16 "https://www.google.com/search?q={}&udm=14",
17 urlencoding::encode(query)
18 )
19 }
20
21 pub fn image_search(query: &str) -> String {
22 format!(
23 "https://www.google.com/search?q={}&udm=2",
24 urlencoding::encode(query)
25 )
26 }
27
28 pub fn video_search(query: &str) -> String {
29 format!(
30 "https://www.google.com/search?q={}&tbm=vid",
31 urlencoding::encode(query)
32 )
33 }
34
35 pub fn short_video_search(query: &str) -> String {
36 format!(
37 "https://www.google.com/search?q={}+shorts&tbm=vid",
38 urlencoding::encode(query)
39 )
40 }
41
42 pub fn news_search(query: &str) -> String {
43 format!(
44 "https://www.google.com/search?q={}&tbm=nws",
45 urlencoding::encode(query)
46 )
47 }
48
49 pub fn forum_search(query: &str) -> String {
50 format!(
51 "https://www.google.com/search?q={}&udm=18",
52 urlencoding::encode(query)
53 )
54 }
55
56 pub fn shopping_search(query: &str) -> String {
57 format!(
58 "https://www.google.com/search?q={}&tbm=shop",
59 urlencoding::encode(query)
60 )
61 }
62
63 pub fn product_search(query: &str) -> String {
64 format!(
65 "https://www.google.com/search?q={}&tbm=shop",
66 urlencoding::encode(query)
67 )
68 }
69
70 pub fn books_search(query: &str) -> String {
71 format!(
72 "https://www.google.com/search?q={}&tbm=bks",
73 urlencoding::encode(query)
74 )
75 }
76
77 pub fn autocomplete(query: &str) -> String {
78 format!(
79 "https://suggestqueries.google.com/complete/search?client=chrome&q={}",
80 urlencoding::encode(query)
81 )
82 }
83
84 pub fn ai_overview(query: &str) -> String {
85 format!(
86 "https://www.google.com/search?q={}",
87 urlencoding::encode(query)
88 )
89 }
90
91 pub fn ai_mode(query: &str) -> String {
92 format!(
93 "https://www.google.com/search?q={}&udm=50",
94 urlencoding::encode(query)
95 )
96 }
97
98 pub fn scholar_search(query: &str) -> String {
99 format!(
100 "https://scholar.google.com/scholar?q={}",
101 urlencoding::encode(query)
102 )
103 }
104
105 pub fn patents_search(query: &str) -> String {
106 format!(
107 "https://patents.google.com/?q={}",
108 urlencoding::encode(query)
109 )
110 }
111
112 pub fn maps_search(query: &str) -> String {
113 format!(
114 "https://www.google.com/maps/search/{}",
115 urlencoding::encode(query)
116 )
117 }
118
119 pub fn finance_quote(ticker: &str) -> String {
120 format!(
121 "https://www.google.com/finance/quote/{}",
122 urlencoding::encode(ticker)
123 )
124 }
125
126 pub fn trends_search(query: &str) -> String {
127 format!(
128 "https://trends.google.com/trends/explore?q={}",
129 urlencoding::encode(query)
130 )
131 }
132
133 pub fn flights_search(origin: &str, dest: &str) -> String {
134 format!(
135 "https://www.google.com/travel/flights?q=Flights+from+{}+to+{}",
136 urlencoding::encode(origin),
137 urlencoding::encode(dest)
138 )
139 }
140
141 pub fn hotels_search(location: &str) -> String {
142 format!(
143 "https://www.google.com/travel/hotels/{}",
144 urlencoding::encode(location)
145 )
146 }
147
148 pub fn travel_explore(destination: &str) -> String {
149 format!(
150 "https://www.google.com/travel/explore?q={}",
151 urlencoding::encode(destination)
152 )
153 }
154
155 pub fn youtube_search(query: &str) -> String {
156 format!(
157 "https://www.youtube.com/results?search_query={}",
158 urlencoding::encode(query)
159 )
160 }
161
162 pub fn youtube_shorts_search(query: &str) -> String {
163 format!(
164 "https://www.youtube.com/results?search_query={}&sp=mREBAgAL",
165 urlencoding::encode(query)
166 )
167 }
168
169 pub fn youtube_video(video_id: &str) -> String {
170 if video_id.starts_with("http") {
171 video_id.to_string()
172 } else {
173 format!(
174 "https://www.youtube.com/watch?v={}",
175 urlencoding::encode(video_id)
176 )
177 }
178 }
179
180 pub fn youtube_channel(channel: &str) -> String {
181 if channel.starts_with("http") {
182 channel.to_string()
183 } else if channel.starts_with('@') {
184 format!("https://www.youtube.com/{}", channel)
185 } else {
186 format!(
187 "https://www.youtube.com/channel/{}",
188 urlencoding::encode(channel)
189 )
190 }
191 }
192
193 pub fn youtube_playlist(playlist_id: &str) -> String {
194 if playlist_id.starts_with("http") {
195 playlist_id.to_string()
196 } else {
197 format!(
198 "https://www.youtube.com/playlist?list={}",
199 urlencoding::encode(playlist_id)
200 )
201 }
202 }
203
204 pub fn lens_visual_matches(image_url: &str) -> String {
205 format!(
206 "https://lens.google.com/uploadbyurl?url={}",
207 urlencoding::encode(image_url)
208 )
209 }
210
211 pub fn lens_exact_matches(image_url: &str) -> String {
212 format!(
213 "https://lens.google.com/uploadbyurl?url={}",
214 urlencoding::encode(image_url)
215 )
216 }
217
218 pub fn lens_products(image_url: &str) -> String {
219 format!(
220 "https://lens.google.com/uploadbyurl?url={}",
221 urlencoding::encode(image_url)
222 )
223 }
224
225 pub fn lens_about_image(image_url: &str) -> String {
226 format!(
227 "https://lens.google.com/uploadbyurl?url={}",
228 urlencoding::encode(image_url)
229 )
230 }
231}