Jump to content

IMDb lookup


DW1
 Share

Recommended Posts

Returns an array of Movie Titles and links from IMDb

I can think of many things that could use this. I am just using for a movie viewer on my network share.

PLEASE DOWNLOAD THE SCRIPT BELOW. DO NOT COPY AND PASTE. ( script will not post into forums correctly due to '&' HTML variables. It will not display correctly because it reads "& # 3 4 ;" (no spaces) as " )

OLD DOWNLOAD @ 122 hits

IMDBlookup.au3

#include-once
#include <Inet.au3>
#include <String.au3>
;===============================================================================
;
; Description:      Returns an array of Movie Titles and links from IMDb
; Parameter(s):     $searchstring - Input the movie name to search for
; Requirement(s):   Includes:
;                       #include <Inet.au3>
;                       #include <String.au3>
; Return Value(s):  On Success - Returns an array.
;                                   $array[X][0] = movie name.
;                                   $array[X][1] = movie link.
;                   On Failure - 0  and Set
;                                   @ERROR to:  1 - No links found
;                                   @ERROR to:  2 - Couldn't Connect to IMDb
;                                   @ERROR to:  3 - Input Search String is blank
; Author(s):        Danny Williams
; Note(s):  EMAMPLE:
;               #include <array.au3>
;               #include <IMDblookup.au3>
;               #include<IE.au3>
;               $array = _IMDblookup(InputBox("IMDb Lookup Function", "Movie Name:"))
;               If @error Then
;                   If @error = 1 Then MsgBox(0, "Error", "Error - " & @error & " - No Links Found" )
;                   If @error = 2 Then MsgBox(0, "Error", "Error - " & @error & " - Couldn't Connect To IMDb" )
;                   If @error = 3 Then MsgBox(0, "Error", "Error - " & @error & " - Input Search String Was Blank" )
;               Else
;                   _ArrayDisplay($array)
;                   _IECreate($array[0][1], 0, 1, 0)
;               EndIf
;===============================================================================
Func _IMDblookup($searchstring)
    If $searchstring = "" Then
        SetError( 3 )
        Return 0
    EndIf
    $searchstring = textfilter($searchstring)
    $url1 = "http://www.imdb.com/find?s=all&q=" 
    $url2 = $searchstring
    $url3 = "&x=0&y=0" 
    $source = _INetGetSource($url1 & $url2 & $url3)
    If @error Then
        MsgBox(0, "test", $source )
        SetError( 2 )
        Return 0
    EndIf
    $tstring = _StringBetween($source, "<title>", "</title>" )
    If @error = 1 Then
        SetError( 1 )
        Return 0
    EndIf
    If $tstring[0] <> "IMDb  Search" Then
;~      $estring = _StringBetween( $source, "/title/", "/trailers';" )
        $estring = _StringBetween( $source, "/title/",'/">')
        If @error Then
            MsgBox(0, "TEST $source", $source )
            ClipPut( $url1 & $url2 & $url3 )
            MsgBox(0, "ERROR", "Failed to find movie" & @CRLF & 'Line' & @ScriptLineNumber & ': _StringBetween( $source, "/title/", "/trailers' & "'" & ';" )' )
            SetError( 1 )
            Return 0
        EndIf
        Dim $errorarray[1][2]
        $errorarray[0][0] = $tstring[0]
        $errorarray[0][1] = 'http://www.imdb.com/title/' & $estring[0] & "/"
        Return $errorarray
    EndIf
    $array = _StringBetween($source, '<a href="/title/', '/"')
    If @error = 1 Then
        SetError( 1 )
        Return 0
    EndIf
    $links = CompactArray($array)
    Dim $title[UBound($links) ]
    For $var = 0 To UBound($links) - 1
        $tempsb = _StringBetween($source, $links[$var] & '/">', "</a>")
        If @error Then
            $title[$var] = ""
        Else
            $tts = $tempsb[0]
            $tts = StringReplace($tts, "&", "&")
            $tts = StringReplace($tts, """, '"')
            $title[$var] = $tts
        EndIf
    Next
    Dim $newarray[UBound($title) ][2]
    For $evar = 0 To UBound($title) - 1
        $newarray[$evar][0] = $title[$evar]
        $newarray[$evar][1] = 'http://www.imdb.com/title/' & $links[$evar] & "/"
    Next
    Return $newarray
EndFunc   ;==>_IMDBlookup
Func CompactArray($compactme)
    Dim $testarray[1]
    $testarray[0] = ""
    $bound = 0
    For $avar = 0 To UBound($compactme) - 1
        If StringLen($compactme[$avar]) = 9 Then
            $tester = 0
            For $bvar = 0 To UBound($testarray) - 1
                If $compactme[$avar] = $testarray[$bvar] Then $tester += 1
            Next
            If $tester = 0 Then
                ReDim $testarray[$bound + 1]
                $testarray[$bound] = $compactme[$avar]
                $bound += 1
            EndIf
        EndIf
    Next
    Return $testarray
EndFunc   ;==>CompactArray
Func textfilter($searchstring)
    $searchstring = StringReplace($searchstring, "%", "%25")
    $searchstring = StringReplace($searchstring, "!", "%21")
    $searchstring = StringReplace($searchstring, '"', "%22")
    $searchstring = StringReplace($searchstring, '#', "%23")
    $searchstring = StringReplace($searchstring, '$', "%24")
    $searchstring = StringReplace($searchstring, '&', "%26")
    $searchstring = StringReplace($searchstring, "'", "%27")
    $searchstring = StringReplace($searchstring, "(", "%28")
    $searchstring = StringReplace($searchstring, ")", "%29")
    $searchstring = StringReplace($searchstring, "+", "%2B")
    $searchstring = StringReplace($searchstring, ",", "%2C")
    $searchstring = StringReplace($searchstring, "/", "%2F")
    $searchstring = StringReplace($searchstring, ":", "%3A")
    $searchstring = StringReplace($searchstring, ";", "%3B")
    $searchstring = StringReplace($searchstring, "<", "%3C")
    $searchstring = StringReplace($searchstring, "=", "%3D")
    $searchstring = StringReplace($searchstring, ">", "%3E")
    $searchstring = StringReplace($searchstring, "?", "%3F")
    $searchstring = StringReplace($searchstring, "@", "%40")
    $searchstring = StringReplace($searchstring, '[', "%5B")
    $searchstring = StringReplace($searchstring, '\', "%5C")
    $searchstring = StringReplace($searchstring, ']', "%5D")
    $searchstring = StringReplace($searchstring, '^', "%5E")
    $searchstring = StringReplace($searchstring, "`", "%60")
    $searchstring = StringReplace($searchstring, '{', "%7B")
    $searchstring = StringReplace($searchstring, '|', "%7C")
    $searchstring = StringReplace($searchstring, '}', "%7D")
    $searchstring = StringReplace($searchstring, "~", "%7E")
    $searchstring = StringReplace($searchstring, " ", "+")
    Return $searchstring
EndFunc   ;==>textfilter

OLD DOWNLOAD @ 122 hits

IMDBlookup.au3

EDIT: added another error code for unable to connect to IMDb.

EDIT2: Added more error codes.

EDIT3: Updated example with error checking.

EDIT4: Updated code for IMDB site updates

Edited by danwilli
Link to comment
Share on other sites

Following error appeared. Probably due to no way to get the source? I have proxy set in IE that doesnt' work without vpn connection. Maybe an option to use proxy or not. I don't always have proxy disabled in iE.

C:\Projects\Project.Au3\Includes\imdb.au3 (32) : ==> Subscript used with non-Array variable.:

If $tstring[0] <> "IMDb Search" Then

If $tstring^ ERROR

->17:30:46 AutoIT3.exe ended.rc:1

+>17:30:46 AutoIt3Wrapper Finished

>Exit code: 1 Time: 39.535

C:\Projects\Project.Au3\Includes\imdb.au3 (32) : ==> Subscript used with non-Array variable.:

If $tstring[0] <> "IMDb Search" Then

If $tstring^ ERROR

->17:31:12 AutoIT3.exe ended.rc:1

+>17:31:13 AutoIt3Wrapper Finished

>Exit code: 1 Time: 37.607

Similar error happens when u use

#include <array.au3>
#include <C:\Projects\Project.Au3\Includes\imdb.au3>
#include<IE.au3>

$array = _IMDblookup(InputBox("IMDb Lookup Function", "Movie Name:"))
_ArrayDisplay($array)
_IECreate($array[0][1], 0, 1, 0)

and you press ESC on InputBox.

C:\Projects\Project.AU3\Scene.IMDB.au3 (7) : ==> Subscript used with non-Array variable.:

_IECreate($array[0][1], 0, 1, 0)

_IECreate($array^ ERROR

Simple checks for "correct values" should be added.

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Thank you MadBoy, I have added a check for successful source grab from IMDb. Now if somebody cannot connect, it will return 0 and set @error to 2.

Thank you for picking up on this. If you run into any others, please post them and I will try to put in error checking for it.

Original post/source updated.

Link to comment
Share on other sites

  • 7 months later...

i get the following when i run, and i did rightclick to download source.

C:\Users\Corey\Documents\Auto It\IMDB Lookup\IMDblookup.au3 (57) : ==> Subscript used with non-Array variable.:
$errorarray[0][1] = 'http://www.imdb.com/title/' & $estring[0] & "/"
$errorarray[0][1] = 'http://www.imdb.com/title/' & $estring^ ERROR
Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

Your http string replace code was useful as a guide to code a better version of that part

func stringtohttp($str)
    for $i=33 to 47
        $str=stringreplace($str, chr($i), '%'&hex($i, 2))
    next
    
    for $i=58 to 64
        $str=stringreplace($str, chr($i), '%'&hex($i, 2))
    next
    $str=StringReplace ($str, ' ', '+')
    return ($str)
endfunc
Edited by Adam1213
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...