From cf06adbfab9566c5cbbc7112c737859d92434d52 Mon Sep 17 00:00:00 2001 From: Alexey Barabanov Date: Mon, 10 Nov 2025 13:14:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=A9=D0=95=20=D0=A6=D0=A9=D0=9A=D0=9B?= =?UTF-8?q?=D0=A8=D0=A2=D0=9F!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- replace.bat | 61 ++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/replace.bat b/replace.bat index 8f95f44..ac6e9df 100644 --- a/replace.bat +++ b/replace.bat @@ -1,42 +1,41 @@ @echo off -chcp 65001 >nul -setlocal enabledelayedexpansion +setlocal -if "%~1"=="" ( - echo ERROR: Specify file path - echo Example: replace.bat "C:\path\to\file.xml" "https://gfx.tvstart.ru" - exit /b 1 -) -if "%~2"=="" ( - echo ERROR: Specify new URL - echo Example: replace.bat "C:\path\to\file.xml" "https://gfx.tvstart.ru" - exit /b 1 +set "vmix_file=%~1" +if "%vmix_file%"=="" ( + echo Usage: %0 filename.vmix + pause + exit /b 1 ) -set "FILE=%~1" -set "NEWURL=%~2" - -if not exist "!FILE!" ( - echo ERROR: File not found: !FILE! - exit /b 1 +if not exist "%vmix_file%" ( + echo File "%vmix_file%" not found! + pause + exit /b 1 ) -echo Processing: !FILE! -echo New URL: !NEWURL! -echo. +set "replace=https://per.tvstart.ru" +set "temp_file=%vmix_file%.tmp" -copy "!FILE!" "!FILE!.backup" >nul 2>&1 -if !errorlevel! equ 0 ( - echo Backup created: !FILE!.backup +echo Processing: %vmix_file% + +powershell -Command " +$content = Get-Content '%vmix_file%' -Raw +$pattern = 'https?:\/\/\d*\.\d*\.\d*\.\d*:\d*|https?:\/\/\w*\.\w*\.\w*' +$replacement = '%replace%' +$result = $content -replace $pattern, $replacement +$result | Out-File '%temp_file%' -Encoding UTF8 +" + +if exist "%temp_file%" ( + move /y "%temp_file%" "%vmix_file%" > nul + echo Replacement completed successfully! + echo URLs matching these patterns were replaced: + echo - IP addresses with ports (http://127.0.0.1:8000 etc.) + echo - Three-part domains (https://gfx.tvstart.ru etc.) + echo Replacement: %replace% ) else ( - echo WARNING: Backup failed + echo Error: Failed to process file ) -powershell -Command "$content = [System.IO.File]::ReadAllText('%FILE%'); $pattern = 'http[s]?://[^/<\"]+(/[^<\"]*)?'; $content = $content -replace $pattern, '%NEWURL%$1'; [System.IO.File]::WriteAllText('%FILE%', $content, [System.Text.Encoding]::UTF8); Write-Host 'SUCCESS: Replacement completed'" - -if errorlevel 1 ( - echo ERROR: PowerShell command failed -) - -echo. pause \ No newline at end of file