A DVD video folder contains several files
Suppose you would like to index dvd-videos and those videos reside on a server, each video having it’s own folder.
You would then get a structure like you see below.

Notice how every DVD folder has a VIDEO_TS folder. In that folder you will always find a file called VIDEO_TS.IFO.
The VIDEO_TS.IFO file is a configuration file that defines the disc structure.
One DVD video folder should be one ADAM record
We want to map one DVD video to one ADAM record. Below you can see the structure.

MediaEngines can’t add files to a record, IndexMaintenanceJob can
When you have a file type that is not supported by ADAM out of the box, you would normally create a custom MediaEngine and attach it to the file type.
But MediaEngines only have the ability to add information to one record, based on one single file.
It is not possible in MediaEngines to add additional files to a record before it is saved to the database.
Because the DVD video folder contains several files that have to be merged into one record, we need to go one step up in the processing of files.
While MediaEngines are responsible for adding information to a record, IndexMaintenanceJobs are responsible for creating a record for a file, attaching the file to the record, calling the MediaEngines and saving the record to ADAM.
This is where we will plug-in.
Between creating the record for the file and saving the record to ADAM, we will write some custom code to attach the other DVD files to the record.
Overriding IndexMaintenanceJob
To plug-in some custom code to the IndexMaintenanceJob, we need to override it.
We want to plug in somewhere between creating a new record and saving the record to ADAM.
The OnCatalog method is the perfect place to do that, so we will override OnCatalog.
Plugging into the OnCatalog method
In the OnCatalog override, we will perform the following steps:
- Read the VIDEO_TS.IFO file and retrieve the structure of the DVD (table of contents)
-
Run through every file referenced by the VIDEO_TS.IFO and perform these actions:
- Add the file to the record
- Create previews of the file
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
using System;
using System.IO;
using Adam.Core;
using Adam.Core.Indexer;
using Adam.Core.Records;
using Adam.Tools.ExceptionHandler;
namespace DvdIndexer.OneDvdIsOneRecord
{
public class DvdIndexMaintenanceJob : IndexMaintenanceJob
{
public DvdIndexMaintenanceJob(Application app)
: base(app)
{
// TODO: if needed, you can add some constructor logic here
}
protected override void OnCatalog(CatalogEventArgs e)
{
base.OnCatalog(e);
// if the file is not a VIDEO_TS.IFO file, we don't need to do anything else
if (!IsVideoTsIfoFile(e.Path))
{
return;
}
DvdFile videoTsIfoFile = new DvdFile(e.Path);
// add files to the record and create previews
foreach (string dvdFilePath in videoTsIfoFile.ReferencedFiles)
{
DvdFile dvdFile = new DvdFile(dvdFilePath);
// add file to the record
FileVersion dvdFileVersion = e.Record.Files.AddFile(dvdFilePath);
// create preview for the file and add it to the file version
dvdFileVersion.Previews.Add(dvdFile.GetPathToPreview());
}
}
private bool IsVideoTsIfoFile(string path)
{
return path.Equals("VIDEO_TS.IFO", StringComparison.InvariantCultureIgnoreCase);
}
}
}
|
Making sure all files are available
The IndexerMaintenanceJob is started by an indexer task.
It is not safe to assume that the indexer task will start the IndexerMaintenanceJob after all files are copied to the server.
In fact it is safer to assume that not all files will be available.
With the code sample above, the indexing of the VIDEO_TS.IFO file will often fail.
Since you don’t want to perform any manual action every time a DVD is indexed, ADAM has foreseen an easy way of automatically rescheduling the indexing of a file.
When you discover that a referenced file is not available, you simply throw a MissingImportException.
The code for checking if the every reference file is available looks something like this:
| C# |
1
2
3
4
5
6
7
8
9
|
// go through all referenced file paths an check if the file exists
foreach (string dvdFilePath in videoTsIfoFile.ReferencedFiles)
{
if (!System.IO.File.Exists(dvdFilePath))
{
// IMPORTANT: throw a MissingImportException to automatically reschedule the indexing of the DVD
throw ExceptionManager.SetExceptionData(new MissingImportException("Referenced DVD file could not be found"), false);
}
}
|
You have probably noticed that we created a new foreach loop and that we didn’t put the throwing of the exception in the foreach loop where we create the previews.
There is a very good and simple reason for this: performance.
Creating previews of media will always take longer then checking if the files are available.
If we would merge the two foreach loops in one and only one file was not available, we would end up having wasted a lot of time creating previews without having indexed the DVD.
Therefore it is better to check if all files exists before we start creating previews.
Making sure only the VIDEO_TS.IFO file is indexed
The custom IndexMaintenanceJob will (in it's current form) index all files; the VIDEO_TS.IFO file, images, ... but also the other DVD files.
Each file will result in a record, unless we add some code to avoid adding the file as a record.
By overriding the OnPreCatalog method, we can prevent ADAM from creating a record for files that are part of a DVD video, but that are not the VIDEO_TS.IFO file.
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
protected override void OnPreCatalog(PreCatalogEventArgs e)
{
base.OnPreCatalog(e);
if (!IsVideoTsIfoFile(e.Path))
{
// the file is a VIDEO_TS.IFO file, we don't need to do anything here
return;
}
// checking if the file to catalog is part of a DVD video folder
if (IsFilePartOfDvdVideo(e.Path))
{
// the file is part of a DVD video folder, we don't want to process this file
e.Action = CatalogAction.Fail;
}
}
private bool IsFilePartOfDvdVideo(string path)
{
DirectoryInfo folderOfFile = new FileInfo(path).Directory;
return folderOfFile.GetFiles("VIDEO_TS.IFO").Length != 0;
}
|
Registering the custom IndexMaintenanceJob
Creating the code and building an assembly doesn’t mean ADAM knows it exists.
You should register the assembly and the custom IndexMaintenanceJob in ADAM.
For more info on how to do that, you can consult your ADAM help and navigate to Developer Guide > Core > Indexers > Developing a new Indexer Process Engine.
At the bottom of the page you will find info on how to register the assembly.
Setting up an indexer task for DVD videos
Now that our code is written, the assembly built and registered in ADAM, we need to perform one last action to get things working.
Create a new indexer task.
I will not tell you how to create an indexer job (if you would not know how, you can go to ADAM help and navigate to Admin Guide > Indexing > Creating an Indexer task).
What I will tell you is which settings are important for this job:
- Process Engine: in the list you should select the name of the new custom IndexMaintenanceJob
- Import restrictions: choose wait for imports. This insures that when we throw the MissingImportException, the indexing of the file will be automatically rescheduled.
- Maximum missing import retries: set the amount to more than one. This setting determines how many times the task of indexing the file will be automatically rescheduled before it will fail.