random user agents
This commit is contained in:
parent
4e8ca3192f
commit
8e5f8c8a10
8 changed files with 418 additions and 12 deletions
7
video.go
7
video.go
|
@ -117,7 +117,7 @@ func testInstanceAvailability(instance string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func makeHTMLRequest(query string) (*VideoAPIResponse, error) {
|
||||
func makeHTMLRequest(query, safe, lang string, page int) (*VideoAPIResponse, error) {
|
||||
var lastError error
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
@ -127,7 +127,7 @@ func makeHTMLRequest(query string) (*VideoAPIResponse, error) {
|
|||
continue // Skip this instance because it's still disabled
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("https://%s/search?q=%s&filter=all", instance, url.QueryEscape(query))
|
||||
url := fmt.Sprintf("https://%s/search?q=%s&filter=all&safe=%s&lang=%s&page=%d", instance, url.QueryEscape(query), safe, lang, page)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil || resp.StatusCode != http.StatusOK {
|
||||
log.Printf("Disabling instance %s due to error or status code: %v", instance, err)
|
||||
|
@ -151,8 +151,7 @@ func makeHTMLRequest(query string) (*VideoAPIResponse, error) {
|
|||
func handleVideoSearch(w http.ResponseWriter, query, safe, lang string, page int) {
|
||||
start := time.Now()
|
||||
|
||||
// Modify `makeHTMLRequest` to also accept `safe`, `lang`, and `page` parameters if necessary
|
||||
apiResp, err := makeHTMLRequest(query)
|
||||
apiResp, err := makeHTMLRequest(query, safe, lang, page)
|
||||
if err != nil {
|
||||
log.Printf("Error fetching video results: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue