lm: list movies, a command-line tool
*lm* is a command-line tool which lists movies, loosely inspired from ls. Extra features allow you to download subtitles, and interact with the opensubtitles hash database. *lm* is not english oriented, and is able to provide information for all movie files.
The starting point of this little project is here at Goffi’s website. His idea was to build a command-line tool to list/filter/sort movies in current directory, using IMDbPy package to get all metadata information. When I saw the script, few months ago, I just made some modifications I though useful like displaying results in an html page with links to trailers, etc... Little by little, I realized it was a great tool to keep track of files without too much effort.
1.2 Brief features overview
Here is a short list of what you can do with *lm*:
list all movie files in current directory (recursive search) in your terminal
- filter by genre, actor, country, file size
- sort by name, rating
export this list to an html view
- with cover
- link to trailers and IMDb page
- download subtitles in any languages (source opensubtitles.org)
1.3 Underlying tools
*lm* uses Opensubtitles API through XMLRPC protocol (default python’s module xmlrpclib) to match movie file hash with their database. If a movie file hash is not know by Opensubtitles, you can send them the information with *lm*, and then participate to this collaborative referencing.
IMDb provides all metadata information (genre, actors, outline, etc...), and is called through imdbpy package.
Check the very complete official download page, you will probably see that it’s available in the package repository of your distribution. Some (un)official installers are built for Mac Os X and Windows.
IMDbPY requires *lxml* module to speed up parsing. If it’s not installed, make sure to have BeautifulSoup instead.
Note: If you’d like to install it from sources, you may just stick to the minimal configuration.
colorama (optional, for windows users only)
*lm* is mainly designed to return results on a terminal, like *ls* function. To ’map’ terminal coloration on the windows terminal, please install this package.
3 Features in detailsLet’s suppose we are in a folder with following files:
/films/ Cinema Paradiso/ 1988.Cinema.Paradiso.mkv ATB/ Attack.the.Block.avi dogville/ DOGVILLE-2003.mkv trailer.avi
xx@xx/films$ ./lm.py Attack the Block (Attack.the.Block.avi) Dogville (DOGVILLE-2003.mkv) Nuovo Cinema Paradiso (1988.Cinema.Paradiso.mkv)
Lists all files in dir and sub dirs, sorted by name with minimal description displayed.
Longer description (-l)
xx@xx/films$ ./lm.py -l Attack the Block (2011,6.8,4475Mo) [Comedy, Horror, Sci-Fi] from Joe Cornish: Attack.the.Block.avi Dogville (2003,8.0,3640Mo) [Drama, Mystery, Thriller] from Lars von Trier: DOGVILLE-2003.mkv Nuovo Cinema Paradiso (1988,8.5,8137Mo) [Drama] from Giuseppe Tornatore: 1988.Cinema.Paradiso.mkv
Displays year, imdb rating, file size, genres and directors.
Outline (-o)[+/-] show/hide this output
>xx@xx/films$ ./lm.py -o Attack the Block (Attack.the.Block.avi) *** A teen gang in South London defend their block from an alien invasion. Dogville (DOGVILLE-2003.mkv) *** A woman on the run from the mob is reluctantly accepted in a small Colorado town. In exchange, she agrees to work for them. As a search visits town, she finds out that their support has a price. Yet her dangerous secret is never far away... Nuovo Cinema Paradiso (1988.Cinema.Paradiso.mkv) *** A filmmaker recalls his childhood, when he fell in love with the movies at his village’s theater and formed a deep friendship with the theater’s projectionist.
Longest description (-L)
xx@xx/films$ ./lm.py -L
Try it! Actors, and long outline are displayed.
Open result in an html page (-S)
xx@xx/films$ ./lm.py -S
|Attack the Block
note: 6.8, votes: 26.0K
note: 8.0, votes: 59.0K
Nuovo Cinema Paradiso
note: 8.5, votes: 62.0K
This view has direct links to movie trailers (click on covers) and IMDb movie pages (click on title).
Open IMDb page (-s)
xx@xx/films$ ./lm.py -s
Will open IMDb pages, pointing on every selected movies. Be careful and don’t use this parameter when too many movie files are selected.
Filter files (-f @xx:yy)
You can filter movies with the following syntax: “@keyword:filter,filter,filter@keyword2:filter,filter”. Filter is case insensitive.
xx@xx/films$ ./lm.py -f @genre:drama ... xx@xx/films$ ./lm.py -f @genre:drama@size:+2000 ...
You can filter by genre, country, actors, size (@size:+900 or @size:-400), and by identification confidence (@unsure). Check color interpretation part of this page.
3.2 Color interpretation
When displayed in your terminal, titles can have different colors.
The best! It means that your movie hash matches an Opensubtitles known movie. 95% sure to display the right title.
Not bad. We did’nt find any matches in Opensubtitles, but we looked through IMDb, and are quite confident. 80% chance to display the right title.
We didn’t find anything on Opensubtitles, and we didn’t find any good matches in IMDb results either. We strongly recommend you to manually confirm this movie with the shell interactive command: lm.py YOUR_DIR -f @unsure --confirm.
Download subtitles (--donwload language)
xx@xx/films$ ./lm.py --download eng
Looks for subtitles on Opensubtitles database. By order of preference, *lm* chooses first: perfect file hash match, and if nothing is found, it looks for most downloaded subtitles linked to this imdb id. Subtitles files are downloaded into every movie file directory with the syntax “MOVIEFILENAME_ENG_LM1.srt” (replace ENG with chosen language). Up to 3 subtitles are donwloaded per movie.
limit: Opensubtitles limits downloads to 200 per day, please take this into consideration and don’t overload them!
language: please provide a ISO639 code as described HERE. eng/fre/ger are some examples.
503 Service Unavailable: Sometimes, Opensubtitles server is unreachable. Try again a few minutes/hours later.
Manually search/confirm movie (--confirm)
This command will take you through a confirmation process. You may have to provide other information to accurately identify the movies (imdb id, title or year).[+/-] afficher/cacher cette procédure
>xx@xx/films$ ./lm.py--confirm *************** File to confirm *************** absolute path : ~/films/dogville/DOGVILLE-2003.mkv basename : DOGVILLE-2003.mkv Dogville (2003,8.0,3640Mo) [Drama, Mystery, Thriller] from Lars von Trier: DOGVILLE-2003.mkv Do you confirm stored info? (y/n):n Will you provide an IMDb id? (y/n):n please enter movie title: dogville please enter year, leave blank if unknown: 2003 ratio <0.7 & year, we retry on base results ratio ==> dogville (for [dogville]) 1.000000 --> movie found title: Dogville --> movie found year: 2003 Confirm this result? (y/n):y movie saved
Upload movie hash and imdb id to Opensubtitles (--upload)
Selects all movies whose hash was not found on Opensubtitles but whose title was found on IMDb, and send (hash, imdb id) couple to Opensubtitles database. You will be asked to confirm before processing.
Delete files from cache (-d)
Delete selected movies from cache. You will be asked to confirm before processing. To delete all cache call: "./lm.py cache -d"
Reset cache (--reset)
Delete every cache file (stored in ~/.lm/ directory). You will be asked to confirm before processing.
IMDb downloads are long
Advice: Each time you launch *lm*, it gets metadata for files it doesn’t know, which is really slow. So, make sure to test it on a directory with a few movies.
Basically, all metadata (text data, not pictures) are stored with cPickle in the hidden directory ~/.lm/.
Here are the imdb searching steps:
- Build hash for file
- Call Opensubtitles through XMLRPC protocol.
- Do they know this hash? If yes => perfect, we get an imdb_id and exit
- Otherwise, try to guess movie title/year from the filename (omit some stop words and look for a potential year in the movie filename)
- Send guessed title to IMDB, get the list of results
- If we guessed a year (at step 4), limit results to movies released this year
- Find the best match on all results, for ALL AKAS (non original titles)
- If the best match isn’t good enough, and if we filtered results at step 6, GOTO 7 with non-filtered imdb results.
Note: *lm* is not english oriented at all. Example "sexcrimes.avi" will match "wild things" its original title.