Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #powershell script to scrape discovery plus easier (LEGAL- need paid account, but free trial works too)
- while (! ((Read-Host -Prompt "Show URL (e.g. discoveryplus.com/show/alone)") -match "/show/([\w\-]+)") ) {
- Write-Host "Invalid URL!"
- }
- $altid = $Matches[1]
- while (!(($input0 -eq "y") -or ($input0 -eq "n"))) {
- $input0 = (Read-Host -Prompt "Do you want ALL seasons? (y/n)").ToLower()
- }
- $want_all_seasons = $input0 -eq "y"
- $want_seasons = @()
- while (!($want_all_seasons -or $want_seasons[0])) {
- $want_seasons = (Read-Host -Prompt "Type list of seasons (e.g. 2,3)") -split "\D+"
- }
- while (!(($qualityInput -eq "y") -or ($qualityInput -eq "n"))) {
- $qualityInput = (Read-Host -Prompt "Do you want 720p files to save space and time? Otherwise max. (y/n)").ToLower()
- }
- $browser = Read-Host -Prompt "Browser (e.g. brave,chrome)"
- Read-Host -Prompt "Full path where season folders should go (leave blank for no change)" | cd
- Write-Host; Write-Host "---------------------------";Write-Host
- #token / cookie is required to use api, so create anonymous one
- $token = (ConvertFrom-Json (iwr "https://us1-prod-direct.discoveryplus.com/token?realm=go&shortlived=true").Content).Data.attributes.token
- $cookie = New-Object System.Net.Cookie -Property @{ Name="st"; Value=$token; Domain="us1-prod-direct.discoveryplus.com" }
- $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
- $session.Cookies.Add($cookie)
- #fetch hidden information
- $jsonDump = ConvertFrom-Json (iwr ("https://us1-prod-direct.discoveryplus.com/cms/routes/show/"+$altid+"?include=default") -WebSession $session -Headers @{"accept" = "*/*"; "x-disco-client" = "WEB:UNKNOWN:dplus_us:2.25.4"; "x-disco-params" = "realm=go,bid=dplus,hn=www.discoveryplus.com,hth=,features=ar"}).Content
- foreach ($inc in $jsonDump.included) {
- if ($inc.attributes -and ($inc.attributes.alternateId -eq $altid)) {
- $showIdStr = $inc.attributes.analyticsId.Substring(3)
- $trueSeasons = $inc.attributes.seasonNumbers
- } ElseIf ($inc.attributes -and ($inc.attributes.name -eq "generic-show-episodes")) {
- $cmsid = $inc.id
- }
- if ($showIdStr -and $cmsid) { break }
- }
- if ($want_all_seasons) {
- $want_seasons = $trueSeasons
- }
- $dlformat = "bv[vbr<9000]+ba"
- if ($qualityInput -eq "y") {
- $dlformat = "(bv[vbr<3100]/wv)+(ba[abr<150]/wa)"
- }
- foreach ($season in @($want_seasons)) {
- $old = $jsonDump
- #fetch list of episodes from database
- $jsonDump = ConvertFrom-Json (iwr ("https://us1-prod-direct.discoveryplus.com/cms/collections/"+$cmsid+"?include=default&pf[seasonNumber]="+$season+"&pf[show.id]="+$showIdStr) -WebSession $session -Headers @{"accept" = "*/*"; "x-disco-client" = "WEB:UNKNOWN:dplus_us:2.25.4"; "x-disco-params" = "realm=go,bid=dplus,hn=www.discoveryplus.com,hth=,features=ar"}).Content
- if ($old -eq $jsonDump ) { continue }
- #loop thru and download videos
- For ($i=0; $i -lt $jsonDump.included.Length; $i++) { #foreach isn't in order
- $inc = $jsonDump.included[$i]
- if ($inc.relationships -and $inc.relationships.show -and ($inc.relationships.show.data.id -eq $showIdStr) -and ($inc.attributes.path.IndexOf("-trailer") -eq -1)) {
- yt-dlp ("https://www.discoveryplus.com/video/"+$inc.attributes.path) --cookies-from-browser $browser -f $dlformat -o ("/S"+$season+"/E%(episode_number)02d %(title)s.%(ext)s") --retry-sleep exp=1
- }
- }
- }
- Read-Host -Prompt "ALL DONE!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement