vivithemage / mrisa

MRISA - Meta reverse image search api
http://mrisa.mage.me.uk/
GNU General Public License v2.0
264 stars 63 forks source link

Extending the search by using Yandex Image search #15

Open phanirithvij opened 6 years ago

phanirithvij commented 6 years ago

I think Yandex is cool. I am suggesting of adding an option to choose between providers (search engines)

But Yandex has no Best_Guess

{
"image_url":"IMAGE_URL",
"yandex":true,
"google":true
}

Examples

https://www.yandex.com/images/search?text=http%3A%2F%2Fiphones-wallpapers.com%2Fwp-content%2Fuploads%2F2018%2F04%2Fiphone-wallpaper-deadpool-luxury-funny-deadpool-wallpaper-hd-o-oshka-pinterest-of-iphone-wallpaper-deadpool.jpg&img_url=http%3A%2F%2Fiphones-wallpapers.com%2Fwp-content%2Fuploads%2F2018%2F04%2Fiphone-wallpaper-deadpool-luxury-funny-deadpool-wallpaper-hd-o-oshka-pinterest-of-iphone-wallpaper-deadpool.jpg&rpt=imageview

https://www.yandex.com/images/search?text=https%3A//avatars2.githubusercontent.com/u/29627898%3Fs%3D88%26v%3D4&img_url=https%3A//avatars2.githubusercontent.com/u/29627898%3Fs%3D88%26v%3D4&rpt=imageview

Format to search by url of an image

URL_FORMAT: https://www.yandex.com/images/search? + text=IMAGE_URL & + img_url=IMAGE_URL & + rpt=imageview

Where IMAGE_URL is escaped

vivithemage commented 6 years ago

Sounds good. I think completely seperating the results of each search engine and then simply omiting the best guess on Yandex may be a good way to structure the results.

phanirithvij commented 6 years ago

I don't know PHP but I used curl to PHP generator

For the Feature ideas examples on different languages

PHP

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://localhost:5000/search");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,    "{
                                                \"image_url\":\"http://placehold.it/350x150.png\",
                                                \"resized_images\":true
                                        }");

curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

echo $result

?>
phanirithvij commented 6 years ago

I only know basics of go but used a generator

Go

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
)

// Payload : json struct
type Payload struct {
    ImageURL      string `json:"image_url"`
    ResizedImages bool   `json:"resized_images"`
}

func main() {
    data := Payload{
        // fill struct
        ImageURL:      "http://placehold.it/350x150.png",
        ResizedImages: true,
    }

    payloadBytes, err := json.Marshal(data)
    if err != nil {
        // handle err
        fmt.Println("error:>", err)
    }
    body := bytes.NewReader(payloadBytes)

    req, err := http.NewRequest("POST", "http://localhost:5000/search", body)
    if err != nil {
        // handle err
        fmt.Println("error:>", err)
    }

    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)

    if err != nil {
        // handle err
    }

    if resp.StatusCode == http.StatusOK {
        bodyBytes, _ := ioutil.ReadAll(resp.Body)
        bodyString := string(bodyBytes)
        fmt.Println(bodyString)
    }

    defer resp.Body.Close()
}
phanirithvij commented 6 years ago

Nothing on ruby either but curl to ruby online

Ruby

require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("http://localhost:5000/search")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request.body = JSON.dump({
  "image_url" => "http://placehold.it/350x150.png",
  "resized_images" => true
})

req_options = {
  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

puts response.code, response.body
phanirithvij commented 6 years ago

Perl by using LWP I don't know Perl either

Perl and LWP

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

my $server_endpoint = "http://localhost:5000/search";

# set custom HTTP request header fields
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('content-type' => 'application/json');

# add POST data to HTTP request body
my $post_data = '{
                "image_url": "http://placehold.it/350x150.png",
                "resized_images":true
                }';
$req->content($post_data);

my $resp = $ua->request($req);
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    print "Received reply: $message\n";
}
else {
    print "HTTP POST error code: ", $resp->code, "\n";
    print "HTTP POST error message: ", $resp->message, "\n";
}
phanirithvij commented 6 years ago

Couldn't find a Java code.

phanirithvij commented 6 years ago

Php, Go, Perl, Ruby examples are working

vivithemage commented 6 years ago

@phanirithvij Great! I just commented in the other issue.