Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- # Define the path to yt-dlp executable
- $ytDlpPath = ".\yt-dlp.exe"
- # Define the download directory
- $downloadDir = "<downloadDirectory"
- # Define the archive file path
- $archiveFilePath = ".\archive.txt"
- # Define the destination directory for downloaded videos
- $destinationDir = "<destinationDirectory>"
- # Define the notification title and message
- $notificationTitle = "New Youtube Videos"
- # Download videos using yt-dlp
- & $ytDlpPath `
- --cookies-from-browser <browser>`
- --no-playlist `
- --break-on-existing `
- --dateafter today `
- --match-filter "!is_live & !post_live & !was_live" `
- --reject-title "livestream" `
- --concurrent-fragments 20 `
- --playlist-end 100 `
- --embed-chapters `
- --sponsorblock-mark all `
- --download-archive $archiveFilePath `
- --write-subs `
- --sub-format "ass/srt/best" `
- --sub-langs en.*,en,-live_chat `
- --convert-subs srt `
- --embed-metadata `
- --extractor-args "youtubetab:approximate_date" `
- -o "$downloadDir\[%(channel)s] - %(title)s.%(ext)s" :ytsubs://user/
- # Modify archive file
- $content = Get-Content -Path $archiveFilePath -Tail 10
- Set-Content -Path $archiveFilePath -Value $content
- # Generate data for notification
- if (Test-Path "$downloadDir\*") {
- # Get all the video files in the download directory
- $videoFiles = Get-ChildItem -Path $downloadDir -File
- # Create a dictionary to store the count of videos for each channel
- $channelCount = @{}
- # Iterate through each video file and extract the channel name
- foreach ($file in $videoFiles) {
- # Extract the channel name from the file name
- $channelName = ($file.Name -split '\[|\]')[1]
- # Increment the count for the channel in the dictionary
- if ($channelCount.ContainsKey($channelName)) {
- $channelCount[$channelName]++
- } else {
- $channelCount[$channelName] = 1
- }
- }
- $notificationMessage = ""
- $channelIndex = 0
- foreach ($channel in $channelCount.Keys) {
- $count = $channelCount[$channel]
- if ($count -eq 1) {
- # If there is only one video for the channel, just show the channel name
- $notificationMessage += "$channel"
- } else {
- # If there are multiple videos for the channel, show the channel name with the count in parentheses
- $notificationMessage += "$channel ($count)"
- }
- $channelIndex++
- # Add a comma and space if this is not the last item in the dictionary
- if ($channelIndex -ne $channelCount.Count) {
- $notificationMessage += ", "
- }
- }
- $notification = New-Object System.Windows.Forms.NotifyIcon
- $notification.Icon = [System.Drawing.SystemIcons]::Information
- $notification.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
- $notification.BalloonTipTitle = $notificationTitle
- $notification.BalloonTipText = $notificationMessage
- # move all downloaded items to NAS
- Move-Item -Path "$downloadDir\*" -Destination $destinationDir
- # Create an M3U playlist file with all the video files in the destination folder
- $playlistPath = Join-Path -Path $destinationDir -ChildPath "playlist.m3u"
- Get-ChildItem -Path $destinationDir -File | Where-Object { $_.Extension -in ".mp4", ".mkv", ".avi", ".webm" } | Select-Object -ExpandProperty FullName | Out-File -FilePath $playlistPath -Encoding utf8;
- $notification.Visible = $true
- $notification.ShowBalloonTip(10000)
- $notification.Dispose()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement