Merging Categories
Posted: 2013-05-03 16:04:59
Categories of movies can have different values but same meanings, e.g. 'Sci-Fi' and 'Science Fiction' - or different languages. To join these categories together to one category I have written a little script. You have to write your wishes into the script code - it's not very smart, but easy.
The language code is '?', but I would encourage to introduce a new code 'TOOLS' for all the scipts which enhances dates without getting information from the internet, e.g. 'Find Duplicates', 'Remove BadChars' etc.
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Nikolaus Mueller-Buechele
Title=Category replace
Description=replaces values of category, e.g. to combine different languages
Site=forum.antp.be/phpbb3/profile.php?mode=viewprofile&u=5684
Language=?
Version=1.0
Requires=
Comments=You have to edit the script!
License=Free
GetInfo=0
RequiresMovies=1
[Options]
CatSep=0|0|0=Categories separated by comma (default)|1=Categories separated by slash
[Parameters]
***************************************************)
program CategoryReplace;
(* Script to merge categories with different values - e.g. different languages
You have to define the values of concerning categories. *)
var
i, catpos : integer;
CatSeparator, CatField, CatToChange, LeftOfCat : string;
CatList : TStringList;
begin
CatList := TStringList.create;
(***************************************************
set values: IT'S UP TO YOU!
You have to define couples of values:
the first value is the category you want to change - the index number will be even,
the second value ist the category you want to join with - the index number will be odd
Syntax:
CatList.add('<first value>');
CatList.add('<second value>');
*)
CatList.add ('Sci-Fi');
CatList.add ('Science-Fiction');
CatList.add ('Family');
CatList.add ('Kinder-/Familienfilm');
CatList.add ('Grusel');
CatList.add ('Horror');
CatList.add ('Adventure');
CatList.add ('Abenteuer');
CatList.add ('War');
CatList.add ('Krieg');
CatList.add ('Music');
CatList.add ('Musikfilm');
CatList.add ('Musik');
CatList.add ('Musikfilm');
CatList.add ('Romance');
CatList.add ('Liebe/Romantik');
CatList.add ('Romanze');
CatList.add ('Liebe/Romantik')
CatList.add ('Sport');
CatList.add ('Sportfilm');
(* end set values
***************************************************)
//get separator of multiple categories
case GetOption('CatSep') of
0: CatSeparator := ',';
1: CatSeparator := '/';
end;
for i:=0 to CatList.count -2 do
begin
//break if index is odd
if i mod 2 = 1 then
continue;
//the value to change (=CatToChange) must be a substring of fieldCategory,
//delimited with CatSeparators or start-/end-of-field
CatField:=trim(GetField(fieldCategory));
CatToChange:=trim(CatList.GetString(i));
CatPos:= pos(CatToChange, CatField);
while CatPos > 0 do
begin
LeftOfCat:=trim(copy(CatField,1,CatPos-1));
// preserve rest of category list
Delete (CatField, 1, CatPos+ length(CatToChange)-1);
CatField:= trim(CatField);
(*check: substring in front of CatToChange is empty or ends with separator - AND -
substring behind of CatToChange is empty or begins with separator
if true, replace value of category.*)
if ((CatPos=1) OR (copy(LeftOfCat,length(LeftOfCat),1)=CatSeparator)) AND
((pos(CatSeparator, CatField)=1) OR (CatField='')) then
SetField(fieldCategory, StringReplace( GetField(fieldCategory), CatToChange, trim(CatList.GetString(i+1))));
CatPos:= pos(CatToChange, CatField);
end;
end;
CatList.Clear;
CatList.Free;
end.