Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

## ❗ Примечание

Expand Down
9 changes: 7 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## Powershell by Dragoy
# Кастомные скрипты

1. Translate (Powershell by Dragoy) — Скачивает видео, перевод и смешивает
2. Translate_subs — Скачивает видео, субтитры и смешивает

## Translate (Powershell by Dragoy)

### 🔱 Зависимости

Expand Down Expand Up @@ -27,4 +32,4 @@
Скрипт загрузит видео, добавит русский закадровый голос и объединит звуковые дорожки. Переведенное видео будет сохранено в той же директории, что и скрипт.

### Notes
- Команды `yt-dlp`, `ffmpeg`, `vot-cli` должны быть доступны из командной строки. Убедитесь, что пути к их исполняемым файлам добавлены в переменную окружения PATH вашей системы.
- Команды `yt-dlp`, `ffmpeg`, `vot-cli` должны быть доступны из командной строки. Убедитесь, что пути к их исполняемым файлам добавлены в переменную окружения PATH вашей системы.
64 changes: 64 additions & 0 deletions scripts/translate_subs.ps1
Original file line number Diff line number Diff line change
@@ -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."
}