Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Clear-Host
- function New-RandomFileName{
- Param ( [Parameter(Mandatory=0)][string]$Path ="$ENV:Temp",
- [Parameter(Mandatory=0)][string]$Extension = '.tmp',
- [Parameter(Mandatory=0)][int]$MaxLen = 7
- )
- if($Extension[0] -ne '.') { $Extension = $('.' + $Extension) }
- return Join-Path $Path $(((New-Guid).Guid).replace('-',(0..9 | Get-Random)).SubString(0,$MaxLen) + $Extension)
- }
- function Save-RedditVideo{
- param(
- [Parameter(Mandatory=$true, ValueFromPipeline=$true, HelpMessage="url", Position=0)]
- [string]$Url
- )
- try{
- $d = Invoke-RestMethod "$Url.json"
- $link = $d[0].data.children.data.secure_media.reddit_video.fallback_url
- Write-Output $link
- $fn = New-RandomFileName -Extension '.mp4'
- Write-Output $fn
- [System.Net.WebClient]::New().DownloadFile($link, $fn)
- #Invoke-WebRequest $link -Out $fn
- Invoke-Expression $fn
- } catch {
- $_.Exception.Message | Write-Warning
- return $null
- }
- }
- Save-RedditVideo 'https://www.reddit.com/r/ThisLooksFun/comments/w0glkr/thislooksfun/'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement