Repository navigation
Expand file tree
/
Copy pathClear-WatchedVideo.ps1
More file actions
66 lines (62 loc) · 2.75 KB
/
Copy pathClear-WatchedVideo.ps1
File metadata and controls
66 lines (62 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[string] $VideoFileOrArgumentList
)
function Test-VideoExtension($file) {
$file.Extension -eq ".mp4" -or $file.Extension -eq ".webm" -or $file.Extension -eq ".3gp" -or $file.Extension -eq ".mkv" `
-or ($file.Directory.Name -ieq "Videos" -and $file.Extension -eq ".json")
}
function Replace-VideoWithMarker($file) {
$fileDirectory = $file.Directory.FullName
$marker = $file.BaseName + ".txt"
$newFile = New-Item -Path $fileDirectory -Name $marker -ItemType File
# .json file is typically when the "Mark Downloaded" feature of Backup-VideoDescription was used.
# Set marker date to when the json file was created (last modified is video publishing date, and today's date is not correct)
if ($file.Extension -eq ".json") {
$dateWatched = Get-Date -Format "o" $file.CreationTime
} else {
$dateWatched = Get-Date -Format "o"
}
$dateWatched | Out-File -Encoding ASCII -LiteralPath $newFile
$newFile.LastWriteTime = $file.LastWriteTime
Remove-ItemSafely -LiteralPath $file.FullName
Write-Information -InformationAction Continue "Wrote marker to replace $file"
# Find related files and move them to the Recycle Bin
#$escapedBaseName = [Management.Automation.WildCardPattern]::Escape($file.BaseName)
$relatedFiles = Get-ChildItem -LiteralPath $fileDirectory -Filter ($file.BaseName + ".*") | ? { $_ -notlike '*.txt' }
if ($relatedFiles) {
Remove-ItemSafely -LiteralPath $relatedFiles
}
Write-Information -InformationAction Continue "Recycled related files:"
foreach ($file in $relatedFiles) {
Write-Information -InformationAction Continue $file
}
}
if (Test-Path -LiteralPath $VideoFileOrArgumentList) {
$file = Get-ChildItem $VideoFileOrArgumentList
if (Test-VideoExtension $file) {
Replace-VideoWithMarker $file
} else {
# Argument list is stored in a file, something which TotalCommander tends to do
$argumentList = Get-Content $file.FullName
foreach ($filePath in $argumentList) {
if (Test-Path -LiteralPath $filePath) {
$file = Get-ChildItem -LiteralPath $filePath
if (Test-VideoExtension $file) {
Replace-VideoWithMarker $file
} else {
Write-Error "File $file does not have a known video extension"
}
} else {
Write-Error "File $file does not have a known video extension or isn't a file list. File $filePath not found"
break
}
}
}
Write-Host "Done"
pause
} else {
Write-Error "File $VideoFile not found"
pause
}