参照している素材ファイルごとコピーするプログラムです。実行前に関連ファイルのバックアップを強く推奨。
<#
.SYNOPSIS
ゆっくりムービーメーカー4のYMMPファイルをコピー
.DESCRIPTION
YMMPファイル以外に素材ファイルをコピー先のディレククトリにサブディレクトリ作成しコピー
.EXAMPLE
実行例
.INPUTS
入力
.OUTPUTS
出力
.PARAMETER 引数名
引数
.LINK
関連URL
#>
param(
[string]
$srcFile="コピー元の.ymmpのパス",
[string]
$dstFile="コピー先.ymmpのパス"
)
#Write-Host $srcFile
#Write-Host $dstFile
$dstDir = Split-Path $dstFile
$srcDir = Split-Path $srcFile
$audioDir = Join-Path $dstDir "Audio"
$videoDir = Join-Path $dstDir "Video"
$imageDir = Join-Path $dstDir "Image"
$textDir = Join-Path $dstDir "Text"
$outputDir = Join-Path $dstDir "Output"
if (-not (Test-Path $audioDir)) { New-Item $audioDir -ItemType Directory }
if (-not (Test-Path $videoDir)) { New-Item $videoDir -ItemType Directory }
if (-not (Test-Path $imageDir)) { New-Item $imageDir -ItemType Directory }
if (-not (Test-Path $textDir)) { New-Item $textDir -ItemType Directory }
if (-not (Test-Path $outputDir)) { New-Item $outputDir -ItemType Directory }
# チャプターファイルのコピー
$basename = [System.IO.Path]::GetFileNameWithoutExtension($srcFile)
$chapterSrcFile = Join-Path $srcDir "${basename}.txt"
if (Test-Path $chapterSrcFile) {
$chapterDstFile = Join-Path $outputDir "${basename}.txt"
Copy-Item -Path $chapterSrcFile -Destination $chapterDstFile -Force
}
# ymmp読み込み
$data = Get-Content -LiteralPath $srcFile -Encoding UTF8 | ConvertFrom-Json
# YMMPファイルのパスをセット
$data.FilePath = $dstFile
# Itemsの件数取得
$count = ($data.Timelines.Items).Count
for ($i = 0; $i -lt $count; $i++)
{
# Itemsループ
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.VoiceItem, YukkuriMovieMaker") {
# 読み上げ音声
# 何もしない
continue
}
$source = $data.Timelines.Items[$i].FilePath
$fileName = Split-Path $source -Leaf
$destination = ""
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.VideoItem, YukkuriMovieMaker") {
# 動画
$destination = Join-Path $videoDir $fileName
}
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.AudioItem, YukkuriMovieMaker") {
# 音声
$destination = Join-Path $audioDir $fileName
}
if ($data.Timelines.Items[$i].'$type' -eq "YukkuriMovieMaker.Project.Items.ImageItem, YukkuriMovieMaker") {
# 静止画
$destination = Join-Path $imageDir $fileName
}
Write-Host $destination
# 素材ファイルのコピー
Copy-Item -Path $source -Destination $destination -Force
# コピー先のパスをセット
$data.Timelines.Items[$i].FilePath = $destination
}
# YMMPファイルの保存
$data | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $dstFile -Encoding UTF8
コメント