IMDB Search Powershell Function


SUBMITTED BY: Guest

DATE: Nov. 14, 2013, 7:01 a.m.

FORMAT: Text only

SIZE: 5.0 kB

HITS: 1038

  1. # IMDB Search Powershell Function
  2. #
  3. Function IMDBSearch ($MovieTitle)
  4. {
  5. $MovieTitle = $MovieTitle.ToString()
  6. $MovieTitle = $MovieTitle.Replace(".avi","")
  7. $MovieTitle = $MovieTitle.Replace(".mkv","")
  8. $MovieTitle = $MovieTitle.Replace(".wmv","")
  9. $MovieTitle = $MovieTitle.Replace(".mp4","")
  10. $MovieTitle = $MovieTitle.Replace("(CD1)","")
  11. $MovieTitle = $MovieTitle.Replace("[CD1]","")
  12. $MovieTitle = $MovieTitle.Replace("(CD2)","")
  13. $MovieTitle = $MovieTitle.Replace("[CD2]","")
  14. $MovieTitle = $MovieTitle.Replace("(CD3)","")
  15. $MovieTitle = $MovieTitle.Replace("[CD3]","")
  16. $MovieTitle = $MovieTitle.Replace("part1","")
  17. $MovieTitle = $MovieTitle.Replace("part2","")
  18. $MovieTitle = $MovieTitle.Replace("divx","")
  19. $MovieTitle = $MovieTitle.Replace("dvdrip","")
  20. $MovieTitle = $MovieTitle.Replace("R5","")
  21. $MovieTitle = $MovieTitle.Replace("screener","")
  22. $MovieTitle = $MovieTitle.Replace("cam","")
  23. $MovieTitle = $MovieTitle.Replace("."," ")
  24. $MovieTitle = $MovieTitle.Replace("-"," ")
  25. $SearchBase = "http://google.com/search?btnI=1&q=site:imdb.com/title"
  26. $url = $SearchBase + " " + $MovieTitle
  27. [net.httpWebRequest] $request = [net.webRequest]::create($url)
  28. [net.httpWebResponse] $response = $request.getResponse()
  29. $responseStream = $response.getResponseStream()
  30. $sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
  31. $result = $sr.ReadToEnd()
  32. $spaceman = $result.Split("<")
  33. $TitleString = $spaceman | where {$_.Contains('meta name="title" content="')} -ErrorAction SilentlyContinue
  34. Write-Host (("=") * 30)
  35. if (!$TitleString) {Write-Host "Hmm. Not getting results for $MovieTitle"}
  36. else {
  37. if ($TitleString.Contains("Memorable quotes"))
  38. {
  39. $RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
  40. $RunnerUp = $RunnerUp.Substring(27)
  41. $RunnerUp = $RunnerUp.Remove($RunnerUp.Length -11)
  42. $url = $RunnerUp
  43. [net.httpWebRequest] $request = [net.webRequest]::create($url)
  44. [net.httpWebResponse] $response = $request.getResponse()
  45. $responseStream = $response.getResponseStream()
  46. $sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
  47. $result = $sr.ReadToEnd()
  48. $spaceman = $result.Split("<")
  49. }
  50. if ($TitleString.Contains("Full cast and crew"))
  51. {
  52. $RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
  53. $RunnerUp = $RunnerUp.Substring(27)
  54. $RunnerUp = $RunnerUp.Remove($RunnerUp.Length -15)
  55. $url = $RunnerUp
  56. [net.httpWebRequest] $request = [net.webRequest]::create($url)
  57. [net.httpWebResponse] $response = $request.getResponse()
  58. $responseStream = $response.getResponseStream()
  59. $sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
  60. $result = $sr.ReadToEnd()
  61. $spaceman = $result.Split("<")
  62. }
  63. if ($TitleString.Contains("External reviews"))
  64. {
  65. $RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
  66. $RunnerUp = $RunnerUp.Substring(27)
  67. $RunnerUp = $RunnerUp.Remove($RunnerUp.Length -19)
  68. $url = $RunnerUp
  69. [net.httpWebRequest] $request = [net.webRequest]::create($url)
  70. [net.httpWebResponse] $response = $request.getResponse()
  71. $responseStream = $response.getResponseStream()
  72. $sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
  73. $result = $sr.ReadToEnd()
  74. $spaceman = $result.Split("<")
  75. }
  76. if ($TitleString.Contains("Plot Summary"))
  77. {
  78. $RunnerUp = $spaceman | where {$_.Contains('link rel="canonical"')} -ErrorAction SilentlyContinue
  79. $RunnerUp = $RunnerUp.Substring(27)
  80. $RunnerUp = $RunnerUp.Remove($RunnerUp.Length -16)
  81. $url = $RunnerUp
  82. [net.httpWebRequest] $request = [net.webRequest]::create($url)
  83. [net.httpWebResponse] $response = $request.getResponse()
  84. $responseStream = $response.getResponseStream()
  85. $sr = new-object IO.StreamReader($responseStream) -ErrorAction SilentlyContinue
  86. $result = $sr.ReadToEnd()
  87. $spaceman = $result.Split("<")
  88. }
  89. $TitleString = $spaceman | where {$_.Contains('meta name="title" content="')} -ErrorAction SilentlyContinue
  90. $ScoreString = $spaceman | where {$_.Contains("star-box-giga-star")} -ErrorAction SilentlyContinue
  91. if (!$ScoreString){$IMDBScore = "Could Not Determine"}
  92. if ($ScoreString) {$IMDBScore = $ScoreString.Substring($ScoreString.Length -4, 4)}
  93. $TitleString = $TitleString.Substring(27)
  94. $TitleString = $TitleString.Remove($TitleString.Length -20)
  95. Write-Host "Your Input: $MovieTitle`rMy Best Guess: $TitleString`rIMDB Rating: $IMDBScore"
  96. Write-Host (("=") * 30)
  97. }
  98. }
  99. $Movies = Get-ChildItem y:\
  100. foreach ($movie in $Movies){IMDBSearch $movie}

comments powered by Disqus