是不是会从油管载几个音乐视频,为了方便转换为MP3,在Win10试了PowerShell,尚未完全批处理,分为步骤如下:
1. 搜集目录下近期下载的MV文件列表
```
# List input file name
Get-ChildItem -Path I:\YOUGET\MusicVideos\*.mp4 |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-30) } |
Select Name
```
2. 自定义输出的MP3文件名,将其与对应的输入文件名一起存放到一个字符串中,稍后转换为一个Hashtable结构。
```
# Construct a hashtable, using Output MP3 name as key, and input file name as Value.
$nmapping=@"
mp3-file1 = ...
mp3-file2 = ...
mp3-file3 = ...
"@
$hash = ConvertFrom-StringData $nmapping
```
3. 遍历Hashtable的元素,执行 ffmpeg 命令来转换为MP3。
```
# Loop the hash table, and run ffmpeg
foreach ($h in $hash.GetEnumerator()) {
$InputFileName = "I:\YOUGET\MusicVideos\" + "$($h.Value)"
$OutputFileName = "I:\YOUGET\MP3\" + "$($h.Name)" + ".MP3"
Write-Host "Convertign $InputFileName to $OutputFileName ..."
ffmpeg -i "$InputFileName" -vn -ab 256k "$OutputFileName"
}
```
参考了以下文档:
1. [The PowerShell Foreach Loop](https://adamtheautomator.com/powershell-foreach/) and a similar discussion in [StackOverflow](https://stackoverflow.com/questions/9015138/looping-through-a-hash-or-using-an-array-in-powershell)
2. [Use Get-ChildItem to Find Files by Date and Time](https://www.pdq.com/blog/using-get-childitem-find-files/)
3. [PowerShell: About HashTable](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7.2#displaying-hash-tables)
4. [ffmpeg之常用音频转换](https://dangger.github.io/2015/10/30/index.html)
评论