💾 Archived View for ait.place › dot › bin › .local › bin › imdb.txt captured on 2021-12-03 at 14:04:38.
-=-=-=-=-=-=-
#!/bin/sh # Get your own key if invalid: http://www.omdbapi.com/apikey.aspx apiKey=369615e usage() { cat <<EOF Description: Provides relevant information about a certain movie. Depends on: curl, jq Usage: command [string] Examples: movies Argo movies Inception EOF } if [ -z "$*" ] ; then usage else # Format the inputs to use for the api. movie=$(echo "$@" | tr ' ' '+' | sed 's/-d+//g') # make send request url="http://www.omdbapi.com/?apikey=$apiKey&plot=full&t=$movie" checkjq="$(command -v jq)" rawjson="$(curl -s $url)" [ "$(echo $rawjson | jq -r '.Response')" = "False" ] && echo $rawjson | jq -r ".Error" && exit 1 if [ ! -z "$checkjq" ];then echo $rawjson | jq -r '(([.Title," - ",.Year]| (., map(length*"-")))|join("")), .Plot, "", (.? | del(.Title,.Year,.Plot,.Ratings,.Response, .imdbID) | del(.[] | select(.=="N/A")) | to_entries[] | [.[]] | join(": \t")), (.Ratings[] | [.Source,.Value]|join(": "))' else echo $rawjson | python -m json.tool fi fi