Jump to content

Recommended Posts

Posted

Hi all!

I'm trying to write a script that automatically retrieves some data from IMDB for an array of movie titles.

I want it to output something like this: title,year,genre,duration,writer,director,maincast .

Can you suggest me the smoothest way to do it?

Posted (edited)

Hi,

Take a look at the _InetGetSource and the _String*/String* functions.

This website might have a web API which should be better for your need ;)

Br, FireFox.

Edited by FireFox
Posted
http://mymovieapi.com is how you could do it.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

You can use _INetGetSource with API I linked to. Don't forget it's for non-commercial use.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Don't worry it's just for personal use;)

My basic knowledge let me write this script:

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

HotKeySet("{esc}","ExitScript")

$1 = TrayCreateItem("Go!",-1,-1,1)
TrayItemSetOnEvent(-1,"_go")
TrayCreateItem("")
$a = TrayCreateItem("About")
TrayItemSetOnEvent(-1,"_about")
TrayCreateItem("")
$e = TrayCreateItem("Exit (Esc)")
TrayItemSetOnEvent(-1,"ExitScript")
TraySetToolTip("IMDB lookup")

Global $result[7]

While True ; Forever
    Sleep(100)  
WEnd

Func _about()
    TrayTip(" IMDB lookup","Script Function: Retrieve a movie's infos from IMDB",10)
EndFunc

Func exitscript()
    Exit
 EndFunc
 
 Func _go()

For $i=0 to 6
   $result[$i]='not found'
Next
    
Local $title = InputBox('IMDB lookup','Please enter movie title')
Local $dummy

If @error Then
   MsgBox(0,'ERROR','Invalid parameters')
   SetError(0)
   Return 0
EndIf

StringReplace($title,' ','+')

TrayTip('Working...',$title,30)

Local $response = _INetGetSource('http://mymovieapi.com/?title='&$title&'&type=json&plot=none&episode=0&limit=1&yg=0&mt=none&lang=en-US&offset=&aka=simple&release=simple&business=0&tech=0')

$dummy=_StringBetween($response, '"title": "','", "filming_locations":')
If Not @error then 
   $result[0]=$dummy[0]
   Else
   SetError(0)
EndIf

$dummy=_StringBetween($response, '"year":',', "country":')
If Not @error then 
   $result[1]=$dummy[0]
   Else
   SetError(0)
EndIf

$dummy=_StringBetween($response, '[{"runtime": ["',' min"],')
If Not @error then 
   $result[2]=$dummy[0]
   Else
   SetError(0)
EndIf

$dummy=_StringBetween($response, '"genres": [','], "rated"')
If Not @error then 
   $result[3]=$dummy[0]
   Else
   SetError(0)
EndIf
   
$dummy=_StringBetween($response, '"writers":','], "imdb_id"')
If Not @error then 
   $result[4]=$dummy[0]
   Else
   SetError(0)
EndIf

$dummy=_StringBetween($response, '"directors": ["', '], "rating_count":')
If Not @error then 
   $result[5]=$dummy[0]
   Else
   SetError(0)
EndIf

$dummy=_StringBetween($response, '"actors": [','], "also_known_as":')
If Not @error then 
   $result[6]=$dummy[0]
   Else
   SetError(0)
EndIf

_ArrayDisplay($result)
EndFunc

I believe there is a better way to extract the data from the json string, but the json udf i found seemed a bit too complicated for me.

Any suggestions?

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
  • Recently Browsing   0 members

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