PowerShell WPK NetFlix Viewer Using Microsoft’s OData

March 28, 2010

in Microsoft,Netflix,OData,PowerShell,WPF,WPK

Netflix has partnered with Microsoft to create an OData API for the Netflix catalog information. Here it is OData Catalog API (Preview).

Assuming you have Windows 7 installed (PowerShell comes out of the box) and PowerShell Pack the script below should work.

If you don’t have Windows 7 no problem, you can download PowerShell Version 2 for your OS HERE.

image

The Viewer

Miguel de Icaza’s talks about NetFlix and OData in his post OData Client goes Open Source.

Here are some other ‘queries’ you can try in the viewer, just copy/paste it in the text box at the top and press enter.

  • Name eq ‘The Name of The Rose’
  • ReleaseYear le 1989 and ReleaseYear ge 1980 and AverageRating gt 4
  • Type eq ‘Movie’ and Instant/Available eq true and (Rating eq ‘G’ or Rating eq ‘PG-13′)
  • Type eq ‘Movie’ and Instant/Available eq true and (Rating ne ‘R’ and Rating ne ‘NC-17′ and Rating ne ‘UR’ and Rating ne ‘NR’)
  • substringof(‘bank’,Synopsis) and ReleaseYear eq 2010

The Code

Function Get-NetFlixTitles {
    param ($filter)            

    $url = "http://odata.netflix.com/Catalog/Titles?`$filter="                

    $wc   = New-Object net.webclient
    $feed = [xml]($wc.downloadstring("$($url)$($filter)"))            

    $feed |
        select -ExpandProperty feed |
        select -ExpandProperty entry |
            ForEach {
                New-Object PSObject -Property @{
                Title = $_.title.'#text'
                Url = $_.properties.TinyUrl
            }
    }
}            

Import-Module wpk            

New-Window -Title "NetFlix OData" -WindowStartupLocation CenterScreen -Width 1200 -Height 600 -Show -On_Loaded {
    $lstBox = $window | Get-ChildControl lstBox
    $lstBox.ItemsSource = @(Get-NetFlixTitles "ReleaseYear eq 2010")
} {
    New-Grid -Rows 32, 1* -Columns 300, 900* {            

        New-TextBox -Name txtBox -Text "ReleaseYear eq 2010" -Row 0 -ColumnSpan 2 -Margin 3 -On_PreviewKeyUp {
            if($_.Key -eq "Enter") {
                $lstBox = $window | Get-ChildControl lstBox
                $txtBox = $window | Get-ChildControl txtBox
                $lstBox.ItemsSource = @(Get-NetFlixTitles "$($txtBox.Text)")
            }
        }            

        New-ListBox -Name lstBox -Row 1 -Column 0 -DisplayMemberPath Title `
            -On_SelectionChanged {
                $browser = $window | Get-ChildControl browser
                $browser.Source = $this.SelectedItem.Url
            }            

        New-WebBrowser -Name browser -Column 1 -Row 1
    }
}

Download the PowerShell Script

{ 3 trackbacks }

Tweets that mention PowerShell WPK NetFlix Viewer Using Microsoft’s OData -- Topsy.com
03.29.10 at 11:38 am
uberVU - social comments
03.30.10 at 7:07 am
Tweets that mention PowerShell WPK NetFlix Viewer Using Microsoft’s OData -- Topsy.com
03.30.10 at 7:58 am

{ 1 comment… read it below or add one }

Bernd Kriszio 04.11.10 at 8:07 am

Thanks Doug,
for providing WPK eamples

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Contrat Creative Commons

© 2007-2012, Doug Finke