Miran's MovieDB Poster Downloader

This rename script tries to download the movie poster from themoviedb.com.

Update: NEWER VERSION

There is a new Version of the script utilizing the new DOpus 11 Script functionality. You can find it in a separate thread of the Script Add-Ins forum:

TheMovieDB Poster&Info Downloader V2.0

Installation
Download and unzip the .orb file and import it the usual way.

Customize "Old Name" and "New Name" in DOpus rename dialog according to
your movie naming scheme. "New Name" must contain the movie title only!

Warnings
This script is very basic, at the moment there is no
error handling at all. If there is a problem the script will just fail.

Feel free to use, optimize and enhance the script. Please post your changes in this thread of the Dopus Resource Centre forum.

Many Thanks go to the themoviedb.com community for this great service.
Mirans MovieDB Poster Downloader.zip (1.81 KB)

Once again, thanks for this. I wanted to try it but received the following in the scripts section of the logs...

Error at line 104, position 1
ActiveX component can't create object: 'ScriptControl'
Script error - script aborted

Appreciate your sharing this awesome work. I can't tell you how much your TV script has helped. I hope to payback one day...

hmm, seems like the msscript.ocx is missing on your computer.

google brought up this info
http://social.technet.microsoft.com/Forums/en-US/w7itprogeneral/thread/30b04caf-6c38-4982-b28c-81449559e1a5

I am not sure if this could help.

as a workaround you could blank out the encodeURI function in the rename script

just replace

function encodeURI(uri)
	Dim SC
	Set SC = CreateObject("ScriptControl")
	SC.Language = "JScript"
	encodeURI = SC.Run("encodeURI",uri)
end function

with

function encodeURI(uri)
	encodeURI = uri
end function

The script will work without this function for all movies that don't have any special characters in the title.
e.g. "the Matrix" should work, while "Männerherzen" would not.

The encodeURI function is more or less a "hack", I could not find a proper function in vbs, therefore I just call a jscript function. Maybe a VBS-Expert could give a hint how to do the URI encoding without the jscript thing.

I appreciate the help. It turns out (as you stated) that msscript.ocx is not included in windows 7 64 bit the way it was before. I'll continue to look into this.

As a test, i tried your suggestion to change encodeURI() to just return what was passed and it worked like a charm (I'll be sure to watch out for the caveat you mentioned).

I'll also report back if I find a way for msscript to work for this type install.

Have a great weekend!

After googling a lilttle, it looks like there is no 64bit version of msscrip.ocx. Too Bad. But I am pretty sure that there is a native vbs function for encoding uris the same way as the jscript function does. I just could not find the right one.
Maybe someone with more experience in vbs could help out with the right command.

This is useful... thanks for posting it Miran.

For those interested in this rename script - some notes:

  • Some anti-virus engines may flag the VBscript code contained in the button as a "VBS/Psyme" trojan detection... I've looked at the code and don't see any real concern, McAfee probably doesn't like the loading of the url to get the image file from the website.
  • If (like me...) you want to just use this as a "button" on a toolbar, then after following the instructions provided by Miran to import the rename preset (you can also just copy the extracted Mirans MovieDB Poster Downloader.orp file to the /dopusdata\Rename Presets folder), here's an example button you can paste to your toolbar and just click on after selecting one or more movie/video files in the lister (as opposed to opening the rename dialog and selecting the preset):

<?xml version="1.0"?> <button backcol="none" display="both" icon_size="large" textcol="none"> <label>Get Movie Coverart Online</label> <icon1>#filmstrip</icon1> <function type="normal"> <instruction>Rename PRESET=&quot;Mirans MovieDB Poster Downloader&quot;</instruction> </function> </button>
About the issue on 64bit windows and the apparent failure in being able to call a "ScriptControl" object... well, I didn't really look into it - but I find it hard to believe no mechanism exists to do this on 64bit. I don't think VBscript has a native "encodeURI" equivalent, but I imagine there's probably some manual VBscript stuff you could use in place of calling the javascript function. In fact - I recall some "web safe" rename scripts here on the forum that might perhaps be combined to achieve a similar enough effect.

[quote="Miran"]But I am pretty sure that there is a native vbs function for encoding uris the same way as the jscript function does. I just could not find the right one.
Maybe someone with more experience in vbs could help out with the right command.[/quote]

There's the VBScript escape function which is often good enough (I've used it myself for this), but it has this discouraging note below it:

Unfortunately, MSDN is vague about the actual difference. I suspect it's that VBScript one encodes : / ; ? while the JScript one leaves them as-is. If so, the VBScript one makes sense for encoding URI path components (e.g. filenames) but not whole paths. I might be wrong, though.

Opus rename scripts can be in JScript as well as VBScript but that doesn't help much with existing code.

After a little bit of screwing around with adapting some of the web safe rename vbscript stuff into this script - it occurs to me that that is probably just silly... while it works, it won't be as functional as using the javascript encodeURI function.

Opus supports JavaScript for rename scripts as well - so I guess maybe the cleanest answer is to just to the whole darn thing in javascript... 'duh?

EDIT: Just saw Leo's note as I was posting this... I also ignored just using escape() because of that note, though I didn't bother to look at what the difference is. If it really does just come down to chars like ": / ; ?" being encoded... then for this particular use case:

a.) the only one of those chars that is a valid windows filename char is the semicolon anyway, so maybe just run escape() against the movie filename, then go BACK at the resulting encoded string an re-process it to either un-encode it or potentially re-direct it to a "colon" char (I can't be the only one who uses semicolons in place of colons in my filenames :slight_smile:)
b.) who knows... the moviedb search facility may make sense of those chars if they're encoded anyway... though again, if someone decides to use a semicolon in place of a colon in a movie title, then maybe the way above is the right way to go (i.e. for a filename like "Transformers; Revenge of the Fallen.mpg")

PHPBB_IMPORT_WARNING CODE_NEAR_LI

As luck would have it, it appears that themoviedb.org website has been experiencing some severe accessibility issues over the last few days. When I first sat down to make some mods to Mirans' original vbscript code on Wednesday, I got good results back... though even at that time the test movie query I was using (The Matrix) generated either current (4-20) or stale (4-18) data (in the <last_modified_at> tag). Weird... I didn't see any "news" post or anything like that acknowledging that they are having issues though, so I really have no idea what's going on... but as of yesterday, it wasn't just the api queries used by the script that were failing. Other parts of the website were throwing 503 - bad gateway errors and other things...

At any rate, since I had a good bit of XML output from previous queries from Mirans' original vbscript code... I just saved that to a file and loaded it into my script instead of the real search url. So, I'm reasonably sure that this version re-written in javascript should work as intended once themoviedb.org website queries start working again...

// ****************************** Change log ****************************** // 2010-12-30 v0.5 Initial Release // 2011-01-02 v0.5.1 Added URI encoding for MovieTitle // 2011-01-28 v0.5.2 Utilized DOpus rename funktions to extract MovieName // 2011-04-21 v0.5.2j jscript release with error checking by steje // // ************************************************************************
Besides being re-written in javascript... there are also a few notable modifications to Mirans' original code:
[ul][li]There are several error checks added to the code, to log an error (to the Opus 'Output Window -> Log:Script Output') in a few cases - such as if themoviedb.org query doesn't return a valid XML response or the website is unreachable (could also be due to no internet connection though) and also an error if there are no search results from the website for the movie title that was queried on.[/li]
[li]TMDb queries generally seem to return multiple search results... that is - multiple "Movie Title" matches... for instance, a query on "The Matrix" returns 7 results, including "The Matrix", "The Matrix Reloaded", "The Matrix Revolutions", and "Matrix Dezionised" among others. It looks like the "best" match is generally returned as the first search result - but particularly if a user specifies the image size using the new option (mentioned below), and the first (most likely 'correct') movie search result for some reason does NOT contain an image of the user-specified size, then without some other precautions the new code would have potentially dropped into one of the 'other' ('incorrect') movie search results and basically save the wrong movies image. To prevent this, the new code limits the images it checks to just those included in the first movie search result... it's not something most users should ever really care about - and won't functionally behave any different than Mirans original script code which always saved the 'first' image out of all images returned amongst all the movie search results... just mentioning it here in case the TMDb website returns a first search result for a movie other than what the user intended. I guess that could happen if you had either an incorrect filename for your movie, or if the website just doesn't always interpret the filename correctly or return the 'best' match as the first search result. Anyhow, theres the thought process behind limiting the image match to just the first movie search results list of images...[/li]
[li]TMDb queries also generally seem to return multiple images for each search result... for instance, a relatively large image is often the first image returned with a size of "original". There are often "cover" and "thumb" image sizes as well - along with others. A control flag (MovieDB_PosterSize) has been added that let's you determine which "poster size" you want the script to save.

[code]// ************************************************************************
// * Options *
// ************************************************************************

var MovieDB_APIKey, MovieDB_Language, MovieDB_PosterSize, MovieDB_PosterUrl, MovieDB_Url;

MovieDB_APIKey = "2cc30e3146b2f44d504561e96cfb358e";
MovieDB_Language = "en";
// Flag to control preferred image size, look at the XML output for ideas
// about the different size categories TMDb seems to use, i.e. original,
// cover, thumb, etc... the default value of "0" will cause the script to
// save the first image returned in the list of images (of which there)
// will often be multiple sizes...
MovieDB_PosterSize = 0;
MovieDB_PosterUrl = "";
MovieDB_Url = "http://api.themoviedb.org/2.1/";[/code]
...by default, the value is set to 0 and causes the script to behave the same Mirans original code - which is that the script will save ~whatever the very first image is that is returned. I added this flag so that a.) in case the website returned arbitrary "first" images, the user could reasonably limit getting potentially wildly different image sizes saved, and b.) even if the website ALWAYS returns the large image size (tagged as "original") consistently as the first image, if a user prefers to save the smaller "cover" image, they can do so... eg. by changing the default MovieDB_PosterSize = 0; in the script to MovieDB_PosterSize = "cover";... If the user-specified size cannot be found, then the script defaults back to Mirans original codes behavior (it saves the first image in the list, same as the default MovieDB_PosterSize = 0; value).[/li][/ul]
Besides those changes, I've also included a sample 'button' (DCF file) in the archive along with th rename preset. It's similar to the button code posted above...

Lastly, only the errors are saved to the Opus Script Log - which you can view by turning on the Output Window from the Opus9 Tools menu... If you want to see more messaging about what the script code is doing, then as with Mirans original code, you change the value of the LogLevel variable up towards the top of the script from it's default LOG_WARN to LOG_DEBUG.

[code]// ************************************************************************
// * System *
// ************************************************************************

var LOG_DEBUG = 0;
var LOG_INFO = 1;
var LOG_WARN = 2;
var LOG_ERR = 3;
var LOG_ALERT = 4;

var LogLevel = LOG_WARN;[/code]
Thanks again to Miran for his original work, hope however many people liked his original script finds this useful - particularly any users on 64bit Win7 with special characters in their movie filenames :slight_smile:... though others may also find the new option to specify the image size useful as well.

Feedback welcome... enjoy!
Mirans MovieDB Poster DownloaderJS.zip (2.71 KB)

Checked the TMDb forums and saw several members post about having the same api failures for the last several days...

After a check on TMDb twitter page... it appears that the site is amongst many other sites that have been affected by the Amazon Web Services / Cloud outage. Ouch... that should put the breaks on some of my customers interest in public cloud services :slight_smile:.

I finally switched to 64bit Win7 myself and updated to steje's JS-Version of the script.

And while twiddling with the script I made a small enhancement. The script is now able write an "error" file if no cover could be found and downloaded. This helps (at least me :smiley:) to quickly get an overview which movies still have no cover.
As always this could be turned off in the options part of the script

// Create an Error File if there could no poster be found (1=on; 0=off)
MovieDB_NotFoundFile = 1;
MovieDB_NotFoundFileExtension = "error"

PS:
Due to the huge contribution of steje, I thought it is only fair to rename the script to a plain "TheMovieDB Poster Downloader" :smiley: .
TheMovieDB Poster Downloader V0.6.zip (2.83 KB)

Thanks for the ack Miran... now that I've got a system that encode my DVD rips in less than 9 hours, I've accelerated my video streaming to living room TV plans and will be using this quite a bit now.

TheMovieDB.org updated their API to V3.0. Sadly they dropped the xml support and rendered the existing script useless. As I still use this function a lot, the updated the script to the new JSON-Based Api.

Installation
Download and unzip the .orb file and import it the usual way.

Customize "Old Name" and "New Name" in DOpus rename dialog according to
your movie naming scheme. "New Name" must contain the movie title only!

New Function
With the new and easy to use JSON-API I made a small enhancement. The script is now able write an "Info" file with some additional Information about the movie. This new function is turned of by default but could easily be turned on in the options part of the script

// Create an additional Info File
MovieDB_InfoFile = 1;
MovieDB_InfoFileExtension = "nfo";

Warnings
To "parse" the JSON-Response I use an un-sanitized eval! This is a potential security breach. If someone manages to hijack themoviedb.org he might exploit it and do harm to you computer.

Feel free to use, optimize and enhance the script. Please post your changes in this thread of the Dopus Resource Centre forum.
TheMovieDB Poster Downloader V0.7.zip (3.28 KB)

There is a new Version of the script utilizing the new DOpus 11 Script functionality. You can find it in a new thread of this forum:

DO11: TheMovieDB Poster&Info Downloader V2.0