A Command Line Movie Scraper For Dune Media Players

My WD TV Live Hub media player recently died after four years of faithful service. I was going to get another one but (a) it has been discontinued, (b) I was getting sick of the fan noise, and (c) the newer models seem cursed with firmware glitches and a general lack of support. So I began looking for something else.

I did consider building a home theatre PC, but my dabblings with Kodi were a disappointment. There can be no doubt that such a setup has enormous flexibility, with a slick interface and powerful library features… but the video quality simply wasn’t good enough. I imagine that top-end hardware combined with madVR would produce a beautiful picture, but I wanted something small, quiet and not too expensive. Everyone seems to recommend running Kodi on a Chromebox or an NUC, but these weak little beasts cannot compete with even the lowliest dedicated hardware media player. (In truth, I don’t think any general-purpose computer can beat the subtle magnificence of a Sigma Designs chipset…)

So I gave up on the whole PC idea. Instead, and after a long and traumatising search, I settled finally on a Dune HD TV–303D. And oh my goodness! It is superb. The video and audio are unimpeachable. It is the best media player I have ever owned…

But the menus are a little dull. After seeing Kodi, I was corrupted by the shiny. I wanted a pretty movie library, with descriptions and pictures and run times and all that kind of stuff.

Focussing almost entirely on playback quality, Dune devices have no inbuilt metadata/artwork scraping functionality… yet there exist many pieces of software (e.g. Zappiti or yaDIS) that can do the job externally, and turn a collection of movie files into something that looks halfway decent. But of course: none of these applications run under Linux (apart from YAMJ, which gave me the headaches). This vexed me greatly, but I then discovered that the good people of Dune have an open standard when it comes to user customisation, making it trivial to write my own little movie management thing.

I guess the number of Linux users with Dune media players is very small… but there must be some of you out there, so I thought I’d share my bit of code. But first, perhaps I should show you what it does. You essentially end up with a big movie folder that resembles this (name + cover image/run time):

Dune Media Player: Movie List

…and when selecting a title, you get a nice info screen like this:

Dune Media Player: Movie Info

(Once here, simply press ‘ENTER’ on the remote to start playing the video, or ‘RETURN’ to go back to the movie list…)

If that looks like something you could use, then please read on…

Installation

You can grab a copy of the script + auxiliary files here: DuneMediaScraper.tar.gz

It has the following dependencies:

…all of which should be available via your package manager. (In fact, it would be very odd if they weren’t already installed…)

Oh, and it makes use of the Verdana typeface as well (because I tried them all, and Verdana looks best). You should make sure that this is available on your system… (e.g. under OpenSUSE you would simply install the package ‘fetchmsttfonts’)

The script also assumes that you have:

  1. A single source folder containing unsorted movie files – i.e. no subdirectories, and with one file per movie. (Any subtitle files must have the same name, excluding extension, as their corresponding movie)
  2. A single destination folder (a network share, or the Dune internal hard disk) which can be accessed both by your PC and your Dune media player, to serve as a home for the generated movie library. (Alternatively, you could set the output to anywhere you want and then copy the library by hand, but you’re on your own there)

With that in mind, download DuneMediaScraper.tar.gz then open a terminal and enter:

$ cd path/to/download/directory
$ tar -xvzf DuneMediaScraper.tar.gz
$ cd DuneMediaScraper
$ ls -l

The first thing you should see is the file ‘dune_folder.txt’. You must copy this to the root of your movie library destination folder:

$ cp dune_folder.txt /path/to/Dune/movie/storage

This configures how everything is displayed when you navigate to ‘/path/to/Dune/movie/storage’ on the media player itself.

Secondly, you’ll need to open the file ‘ScrapeMovies.bash’ in your favourite text editor, and set three variables. It’s easiest if I just post the relevant section of the code, then explain:

3   #######################################
4   # User variables                      #
5   #######################################
6
7   # This script accesses the following online services:
8   #
9   # - 'The Open Movie Database' (http://www.omdbapi.com/)
10  #   => Used to obtain movie info
11  #
12  # - 'The Movie Database' (https://www.themoviedb.org/)
13  #   => Used to obtain movie artwork
14  #      (Mandatory attribution notice: This product uses
15  #       the TMDb API but is not endorsed or certified by TMDb)
16  #
17  # In order to download artwork from 'The Movie Database' you
18  # will need to get an 'API key'. You can do this by registering
19  # for a free account at www.themoviedb.org (see this FAQ for
20  # details: https://www.themoviedb.org/faq/api).
21  # Once you have an 'API key', assign it to the following variable:
22  API_KEY="insert_api_key_here"
23
24  # Source and destination video directories...
25  SRC_DIR="/path/to/unsorted/movies"
26  DEST_DIR="/path/to/Dune/movie/storage"

Save the script, then go back to the terminal and enter:

$ chmod a+x ScrapeMovies.bash

Now you’re ready to go!

Usage

To format your unsorted movies, just open a terminal and type:

$ ./ScrapeMovies.bash

The script will iterate through everything in the source folder, using file names to search for movie info – you’ll see an output something like this:

##############################
Processing: Forrest_Gump.mkv
##############################

Movie found...

- Title: Forrest Gump
- Year:  1994
- Plot:  Forrest Gump, while not intelligent, has accidentally been present at many historic moments, but his true love, Jenny Curran, eludes him.

Is this correct? (y/n): y

If the particular file is identified correctly then type ‘y’ when prompted; artwork will be generated, and all relevant files moved to a new directory in the movie library destination folder:

Writing NFO -> /path/to/Dune/movie/storage/Forrest Gump (1994)/movie.nfo
tmdb_cover.jpg -> /path/to/Dune/movie/storage/Forrest Gump (1994)/
cover.aai -> /path/to/Dune/movie/storage/Forrest Gump (1994)/
tmdb_background.jpg -> /path/to/Dune/movie/storage/Forrest Gump (1994)/
background.aai -> /path/to/Dune/movie/storage/Forrest Gump (1994)/
Forrest_Gump.mkv -> /path/to/Dune/movie/storage/Forrest Gump (1994)/

Additionally, a preview of the info screen will be displayed (so you can check that everything is okay). Just close the image window to continue.

Sometimes the wrong movie is identified; if so, type ‘n’. Sometimes, too, nothing is found at all (e.g. when the file name has a typo, or omits punctuation or something). In either case, you will be prompted for an IMDb ID:

##############################
Processing: One_Flew_Over_the_Cuckoos_Nest.mp4
##############################

Error - Movie not found...

Please enter IMDB ID: 

You can find this very easily by visiting the IMDb website and manually searching for the correct movie. Once you have found the right page, check the web address in your browser – it’ll be something like this:

http://www.imdb.com/title/tt0073486/?ref_=chttp_tt_15

You need the segment consisting of ‘tt’ followed by 7 numbers: in this example, it is tt0073486. Just copy and past this into the terminal:

##############################
Processing: One_Flew_Over_the_Cuckoos_Nest.mp4
##############################

Error - Movie not found...

Please enter IMDB ID: tt0073486

Movie found...

- Title: One Flew Over the Cuckoo's Nest
- Year:  1975
- Plot:  Upon admittance to a mental institution, a brash rebel rallies the patients to take on the oppressive head nurse.

Is this correct? (y/n):

…then carry on as before.

And that’s about it. Whenever you obtain new movies, drop them into your source folder and rerun the script. Nothing else is required.

I might write another script for handing TV episodes… but this is considerably more difficult. Maybe later. At the moment, I have too much game coding to do…