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 21.07.2022 um 11:19:16 Uhr
Beitrag wegen Beschwerde von Yandex geschlossen => Papierkorb

Content-ID: 3371824833

Url: https://administrator.de/forum/direktlink-bildersuche-kontextmenue-im-windows-explorer-3371824833.html

Ausgedruckt am: 20.04.2025 um 21:04 Uhr

colinardo
Lösung colinardo 18.07.2022, aktualisiert am 21.07.2022 um 11:21:03 Uhr
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
PeterleB
PeterleB 19.07.2022 aktualisiert um 07:32:34 Uhr
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
colinardo
colinardo 19.07.2022 aktualisiert um 07:51:42 Uhr
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
PeterleB
PeterleB 20.07.2022, aktualisiert am 21.07.2022 um 11:21:43 Uhr
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
PeterleB
PeterleB 21.07.2022 aktualisiert um 11:07:50 Uhr
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
colinardo
colinardo 21.07.2022 aktualisiert um 11:22:58 Uhr
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!