Advertisement
Guest User

Untitled

a guest
Aug 26th, 2022
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.44 KB | Science | 0 0
  1. $ErrorActionPreference = "Stop"
  2. $ProgressPreference = "SilentlyContinue"
  3.  
  4. $url = "https://archive.org/details/CNBC_20191029_170000_The_Exchange"
  5. $savePath = "C:\Temp"
  6.  
  7. $showName = Split-Path -Path $url -Leaf
  8. $showSavePath = [IO.Path]::Combine($savePath, $showName)
  9. if (!(Test-Path -Path $showSavePath)) { $null = mkdir $showSavePath }
  10.  
  11. $page = Invoke-WebRequest -Uri $url -UseBasicParsing
  12. if (!($page.Content -match "js-tv3-init.+?value='(.+?)'")) { throw "Failed to extract video segments from web page" }
  13.  
  14. $videoUrls = ($Matches[1] | ConvertFrom-Json).'TV3.clipstream_clips'
  15. $segmentCount = 1
  16. $ffmpegFileList = [IO.Path]::Combine($showSavePath, "ffmpegJoin.txt")
  17. foreach ($videoUrl in $videoUrls)
  18. {
  19.   $segmentFileName = [IO.Path]::Combine($showSavePath, "$($showName)_$($segmentCount.ToString('0000')).mp4")
  20.  
  21.   Write-Output "Downloading '$($videoUrl)' to '$($segmentFileName)'"
  22.   Invoke-WebRequest -Uri $videoUrl -UseBasicParsing -OutFile $segmentFileName
  23.  
  24.   "file '$($segmentFileName -replace "\\", "/")'" | Out-File -FilePath $ffmpegFileList -Encoding ascii -Append
  25.  
  26.   $segmentCount++
  27.  
  28.   #Start-Sleep -Milliseconds (Get-Random -Minimum 250 -Maximum 1500)
  29. }
  30.  
  31. $joinedVideoFileName = $segmentFileName = [IO.Path]::Combine($showSavePath, "$($showName).mp4")
  32. $ffArgs = @("-f concat", "-safe 0", "-i", "`"$ffmpegFileList`"", "-c copy", "`"$joinedVideoFileName`"")
  33.  
  34. Start-Process -FilePath ffmpeg -ArgumentList $ffArgs -Wait -NoNewWindow
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement