Movie Database / File Name Automatisation

I have installed the Movie Database Plugin and a corresponding shortcut as it is described under this link and this video.

If I add a movie by clicking on the Media DB plugin, it automatically replaces “:“ by " -”. For example, "Star Wars - Episode I“ instead of "Star Wars: Episode I“. This is how I want it to be.

However, if I add a movie through the shortcut (cmd+p → "add movie“), then the ":“ does not get replaced, just removed, meaning the new file gets named e.g. "Star Wars Episode I“.

How can I get the automatisation of " -" instead of ":“, even if I add a movie through the shortcut?

I have a feeling that it has to be fixed through the movie.js script, but I am really no expert.

EDIT: Try the code in this post instead of the code written below.

The following works in my local tests:

  1. Make a backup of movie.js
  2. Open movie.js
  3. Find (around line 110):
function replaceIllegalFileNameCharactersInString(string) {
return string.replace(/[\\,#%&\{\}\/*<>?$\'\":@]*/g, "");
  1. Delete the function above and replace it with:
function replaceIllegalFileNameCharactersInString(string) {
  return string.replace(/[\\,#%&\{\}\/*<>?$\'\"@]*/g, "");

function replaceIllegalFileNameCharactersInString(string) {
  return string.replace(/:/g, " -");
  1. Save movie.js and see if it works as you want it to.
  2. If it doesn’t work, you have the backup file to revert to.
  3. If it does work, joy.

Uh… Shouldn’t one of those replacement functions have a different name and call the other, @eightning ?

1 Like

I don’t know. I had the same problem as the OP and edited the movie.js file as above and it worked fine. Does look clunky.

I just removed the colon from the first function, which removes illegal characters and doesn’t replace them with anything, and then created an identical function to find the colon only and replace it with a space and a hyphen.

Used that for about 1,000 files without any problems. But I totally believe you when you say it isn’t standard. :flushed:

It would be better to do both at once like in the following:

function replaceIllegalFileNameCharactersInString(string) {

  return string.replace(/:/g, " -")
    .replace(/[\\,#%&\{\}\/*<>?$\'\"@]*/g, "")

This would replace the colon first, and then remove the illegal characters.

Updated: Removed an extra .string in between the replace functions. It shouldn’t be there in the first place…

1 Like

I tried to make it work along those lines, but couldn’t get the syntax right (my DNA is entirely orangutan and Neanderthal).

Repeating the function (if that’s the right term) did work.

I tried your code—many thanks. It asks for a movie name but doesn’t create the note. Something makes it stall.

I tried adding a semi-colon after .string.replace(/[\\,#%&\{\}\/*<>?$\'\"@]*/g, "") but that didn’t help. :person_shrugging:t3:

Well, this works …

function replaceIllegalFileNameCharactersInString(string) {
  return string.replace(/:/g, " -")
    .replace(/[\\,#%&\{\}\/*<>?$\'\"@]*/g, "");

… but I have no idea if it is really ‘clean’ or not. :face_with_spiral_eyes:

Yeah, that’s the right syntax. I did have an extra .string in there. I was on mobile, so I didn’t clearly see that one. Sorry…

1 Like

Repeating the function shouldn’t work, so I’m a little baffled that did work. Are you sure you actually managed to enter both functions when you just repeated running it? That would be considered a rather serious bug in Javascript.

Did your test case really encompass the need to run both functions to make it work? Or did something else somewhere kick in? I’m pretty sure you shouldn’t be able to run an arbitrarily choice of those two functions.

1 Like

Well, I followed the exact same set up as the OP, but back in December. When I realized that the colons were being deleted, I played around with the movies.js file and came up with the solution above.

I don’t really understand the intricacies of what happens, but when I add a new movie, a window opens asking for a title or IMDb code number. If I put that in, I then get a couple of prompts to do with the metadata I want, such as my rating, where the movie was watched, etc. The note then appears in the right folder, and if the title has a colon in it, the file name appears with a hyphen instead.

I don’t run or do anything extra to the description given in the links provided by the OP.

My hacked js file has worked to add nearly 1000 notes. Have not noticed any problems: fast and efficient. The new code is obviously cleaner, so I will use that in the future.

Don’t know why the hacked code works. I tried tons of different ideas until I hit on the repetition, and because it worked, I just stuck with it.