Hope someone ( other than me ) appreciate!!
Seraphico
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Claudio Rinaldi ( rinaldiclaudio@gmail.com )
Title=MyMovies
Description=Get movie info from MyMovies.it
Site=www.mymovies.it
Language=IT
Version=1.1
Requires=3.5.1
Comments=
License=
GetInfo=1
[Options]
***************************************************)
program MyMoviesIT;
uses
Pivlib; // Pivello's scripts common library
const
UrlBase = 'http://www.mymovies.it';
UrlRicerca = '&titolo_orig=®ista=&attore=&id_genere=-1&nazione=&clausola1=-1&anno_prod=&clausola2=-1&stelle=-1&id_manif=-1&anno_manif=&disponib=-1&ordinamento=1&submit=Inizia+ricerca+%BB';
QueryBase = UrlBase + '/database/ricerca/avanzata/?titolo=';
QueryFilm = UrlBase + '/dizionario/recensione.asp?id=';
ImagePath = UrlBase + '/filmclub/';
cStartNumRis = 'nel Titolo. Ho trovato '; // Result Number start Marker
cEndNumRis = ' film.</h2>'; // Result Number end Marker
cStartId = 'recensione.asp?id='; // ID start marker
cEndId = '" title="'; // ID end marker
cStartTitle = '<h2>('; // Title start marker
cEndTitle = ')</h2>'; // Title end marker
cStartTranslTitle = '<h1>'; // Translated title start marker
cEndTranslTitle = '</h1>'; // Translated title end marker
cStartImage2 = '<img src="'; // Image start marker
cEndImage2 = '"'; // Image end marker
cStartDirector = 'Un film di '; // Director start marker
cStartCast = ' Con '; // Actor start marker
cStartCategory = ' Genere '; // Catogory start marker
cEndCategory = '</a>,'; // Category end marker
cStartDuration = ' colore '; // Duration start marker
cStartDuration2 = ' b/n '; // Duration2 start marker
cEndDuration = ' minuti'; // Duration end marker
cStartCountry = 'Produzione '; // Country start Marker
cEndCountry = ' <a'; // Country end marker
cStartYear = 'href='; // Year start marker
cEndYear = '</a>'; // Year end marker
cStartDesc = '<p style="'; // Description start marker
cEndDesc = '</p>'; // Description end marker
cStartComm = '<span style="'; // Comment start marker
cEndComm = '</span>'; // Comment end marker
cStartTitleList = '">'; // Title list start marker
cEndTitleList = '</a>'; // Title list end marker
cStartImage = 'src="http://www.mymovies.it/filmclub/';
cEndImage = '"';
var
MovieUrl, MovieName, TranslatedStr, PageStr: string;
// -----------------------
// ANALYZE MOVIE DATA PAGE
// IN: none
// OUT: set Ant fields
// -----------------------
procedure AnalyzeMoviePage;
var
cImage : string;
begin
// Get packed title main page
PageStr := RemoveExtraChars(MovieUrl);
// Translated Title field
SetField(fieldTranslatedTitle, GetValueEx(PageStr, cStartTranslTitle, cEndTranslTitle,true,false));
PageStr := GetPageStr;
// Original Title field
SetField(fieldOriginalTitle, GetValueEx(PageStr, cStartTitle, cEndTitle, true, false));
if(GetField(fieldOriginalTitle)='')then
SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
PageStr := GetPageStr;
// Director Field
SetField(fieldDirector, GetValueEx(PageStr, cStartDirector, cStartCast, false, false));
PageStr := GetPageStr;
// Actors Field
SetField(fieldActors, GetValueEx(PageStr, cStartCast, cStartCategory, false, false));
PageStr := GetPageStr;
// Category Field
SetField(fieldCategory, GetValueEx(PageStr, cStartCategory, cEndCategory, true, false));
PageStr := GetPageStr;
// Duration field
SetField(fieldLength, GetValueEx(PageStr, cStartDuration, cEndDuration, true, false));
if ( GetField(fieldLength) = '' ) then
SetField(fieldLength, GetValueEx(PageStr, cStartDuration2, cEndDuration, true, false));
PageStr := GetPageStr;
// Country field
SetField(fieldCountry, GetValueEx(PageStr, cStartCountry, cEndCountry, true, false));
PageStr := GetPageStr;
// YearField
SetField(fieldYear, GetValueEx(PageStr, cStartYear, cEndYear, true, true));
PageStr := GetPageStr;
// Get film image
cImage := GetValueEx(PageStr, cStartImage, cEndImage, true, false);
if cImage = '' then
cImage := GetValueEx(PageStr,cStartImage2, cEndImage2, true, false)
else
cImage := ImagePath + cImage;
if cImage <> '' then
GetPicture(cImage);
PageStr := GetPageStr;
// Description Field
SetField(fieldDescription, GetValueEx(PageStr, cStartDesc, cEndDesc, true, true));
PageStr := GetPageStr;
// Comments Field
SetField(fieldComments, GetValueEx(PageStr, cStartComm, cEndComm, true, true));
PageStr := GetPageStr;
//if cImage = '' then begin
// cImage := GetValueEx(PageStr,,,true,false);
//end
// Movie URL field
SetField(fieldURL, MovieUrl);
end;
// ------------------------------------------------------------------
// FILL PICKTREE CONTROL WITH LINKS & TITLES or RETURN ONE PAGE LINK
// if OneFilm flag true return Film Id else populate PickTree
// IN: OneFilm flag (bool)
// OUT: one page ID (string)
// ------------------------------------------------------------------
function PopulatePickTree(OneFilm: boolean): string;
var
cFilmId,cFilmTitle: string;
StartPos,EndPos: integer;
begin
if OneFilm then begin
cFilmId := GetValueEx(PageStr,cStartId,cEndId,false,false);
result := QueryFilm + cFilmId;
end
else begin
PickTreeClear;
repeat
StartPos := pos(cStartTranslTitle, PageStr);
if StartPos > 0 then begin
Delete(PageStr, 1, StartPos - 1);
cFilmId := GetValueEx(PageStr,cStartId,cEndId,true,false); // Get ID
PageStr := GetPageStr;
cFilmTitle := GetValueEx(PageStr,cStartTitleList,cEndTitleList,true,false); // Get Title
PageStr := GetPageStr;
PickTreeAdd(cFilmTitle, QueryFilm + cFilmId);
end;
until(StartPos = 0);
result := '';
end
end;
// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE:
// IN: page Url (string)
// OUT: none
// ---------------------------------
procedure AnalyzeSearchPage(Url: string);
var
NumRisultati : string;
begin
PageStr := RemoveExtraChars(Url);
NumRisultati := GetValueEx(PageStr, cStartNumRis, cEndNumRis, true, false);
if ( (NumRisultati = '0') or (NumRisultati = '')) then
begin
ShowMessage('Title not found / Nessun film trovato.');
exit;
end
if NumRisultati = '1' then
MovieUrl := PopulatePickTree(true)
else
begin
PopulatePickTree(false);
if not PickTreeExec(MovieUrl) then // ..select one
exit;
end;
AnalyzeMoviePage;
end;
// --------------------------------------------------
// GET FIELD VALUES FROM PACKED PAGE
// IN: Start marker (String)
// End marker (string)
// Cut Start Marker (bool)
// Cut End Marker (bool)
// OUT: value (string)
// --------------------------------------------------
function GetValueEx(MyPageStr,cStartMarker,cEndMarker: string;bCutEnd,bAdjust: boolean): string;
var
StartPos: integer;
EndPos: integer;
Value: string;
begin
Value := '';
StartPos := pos(cStartMarker, MyPageStr);
if ( StartPos = 0 ) then exit; // Not found
StartPos := StartPos + length(cStartMarker);
Delete(MyPageStr, 1, StartPos -1);
EndPos := pos(cEndMarker, MyPageStr);
if EndPos > 0 then begin
Value := copy(MyPageStr, 0, EndPos-1);
if bCutEnd then
EndPos := EndPos + length(cEndMarker);
Delete(MyPageStr, 1, EndPos -1);
if bAdjust then
Value := '<' + Value;
end;
TmpPageStr := MyPageStr;
HTMLRemoveTags(Value);
HTMLDecode(Value);
result := Trim(Value);
end;
// ----------
// MAIN:
// IN: none
// OUT: none
// ----------
begin
if CheckVersion(3,5,0) then
begin
TranslatedStr := GetField(fieldTranslatedTitle);
MovieName := GetField(fieldOriginalTitle);
if (TranslatedStr <> '') then
MovieName := TranslatedStr;
if(Input('MyMovies.It', 'Enter the title of the movie', MovieName)) then
begin
InitializePivLib;
MovieUrl := QueryBase + StringReplace(MovieName,' ','+') + UrlRicerca;
AnalyzeSearchPage(MovieUrl);
FinalizePivLib;
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.