xDBImportExport - import/export database items.

Xlobby plugin development

xDBImportExport - import/export database items.

Postby S Pittaway on Fri Jun 09, 2006 1:36 pm

xDBImportExport


This plugin will import/export xlobby databases so settings will not be lost if the database is deleted.

Before it modifies the database (durring an import) it will save a copy of the original database as database.xml.bup, so if anything goes wrong you can restore it from there.

This is something I knocked up for myslef a while ago (I kept moving my films and having to re-spider them) because I could not be bothered using dvd profiler.

I have tried to make the code a bit more readable and it should now work on nested structures (eg Movies\TV\Futuramma\Series1, Movies\TV\Futuramma\Series2 etc) its also not limited to the movie database.

I do not parse the database file properly (I do not use any xml functions), instead i effectively treat the database as a big text file and do lots of automated copy/paste operations – its not pretty but it works for me.

If anyone feels like coding it properly go for it, but be nice and share the source code so others can see how it works 


Download link (including source code) -
http://www.france.xlobby.com/plugins/xD ... Export.zip (updated on 9 June 2006)



Functions are -

export:database_path
This will look for the file database_path and save any Items in lots of files called <parameter>.xImportExport, where <PARAMETER> is the parameter entry in the database, if <parameter> is a directory it will create a file called <parameter>\dir.xImportExport.
It will export all fields for an item appart from the <coverart> tag, if there is anything else I should skip let me know.

import:database_path
This will look for the file database_path and for each Item in it it will try and find the matching <parameter>.xImportExport file.
If it does find a xImportExport file it will replace the <item> data with that contained in the file. If an xImportExport file is not found the data will not be changed.



Notes

The database path can be a simple string like movies or music or a path to a file.

If you pass in a simple string the plugin will assume you ment -
movies -> ...\XLobby\Databases\movies.xml

If you pass in a path and the plugin can not find the file you specified, it will check to see if there is a matching path inside inside the Xlobby directory -
C:\FunnyDbLocation\DB.xml –> full path specified.
skins\Htpc\databases\menu.xml -> ...\XLobby\skins\Htpc\databases\menu.xml

If it still fails to find the file an error message is shown.

Please remeber that this is not a “smart process” and if the data in xImportExport file is rubish the database will be corrupted...

I have tested this on my movie, picture and music databases, but if you have manually edited your database altered its layout it may not work...



Sean.
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Postby P3rv3rt B3ar on Fri Jun 09, 2006 2:53 pm

Thanx for making this available. Ill be needing it soon and im sure this is going to save me lot of time.
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Problem exporting/importing databases

Postby R32 on Tue Sep 12, 2006 10:39 pm

Sean,
I've been playing around with your plugin but am having some issues. When I try to export a database it gives me an error stating that it failed to save export file - System.NotSupportedException: The given path's format is not supported.

I created an event using your plugin and choose export. For the variable I tried both the path to the database and just the name of the database it's self but I still get the same error. It gives me this error for each item in my database but it does create the .xImportExport file for each item.

I was wanting to backup my movies database (I've only tried with my InTheaters database) because I use AntMovie catalog and have been adding stills. The problem is that when I add a new movie in Ant and start Xlobby the database is rebuilt from scratch and I loose all my still information for each movie. I thought that I could use your plugin to "merge" the newly created movies database with the old one to get my stills information back. Is my thinking correct?

Thanks!
R32
 
Posts: 34
Joined: Tue Jan 31, 2006 11:24 pm

Postby S Pittaway on Wed Sep 13, 2006 9:08 am

Firstly, you are right it should do what you want (i was fed up of lossing al;l my plots etc whenever i moved my films arround).

i just call an event with -

Plugin:xDBImportExport
Command:export
Variables:movies

Or

Plugin:xDBImportExport
Command:import
Variables:movies

I have never seen that error message...


The only time i have had problems with this is when i have forgot to make my film directories write-able (i store them on a central server, default access is read only).

If you want you could send me a copy of your movies.xml file and when i get chance i will see if i can see whats differant? if so try (sean dot pittaway at dai dot co dot uk).




I dont know if you can code but all i do is parse the xml file and try and get ithe file name from the paramater, its really simple code -


//WORK OUT THE PATH FROM THE PARAMETER
if (UcaseTrimLine.StartsWith("<PARAMETER>"))
{
int Pos1 = m_FileData[m_FileLine].IndexOf('>');
int Pos2 = m_FileData[m_FileLine].LastIndexOf('<');

if (Pos1 > -1 && Pos2 > -1)
{
ParamterPath = m_FileData[m_FileLine].Substring(Pos1 + 1, Pos2 - Pos1 - 1);
ParamterPath = RemoveSpecialXMLChars(ParamterPath);

//IF ITS A DIR AND A /
if (Directory.Exists(ParamterPath))
ParamterPath = ParamterPath + "\\dir.xImportExport";
else
ParamterPath = ParamterPath + ".xImportExport";
......




I had a quick google and i could try System.IO.Path.Combine() to build up the save file names.

Aslo make sure your %temp% and %tmp% system variables are set correctly.
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Postby R32 on Fri Oct 06, 2006 1:46 pm

I figured out my problem. I have two systems that I use, one is my actual HTPC the other is for testing, everything is identical between the two...well almost. The problem was when running your plugin on my test system the parameter vairable points to a drive that does not exist. After making sure to manually back up my database I ran your plugin on my main HTPC without any problems at all. Both the export and import functions worked without problem on my main HTPC.

Thanks for the great plugin, it will save me a lot of time and frustration!
R32
 
Posts: 34
Joined: Tue Jan 31, 2006 11:24 pm

Postby S Pittaway on Sat Oct 07, 2006 3:11 pm

great. i always like it when i dont have to do anything :)
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England