[REL] ConcatFields to concat filenames (for MyFilms plug)

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
HappyTalk
Posts: 19
Joined: 2006-11-02 23:44:37

[REL] ConcatFields to concat filenames (for MyFilms plug)

Post by HappyTalk »

This script will append Source fields (used to store filenames) with a ;
between each one. Mode 0 relies on Title field being named .01 .02 for entries to
be grouped, sorted & appended (edit script to customise). Mode 1 just blindly
concatenates all entries. NOTE script requires additional unit
avail from http://www.antp.be/temp/scripts/AutoUtils.pas

Title Source
Fight Club.01 e:\Fight Club.01.avi
Fight Club.02 e:\Fight Club.02.avi
Fight Club.03 e:\Fight Club.03.avi

Will Become

Fight Club (1) e:\Fight Club.01.avi
Fight Club (2) e:\Fight Club.02.avi;e:\Fight Club.01.avi
Fight Club (3) e:\Fight Club.02.avi;e:\Fight Club.01.avi;e:\Fight Club.03.avi

Mode0: The number in brackets appended to Title indicates the number of entries it
contains. So you can then just delete all entries with lower (n) values.
Ant presents items in number not alpha order so you can append many different
sets at once IF they are naturally grouped numerically, otherwise you should concat
one group at a time. Easy idea is to set Ant options to repeat same script, then select
group of items & hit F6 to concat.

Mode1: Simply appends ALL items selected in whatever order Ant sends them
Use this if you don't have items suitably named, but you'll have to then
check the files order and which records to delete yourself manually after
concat

Written to allow use of MyFilms plugin for MediaPortal multiple filenames.


--------------------------

ConcatFields.ifs

Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=HappyTalk
Title=ConcatFields
Description=Sequentially append similar Source entries
Site=
Language=EN
Version=25 du 23/05/2005
Requires=3.5
Comments=This script will append Source fields (used to store filenames) with a ; |between each one. Mode 0 relies on Title field being named .01 .02  for entries to|be grouped, sorted & appended (edit script to customise). Mode 1 just blindly |concatenates all entries. NOTE script requires additional unit |avail from http://www.antp.be/temp/scripts/AutoUtils.pas| |     Title                      Source|Fight Club.01    e:\Fight Club.01.avi|Fight Club.02    e:\Fight Club.02.avi|Fight Club.03    e:\Fight Club.03.avi||             Will Become||Fight Club (1)    e:\Fight Club.01.avi|Fight Club (2)    e:\Fight Club.02.avi;e:\Fight Club.01.avi|Fight Club (3)    e:\Fight Club.02.avi;e:\Fight Club.01.avi;e:\Fight Club.03.avi||Mode0: The number in brackets appended to Title indicates the number of entries it |contains. So you can then just delete all entries with lower (n) values.|Ant presents items in number not alpha order so you can append many different |sets at once IF they are naturally grouped numerically, otherwise you should concat |one group at a time. Easy idea is to set Ant options to repeat same script, then select |group of items & hit F6 to concat.||Mode1: Simply appends  ALL items selected in whatever order Ant sends them|Use this if you don't have items suitably named, but you'll have to then|check the files order and which records to delete yourself manually after|concat||Written to allow use of MyFilms plugin for MediaPortal multiple filenames.|
License=
GetInfo=1

[Options]
Mode=1|0|0=Use Title.01 format for proper sorting & multiple groups|1=Simple append of all items in order they come

***************************************************)

program ConcatFields;
uses
  AutoUtils;

const
  VersionScript = '29/11/2006';
  NomScript = 'ConcatFields';
var
  Mode: Integer;
  FirstExec, BaseTitle, FileList: string;
  arrayFiles : array of string;

procedure ConcatFiles();
var
  Title, FileName: string;
  CurBaseTitle: string;
  i, cnt: integer;
begin
  Title := GetField(fieldOriginalTitle);
  Filename := GetField(fieldSource);

  CurBaseTitle := nposLeft('.', Title, 1, true);  // Lost.1x01.Pilot.01 = Lost.1x01.Pilot
  if (CurBaseTitle <> BaseTitle) then
  begin
    BaseTitle := CurBaseTitle; //store new base title
    for i := 0 to 15 do
      arrayFiles[i] := '';
  end;
  i := StrToInt(StrLeft(nposRight('.', Title, 1, true),2),0);
  arrayFiles[i] := Filename;

  cnt := 0;
  Filename := '';
  for i := 0 to 15 do
  begin
    if (arrayFiles[i] <> '') then
    begin
      if Filename <> '' then Filename := Filename + ';';
      Filename := Filename + arrayFiles[i];
      cnt := cnt + 1;
    end;
  end;

  SetField(fieldOriginalTitle, CurBaseTitle + ' (' + IntToStr(cnt) + ')');
  SetField(fieldSource, Filename);
  SetField(fieldChecked, 'x')
end;

procedure ConcatFiles2();
var
  Title, FileName: string;
  CurBaseTitle: string;
  i, cnt: integer;
begin
  Filename := GetField(fieldSource);
	
  if FileList <> '' then FileList := FileList + ';';
  FileList := FileList + FileName;

  SetField(fieldSource, FileList);
  SetField(fieldChecked, 'x')
end;


begin
  if CheckVersion(3,5,0) then
  begin
    if FirstExec <> 'N' then
    begin
      SetArrayLength(arrayFiles, 16);
      Mode := (GetOption('Mode'));
    end;

    if (Mode = 0) then
      ConcatFiles()
    else
      ConcatFiles2();
    
    FirstExec := 'N';

  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
    exit;
end.

Post Reply