83 lines
3.0 KiB
PowerShell
83 lines
3.0 KiB
PowerShell
## Patreon Regulation
|
|
# Set URL and Location
|
|
$URL = "https://www.patreon.com/cw/TheRegulationPod"
|
|
$folderPath = "\\truenas3.kwyjibo.info\RegulationPodcast$"
|
|
|
|
Set-Location $folderPath
|
|
|
|
$rejects = @()
|
|
$rejects_string = $rejects -join '|'
|
|
|
|
# Download flat playlist
|
|
Write-Verbose -Message "Download flat playlist"
|
|
$flat = D:\youtube-dlp\yt-dlp.exe -j --flat-playlist $URL
|
|
$flat | Set-Content -Path Patreon_TheRegulationPod.json
|
|
|
|
# load json into memory, convert to psobject
|
|
$json = Get-Content -Path Patreon_TheRegulationPod.json | ConvertFrom-Json
|
|
|
|
# Load all .mp4 files into memory once at the start
|
|
$mp4Files = Get-ChildItem -Path $folderPath -Recurse -Filter "*.mp4"
|
|
|
|
ForEach ($obj in $json) {
|
|
# Initialize $fileFound as null for each iteration
|
|
$fileFound = $false
|
|
|
|
# Extract information from the JSON object
|
|
$videoUrl = $obj.webpage_url
|
|
$Title = $obj.title
|
|
$Id = $obj.id
|
|
|
|
# Log the start of the process
|
|
Write-Verbose -Message "Start $Id ##### $Title"
|
|
|
|
# Check if the title matches any reject term using wildcards
|
|
$reject_matches = $rejects | Where-Object { $Title -like "*$($_)*" }
|
|
|
|
# If matches are found, reject the title
|
|
If ($reject_matches) {
|
|
Write-Warning -Message "Skip $Id ##### $Title"
|
|
}
|
|
Else {
|
|
# downloaded already?
|
|
# Regular expression to match the ID after "patreon-" and before the closing bracket
|
|
$regex = "(?i)patreon-$Id"
|
|
|
|
# Check if any file already exists that matches the video ID
|
|
$fileFound = $mp4Files | Where-Object { $_.Name -match $regex }
|
|
|
|
# If no file is found, notify the user
|
|
if ($fileFound) {
|
|
Write-Warning "File found with the Patreon ID: $Id"
|
|
}
|
|
Else {
|
|
# Execute yt-dlp command for non-rejected videos
|
|
try {
|
|
Write-Warning -Message "Dwnld $Id ##### $Title"
|
|
#$attemptedDownloads.Add($obj)
|
|
D:\youtube-dlp\yt-dlp.exe $URL `
|
|
--write-info-json `
|
|
--write-thumbnail `
|
|
--convert-thumbnails jpg `
|
|
--no-progress `
|
|
-t sleep `
|
|
--rate-limit 5M `
|
|
-o "Unsorted/Season %(release_date>%y,upload_date>%y|Unknown)s/%(release_date>%Y%m%d,upload_date>%Y%m%d)s - %(title).180B [%(extractor)s-%(id)s].%(ext)s" `
|
|
-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" `
|
|
-S vcodec:h264 `
|
|
--reject-title $rejects_string `
|
|
--cookies-from-browser firefox #"D:\youtube-dlp\20251024_currentsite_cookies.firefox-private.txt"
|
|
# --playlist-reverse `#`
|
|
#--extractor-args "youtube:player_client=default,web_safari;player_js_version=actual"
|
|
# --reject-title "Dude Soup|Podcast" ` # FH
|
|
}
|
|
catch {
|
|
Write-Error "Failed to download $Id - $_"
|
|
}
|
|
}
|
|
}
|
|
|
|
# Log the end of the process
|
|
Write-Verbose -Message "End $Id ##### $Title"
|
|
}
|