Last active
May 8, 2018 23:11
-
-
Save Sam-Martin/d6d1ac7fcd7ac72681def35f7fbe957c to your computer and use it in GitHub Desktop.
Scrape Rotten Tomatoes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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