Hi!
I'm working on a script to export AMC catalog to xml file. I need different format than SaveAs does, to import the catalog to the XBOX Media Center database (what a wonderful player!) and I'm stuck with an issue.
I select many movies, hit F6 and run my script in batch. What I need for the script is to ask for filename and to write the xml header lines during first pass only, and to write the footer during last pass. But I can't figure out how the script can "know" when it starts/finishes the batch. Is this possible somehow?
Ehm, a second problem I've just encountered: the best xml export algorithm I could invent is to TStringList.LoadFromFile, append movie lines, then TStringList.SaveToFile. It's slow as the file grows, but works. With one exception: the first pass, when there is no xml file yet, so LoadFromFile fails with script error. I tried try-except but it fails anyway. Is there a way to catch the file-not-found LoadFromFile error programmatically? That could be the first-run signal too...
The last run signal is not that important, I can remove/append closing xml tag on every run, but I desperately need a way (or a trick!) to determine the first run in a batch. Anyone can help?
Best regards and thanks for such great software!
dowiew
How a script can determine its first/last run in batch?
Hi,
To know if it is the first movie, you can define a global variable that you modify and check in the next passes: the values of global variables are kept between runs. Like a "AlreadyInitialized" variable that you switch to True if it is not yet the case, and at the same time you do the stuff to do at first movie (if I remember well, variables are initialized to false for Boolean, 0 for integer, and empty for the strings, but you should test to be sure).
That may also partially solve the Load/Save problem: no need to reload the TStringList as it is kept between movies.
But you have to save it each time as you cannot know when you reach the last movie unfortunately.
That also removes the non-existing file problem I guess, if you do not have to load the file anymore.
To know if it is the first movie, you can define a global variable that you modify and check in the next passes: the values of global variables are kept between runs. Like a "AlreadyInitialized" variable that you switch to True if it is not yet the case, and at the same time you do the stuff to do at first movie (if I remember well, variables are initialized to false for Boolean, 0 for integer, and empty for the strings, but you should test to be sure).
That may also partially solve the Load/Save problem: no need to reload the TStringList as it is kept between movies.
But you have to save it each time as you cannot know when you reach the last movie unfortunately.
That also removes the non-existing file problem I guess, if you do not have to load the file anymore.
Thank you for your reply!
I've already made some tests with global variables before and I still couldn't determine first pass. The variable is global and as you say "is kept between runs" - but also between batches, isn't it? Here's what I get: I set it to "AlreadyInitialized" when run first. Script initializes, runs for all movies and finishes ok. After a few days I run the script again and what I get during first run? "AlreadyInitialized", right? But this is the first run! I don't want it initialized. And I don't want to go to ini file to clear the variable manually, as I'm preparing this script for several XBMC forum users and not everyone would know how to do it...
Can the global variable be named or set value with current date/time? That would solve the problem. Should I invoke external command.com /c date >file, load the file and check date, or such? Can't the file read error be trapped?
Or maybe I'm doing something wrong.
Could you please give me some hint?
dowiew
I've already made some tests with global variables before and I still couldn't determine first pass. The variable is global and as you say "is kept between runs" - but also between batches, isn't it? Here's what I get: I set it to "AlreadyInitialized" when run first. Script initializes, runs for all movies and finishes ok. After a few days I run the script again and what I get during first run? "AlreadyInitialized", right? But this is the first run! I don't want it initialized. And I don't want to go to ini file to clear the variable manually, as I'm preparing this script for several XBMC forum users and not everyone would know how to do it...
Can the global variable be named or set value with current date/time? That would solve the problem. Should I invoke external command.com /c date >file, load the file and check date, or such? Can't the file read error be trapped?
Or maybe I'm doing something wrong.
Could you please give me some hint?
dowiew
YES! It works. I didn't realize that globals were not destroyed between runs. This solves all the major problems.
The minor one still exists, I mean there is no way to tell when is the last run, so I can't keep the growing xml stringlist in a global variable, but I have to load/save it on every run, and that is slow. But hey, it takes a minute or two per batch from time to time, so we can live with it...
BTW, I've had an attempt to write a script that would export AMC-compatible xml file, with movies filtered-out by some criteria, to import it back. To overcome poor Filter/Search capabilities built-in. I gave up for now as the task would require too much work/time. But should I? Are you ever going to release a next version with more features? Filter/Search especially?
Thank you very much for your support!
dowiew
The minor one still exists, I mean there is no way to tell when is the last run, so I can't keep the growing xml stringlist in a global variable, but I have to load/save it on every run, and that is slow. But hey, it takes a minute or two per batch from time to time, so we can live with it...
BTW, I've had an attempt to write a script that would export AMC-compatible xml file, with movies filtered-out by some criteria, to import it back. To overcome poor Filter/Search capabilities built-in. I gave up for now as the task would require too much work/time. But should I? Are you ever going to release a next version with more features? Filter/Search especially?
Thank you very much for your support!
dowiew
It's a pity to hear that... I don't have much time either so I know what you mean. But now it seems a little risky to use AMC... Our catalogs grow and in a few years when some newer Windows version comes out and AMC would stop working... what we poor users will do...
Anyway, I just posted the script I made on the Scripts forum. In case some other XBOX users would want to read their AMC movie info on TV.
The script works great now. Thank you!
Anyway, I just posted the script I made on the Scripts forum. In case some other XBOX users would want to read their AMC movie info on TV.
The script works great now. Thank you!
The program works fine in Vista (well, at least version 3.5.1 "beta") so you are still OK for some time. Even if I do not add feature I can fix bugs.
And as it is being opensource it may be continued by someone else if it is really needed. That is still better than closed-source freeware or even commercial program that can stop any day, leaving nothing behind it.
And as it is being opensource it may be continued by someone else if it is really needed. That is still better than closed-source freeware or even commercial program that can stop any day, leaving nothing behind it.