Skip to content

Instantly share code, notes, and snippets.

@m-hayabusa
Last active September 13, 2022 14:18
Show Gist options
  • Save m-hayabusa/1e2afe7d4225397d0fd47a4fbac6c4ba to your computer and use it in GitHub Desktop.
Save m-hayabusa/1e2afe7d4225397d0fd47a4fbac6c4ba to your computer and use it in GitHub Desktop.
VRCで撮った画像にタイムスタンプ入れるやつ

つかいかた

  1. write-timestamp.ps1を保存
  2. PowerShellを起動
  3. 実行
  • > write-timestamp.ps1 -Pathes @("C:\Program Files (x86)\Steam\userdata\308230826\760\remote\438100\screenshots", "C:\Users\hayabusa\Amazon Drive\Pictures\Quest") -DestPath "D:\VRCImage\" (そこにあるファイルに日付を付けてD:\VRCImageへ移動)
  • > write-timestamp.ps1 -Pathes "C:\Users\hayabusa\Pictures\VRChat" (-DestPathを指定しなければ移動しません)
Param(
[array]$Pathes,
$DestPath
)
$path_to_exiftool = "$($env:LocalAppData)\Programs\VRChat-Exif-Writer\node_modules\exiftool.exe\vendor\exiftool.exe"
$destDirRoot = $DestPath
$Pathes | ForEach-Object {
$_ | Get-ChildItem -Recurse | ForEach-Object {
$newDate = $null
$datetime = $null
$matched = $null
$year = $null
$mon = $null
if ($_ -match 'VRChat[_ ](?:(?:.*)_)?(\d+)[- ](\d+)[- ](\d+)[_ ](\d+)[- ](\d+)[- ](\d+).*.(?:(?:png)|(?:jpg))$') {
$matched = "image"
$newDate = "$($Matches.1):$($Matches.2):$($Matches.3) $($Matches.4):$($Matches.5):$($Matches.6)"
$year = $Matches.1
$mon = $Matches.2
}
if ($_ -match '(?:438100_)?(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})_1(?:_vr)?.(?:(?:jpg)|(?:png))$') {
if ($_ -match '.*Steam\\.*\\screenshots\\thumbnails\\.*') {
return
}
$matched = "image"
$newDate = "$($Matches.1):$($Matches.2):$($Matches.3) $($Matches.4):$($Matches.5):$($Matches.6)"
$year = $Matches.1
$mon = $Matches.2
}
elseif ($_ -match '(?:(?:com.vrchat.oculus.quest)|(?:VirtualDesktop.Android)|(?:com.polygraphene.alvr))-(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2}).(jpg|mp4)$') {
if ($Matches.7 -eq "jpg") {
$matched = "image"
} else {
$matched = "video"
}
$newDate = "$($Matches.1):$($Matches.2):$($Matches.3) $($Matches.4):$($Matches.5):$($Matches.6)"
$year = $Matches.1
$mon = $Matches.2
}
if ($matched -eq "image") {
$datetime = $(&${path_to_exiftool} -EXIF:DateTimeOriginal $_.FullName -charset utf8)
if ($datetime -eq $null) {
Write-host "WRITE" $_ $newDate
&${path_to_exiftool} -overwrite_original -EXIF:DateTimeOriginal=$newDate $_.FullName -charset utf8 > $null
} else {
Write-Host " " $_
}
} elseif ($matched -ne $null) {
Write-Host " " $_
}
if ($destDirRoot -ne $null -and $matched -ne $null) {
if ($mon.Length -eq 1) {
$mon = "0$mon"
}
$destDir = "$destDirRoot\$year-$mon\"
New-Item -ItemType Directory -Force -Path $destDir > $null
Move-Item -Path $_ -Destination $destDir
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment