Advertisement
Guest User

powershellScriptName.ps1

a guest
Mar 17th, 2023
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. Add-Type -AssemblyName System.Windows.Forms
  2. Add-Type -AssemblyName System.Drawing
  3. # Define the path to yt-dlp executable
  4. $ytDlpPath = ".\yt-dlp.exe"
  5.  
  6. # Define the download directory
  7. $downloadDir = "<downloadDirectory"
  8.  
  9. # Define the archive file path
  10. $archiveFilePath = ".\archive.txt"
  11.  
  12. # Define the destination directory for downloaded videos
  13. $destinationDir = "<destinationDirectory>"
  14.  
  15. # Define the notification title and message
  16. $notificationTitle = "New Youtube Videos"
  17.  
  18. # Download videos using yt-dlp
  19. & $ytDlpPath `
  20. --cookies-from-browser <browser>`
  21. --no-playlist `
  22. --break-on-existing `
  23. --dateafter today `
  24. --match-filter "!is_live & !post_live & !was_live" `
  25. --reject-title "livestream" `
  26. --concurrent-fragments 20 `
  27. --playlist-end 100 `
  28. --embed-chapters `
  29. --sponsorblock-mark all `
  30. --download-archive $archiveFilePath `
  31. --write-subs `
  32. --sub-format "ass/srt/best" `
  33. --sub-langs en.*,en,-live_chat `
  34. --convert-subs srt `
  35. --embed-metadata `
  36. --extractor-args "youtubetab:approximate_date" `
  37. -o "$downloadDir\[%(channel)s] - %(title)s.%(ext)s" :ytsubs://user/
  38. # Modify archive file
  39. $content = Get-Content -Path $archiveFilePath -Tail 10
  40. Set-Content -Path $archiveFilePath -Value $content
  41.  
  42. # Generate data for notification
  43. if (Test-Path "$downloadDir\*") {
  44. # Get all the video files in the download directory
  45. $videoFiles = Get-ChildItem -Path $downloadDir -File
  46.  
  47. # Create a dictionary to store the count of videos for each channel
  48. $channelCount = @{}
  49.  
  50. # Iterate through each video file and extract the channel name
  51. foreach ($file in $videoFiles) {
  52. # Extract the channel name from the file name
  53. $channelName = ($file.Name -split '\[|\]')[1]
  54.  
  55. # Increment the count for the channel in the dictionary
  56. if ($channelCount.ContainsKey($channelName)) {
  57. $channelCount[$channelName]++
  58. } else {
  59. $channelCount[$channelName] = 1
  60. }
  61. }
  62. $notificationMessage = ""
  63. $channelIndex = 0
  64.  
  65. foreach ($channel in $channelCount.Keys) {
  66. $count = $channelCount[$channel]
  67.  
  68. if ($count -eq 1) {
  69. # If there is only one video for the channel, just show the channel name
  70. $notificationMessage += "$channel"
  71. } else {
  72. # If there are multiple videos for the channel, show the channel name with the count in parentheses
  73. $notificationMessage += "$channel ($count)"
  74. }
  75. $channelIndex++
  76.  
  77. # Add a comma and space if this is not the last item in the dictionary
  78. if ($channelIndex -ne $channelCount.Count) {
  79. $notificationMessage += ", "
  80. }
  81. }
  82.  
  83. $notification = New-Object System.Windows.Forms.NotifyIcon
  84. $notification.Icon = [System.Drawing.SystemIcons]::Information
  85. $notification.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
  86. $notification.BalloonTipTitle = $notificationTitle
  87. $notification.BalloonTipText = $notificationMessage
  88.  
  89. # move all downloaded items to NAS
  90. Move-Item -Path "$downloadDir\*" -Destination $destinationDir
  91.  
  92. # Create an M3U playlist file with all the video files in the destination folder
  93. $playlistPath = Join-Path -Path $destinationDir -ChildPath "playlist.m3u"
  94. Get-ChildItem -Path $destinationDir -File | Where-Object { $_.Extension -in ".mp4", ".mkv", ".avi", ".webm" } | Select-Object -ExpandProperty FullName | Out-File -FilePath $playlistPath -Encoding utf8;
  95.  
  96. $notification.Visible = $true
  97. $notification.ShowBalloonTip(10000)
  98. $notification.Dispose()
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement