docker / build (push) Successful in 1m26s
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
75 lines
3.3 KiB
PowerShell
75 lines
3.3 KiB
PowerShell
# Вызов сервиса grabber-ai из PowerShell.
|
|
#
|
|
# Примеры (из корня проекта):
|
|
# powershell -NoProfile -ExecutionPolicy Bypass -File examples\powershell\predict.ps1 -Text "Перевод: Дублированный | MovieDalen"
|
|
# powershell -NoProfile -ExecutionPolicy Bypass -File examples\powershell\predict.ps1 -HtmlFile page.html
|
|
# powershell -NoProfile -ExecutionPolicy Bypass -File examples\powershell\predict.ps1 -ReleaseUrl "https://rutracker.org/forum/viewtopic.php?t=123"
|
|
# (kinozal: cookie обычно не нужен; если раздача закрыта для гостей — добавьте -Cookie "uid=..; pass=..")
|
|
# pwsh -File examples\powershell\predict.ps1 -Text "..." -Url http://host:8000
|
|
#
|
|
# Тело запроса отправляется UTF-8 байтами — это одинаково работает и в
|
|
# Windows PowerShell 5.1, и в PowerShell 7 (в 5.1 строковый -Body без этого
|
|
# уходит в ISO-8859-1 и кириллица ломается).
|
|
|
|
param(
|
|
[string]$Url = "http://127.0.0.1:8000",
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'Text')]
|
|
[string]$Text,
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'Html')]
|
|
[string]$HtmlFile,
|
|
[Parameter(Mandatory = $true, ParameterSetName = 'Release')]
|
|
[string]$ReleaseUrl,
|
|
[Parameter(ParameterSetName = 'Release')]
|
|
[string]$Cookie
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch { }
|
|
|
|
if ($HtmlFile) {
|
|
# [IO.File]::ReadAllText даёт чистую строку (Get-Content прикрепляет
|
|
# свойства PSPath, и ConvertTo-Json отправил бы объект вместо строки)
|
|
$path = (Resolve-Path -LiteralPath $HtmlFile).Path
|
|
$html = [IO.File]::ReadAllText($path, [Text.Encoding]::UTF8)
|
|
if ($html.Contains([string][char]0xFFFD)) { # utf-8 не вышел — пробуем cp1251
|
|
$html = [IO.File]::ReadAllText($path, [Text.Encoding]::GetEncoding(1251))
|
|
}
|
|
$payload = @{ html = $html }
|
|
} elseif ($ReleaseUrl) {
|
|
$payload = @{ url = $ReleaseUrl }
|
|
if ($Cookie) { $payload.cookie = $Cookie }
|
|
} else {
|
|
$payload = @{ text = $Text }
|
|
}
|
|
|
|
$json = $payload | ConvertTo-Json
|
|
$bytes = [Text.Encoding]::UTF8.GetBytes($json)
|
|
|
|
try {
|
|
$r = Invoke-RestMethod -Uri "$Url/predict" -Method Post `
|
|
-ContentType 'application/json' -Body $bytes
|
|
} catch {
|
|
if ($_.Exception.Response) {
|
|
# сервис ответил ошибкой (например, трекер вернул 403) — показываем его текст
|
|
$detail = $_.ErrorDetails.Message
|
|
Write-Error "Сервис вернул ошибку: $detail"
|
|
} else {
|
|
Write-Error "Сервис недоступен ($Url). Запуск: python -m src.service`n$_"
|
|
}
|
|
exit 1
|
|
}
|
|
|
|
if ($r.studios) {
|
|
"18+ релиза: $($r.is_18plus) типы: $($r.translation_types -join ', ')"
|
|
}
|
|
if ($r.tracks) {
|
|
$r.tracks | Format-Table translation_type, studio, is_18plus,
|
|
type_confidence -AutoSize
|
|
foreach ($t in $r.tracks) {
|
|
" текст: $($t.segment)"
|
|
if ($t.studio_span) { " спан: $($t.studio_span)" }
|
|
}
|
|
} else {
|
|
"дорожки озвучки не найдены"
|
|
}
|