Advertisement
sirelkilla

discovery + yt-dlp helper

Jul 31st, 2023 (edited)
1,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #powershell script to scrape discovery plus easier (LEGAL- need paid account, but free trial works too)
  2. while (! ((Read-Host -Prompt "Show URL (e.g. discoveryplus.com/show/alone)") -match "/show/([\w\-]+)") ) {
  3.     Write-Host "Invalid URL!"
  4. }
  5. $altid = $Matches[1]
  6. while (!(($input0 -eq "y") -or ($input0 -eq "n"))) {
  7.     $input0 = (Read-Host -Prompt "Do you want ALL seasons? (y/n)").ToLower()
  8. }
  9. $want_all_seasons = $input0 -eq "y"
  10. $want_seasons = @()
  11. while (!($want_all_seasons -or $want_seasons[0])) {
  12.     $want_seasons = (Read-Host -Prompt "Type list of seasons (e.g. 2,3)") -split "\D+"
  13. }
  14. while (!(($qualityInput -eq "y") -or ($qualityInput -eq "n"))) {
  15.     $qualityInput = (Read-Host -Prompt "Do you want 720p files to save space and time? Otherwise max. (y/n)").ToLower()
  16. }
  17. $browser = Read-Host -Prompt "Browser (e.g. brave,chrome)"
  18. Read-Host -Prompt "Full path where season folders should go (leave blank for no change)" | cd
  19. Write-Host; Write-Host "---------------------------";Write-Host
  20. #token / cookie is required to use api, so create anonymous one
  21. $token = (ConvertFrom-Json (iwr "https://us1-prod-direct.discoveryplus.com/token?realm=go&shortlived=true").Content).Data.attributes.token
  22. $cookie = New-Object System.Net.Cookie -Property @{ Name="st"; Value=$token; Domain="us1-prod-direct.discoveryplus.com" }
  23. $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
  24. $session.Cookies.Add($cookie)
  25. #fetch hidden information
  26. $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
  27. foreach ($inc in $jsonDump.included) {
  28.     if ($inc.attributes -and ($inc.attributes.alternateId -eq $altid)) {
  29.         $showIdStr = $inc.attributes.analyticsId.Substring(3)
  30.         $trueSeasons = $inc.attributes.seasonNumbers
  31.     } ElseIf ($inc.attributes -and ($inc.attributes.name -eq "generic-show-episodes")) {
  32.         $cmsid = $inc.id
  33.     }
  34.     if ($showIdStr -and $cmsid) { break }
  35. }
  36. if ($want_all_seasons) {
  37.     $want_seasons = $trueSeasons
  38. }
  39. $dlformat = "bv[vbr<9000]+ba"
  40. if ($qualityInput -eq "y") {
  41.     $dlformat = "(bv[vbr<3100]/wv)+(ba[abr<150]/wa)"
  42. }
  43. foreach ($season in @($want_seasons)) {
  44.     $old = $jsonDump
  45.     #fetch list of episodes from database
  46.     $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
  47.     if ($old -eq $jsonDump ) { continue }
  48.     #loop thru and download videos
  49.     For ($i=0; $i -lt $jsonDump.included.Length; $i++) { #foreach isn't in order
  50.         $inc = $jsonDump.included[$i]
  51.         if ($inc.relationships -and $inc.relationships.show -and ($inc.relationships.show.data.id -eq $showIdStr) -and ($inc.attributes.path.IndexOf("-trailer") -eq -1)) {
  52.             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
  53.         }
  54.     }
  55. }
  56. Read-Host -Prompt "ALL DONE!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement