peterleb
Goto Top

Direktlink Bildersuche (Kontextmenü im Windows Explorer)

Hallo,

die Anfrage gab es schon mal.
Direktlink ...

Leider funktioniert das Script für die Yandex-Bildersuche nicht mehr.
Es findet keine Bilder mehr.
"There are no results for your search."

Hat sich etwas für die Abfrage bei Yandex geändert?

Der liebe colinardo hatte sich damals erfolgreich der Sache angenommen.

Grüße
Peter
Kommentar vom Moderator colinardo am Jul 21, 2022 um 09:19:16 Uhr
Beitrag wegen Beschwerde von Yandex geschlossen => Papierkorb

Content-Key: 3371824833

Url: https://administrator.de/contentid/3371824833

Printed on: June 1, 2024 at 20:06 o'clock

Member: colinardo
Solution colinardo Jul 18, 2022, updated at Jul 21, 2022 at 09:21:03 (UTC)
Goto Top
Da isser wieder der Peter face-smile.
Zitat von @PeterleB:
Hat sich etwas für die Abfrage bei Yandex geändert?
Jepp, so ziemlich alles ... Ist sogar etwas simpler geworden:
function Get-YandexImageSearchResult([string][ValidateScript({Test-Path $_})]$path){
    try{
        $result = Invoke-RestMethod '[ZENSIERT]' -Method Post -ContentType "image/$([io.path]::GetExtension($path).substring(1))" -Body ([io.file]::ReadAllBytes($path))  
        return [ZENSIERT]
    }catch{
        Write-Error $_.Exception.Message
    }
}

$dlg = New-Object System.Windows.Forms.OpenFileDialog
$dlg.Multiselect = $false
$dlg.Title = "Bitte ein Bild für den Upload auswählen:"  
if($dlg.ShowDialog() -eq 'OK'){  
    $url = Get-YandexImageSearchResult -path $dlg.FileName
    if ($url){
        start $url
    }
}
Grüße Uwe
Member: PeterleB
PeterleB Jul 19, 2022 updated at 05:32:34 (UTC)
Goto Top
Das ist der Hammer!
Ich danke Dir.

Muß aber noch etwas dran basteln.
Das Bild soll ja per Rechtsklick im Windows-Explorer übergeben werden.
Das bekomme ich jedoch mithilfe des alten Codes bestimmt hin.

Gruß
Peter
Member: colinardo
colinardo Jul 19, 2022 updated at 05:51:42 (UTC)
Goto Top
Immer gerne.
Zitat von @PeterleB:
Muß aber noch etwas dran basteln.
Das Bild soll ja per Rechtsklick im Windows-Explorer übergeben werden.
Das bekomme ich jedoch mithilfe des alten Codes bestimmt hin.
Das will ich wohl meinen, bist ja hier nicht erst seit gestern Mitglied face-smile. Reicht ja statt dem Dialog ein "param()" mit Parameter im Skriptheader einzubauen und als Dateinamen zu übergeben.

Grüße Uwe
Member: PeterleB
PeterleB Jul 20, 2022, updated at Jul 21, 2022 at 09:21:43 (UTC)
Goto Top
Hallo,

bekomme es doch nicht ganz hin.

param(
    [string]$file
)

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null  
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null  

function Get-YandexImageSearchResult([string][ValidateScript({Test-Path $_})]$path){
    try{
        $result = Invoke-RestMethod '[ZENSIERT]' -Method Post -ContentType "image/$([io.path]::GetExtension($path).substring(1))" -Body ([io.file]::ReadAllBytes($path))  
        return "[ZENSIERT]"  
    }catch{
        Write-Error $_.Exception.Message
    }

    
        $proxyenabled = Get-ItemProperty -Path Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"  
		#if proxy
		if($proxyenabled.ProxyEnable -eq 1) { 
			$proxy = New-Object System.Net.WebProxy("http://xxx.xx.xxx.xxx:80")  
			$creds = New-object System.Net.NetworkCredential("xxxxx","xxxxx")  
			$proxy.Credentials = $creds
			$request.Proxy = $proxy
        }
		#endif proxy

}

function ShowForm(){
    $form1 = New-Object System.Windows.Forms.Form
    $lblStatus = New-Object System.Windows.Forms.Label
    $form1.ClientSize = [System.Drawing.Size]::new(292,62)
    $form1.ControlBox = $False
    $form1.StartPosition = 1
    $form1.FormBorderStyle = 5
    $form1.Name = "form1"  
    $form1.Text = "Uploading ..."  
    $form1.add_Shown({
        $form1.Update()
        $url = Get-YandexImageSearchResult $file
        if ($url){
            start $url
        }
        $form1.Close()
    })

    $lblStatus.Dock = 5
    $lblStatus.Font = New-Object System.Drawing.Font("Arial",13,1,3,0)  
    $lblStatus.Location = [System.Drawing.Point]::new(0,0)
    $lblStatus.Name = "lblStatus"  
    $lblStatus.Size = [System.Drawing.Size]::new(292,62)
    $lblStatus.Visible = $true
    $lblStatus.Text = "Datei-Upload, bitte warten."  
    $lblStatus.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
    $form1.Controls.Add($lblStatus)
    $form1.ShowDialog() | out-null
}
ShowForm

Was ist falsch?
Gruß
Peter
Member: PeterleB
PeterleB Jul 21, 2022 updated at 09:07:50 (UTC)
Goto Top
Hallo,
ich poste nochmal das alte Script.
Mir ist nicht ganz klar, wie ich die neue Funktion richtig einsetze.

param(
    [string]$file
)

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null  
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null  

function Get-YandexImageSearchResult([string][ValidateScript({Test-Path $_})]$path){
    try{
        $boundary = [datetime]::now.Ticks.ToString()
        $p1 = @"  
--$boundary
Content-Disposition: form-data; name="upfile"; filename="$([IO.Path]::GetFileName($path))"  
Content-Type: image/$([System.IO.Path]::GetExtension($path).substring(1))


"@  
        $p2 = @"  
--$boundary
Content-Disposition: form-data; name="upfile"  


--$boundary--

"@  
        $bytes = [System.Text.Encoding]::ASCII.GetBytes($p1) + ([IO.File]::ReadAllBytes($path)) + [System.Text.Encoding]::ASCII.GetBytes($p2)
        $request = [Net.HttpWebRequest] ([Net.HttpWebRequest]::Create('https://yandex.com/images/search?serpListType=horizontal&rpt=imageview&format=json&request=%7B%22blocks%22%3A%5B%7B%22block%22%3A%22b-page_type_search-by-image__link%22%7D%5D%7D'))  
        $request.Method = "POST"  
       
        $proxyenabled = Get-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"  
		#if proxy
		if($proxyenabled.ProxyEnable -eq 1) { 
			$proxy = New-Object System.Net.WebProxy("http://xxx.xxx.xxx.xxx:80")  
			$creds = New-object System.Net.NetworkCredential("xxxxx","xxxxxx")  
			$proxy.Credentials = $creds
			$request.Proxy = $proxy
        }
		#endif proxy
        
        $request.ContentType = "multipart/form-data; boundary=$boundary"  
        $request.ContentLength = $bytes.Length
        $request.AllowAutoredirect = $false
        $stream = $request.GetRequestStream()
        $stream.Write($bytes, 0, $bytes.Length)
        $stream.Close()
        $sr = New-Object System.IO.StreamReader $request.GetResponse().GetResponseStream()

        $url = "https://yandex.com/images/search?$(($sr.ReadToEnd() | ConvertFrom-Json).blocks.params.url)"  
        $sr.Close(); $sr.Dispose()
        return $url
    }catch{
        Write-Error $_.Exception.Message
    }
}

function ShowForm(){
    $form1 = New-Object System.Windows.Forms.Form
    $lblStatus = New-Object System.Windows.Forms.Label
    $form1.ClientSize = [System.Drawing.Size]::new(292,62)
    $form1.ControlBox = $False
    $form1.StartPosition = 1
    $form1.FormBorderStyle = 5
    $form1.Name = "form1"  
    $form1.Text = "Uploading ..."  
    $form1.add_Shown({
        $form1.Update()
        $url = Get-YandexImageSearchResult -path $file
        if ($url){
            start $url
        }
        $form1.Close()
    })

    $lblStatus.Dock = 5
    $lblStatus.Font = New-Object System.Drawing.Font("Arial",13,1,3,0)  
    $lblStatus.Location = [System.Drawing.Point]::new(0,0)
    $lblStatus.Name = "lblStatus"  
    $lblStatus.Size = [System.Drawing.Size]::new(292,62)
    $lblStatus.Visible = $true
    $lblStatus.Text = "Datei-Upload, bitte warten."  
    $lblStatus.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
    $form1.Controls.Add($lblStatus)
    $form1.ShowDialog() | out-null
}
ShowForm

Gruß
Peter
Member: colinardo
colinardo Jul 21, 2022 updated at 09:22:58 (UTC)
Goto Top
Schade, wenn man sich noch nicht mal mehr die Zeit nimmt und die Doku zum Befehl Invoke-RestMethod nachzuschlagen wie man dort einen Proxy mit den Parametern -Proxy und -ProxyCredential verwendet face-sad.
param(
    [string]$file
)
Add-Type -A System.Windows.Forms
Add-Type -A System.Drawing

function Get-YandexImageSearchResult([string][ValidateScript({Test-Path $_})]$path){
    try{
        # create request parameters
        $options = @{
            Uri = '[ZENSIERT]'  
            Method = 'Post'  
            ContentType = "image/$([io.path]::GetExtension($path).substring(1))"  
            Body = [io.file]::ReadAllBytes($path)
        }
        # add proxy options to parameter object if enabled
        if((Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable) -eq 1) {   
	    $options.Proxy = "http://xxx.xx.xxx.xxx:80"  
            $options.ProxyCredential = new-Object PSCredential('username',(ConvertTo-SecureString 'Password' -AsPlainText -Force))  
        }
        # invoke request
        $result = Invoke-RestMethod @Options
        return "[ZENSIERT]"  
    }catch{
        Write-Error $_.Exception.Message
    }
}

function ShowForm(){
    $form1 = New-Object System.Windows.Forms.Form
    $lblStatus = New-Object System.Windows.Forms.Label
    $form1.ClientSize = [System.Drawing.Size]::new(292,62)
    $form1.ControlBox = $False
    $form1.StartPosition = 1
    $form1.FormBorderStyle = 5
    $form1.Name = "form1"  
    $form1.Text = "Uploading ..."  
    $form1.add_Shown({
        $form1.Update()
        $url = Get-YandexImageSearchResult $file
        if ($url){
            start $url
        }
        $form1.Close()
    })

    $lblStatus.Dock = 5
    $lblStatus.Font = New-Object System.Drawing.Font("Arial",13,1,3,0)  
    $lblStatus.Location = [System.Drawing.Point]::new(0,0)
    $lblStatus.Name = "lblStatus"  
    $lblStatus.Size = [System.Drawing.Size]::new(292,62)
    $lblStatus.Visible = $true
    $lblStatus.Text = "Datei-Upload, bitte warten."  
    $lblStatus.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
    $form1.Controls.Add($lblStatus)
    $form1.ShowDialog() | out-null
}
ShowForm
I'm outa here.

Grüße Uwe

#edit# Da Beschwerde von Yandex erhalten, Post geschlossen, zensiert und in Papierkorb verschoben!