# IMDB Search Powershell Function
#
Function IMDBSearch ($MovieTitle)
{
$MovieTitle = $MovieTitle.ToString()
$MovieTitle = $MovieTitle.Replace(".avi","")
$MovieTitle = $MovieTitle.Replace(".mkv","")
$MovieTitle = $MovieTitle.Replace(".wmv","")
$MovieTitle = $MovieTitle.Replace(".mp4","")
$MovieTitle = $MovieTitle.Replace("(CD1)","")
$MovieTitle = $MovieTitle.Replace("[CD1]","")
$MovieTitle = $MovieTitle.Replace("(CD2)","")
$MovieTitle = $MovieTitle.Replace("[CD2]","")
$MovieTitle = $MovieTitle.Replace("(CD3)","")
$MovieTitle = $MovieTitle.Replace("[CD3]","")
$MovieTitle = $MovieTitle.Replace("part1","")
$MovieTitle = $MovieTitle.Replace("part2","")
$MovieTitle = $MovieTitle.Replace("divx","")
$MovieTitle = $MovieTitle.Replace("dvdrip","")
$MovieTitle = $MovieTitle.Replace("R5","")
$MovieTitle = $MovieTitle.Replace("screener","")
$MovieTitle = $MovieTitle.Replace("cam","")
$MovieTitle = $MovieTitle.Replace("."," ")
$MovieTitle = $MovieTitle.Replace("-"," ")
$SearchBase = "http://google.com/search?btnI=1&q=site:imdb.com/title"
$url = $SearchBase + " " + $MovieTitle
[net.httpWebRequest] $request = [net.webRequest]::create($url)
[net.httpWebResponse] $response = $request.getResponse()
$responseStream = $response.getResponseStream()
$sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
$result = $sr.ReadToEnd()
$spaceman = $result.Split("<")
$TitleString = $spaceman | where {$_.Contains('meta name="title" content="')} -ErrorAction SilentlyContinue
Write-Host (("=") * 30)
if (!$TitleString) {Write-Host "Hmm. Not getting results for $MovieTitle"}
else {
if ($TitleString.Contains("Memorable quotes"))
{
$RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
$RunnerUp = $RunnerUp.Substring(27)
$RunnerUp = $RunnerUp.Remove($RunnerUp.Length -11)
$url = $RunnerUp
[net.httpWebRequest] $request = [net.webRequest]::create($url)
[net.httpWebResponse] $response = $request.getResponse()
$responseStream = $response.getResponseStream()
$sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
$result = $sr.ReadToEnd()
$spaceman = $result.Split("<")
}
if ($TitleString.Contains("Full cast and crew"))
{
$RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
$RunnerUp = $RunnerUp.Substring(27)
$RunnerUp = $RunnerUp.Remove($RunnerUp.Length -15)
$url = $RunnerUp
[net.httpWebRequest] $request = [net.webRequest]::create($url)
[net.httpWebResponse] $response = $request.getResponse()
$responseStream = $response.getResponseStream()
$sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
$result = $sr.ReadToEnd()
$spaceman = $result.Split("<")
}
if ($TitleString.Contains("External reviews"))
{
$RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
$RunnerUp = $RunnerUp.Substring(27)
$RunnerUp = $RunnerUp.Remove($RunnerUp.Length -19)
$url = $RunnerUp
[net.httpWebRequest] $request = [net.webRequest]::create($url)
[net.httpWebResponse] $response = $request.getResponse()
$responseStream = $response.getResponseStream()
$sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
$result = $sr.ReadToEnd()
$spaceman = $result.Split("<")
}
if ($TitleString.Contains("Plot Summary"))
{
$RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
$RunnerUp = $RunnerUp.Substring(27)
$RunnerUp = $RunnerUp.Remove($RunnerUp.Length -16)
$url = $RunnerUp
[net.httpWebRequest] $request = [net.webRequest]::create($url)
[net.httpWebResponse] $response = $request.getResponse()
$responseStream = $response.getResponseStream()
$sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
$result = $sr.ReadToEnd()
$spaceman = $result.Split("<")
}
$TitleString = $spaceman | where {$_.Contains('meta name="title" content="')} -ErrorAction SilentlyContinue
$ScoreString = $spaceman | where {$_.Contains("star-box-giga-star")} -ErrorAction SilentlyContinue
if (!$ScoreString){$IMDBScore = "Could Not Determine"}
if ($ScoreString) {$IMDBScore = $ScoreString.Substring($ScoreString.Length -4, 4)}
$TitleString = $TitleString.Substring(27)
$TitleString = $TitleString.Remove($TitleString.Length -20)
Write-Host "Your Input: $MovieTitle`rMy Best Guess: $TitleString`rIMDB Rating: $IMDBScore"
Write-Host (("=") * 30)
}
}
$Movies = Get-ChildItem y:\
foreach ($movie in $Movies){IMDBSearch $movie}