diff --git a/README.md b/README.md index 5954c3f..307594d 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ npm link | Unix | Fish | Musickiller | [Ссылка](https://gitlab.com/musickiller/fishy-voice-over/) | Linux | Bash | s-n-alexeyev | [Ссылка](https://github.com/s-n-alexeyev/yvt) | Cloud | Google Colab | alex2844 | [Ссылка](https://github.com/alex2844/youtube-translate) +3. Скрипт для скачивания видео со встроенными субтитрами (надстройка над vot-cli): [Cсылка](./scripts/) ## ❗ Примечание diff --git a/scripts/README.md b/scripts/README.md index b6e040f..7e8a1e6 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,4 +1,9 @@ -## Powershell by Dragoy +# Кастомные скрипты + +1. Translate (Powershell by Dragoy) — Скачивает видео, перевод и смешивает +2. Translate_subs — Скачивает видео, субтитры и смешивает + +## Translate (Powershell by Dragoy) ### 🔱 Зависимости @@ -27,4 +32,4 @@ Скрипт загрузит видео, добавит русский закадровый голос и объединит звуковые дорожки. Переведенное видео будет сохранено в той же директории, что и скрипт. ### Notes -- Команды `yt-dlp`, `ffmpeg`, `vot-cli` должны быть доступны из командной строки. Убедитесь, что пути к их исполняемым файлам добавлены в переменную окружения PATH вашей системы. +- Команды `yt-dlp`, `ffmpeg`, `vot-cli` должны быть доступны из командной строки. Убедитесь, что пути к их исполняемым файлам добавлены в переменную окружения PATH вашей системы. \ No newline at end of file diff --git a/scripts/translate_subs.ps1 b/scripts/translate_subs.ps1 new file mode 100644 index 0000000..eb289e5 --- /dev/null +++ b/scripts/translate_subs.ps1 @@ -0,0 +1,64 @@ +# Скрипт для PowerShell, который скачивает видео, субтитры и вшивает их (hard-subs, вжигание) (на основе скрипта Dragoy) +# +# Использование: +# .\translate_subs_embed.ps1 <ссылка на видео 1> <ссылка на видео 2> ... +# +# Настройки внешнего вида субтитров задаются на строчке "Вшиваем субтитры с помощью ffmpeg" + +function ProcessVideo($video_link) { + # Создаём временные папки + New-Item -ItemType Directory -Path $temp_dir -ErrorAction SilentlyContinue | Out-Null + New-Item -ItemType Directory -Path $temp_video_dir -ErrorAction SilentlyContinue | Out-Null + New-Item -ItemType Directory -Path $temp_subs_dir -ErrorAction SilentlyContinue | Out-Null + + # Скачиваем видео + yt-dlp -o $temp_video $video_link + + # Скачиваем переведённые субтитры с помощью vot-cli + vot-cli $video_link --subs-srt --output $temp_subs_dir + + # Получаем имена файлов + $video_file = (Get-ChildItem -Path $temp_video_dir | Where-Object { $_.Extension -match "mp4|mkv|webm" })[0].FullName + $subs_file = (Get-ChildItem -Path $temp_subs_dir -Filter *.srt)[0].FullName + + # Подготавливаем путь к субтитрам для ffmpeg в Windows + # Это исправляет ошибку, когда ffmpeg не может найти файл из-за двоеточия в пути (C:\...) + $escaped_subs_path = $subs_file.Replace('\', '/') -replace ':', '\:' + + # Формируем имя итогового файла + $video_base_name = [System.IO.Path]::GetFileNameWithoutExtension($video_file) + $video_ext = [System.IO.Path]::GetExtension($video_file) + $output_file = Join-Path (Get-Location) "$video_base_name-sub$video_ext" + + # Вшиваем субтитры с помощью ffmpeg + ffmpeg -i "$video_file" -vf "subtitles='$escaped_subs_path':force_style='FontSize=12'" -c:a copy -y "$output_file" + + Write-Host "Video with subtitles saved: $output_file" + + # Удаляем временные папки + Remove-Item -Recurse -Force $temp_dir +} + +# Папки +$temp_dir = "./temp" +$temp_video_dir = "$temp_dir/video" +$temp_video = "$temp_video_dir/%(title)s.%(ext)s" +$temp_subs_dir = "$temp_dir/subs" + +# Список ссылок +$video_links = $args + +# Проверка ссылок +if ($video_links) { + foreach ($video_link in $video_links) { + if ([string]::IsNullOrEmpty($video_link)) { + Write-Host "Error: reference not entered." + continue + } + + Write-Host "Processing video: $video_link" + ProcessVideo $video_link + } +} else { + Write-Host "Error: no video links." +} \ No newline at end of file