Advertisement
jerdub1993

IMDB Command

Mar 27th, 2017
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-IMDBItem
  2. {
  3.     <#
  4.     .Synopsis
  5.        Retrieves information about a movie/tv show etc. from IMDB.
  6.     .DESCRIPTION
  7.        This cmdlet fetches information about the movie/tv show matching the specified ID from IMDB.
  8.        The ID is often seen at the end of the URL at IMDB.
  9.     .EXAMPLE
  10.         Get-IMDBItem -ID tt0848228
  11.     .EXAMPLE
  12.        Get-IMDBMatch -Title 'American Dad!' | Get-IMDBItem
  13.  
  14.        This will fetch information about the item(s) piped from the Get-IMDBMatch cmdlet.
  15.     .PARAMETER ID
  16.        Specify the ID of the tv show/movie you want get. The ID has the format of tt0123456
  17.     #>
  18.  
  19.     [cmdletbinding()]
  20.     param([Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
  21.           [string[]] $ID)
  22.  
  23.     BEGIN { }
  24.  
  25.     PROCESS {
  26.         foreach ($ImdbID in $ID) {
  27.  
  28.             $IMDBItem = Invoke-WebRequest -Uri "http://www.imdb.com/title/$ImdbID"
  29.  
  30.             $ItemInfo = $IMDBItem.AllElements
  31.  
  32.             $MoreInfo = ((($ItemInfo | where class -eq "subtext" | select -First 1).innerText).split('|')).trim()
  33.            
  34.             $ItemTitle = (($ItemInfo | where itemprop -eq "name" | select -First 1).innerHTML -split "&nbsp;")[0]
  35.            
  36.             If ($MoreInfo[3] -like "TV Series*") {
  37.                 $Type = "TV Series"
  38.                 $Released = $null
  39.             } Else {
  40.                 $Type = "Movie"
  41.                 [DateTime]$Released = ($MoreInfo[3].Replace("(USA)",""))
  42.             }
  43.  
  44.             $Description = ($iteminfo | where class -eq "summary_text" | select -First 1).innerText
  45.            
  46.             $Rating = (($ItemInfo | where class -eq "imdbRating" | select -First 1).innerText -split "/")[0]
  47.            
  48.             $Genres = (($MoreInfo[2]).Split(",")).Trim()
  49.  
  50.             $MPAARating = $MoreInfo[0]
  51.  
  52.             try {
  53.                 $RuntimeMinutes = New-TimeSpan -minutes (($ItemInfo | where itemprop -eq "duration" | select -First 1).datetime -replace '\D','')
  54.             }
  55.             catch {
  56.                 $RuntimeMinutes = $null
  57.             }
  58.  
  59.             if ($Description -like '*Add a plot*') {
  60.                 $Description = $null
  61.             }
  62.  
  63.             $returnObject = New-Object System.Object
  64.             $returnObject | Add-Member -Type NoteProperty -Name ID -Value $ImdbID
  65.             $returnObject | Add-Member -Type NoteProperty -Name Type -Value $Type
  66.             $returnObject | Add-Member -Type NoteProperty -Name Title -Value $ItemTitle
  67.             $returnObject | Add-Member -Type NoteProperty -Name Genre -Value $Genres
  68.             $returnObject | Add-Member -Type NoteProperty -Name Description -Value $Description
  69.             $returnObject | Add-Member -Type NoteProperty -Name Released -Value $Released
  70.             $returnObject | Add-Member -Type NoteProperty -Name RuntimeMinutes -Value $RuntimeMinutes
  71.             $returnObject | Add-Member -Type NoteProperty -Name Rating -Value $Rating
  72.             $returnObject | Add-Member -Type NoteProperty -Name MPAARating -Value $MPAARating
  73.  
  74.             Write-Output $returnObject
  75.  
  76.             Remove-Variable IMDBItem, ItemInfo, ItemTitle, Genres, Description, Released, Type, Rating, RuntimeMinutes, MPAARating -ErrorAction SilentlyContinue
  77.         }
  78.     }
  79.  
  80.     END { }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement