Watching German TV Shows

by Apr 5, 2021

German public broadcasting companies maintain rich TV archives and let users view their shows through web interfaces. There is typically no way to download shows or easily find their download URLs.

The following script downloads an unofficial directory listing of all the shows and their network locations:

# download the German mediathek database as JSON file
$path = "$env:temp\tv.json"
$url = 'http://www.mediathekdirekt.de/good.json'
Invoke-RestMethod -Uri $url -UseBasicParsing -OutFile $path

Once you have downloaded this file, you can use another script to display a selection dialog and browse for TV shows you’d like to watch. You can then select one or more shows and ask PowerShell to automatically download these videos to your computer.

$Path = "$env:temp\tv.json"

$data = Get-Content -Path $Path -Raw | 
ConvertFrom-Json |
ForEach-Object { $_ } |
ForEach-Object {
  # define a string describing the video. This string will be shown in a grid view window
  $title = '{0,5} [{2}] "{1}" ({3})' -f ([Object[]]$_)
  # add the original data to the string so when the user select a video,
  # the details i.e. download URL is still available
  $title | Add-Member -MemberType NoteProperty -Name Data -Value $_ -PassThru
}

$data |
Sort-Object |
Out-GridView -Title 'Select Video(s)' -OutputMode Multiple |
ForEach-Object {
  # take the download URL from the attached original data
  $url = $_.Data[5]
  $filename = Split-Path -Path $url -Leaf
  $filepath = Join-Path -Path $env:temp -ChildPath $filename
  $title = 'Video download {0} ({1})' -f $_.Data[1], $_.Data[0]
  Start-BitsTransfer -Description $title -Source $url -Destination $filepath
  # you can use a simple web request as well in case BITS isn't available
  # Invoke-WebRequest -Uri $url -OutFile $filepath -UseBasicParsing
  
  # open video in associated player
  Invoke-Item -Path $filepath
}


Twitter This Tip! ReTweet this Tip!