1: #!/usr/bin/rexx
2: /* ---------------------------------------------------------------- */
3: /* A simple excercise to show the ease with which OMDB can be */
4: /* accessed. */
5: /* */
6: /* Retrieves information for a movie/tv series/etc from */
7: /* https://www.omdbapi.com and uses the result to find */
8: /* the poster associated with the movie etc. and display the */
9: /* picture on the screen. */
10: /* */
11: /* Note: Written for linux Mint, where CURL is standard and pix is */
12: /* the standard picture viewer. CURL can be downloaded from */
13: /* https://curl.haxx.se */
14: /* */
15: /* Also: OMDB requires the use of an apikey (free of charge is */
16: /* possible), which can be obtained within minutes. */
17: /* */
18: /* ---------------------------------------------------------------- */
19: /* */
20: /* Originally by Ruurd J. Idenburg */
21: /* */
22: /* No copyright, no licence, no guarantees or warrantees, be it */
23: /* explicit, implicit or whatever. Usage is totally and completely */
24: /* at the users own risk, the author shall not be liable for any */
25: /* damages whatsoever, for any reason whatsoever. */
26: /* */
27: /* Please keep this comment block intact when modifying this code */
28: /* and add a note with date and a description. */
29: /* */
30: /* ---------------------------------------------------------------- */
31: /* 2020/03/06 - Initial version approximately */
32: /* ---------------------------------------------------------------- */
33: -- Get the title we are looking for
34: parse arg title
35: title = title~translate('+',' ')
36: -- I keep the ApiKey as an environment variable for my userid
37: apiKey = Value("OMDB_APIKEY", ,"ENVIRONMENT")
38: -- Catch json output into an array
39: jsonArray = .array~new
40: address system with output using (jsonArray)
41: -- Set the query for OMDB
42: "curl -s 'https://www.omdbapi.com/?t="title"&apikey="apiKey"'"
43: -- Stringify the response
44: json = jsonArray~toString('c')
45: -- Rexxify the json string
46: rexx = .json~new()~fromJson(json)
47: -- Quit when title is not found or some other error
48: if rexx["Response"]=="False" then do
49: say rexx["Error"]
50: exit
51: end
52: -- Get the path to the poster
53: poster = rexx["Poster"]
54: -- Replace spaces in movie title with underscore
55: title = rexx["Title"]~translate('_',' ')
56: -- Set the filename to receive output
57: file = title".jpg"
58: -- Let's get the image if poster is not .nil
59: if (poster=="N/A"|.nil==poster) then do
60: say "No poster available"
61: exit
62: end
63: address system with output stream (file)
64: "curl -s" "'"poster"'"
65: -- Possibly do something more useful here
66: -- pix is the standard picture viewer in Linux Mint 19.3
67: address path "pix" file
68: exit
69:
70: ::requires 'json.cls'