Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scrape Rotten Tomatoes
$RadarrURL = 'http://127.0.0.1:7878'
$RadarrAPIKey = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
#$MovieName = "I Called Him Morgan"
$qualityProfileId = 1
$rootFolderPath = '/data/Movies/'
$rottenTomatoesLink = 'https://www.rottentomatoes.com/top/bestofrt/?year=2017'
function Search-RadarrForFilm{
param([string]$FilmName)
$SearchResults = (iwr "$RadarrURL/api//movie/lookup?apikey=$RadarrAPIKey&term=$FilmName" -Method GET).content | ConvertFrom-Json
return $SearchResults
}
function Add-RadarrFilmFromSearchResult{
param($SearchResult)
$params = @{
title = $SearchResult.title
titleSlug = $SearchResult.titleSlug
images = @(,$SearchResult.images[0])
tmdbId = $SearchResult.tmdbId
rootFolderPath = $rootFolderPath
qualityProfileId = $qualityProfileId
} | ConvertTo-Json
try {
$result = iwr "$RadarrURL/api/movie?apikey=$RadarrAPIKey" -Method POST -Body $Params
}catch{
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd() | ConvertFrom-Json;
Write-Host $responseBody.ErrorMessage
return
}
return $result
}
$result = iwr $rottenTomatoesLink
$matches = $result.Content | Select-String '(?smi)<td>\s*?<a href="/m/.*?>\s*(.*?)</a>.*?</td>' -AllMatches
$Movies = $matches.Matches | %{$_.Groups[1].value}
foreach($Movie in $Movies){
Write-Host $Movie
$SearchResult = Search-RadarrForFilm -FilmName $Movie
if($SearchResult){
Add-RadarrFilmFromSearchResult $SearchResult[0]
}else{
Write-Host "`tNo matches"
}
}
$result = iwr 'https://www.rottentomatoes.com/top/bestofrt/?year=2017'
$matches = $result.Content | Select-String '(?smi)<td>\s*?<a href="/m/.*?>\s*(.*?)</a>.*?</td>' -AllMatches
$matches.Matches | %{$_.Groups[1].value}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment