├── .github └── workflows │ └── publish.yml ├── LICENSE ├── README.md └── search-by-trace.moe.ps1 /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: "Publish" 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | publish: 9 | name: Publish 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: "actions/checkout@main" 13 | - name: Publish to PSGallery 14 | uses: jcwillox/action-publish-powershell-script@main 15 | with: 16 | path: search-by-trace.moe.ps1 17 | nuget_api_key: ${{ secrets.PSGALLERY_KEY }} 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 soruly 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # trace.moe-windows-menu 2 | 3 | [![PowerShell Gallery Version](https://img.shields.io/powershellgallery/v/search-by-trace.moe?style=flat-square)](https://www.powershellgallery.com/packages/search-by-trace.moe/) 4 | [![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/search-by-trace.moe?style=flat-square)](https://www.powershellgallery.com/packages/search-by-trace.moe/) 5 | 6 | Right click images in file explorer to search on trace.moe 7 | 8 | ![](https://images.plurk.com/4mtGacxqdp1VO3dwcHmwgF.png ) 9 | ![](https://images.plurk.com/4MCbCqXAw0G4rGmYsepIqc.png) 10 | 11 | ## Install 12 | Open Windows Terminal (powershell) with administrator privileges (You'll have to enter "Y" multiple times) 13 | ```powershell 14 | Set-ExecutionPolicy -ExecutionPolicy RemoteSigned 15 | Install-Script -Name search-by-trace.moe 16 | search-by-trace.moe.ps1 -install 17 | ``` 18 | 19 | ## Update 20 | ```powershell 21 | Update-Script search-by-trace.moe 22 | ``` 23 | 24 | ## Uninstall 25 | ```powershell 26 | search-by-trace.moe.ps1 -uninstall 27 | Uninstall-Script search-by-trace.moe 28 | ``` 29 | -------------------------------------------------------------------------------- /search-by-trace.moe.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Version 5.1 2 | 3 | <#PSScriptInfo 4 | .VERSION 0.4.0 5 | .GUID 7db8f935-8341-4687-8e7e-7da12448b297 6 | .AUTHOR soruly@gmail.com 7 | .DESCRIPTION search anime screenshot by trace.moe 8 | .TAGS anime image-search 9 | .ICONURI https://trace.moe/favicon128.png 10 | .PROJECTURI https://github.com/soruly/trace.moe-windows-menu 11 | .LICENSEURI https://github.com/soruly/trace.moe-windows-menu/blob/master/LICENSE 12 | #> 13 | 14 | param ( 15 | [switch]$install, 16 | [switch]$uninstall, 17 | [System.IO.FileInfo]$path 18 | ) 19 | $scriptPath = $MyInvocation.MyCommand.Path 20 | $RegistryPath = "Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\Search by trace.moe"; 21 | if ($install) { 22 | if (Test-Path $RegistryPath) { 23 | Remove-Item -Path $RegistryPath -Recurse -Force 24 | } 25 | New-Item -Path $RegistryPath -Name 'command' -Force | Out-Null; 26 | Set-ItemProperty -Path "$RegistryPath\command" -Name '(default)' -Value ('PowerShell -WindowStyle Hidden -File "' + $scriptPath + '" "%V"'); 27 | Set-ItemProperty -Path $RegistryPath -Name '(default)' -Value 'Search by trace.moe'; 28 | Set-ItemProperty -Path $RegistryPath -Name 'Icon' -Value "${Env:WinDir}\System32\shell32.dll,22"; 29 | exit 30 | } 31 | if ($uninstall) { 32 | if (Test-Path $RegistryPath) { 33 | Remove-Item -Path $RegistryPath -Recurse -Force 34 | } 35 | exit 36 | } 37 | if (-not($path)) { 38 | write-host "Usage:" $MyInvocation.MyCommand.Name "[-Path ] [-Install] [-Uninstall]" 39 | exit 40 | } 41 | if (-not(Test-Path -LiteralPath $path)) { 42 | Write-Host "Error: cannot read file " $path 43 | exit 44 | } 45 | 46 | Add-Type -AssemblyName PresentationFramework 47 | Add-Type -AssemblyName System.Drawing 48 | Add-Type -AssemblyName System.IO 49 | 50 | [xml]$xaml = @" 51 | 54 | 55 | 56 | 57 | 63 | 64 | "@ 65 | 66 | $XMLReader = (New-Object System.Xml.XmlNodeReader $xaml) 67 | $form = [Windows.Markup.XamlReader]::Load($XMLReader) 68 | 69 | $titleNative = $form.FindName("titleNative") 70 | $titleRomaji = $form.FindName("titleRomaji") 71 | $timeStamp = $form.FindName("timeStamp") 72 | $similarity = $form.FindName("similarity") 73 | $reference = $form.FindName("reference") 74 | $image = $form.FindName("image") 75 | $video = $form.FindName("video") 76 | $video.LoadedBehavior = [System.Windows.Controls.MediaState]::Manual; 77 | $video.Add_MediaEnded({ 78 | $video.Position = New-TimeSpan 0 79 | $video.Play(); 80 | }) 81 | 82 | $tempSource = Join-Path $env:TEMP -ChildPath "temp.jpg" 83 | $tempImage = Join-Path $env:TEMP -ChildPath "preview.jpg" 84 | $tempVideo = Join-Path $env:TEMP -ChildPath "preview.mp4" 85 | 86 | Copy-Item -LiteralPath $path -Destination $tempSource -Force 87 | 88 | Remove-Item -Path $tempImage 89 | Remove-Item -Path $tempVideo 90 | 91 | $image.Source = "$path" 92 | 93 | $form.Add_ContentRendered({ 94 | $response = Invoke-RestMethod -InFile "$tempSource" -Method Post "https://api.trace.moe/search?cutBorders&anilistInfo" 95 | Remove-Item -Path $tempSource 96 | $result = $response.result 97 | $topResult = $result[0] 98 | 99 | $form.Title = "trace.moe search result" 100 | $titleNative.Content = $topResult.anilist.title.native 101 | $titleRomaji.Content = $topResult.anilist.title.romaji 102 | $timeStamp.Content = [timespan]::fromseconds($topResult.from).tostring("hh\:mm\:ss") + " - " + [timespan]::fromseconds($topResult.to).tostring("hh\:mm\:ss") 103 | $similarity.Content = ($topResult.similarity).toString("P") 104 | $reference.Content = $topResult.filename 105 | 106 | $imageUri = New-Object System.Uri ($topResult.image + "&size=l") 107 | Invoke-WebRequest -URI $imageUri -OutFile $tempImage 108 | $image.Source = $tempImage 109 | 110 | $videoUri = New-Object System.Uri ($topResult.video + "&size=l&mute") 111 | Invoke-WebRequest -URI $videoUri -OutFile $tempVideo 112 | $video.Source = $tempVideo 113 | $video.Play() 114 | }) 115 | 116 | [void]$form.ShowDialog() 117 | 118 | $form.Close() 119 | Remove-Item -Force -Path $tempImage 120 | Remove-Item -Force -Path $tempVideo 121 | --------------------------------------------------------------------------------