Skip to content

Commit 323b16e

Browse files
authored
Merge pull request #6 from bgr/refreshment
Switch to OMDB API, Python 3 support, PEP-8 fixes
2 parents 79fb961 + 783dcb3 commit 323b16e

5 files changed

Lines changed: 342 additions & 138 deletions

File tree

README.md

Lines changed: 117 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,117 @@
1-
*NIX command line tool for retrieving IMDb movie information
2-
============================================================
3-
4-
### Usage:
5-
6-
First set up an alias for the command:
7-
8-
alias imdbtool="python /path/to/imdbtool.py"
9-
10-
### Some interesting usage examples:
11-
12-
Show all info about movie 'Cars'
13-
14-
imdbtool -t Cars
15-
16-
Show all info about latest 'True Grit' movie
17-
18-
imdbtool -t "True Grit"
19-
20-
Show all info about 1969 version of 'True Grit'
21-
22-
imdbtool -t "True Grit" -y 1969
23-
24-
Show best guess for a misspelled name
25-
26-
imdbtool -t "Ture git"
27-
28-
Print movie's rating
29-
30-
imdbtool -t Cars | sed -n '/^imdbrating/{n;p;}'
31-
32-
Download movie's poster
33-
34-
imdbtool -t Cars | wget `sed -n '/^poster/{n;p;}'`
35-
36-
37-
### Additional useful features:
38-
39-
Include full plot summary (not available for some movies)
40-
41-
imdbtool -t "True Grit" --plot full
42-
43-
Include additional data from Rotten Tomatoes
44-
45-
imdbtool -t "True Grit" --tomatoes
46-
47-
Show info by IMDb id
48-
49-
imdbtool -i tt0103064
50-
51-
Print raw JSON or XML data
52-
53-
imdbtool -t Cars -r JSON
54-
55-
56-
### Example to get ratings for all movies in current directory (it will use directory and file names as movie titles):
57-
58-
Save following code to file `get_ratings.sh` (make sure to update the path in line 3):
59-
60-
ls -1 |
61-
while read title; do
62-
res=`python /path/to/imdbtool.py -t "$title"`
63-
rating=`echo "$res" | sed -n '/^imdbrating/{n;p;}'`
64-
restitle=`echo "$res" | sed -n '/^title/{n;p;}' | sed s/*//g`
65-
year=`echo "$res" | sed -n '/^year/{n;p;}'`
66-
echo "$title * $restitle * $year * $rating"
67-
done
68-
69-
Then execute the saved command to fetch all the ratings: `./get_ratings.sh > ratings.txt`
70-
(it'll take a while to retrieve all the data). Then you can open the `ratings.txt` file to see the movie ratings, or you can sort the movies by ratings to pick the best one to watch: `< ratings.txt sort -t* -k4 -r`
71-
72-
73-
## Notes ##
74-
75-
- requires Python 2.7+ (or earlier with installed argparse package)
76-
- for using it on Windows with Cygwin (which currently comes with Python 2.6) check out [this guide][cyg27]
77-
- **thanks to creator of this [great site called IM-D-BAPI][imdbapi]**
78-
79-
I was aware of [this existing tool][fetcher] but unfortunately it was broken at the time I tried it. My implementation relies on the third-party API that handles up to 2 million queries a day, so it's safe to assume that it's author will be keeping it up to date.
80-
On the other hand, IMDb has jumped onto the douchebag bandwagon and issued a cease and desist order to the creator of the [IMDBAPI][imdbapi], so it might stop working any time.
81-
82-
83-
## License ##
84-
85-
This tool is licensed under [GNU Lesser GPL][lgpl] license.
86-
87-
88-
[imdbapi]: http://www.imdbapi.com
89-
[cyg27]: http://www.tux.org/~mayer/cygwin/python/index.html
90-
[fetcher]: http://www.mutexes.org/imdb-movie-fetcher/
91-
[lgpl]: http://www.gnu.org/licenses/lgpl.html
1+
*NIX command line and GUI tool for retrieving OMDb movie/TV information
2+
============================================================
3+
4+
### Usage:
5+
6+
First set up an alias for the command:
7+
8+
alias omdbtool="python /path/to/omdbtool.py"
9+
10+
Or for the gui:
11+
12+
alias omdbtool="python /path/to/omdbtool-gui.py"
13+
14+
Note: in order to use the gui you will need to install [Gooey][gooey]
15+
16+
pip install Gooey
17+
18+
### Some interesting usage examples:
19+
20+
Show all info about the movie 'Cars'
21+
22+
omdbtool -t Cars
23+
24+
Show all info about the series 'Firefly'
25+
26+
omdbtool -t firefly --type series
27+
28+
Show all info about season 1 episode 1 of 'Firefly'
29+
30+
omdbtool -t firefly --season 1 --episode 1
31+
32+
Show all info about season 1 of 'Firefly'
33+
34+
omdbtool -r JSON -t firefly --season 1
35+
36+
Show all info about latest 'True Grit' movie
37+
38+
omdbtool -t "True Grit"
39+
40+
Show all info about 1969 version of 'True Grit'
41+
42+
omdbtool -t "True Grit" -y 1969
43+
44+
Show best guess for a misspelled name
45+
46+
omdbtool -t "Ture git"
47+
48+
Print movie's rating
49+
50+
omdbtool -t Cars | sed -n '/^imdbrating/{n;p;}'
51+
52+
Download movie's poster
53+
54+
omdbtool -t Cars | wget `sed -n '/^poster/{n;p;}'`
55+
56+
57+
### Additional useful features:
58+
59+
Include full plot summary (not available for some movies)
60+
61+
omdbtool -t "True Grit" --plot full
62+
63+
Include additional data from Rotten Tomatoes
64+
65+
omdbtool -t "True Grit" --tomatoes
66+
67+
Show info by IMDb id
68+
69+
omdbtool -i tt0103064
70+
71+
Print raw JSON or XML data
72+
73+
omdbtool -t Cars -r JSON
74+
75+
Print data formated as html
76+
77+
omdbtool --format html -t cars
78+
79+
Print data formated as markdown
80+
81+
omdbtool --format markdown -t cars
82+
83+
84+
85+
### Example to get ratings for all movies in current directory
86+
87+
(it will use directory and file names as movie titles)
88+
89+
Save following code to file `get_ratings.sh` (make sure to update the path in line 3):
90+
91+
ls -1 |
92+
while read title; do
93+
res=`python /path/to/omdbtool.py -t "$title"`
94+
rating=`echo "$res" | sed -n '/^imdbrating/{n;p;}'`
95+
restitle=`echo "$res" | sed -n '/^title/{n;p;}' | sed s/*//g`
96+
year=`echo "$res" | sed -n '/^year/{n;p;}'`
97+
echo "$title * $restitle * $year * $rating"
98+
done
99+
100+
Then execute the saved command to fetch all the ratings: `./get_ratings.sh > ratings.txt`
101+
(it'll take a while to retrieve all the data). Then you can open the `ratings.txt` file to see the movie ratings, or you can sort the movies by ratings to pick the best one to watch: `< ratings.txt sort -t* -k4 -r`
102+
103+
104+
## Notes ##
105+
106+
- works with Python 3 and Python 2.7 or earlier with argparse package installed
107+
- **thanks to the creator of this [great site called OMDBAPI][omdbapi]**
108+
109+
110+
## License ##
111+
112+
This tool is licensed under [GNU Lesser GPL][lgpl] license.
113+
114+
115+
[omdbapi]: http://www.omdbapi.com
116+
[lgpl]: http://www.gnu.org/licenses/lgpl.html
117+
[gooey]: https://github.com/chriskiehl/Gooey

TODO.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Fix CSV output
2+
3+
Add a output file option
4+
5+
Added -v for the api version (The only api out right now is V1 but V2 seems to be on it's way)
6+
7+
Clean up the code
8+
9+
Package both packages into exes with pyinstaller
10+
11+
Add some custom icons

imdbtool.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

omdbtool-gui.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
import argparse
3+
import urllib
4+
import sys
5+
import json
6+
from gooey import Gooey
7+
from gooey import GooeyParser
8+
@Gooey
9+
def main():
10+
parser = argparse.ArgumentParser(description='Get OMDb data for a movie')
11+
parser.add_argument("-t", help="Movie title")
12+
parser.add_argument("-y", help="Year of release", type=int)
13+
parser.add_argument("-i", help="IMDb movie id")
14+
parser.add_argument("-r", help="Return raw XML/JSON response", choices=['JSON','XML'])
15+
parser.add_argument("--plot", help="Length of plot summary", choices=['short','full'])
16+
parser.add_argument("--tomatoes", help="Include Rotten Tomatoes data too", action="store_true")
17+
parser.add_argument("--type", help="movie, series, episode", choices=['movie','series','episode'])
18+
parser.add_argument("--season", help="season number", type=int)
19+
parser.add_argument("--episode", help="episode number", type=int)
20+
parser.add_argument("--format", help="Output formated in html, markdown or csv, leave out for text", choices=['html','markdown','csv'])
21+
args = parser.parse_args()
22+
23+
params = {}
24+
keys = ['t', 'y', 'i', 'plot', 'r', 'tomatoes','type','season','episode']
25+
26+
for k in keys:
27+
if args.__getattribute__(k): params[k] = args.__getattribute__(k)
28+
29+
if len(params) == 0:
30+
parser.print_usage()
31+
sys.exit()
32+
33+
34+
### call OMDb API
35+
36+
apicall = urllib.urlopen('https://www.omdbapi.com/?%s' % urllib.urlencode(params))
37+
result = apicall.read()
38+
apicall.close()
39+
40+
# print raw output and exit, if raw output was requested
41+
if args.r:
42+
print result
43+
sys.exit()
44+
if args.format == 'csv':
45+
result = result.replace('","', ',')
46+
chars_to_remove = ['"','[',']','{','}']
47+
result = result.translate(None, ''.join(chars_to_remove))
48+
print result
49+
sys.exit()
50+
# formats data as html
51+
elif args.format == 'html':
52+
result = result.replace('",', '<br>')
53+
result = result.replace('{','<br><br><br><p>')
54+
chars_to_remove = ['"','[',']']
55+
result = result.translate(None, ''.join(chars_to_remove))
56+
result = result.replace('}','</p>')
57+
print result
58+
sys.exit()
59+
60+
# formats the data as markdown
61+
if args.format == 'markdown':
62+
result = result.replace('",', '\n')
63+
result = result.replace('{','##')
64+
chars_to_remove = ['"','[',']','}']
65+
result = result.translate(None, ''.join(chars_to_remove))
66+
print result
67+
sys.exit()
68+
69+
# Encoding the data from --season option crashs the program this prints the data with out having to encode it
70+
if args.season:
71+
chars_to_remove = ['"', '[', ']','}']
72+
result = result.translate(None, ''.join(chars_to_remove))
73+
result = result.replace(',', '\n')
74+
result = result.replace('{','\n\n\n')
75+
print result
76+
sys.exit()
77+
# print requested info
78+
79+
data = json.loads(result)
80+
for k in data:
81+
print k.lower() + ":"
82+
print data[k].encode('utf-8')
83+
print "\n"
84+
85+
if __name__ == '__main__':
86+
main()

0 commit comments

Comments
 (0)