Sunday, June 21, 2009

Script to change or remove genres in movie xml files

Download
Download Scripts

Version change 09/08/2009 - Now removes duplicate genres from an xml file. For example, if it has the genre 'comedy' three times, it will automatically remove the extra two 'comedy' genres.

Intro
There may be a better way to do this, but this is how I've been doing it and I wanted to make it available to others. If you are using Media Browser and go to sort by Genre, there may be genres you don't want. Or there may be genres that you want renamed. The scripts I am posting will allow you to do both, genre substitutions and genre removals from .xml files (ie: mymovies.xml).

I know it's not fun to read a ton of instructions so I will try to make this short, but I recommend you read this so you know how to use the scripts. If you have questions you can post in the comments or email me.

Overview of the scripts

Below is a list of the scripts and what they do. Before you run any of them, you need to edit the settings in the _Settings.txt file.

BuildGenreList.vbs script

I recommend you run this script first. It will look through all of the movie xml files and will build a list of each unique genre. You will use the results of the script (Genres.txt) to tell the next script what to do.

ChangeGenres.vbs script

This script takes your desired changes and implements them by modifying the xml files that need the specified changes.

RestoreFromBackup.vbs script

This script restores the original .xml files before changes were applied. MakeBackup must be =True in the settings file before running ChangeGenres.vbs if you want to make backup copies.

Using the scripts

Start off by extracting the .zip file into a folder. You want all the scripts and related text files to be in the same folder.

Open the _Settings.txt file. There are some instructions inside but basically here's what you will do.

1) Folders line. Here you set the folder or folders you want to run the scripts against. I have 3 folders that have movies, so for me this line reads Folders=E:\Movies,F:\Movies,G:\Movies. If you only have one movie folder (ex: C:\My Movies\Movies) then your's will read Folders=C:\My Movies\Movies. Separate more than one path with a comma (like my example above).

2) File line. This tells the script the name of the .xml file you want to process. For most people this will be mymovies.xml. So it would read File=mymovies.xml
If your setup uses a different .xml file just set it to be the name of your xml file. Ex: File=yourfile.xml

3) ShowCompletedBox line. If you want to know when the script is finished use ShowCompletedLine=True. If you are running the scripts as a schedule task and you don't want interaction, set it to False. If you have a lot of movies, the script will take a little bit. It's not too bad though. In testing it was about 3 minutes to process 100 movies.

4) MakeBackup line. If you want a backup copy of the .xml file before it gets changed, set this to True. Ex: MakeBackup=True. This will create a file called mymovies.xml.bak (or whatever your file is) and will be the .xml file before changes were made to it.

These settings are used by all scripts. So the first thing you want to do is open _Settings.txt file and edit the settings.

Building a list of genres

Now you can run the BuildGenreList.vbs script. While it is running (same goes for the other script) there will be a file in the folder called _StatusLog.txt. Open this file and you can see how far along the script is. While it is open you will not see the new data being written. After you close it you can re-open it and get refreshed progress. Running this script is optional. If you want to skip it, just create a text file called Genres and in it put the stuff you want changed. Something=Something Else to change, or Something=- to remove.

When it completes, and you will get an annoucement if you set ShowCompletedBox=True, you will have a Genres.txt file in the folder. Open it and you should see each genre in your collection.

Making Genre Changes

You will set how you want things changed using the Genres.txt file.

1) To substite a genre use this syntax: something=something else. So if I want Feel Good changed to Comedy I would find Feel Good in the text file and follow it with =Comedy. So, Feel Good=Comedy. That will change any genre called Feel Good to be Comedy.
Example: Suspense/Thriller=Thriller

2) To remove a genre, find it in the text file and follow it with =-. That's an equals sign and then a minus sign. This will completely remove the genre from the xml files.
Example: Monster Movies=-

Now run the ChangeGenres.vbs script. Again, you can check on it's progress by opening the _StatusLog.txt file. This will tell you what movies have been changed and any actions performed. If, in the _Settings.txt file you have MakeBackup=True, when this runs it will make a copy of the xml file before changes with a .bak extension. When the script finishes the _StatusLog.txt file will have a "Done" line

Doing a Restore

Provided you had MakeBackup=True set in the settings file before you ran the ChangedGenres.vbs script, you will have the ability to restore your original .xml files. The RestoreFromBackup.vbs script also uses the settings in the _Settings.txt file to know what directories to run against. You can also have it tell you when done. And, the progress, and changes, are recorded in the _StatusLog.txt file.

Use the scripts at your own risk. During my testing they are working as designed.

Troubleshooting

I have not tested this with Vista's UAC (User Account Control) enabled. If you have the UAC on then you may need to right click the script and choose 'Run as Administrator' before running them.

When you start the Genres.txt file is empty. You need to either run the BuildGenreList.vbs script, or manually edit the file to have your desired changes.

If you specified an invalid folder it will tell you in the _StatusLog.txt file. If you made a syntax error in the Genres.txt file either no changes will occur where the syntax error is, or you will get incorrect results. If something gets blundered, and you had MakeBackup=True, you can run the RestoreFromBackup.vbs script and it will restore you original .xml files.

I do not have On Error Resume Next enabled in the scripts. That way, if an error occurs the script will stop. If that happens, you can write down the error, or take a screenshot and send it to me.




21 comments:

Jeff said...

Hey Toby, thanks for the script. Worked perfectly the first run.

toby said...

Hey Jeff,
Glad to hear that. I hope people find it helpful.

Sebastian said...

Perfect!!!

toby said...

Thanks Sebastian! Would it be better to have a GUI for this tool? I envisioned it being run as a scheduled task. So that's why no gui and the ability to turn off any interactive output.

But, if this is something where a GUI would be good, let me know and I will make one.

Sebastian said...

Hi Tobi,

I think the usability just with the text file is very easy and almost no possibility to make errors, so for me it's ok that way.
But I love your GUI for the Stark Cover thing!
By the way, I posted a thread in the tutorial section of mediabrowser forum mentioning your tool, hope that's ok...

toby said...

Hi Seabastian,
Thanks for getting back to me. I appreciate your input. Glad you like the gui. It's nice to be able to get an idea of what things will look like before actually running it.

No problem on posting on the forum. Maybe that way more people will know about it and use it.

Thanks!
toby.

Arjan400016 said...

Thanks

Jim said...

These scripts are awesome, thanx.

Anonymous said...

I can't seem to get script to work on my VIDEO_TS folders. It works on my shares that have AVI files.

Below is my entry in _Settings file.


Folders=\\Digital-Srv2\my DVD's - Archive 01\

Under this share are Folders with Movie name that includes the mymovie.xml file and my VIDEO_TS folder.

When I run the script it immediately comes back with DONE. The Log file does not show that it interrogated any of the folder structure under the share.

Any thoughts?

NizZ8 said...

Thanks for sharing, Works great!

Voxen said...

Hi,
Great tool.
But I have a problem with a Genre that I want to change.

Tried this

Sci-Fi=Science Fiction

Deletes all Genres in xml file

So tried this

Science Fiction=Sci-Fi

This just deletes all Sci-Fi and does not replace with Science Fiction.

Reading all the instructions I think it might do with this character (-) in name of Sci-Fi.

Any Ideas?

Mat said...

This works beautifully. Thanks very much.

Now, I'm wondering if with some slight tweaks, you could actually use the same methodology to get rid of unwanted Studio info - I've got numerous films which are Warner Bros This, and Warner Bros. That?

What do you reckon?

Mat said...

And while I'm at it - how about the MovieType category (incl. being able to putting a generic value if there is none!).

Sorry - just think this is a great tool, which has lots of potential for cleaning up those pesky xml files!

toby said...

I hear ya Mat. I actually started working on a Windows form written in VB to do this, and include more advanced features. Then I got too ambitious and bogged down on it. So I am thinking about starting over and maybe I can work in your suggestions, or make the tool more dynamic so you can specify your own values to change. We will see.

Mat said...

I know the feeling! Too easy to get bogged down in the possibilities - hope you manage to find time to take it further.

toby said...

I'm going to start off with just doing genres. I see studios in the xml but I didn't see movietype. I assume you mean like dvd, bluray, that type of thing.

I think this time I've got to think it through better. What I made worked but it was complicated.

toby said...

To Mat or anyone interested...I'm going to have a beta of an app to manage genres and studios in xml files soon. If you want to help me test send me an email at aamjohns@yahoo.com

Thanks,
toby.

chris said...

Hey Toby, fantastic scripting,great job.
Your scripts go beautifully with James971's amazing genre icons hosted at
http://www.thehtpc.ne t/cip/genre/

I know that you said your working on a GUI for the script and im looking forward to that.

I had a quick go at modifying your scripts and _settings.txt file to do the same job for TV series.
It scans the series.xml files ok but cant extract the genre data.I see the syntax is a little different than the mymovies.xml files.
My scripting is next to hopeless and I just wondered how easy it would be to modify the scripts to create a TV Series Genres tool to add to the set.

Thanks for the script and the geat GUI for StarkCovers,is that your build that now comes with it?
Chris

chris said...

PS ive sent you an email to try out the beta..

Jason said...

Worked great, thanks!

robnix said...

You're a life saver. I've been looking for this type of utility for ages. Thank you so much.