-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_Helpers.ps1
59 lines (47 loc) · 1.25 KB
/
_Helpers.ps1
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
function Get-YtVideoStatus {
param(
[string]$videoId
)
$output = yt-dlp --no-warnings --skip-download --flat-playlist "https://www.youtube.com/watch?v=$videoId" -j
if ($LASTEXITCODE -ne 0) {
Throw "Failed to get video info for $videoId"
}
$videoInfo = $output | ConvertFrom-Json
$status = $videoInfo.availability
return $status
}
function UpdateFile {
param(
[string]$file,
[string]$videoId,
[string]$status
)
$content = Get-Content $file
$content = $content -replace "$videoId.*", "$videoId $status"
Set-Content $file $content
}
function Scan-Videos {
<#
.SYNOPSIS
Scans a youtube-dl archive file (text file with a list of video ids) and checks their status -
Checks if any videos have been removed or marked private
#>
param(
[string]$ArchiveFilePath
)
$videos = Get-Content $ArchiveFilePath
foreach ($v in $videos) {
$null, $vid, $status = $v -split ' '
if ([string]::IsNullOrEmpty($vid)) {
continue
}
if (!([string]::IsNullOrEmpty($status))) {
continue
}
$status = Get-YtVideoStatus $vid
Write-Debug "Dected video status: $vid $status"
# Read-Host | Out-Null
UpdateFile $ArchiveFilePath $vid $status
Start-Sleep -Milliseconds 100
}
}