(*
 ---------------------------------------------

 SCRIPT:		GENRE_MOVIE(1)
 CO-AUTHORS:	pra15
 VERSION:		0.0.0.1
 DATE:		22/12/2011

 ---------------------------------------------
*)

  //---------------------- Constants-----------------------

const
 //Script types
 stMovies = 0;
 stPeople = 1; 
 stPoster = 2;
  
 //Script modes
 smSearch   = 0; 
 smNormal   = 1;
 smPhoto    = 2;
 smFinished = 3;
  
 //Parse results
 prError     = 0; 
 prFinished  = 1;
 prList      = 2;
 prListImage = 3;
 prDownload  = 4;
 
 //Download methods
 dmGET  = 0;
 dmPOST = 1;
 
 //Prefix modes
 pmNone   = 0;
 pmEnd    = 1;
 pmBegin  = 2;
 pmRemove = 3; 

 //Movie fields
 mfURL         = 0;
 mfTitle       = 1;
 mfOrigTitle   = 2;
 mfAka         = 3;
 mfYear        = 4;
 mfGenre       = 5;
 mfCategory    = 6;
 mfCountry     = 7;
 mfStudio      = 8;
 mfMPAA        = 9;
 mfRating      = 10;
 mfTags        = 11;
 mfTagline     = 12;
 mfDescription = 13;
 mfDuration    = 14;
 mfFeatures    = 15;
  
 //People fields
 pfURL        = 0;
 pfName       = 1;
 pfTransName  = 2;
 pfAltNames   = 3;
 pfBirthday   = 4;
 pfBirthplace = 5;
 pfGenre      = 6;
 pfBio        = 7;
 pfDeathDate  = 8;
  
 //Credits types
 ctActors    = 0;
 ctDirectors = 1;
 ctWriters   = 2;
 ctComposers = 3;
 ctProducers = 4;
  
 //Script data  
 SCRIPT_VERSION = '0.0.0.1';
 SCRIPT_NAME    = 'GENRE_MOVIE';
 SCRIPT_DESC    = '[EN] Apply Genre to Movie';
 SCRIPT_LANG    = $09; //English
 SCRIPT_TYPE    = stMovies;
 
 BASE_URL    = '';
 RATING_NAME = 'ADE';

 
 SEARCH_STR  = '';
 
 CODE_PAGE   = 0; //Use 0 for Autodetect 

	//------------------------ Global variables ---------------------

var
 Mode : Byte;

	//----------------------------- Functions ------------------------

function GetScriptVersion : String;    //obbligatoire
begin
 Result := SCRIPT_VERSION;
end; 
 
function GetScriptName : String;    //obbligatoire
begin
 Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : String;    //obbligatoire
begin
 Result := SCRIPT_DESC;
end;

function GetBaseURL : AnsiString;    //obbligatoire
begin
 Result := BASE_URL;
end;

function GetScriptLang: Cardinal;    //obbligatoire
begin
 Result := SCRIPT_LANG;
end;

function GetScriptType : Byte;    //obbligatoire
begin
 Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte;    //obbligatoire
begin
 Result := Mode;
end;


function GetRatingName : String; //optional
begin
 Result := RATING_NAME;
end;


function GetCodePage : Cardinal;  //optional
begin
 Result := CODE_PAGE;
end;

function GetDownloadMethod : Byte;  //optional
begin
  Result := dmGET;  
end;

function GetPrefixMode : Byte;
begin
 Result := pmBegin;  
end;


function GetDownloadURL : AnsiString;    //obbligatoria

begin
		logmessage('getdownloadURL demarre')
		Result := 'C:\PVD_Vide.txt';	// Créer Fichier PVD_Vide.txt sur C://
		logmessage('getdownloadURL fin')
end;

//function GetDownloadURL : AnsiString;

//begin
//      Result := 'C:\xxx.txt';
//end;

//---------------------- Parse Page -------------------------//

function ParsePage(HTML : String; URL : AnsiString) : Cardinal;

Var
 URLTemp, StrGenre : string;
 TabURL, TabURL2 : TwideArray;
 I : integer;
begin
	logmessage ('demarre parse page')
//For  I := 1 to 20 do
    //URLTemp := GetFieldValue(I);
    //logmessage(IntToStr(I) + ' : ' + URLTemp);
    //  end;
    URLTemp := GetFieldvalue(8);
    logmessage (URLTemp)
    If Copy(URLTemp,0,4) = 'http' then begin
    ExplodeString(URLTemp, TabURL, '//');
    ExplodeString(TabURL[1], TabURL2, #46);

          if Lowercase(TabURL2[0]) = 'www'  then begin
          AddFieldValue(mfGenre, Uppercase(TabURL2[1]));
          end
          else begin
          AddFieldValue(mfGenre, Uppercase(TabURL2[0]));
          end;
        Result := PrFinished;
        
    end;
end;

//-----------------------Initialisation du script-------------------//

begin
	logmessage ('demarre')
 Mode := smSearch;   //Mode d'initialisation du script
end.
