Advertisement
SkullzyXue

Get Sonarr Episode Data

Jan 7th, 2021
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://github.com/Sonarr/Sonarr/wiki/EpisodeFile
  2. # https://github.com/Sonarr/Sonarr/wiki/Series
  3.  
  4. $url = "http://127.0.0.1:8989/sonarr/api" # copy/paste your sonarr url, add API to the end of it.
  5. $apikey = "?apikey={SONARR API KEY}"
  6.  
  7. $Series = Invoke-RestMethod -Uri "$($url)/series$($apikey)" -Method Get
  8.  
  9. $csv = [ordered]@{
  10.     Title = @()
  11.     Season = @()
  12.     Episode = @()
  13.     Resolution = @()
  14.     QualityName = @()
  15.     QualitySrc = @()
  16.     VideoCodec = @()
  17.     AudioChannels = @()
  18.     AudioCodecs = @()
  19.     RelativePath = @()
  20. }
  21.  
  22. ForEach( $s in $Series ) {
  23.    
  24.     $Episodes = Invoke-RestMethod -Uri "$($url)/episodefile$($apikey)&seriesId=$($s.id)" -Method Get
  25.  
  26.     ForEach( $e in $Episodes ) {
  27.  
  28.         if( $($e.relativePath -imatch "S\d+E\d+") ) {
  29.        
  30.             $csv.Title += @($s.title)
  31.             $csv.Season += @($Matches[0] -replace '(S|E\d+)','')
  32.             $csv.Episode += @($Matches[0] -replace '(E|S\d+)','')
  33.             $csv.Resolution +=  @($e.quality.quality.resolution)
  34.             $csv.QualityName += @($e.quality.quality.name)
  35.             $csv.QualitySrc +=  @($e.quality.quality.source)
  36.             $csv.VideoCodec += @($e.mediaInfo.videoCodec)
  37.             $csv.AudioChannels += @($e.mediaInfo.audioChannels)
  38.             $csv.AudioCodecs += @($e.mediaInfo.audioCodec)
  39.             $csv.RelativePath += @($e.relativePath)
  40.  
  41.         }
  42.  
  43.     }
  44.  
  45. }
  46.  
  47. if( $csv.Title.count -gt 0 ) {
  48.  
  49.     $count  = $csv.Values | ForEach-Object { $_.Count }| Select-Object -Last 1
  50.  
  51.     $keys = $csv.Keys
  52.  
  53.     0..($count-1) | ForEach-Object {
  54.  
  55.       $props = [ordered]@{}
  56.  
  57.       foreach ($key in $keys) {
  58.  
  59.         $props[$key] = $csv[$key][$_]
  60.  
  61.       }
  62.  
  63.       New-Object -Type PSObject -Property $props
  64.  
  65.     } | Export-Csv -Path "C:$($env:HOMEPATH)\Desktop\episodelist.csv" -NoTypeInformation
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement