New script for 35mm.it
Posted: 2004-04-12 13:34:21
Hello, this is my first post.
The 35mm.it script is no longer working... because the site has moved form old .XTML to new .JSP pages.
I have rewritten the script for 35mm.it:
Regards
Pivello
P.S. sorry for my english
The 35mm.it script is no longer working... because the site has moved form old .XTML to new .JSP pages.
I have rewritten the script for 35mm.it:
Code: Select all
// GETINFO SCRIPTING
// 35mm.it - by Pivello
(**************************************************
* Movie importation script for: *
* 35mm.it, http://www.35mm.it *
* *
* (c) 2004 Pivello *
* *
* 12.04.2004 New script for XTML->JSP migration *
* 14.04.2004 Added test for Apache Server down *
* Removed <br> from comments field *
* 15.04.2004 Code optimization *
* Get film image if cover not found *
* *
* For use with Ant Movie Catalog 3.4.1 *
* www.ant.be.tf/moviecatalog ··· www.buypin.com *
* *
* The source code of the script can be used in *
* another program only if full credits to *
* script author and a link to Ant Movie Catalog *
* website are given in the About box or in *
* the documentation of the program *
***************************************************)
program New35mm;
const
UrlBase = 'http://www.35mm.it';
QueryBase = UrlBase + '/film/ricerca/bottom/ricercaschedafilm.jsp?titolo=';
QueryFilm = UrlBase + '/film/scheda/top/scheda.jsp?idFilm=';
QueryCast = UrlBase + '/film/scheda/bottom/cast.jsp?idFilm=';
QueryCover = UrlBase + '/film/scheda/bottom/homevideo.jsp?idFilm=';
QueryMovie = UrlBase + '/film/scheda/frameset/scheda.jsp?idFilm=';
QueryCmnts = UrlBase + '/film/scheda/bottom/recensioni.jsp?idFilm=';
var
Page: TStringList;
MovieUrl, CastUrl, FilmUrl, CoverUrl, CmntsUrl: string;
MovieName, OriginalStr, TranslatedStr, PageStr: string;
// ---------------------------------------------
// PAGE PACKING (remove extra spaces, tabs & CR)
// IN: page Url (string)
// OUT: compact page (string)
// ---------------------------------------------
function RemoveExtraChars(Url: string): string;
var
Temp: string;
PackedPage: string;
CharPos: Integer;
n: Integer;
begin
Page.Text := GetPage(Url);
for n:=0 to Page.Count-1 do
PackedPage := PackedPage + ' ' + Page.GetString(n);
repeat
CharPos := pos(' ', PackedPage);
if CharPos = 0 then
CharPos := pos(#9, PackedPage);
if CharPos <> 0 then
begin
Temp := copy(PackedPage, 1, CharPos -1);
Delete(PackedPage, 1, CharPos);
PackedPage := Temp + PackedPage;
end;
until((pos(' ', PackedPage) = 0) and (pos(#9, PackedPage) = 0));
result := PackedPage;
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 GetValue(StartMarker, EndMarker: string; CutStartMarker, CutEndMarker: boolean): string;
var
StartPos: integer;
EndPos: integer;
Value: string;
begin
Value := '';
StartPos := pos(StartMarker, PageStr);
if (StartPos > 0) then
Delete(PageStr, 1, StartPos-1);
StartPos := pos(StartMarker, PageStr);
EndPos := pos(EndMarker, PageStr);
if ((StartPos > 0)and(EndPos > 0)) then
begin
if CutStartMarker then
StartPos := StartPos + length(StartMarker);
if not CutEndMarker then
EndPos := EndPos + length(EndMarker);
Value := copy(PageStr, StartPos, EndPos-Startpos);
Delete(PageStr, 1, EndPos);
end;
result := Value;
end;
// -----------------------
// ANALYZE MOVIE DATA PAGE
// IN: none
// OUT: set Ant fields
// -----------------------
procedure AnalyzeMoviePage;
var
i, h, m: integer;
Duration, Description, Cast, TempStr, TempImg, hh, mm: string;
begin
// Get packed title main page
PageStr := RemoveExtraChars(FilmUrl);
// Get film image (used if cover not found)
TempImg := getValue('/immagini/film/','" width="150" height="150"',false,true);
// Translated Title field
SetField(fieldTranslatedTitle, getValue('<!-- titolo --> <b>','</b>',true,true));
// Original Title field
SetField(fieldOriginalTitle, getValue('<!-- titolo originale --> <b>','</b>',true,true));
if(GetField(fieldOriginalTitle)='')then
SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
// Country field
SetField(fieldCountry, getValue('<!-- nazionalità --> ','<br>',true,true));
// Duration field
TempStr := getValue('<!--durata del film --> ','<br>',true,true);
Duration := '';
if (length(TempStr) > 0) then
begin
i := Pos('e', TempStr);
hh := copy(TempStr, 1, i - 3);
mm := copy(TempStr, i + 2, Length(TempStr) - i - 2);
h := StrToInt(hh, 2);
m := StrToInt(mm, 2);
Duration := IntToStr(h * 60 + m);
end;
SetField(fieldLength, Duration);
// Category Field
SetField(fieldCategory, getValue('<!-- genere --> <b>','</b>',true,true));
// Director Field
SetField(fieldDirector, getValue('target="_top">','</a>',true,true));
// YearField
SetField(fieldYear, getValue('<!-- anno --> Anno: ','<br>',true,true));
// Producer Field
SetField(fieldProducer, getValue('target=''_TOP''>','</a>',true,true));
// Description Field
Description := '';
repeat
TempStr := getValue('<span class="trecinque_dat">','<br>',true,true);
Description := Description + TempStr+ ' ';
until(TempStr='');
SetField(fieldDescription, Description);
// Actors Field
PageStr := RemoveExtraChars(CastUrl); // Get packed Cast page
PageStr := Copy(PageStr,1,pos('<!-- end list cast -->',PageStr));
Cast := '';
repeat
TempStr := Trim(getValue('target="_top">','</a>',true,true));
if ((Cast<>'') and (TempStr<>'')) then
Cast := Cast + ', ';
Cast := Cast + TempStr;
until((TempStr='')or(Length(TempStr)>20));
if Cast = '' then
begin
PageStr := RemoveExtraChars(CastUrl);
Delete (PageStr,1,pos('<!-- produzione -->',PageStr));
Cast := Trim(getValue('</span><br>','<br> </td>',true,true));
end;
SetField(fieldActors, Cast);
// image
PageStr := RemoveExtraChars(CoverUrl); // Get packed cover page
TempStr := getValue('/immagini/','" align="',false,true);
if TempStr = '' then
TempStr := TempImg;
GetPicture(UrlBase + TempStr, False);
// Size Field
SetField(fieldSize, getValue('Supporto: <span class="trecinque_dat_scuro_nobold">','</span>',true,true));
// Comments Field
PageStr := RemoveExtraChars(CmntsUrl); // Get packed comments page
Delete (PageStr,1,pos('<!-- recensioni redazione esplose -->',PageStr));
TempStr := getValue('<td class="trecinque_dat_scuro_nobold">','<br> <br>',true,true);
HTMLRemoveTags(TempStr);
SetField(fieldComments, TempStr);
// Movie URL field
SetField(fieldURL, MovieUrl);
// Display search result
DisplayResults;
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
TempIdFilm: string;
TempTitle: string;
StartPos: integer;
EndPos: integer;
begin
if OneFilm then
begin
StartPos := pos('/film/scheda.jsp?idFilm=', PageStr);
EndPos := pos(''' target=''_top''', PageStr);
if StartPos > 0 then
begin
TempIdFilm := copy(PageStr, StartPos + 24, EndPos-Startpos-24);
result := QueryMovie + TempIdFilm;
end
end
else
begin
PickTreeClear;
repeat
StartPos := pos('<a href="/film/scheda.jsp?idFilm=', PageStr);
EndPos := pos('" target="_top"', PageStr);
if StartPos > 0 then
begin
TempIdFilm := copy(PageStr, StartPos + 33, EndPos-Startpos-33);
Delete(PageStr, 1, EndPos);
StartPos := pos('">', PageStr);
EndPos := pos('</a>', PageStr);
TempTitle := copy(PageStr, StartPos + 3, EndPos-Startpos-4);
PickTreeAdd(TempTitle, QueryMovie + TempIdFilm);
end;
until(StartPos = 0);
result := '';
end
end;
// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE:
// IN: page Url (string)
// OUT: none
// ---------------------------------
procedure AnalyzeSearchPage(Url: string);
var
FilmId: string;
begin
PageStr := RemoveExtraChars(Url);
if pos('Nessun film trovato.', PageStr) > 0 then
ShowMessage('Title not found / Nessun film trovato.')
else if pos('Si è verificato un errore',PageStr) > 0 then
ShowMessage('Server not available, try later / Server non disponibile, prova più tardi')
else
begin
if pos('Risultato della ricerca:', PageStr) = 0 then
MovieUrl := PopulatePickTree(true) // One title found
else
begin
PopulatePickTree(false); // More titles found..
if not PickTreeExec(MovieUrl) then // ..select one
exit;
end
FilmId := Copy(MovieUrl,59,20); // get film id from movie url
FilmUrl := QueryFilm + FilmId;
CastUrl := QueryCast + FilmId;
CoverUrl := QueryCover + FilmId;
CmntsUrl := QueryCmnts + FilmId;
AnalyzeMoviePage;
end;
end;
// ----------
// MAIN:
// IN: none
// OUT: none
// ----------
begin
if CheckVersion(3,4,1) then
begin
TranslatedStr := GetField(fieldTranslatedTitle);
OriginalStr := GetField(fieldOriginalTitle);
if (TranslatedStr <> '') then MovieName := TranslatedStr else MovieName := OriginalStr;
if (Input('35mm.it - By Pivello', 'Enter the title of the movie / Inserire titolo del film:', MovieName)) then
begin
Page := TStringList.Create;
MovieUrl := QueryBase + UrlEncode(MovieName);
AnalyzeSearchPage(MovieUrl);
Page.Free;
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.1)');
end.
Pivello
P.S. sorry for my english