I try to cut-copy some codes and relative variables from jef script imdb but not works. thanks and sorry for bad eng
original code
- Code: Select all
const
script_name='Film.tv.it';
language='Italian';
version=15;
author='Vlad';
MinProgramBuild=2120;
PCount = 12;
//MaxPicturesCount = 3;
var
title, MovieName, s, s2, s3, s4, year, director, name, character, BasicURL, country, description, salary: string;
episodes, movie_code, movie_site_url, title_code, imdb_code: string;
titles: array of string;
titles_count: integer;
i, j: integer;
director_code, code: string;
directors, writers, actors, characters, genres, imdb_codes: array of string;
duration: integer;
rating, imdb_rating: double;
front_cover_url: string;
posters_exists, ask_amazon: boolean;
original_title, mpaa, mpaa_rating: string;
prefixes: array [1..PCount] of string;
function MovieSearch: integer;
var
i, j, k, l: integer;
title: string;
begin
s:='';
titles_count:=0;
//if the search is forwarded to the movie's page (only one result)
if (pos('<title>Ricerca ', all)<=0) then begin
title_code:=ParseString(all, '<li id="sel"><a href="/scheda.php/film/(\d+)/', 1);
if title_code<>'' then begin
SetSearchResult('movie', title_code);
titles_count:=1;
end;
end
//otherwise check seach results
else begin
i:=pos('<div id="ricerca">', all);
if i>0 then begin
j:=MyPos('<!-- fine ricerca -->', all, i+1);
if j>0 then
s:=copy(all, i+17, j-i-17);
end;
if (s='') or (pos('<h3>Non ho trovato nulla!</h3>', all)>0) then
//Movie not found
else begin
i := pos('<dt><a href="/scheda.php/film/',s);
while i>0 do begin
titles_count:=titles_count+1;
SetLength(titles, titles_count);
j := MyPos('</dd>', s, i+1);
if j<=0 then
j:=MyPos('</dt>', s, i+1);
s2 := copy(s, i, j-i);
title_code:=ParseString(s2, '<a href="/scheda.php/film/(\d+)/', 1);
title:=RemoveTags(s2);
title:=DecodeHTML(title);
title:=ClearExtraSpaces(title);
while (length(title)>0) and (title[1]=' ') do
delete(title, 1, 1);
titles[titles_count-1]:=title_code;
SetSearchResult(title, title_code);
delete(s, 1, j+20);
i:=pos('<dt><a href="/scheda.php/film/', s);
end;
end;
end;
result:=titles_count;
end;
//get movie name by barcode(UPC-12)
function GetMovieNameByUPC(barcode: string): string;
var
url, all, s2, s3, res: string;
i, j: integer;
begin
res:='';
url:=format('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=0J0N83PT9M72BYH98YR2&Operation=ItemSearch&Keywords=%s&SearchIndex=Video&ResponseGroup=Request,Images,Tracks,ItemAttributes', [barcode]);
url:=ReplaceStr(url, ' ', '+', -1);
all:=DownloadURL(url);
//search image by title
i:=pos('<Item>', all);
while (i>0) and (res='') do begin
j:=MyPos('</Item>', all, i+1);
if j>0 then begin
s2:=copy(all, i, j-i);
s3:=ParseString(s2, '<Title>(.*?) \(.*\)</Title>', 1);
if s3='' then
s3:=ParseString(s2, '<Title>(.*?)</Title>', 1);
if s3<>'' then
res:=s3;
end;
i:=MyPos('<Item>', all, i+1);
end;
i:=pos('[', res);
if i>0 then begin
j:=MyPos(']', res, i+1);
if j>0 then
delete(res, i, j-i+1);
end;
result:=res;
end;
//Get search URL by movie name
function GetSearchURLbyName(MovieName: string): string;
var
url: string;
begin
url:=format('http://www.film.tv.it/cerca.php?q=%s&x=0&y=0', [MovieName]);
url:=ReplaceStr(url, ' ', '+', -1);
result:=url;
end;
//Download search results from URL
function DownloadSearchURL(url: string): integer;
begin
all:=DownloadURL(url);
if all='-1' then
result:=-1
else
result:=MovieSearch;
end;
function GetMovieURL(code: string; images_only: boolean): string;
begin
result:=format('http://www.film.tv.it/scheda.php/film/%s/', [code]);
end;
//returned link to front cover
function GetAmazonImages: string;
var
res, all, url, s, s2, s3, amazon_url: string;
i, j: integer;
begin
//discard info in brackets
s:=original_title;
url:=format('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=0J0N83PT9M72BYH98YR2&Operation=ItemSearch&Keywords=%s&SearchIndex=Video&ResponseGroup=Request,Images,Tracks,ItemAttributes', [original_title]);
url:=ReplaceStr(url, ' ', '+', -1);
all:=DownloadURL(url);
//search image by title
amazon_url:='';
i:=pos('<Item>', all);
while (i>0) and (amazon_url='') do begin
j:=MyPos('</Item>', all, i+1);
if j>0 then begin
s2:=copy(all, i, j-i);
s3:=ParseString(s2, '<Title>(.*?) \(.*\)</Title>', 1);
if s3='' then
s3:=ParseString(s2, '<Title>(.*?)</Title>', 1);
s3:=DecodeHTML(s3);
if s3<>'' then
begin
//if title=s3 then begin //!!!
if pos(UpperCase(original_title), UpperCase(s3))=1 then
begin
amazon_url:=ParseString(s2, '<LargeImage><URL>(.*?)</URL>', 1);
end;
end;
end;
i:=MyPos('<Item>', all, i+1);
end;
if amazon_url<>'' then begin
SetImageName('', amazon_url, '', 1);
res:=amazon_url;
end;
result:=res;
end;
//save front cover to file
function SaveFrontCover(url, FileName: string): boolean;
var
fs: TFileStream;
s, referer: string;
i: integer;
begin
referer:='http://www.film.tv.it/gallery.php/film/';
s:=DownloadURLWithReferer(url, referer);
if (length(s)>0) and (s<>'-1') then begin
try
fs:=TFileStream.Create(FileName, fmCreate);
fs.Write(s, Length(s));
fs.Free;
result:=true;
except
result:=false;
end;
end
else
result:=false;
end;
function MovePrefixLeft(name: string): string;
var
i, j: integer;
begin
// replace "The", "A", "An"... to the left
for j:=1 to PCount do
begin
i:=pos(', '+Prefixes[j], name);
if i>0 then
if (i = length(name)-length(Prefixes[j])-1) or
(length(name) >= i+2+length(Prefixes[j])) and (name[i+2+length(Prefixes[j])]=':') then
begin
if Prefixes[j][length(Prefixes[j])] = '''' then
name := Prefixes[j] + copy(name, 1, i-1) + copy(name, i+length(Prefixes[j])+2, length(name)-i-length(Prefixes[j])-2+1)
else
name := Prefixes[j]+' ' + copy(name, 1, i-1) + copy(name, i+length(Prefixes[j])+2, length(name)-i-length(Prefixes[j])-2+1);
break;
end;
end;
Result := name;
end;
function ClearExtraQuotes(name: string): string;
begin
// Clears extra quotes «"»
if length(name)>0 then
if (name[1]='"') and (name[length(name)]='"') then
name := copy(name,2,length(name)-2);
Result := name;
end;
function GetInfo(url: string; images_only: boolean): string;
var
keyword, s, s2, s3, plot_outline, shot, shot_prefix, shot_ext: string;
i, j, k, frames_count: integer;
actors: boolean;
begin
result:='';
all:=DownloadURL(url);
if all='-1' then
result:='-1'
else
result:=all;
movie_code:=ParseString(url, 'http://www.film.tv.it/scheda.php/film/(\d+)/',1);
movie_site_url:=GetMovieSiteURL(movie_code);
//movie title
i:=pos('<h1>', all);
j:=MyPos('</h1>', all, i+1);
title:=copy(all, i+4, j-i-4);
title:=RemoveTags(title);
title:=DecodeHTML(title);
title:=ClearExtraSpaces(title);
i:=pos('>', title);
if i>0 then
delete(title, 1, i);
title := ClearExtraQuotes(title);
title := MovePrefixLeft(title);
if title='' then
exit;
duration:=0;
//original title
i:=pos('[<i>', all);
if i>0 then begin
j:=MyPos('</i>', all, i+1);
s2:=copy(all, i+4, j-i-4);
original_title:=DecodeHTML(s2);
original_title:=ClearExtraSpaces(original_title);
end;
//Countries
i:=pos('<a href="/cerca.php?nazione=', all);
if i>0 then begin
i:=MyPos('">', all, i+1);
j:=MyPos('</a>', all, i+1);
s:=copy(all, i+2, j-i-2);
k:=pos('/', s);
while k>0 do begin
name:=copy(s, 1, k-1);
if name<>'' then SetCountry(name);
if (name='USA') or (name='Gran Bretagna') or (name='Australia') then
ask_amazon:=true;
delete(s, 1, k);
k:=pos('/',s);
end;
if s<>'' then SetCountry(s);
if (s='USA') or (s='Gran Bretagna') or (s='Australia') then
ask_amazon:=true;
end;
//Year
i:=Pos('<a href="/cerca.php?anno=', all);
if i>0 then
year:=copy(all, i+25, 4);
//Genres
i:=Pos('<a href="/cerca.php?genere=', all);
if i>0 then begin
i:=MyPos('">', all, i+1);
j:=MyPos('</a>', all, i+1);
name:=copy(all, i+2, j-i-2);
if name<>'' then SetGenre(name);
end;
//Duration
i:=Pos('durata ', all);
if i>0 then begin
j:=MyPos('''', all, i+1);
s:=copy(all, i+7, j-i-7);
try
duration:=StrToInt(s);
except
end;
end;
//directors and actors
//directors
actors:=true;
i:=pos('Regia di', all);
if i>0 then begin
j:=MyPos('Con ', all, i+1);
k:=MyPos('</div>', all, i+1);
if (j>k) or (j=0) then begin
j:=k;
actors:=false;
end;
s:=copy(all, i, j-i);
i:=pos('<a href=', s);
while i>0 do begin
k:=MyPos('</a>', s, i+1);
s2:=copy(s, i, k-i);
code:=ParseString(s2, '<a href="/scheda.php/persona/(\d+)/', 1);
name:=RemoveTags(s2);
name:=DecodeHTML(name);
name:=ClearExtraSpaces(name);
if name<>'' then
SetPersonName(name, '', 1, code);
delete(s, 1, k+4);
i:=pos('<a href=', s);
end;
//actors
if actors then begin
i:=j+4; //j is taken from the previous
j:=MyPos('</div>', all, i+1);
s:=copy(all, i, j-i);
i:=pos('<a href=', s);
while i>0 do begin
j:=MyPos('</a>', s, i+1);
s2:=copy(s, i, j-i);
code:=ParseString(s2, '<a href="/scheda.php/persona/(\d+)/', 1);
name:=RemoveTags(s2);
name:=DecodeHTML(name);
name:=ClearExtraSpaces(name);
if name<>'' then
SetPersonName(name, '', 3, code);
delete(s, 1, j+4);
i:=pos('<a href=', s);
end;
end;
end;
//image
i:=pos('<img src="http://www.film.tv.it/imgbank/', all);
if i>0 then begin
j:=MyPos('"', all, i+11);
s2:=copy(all, i, j-i+1);
s3:=ParseString(s2, '<img src="(.*?)"', 1);
if s3='/imgbank/DUMMY/locandina.gif' then
s3:=''
else
front_cover_url:=s3;
end;
if front_cover_url<>'' then
SetImageName('', front_cover_url, '', 1);
//description
i:=pos('<p class="sommario">', all);
if i>0 then begin
j:=MyPos('</p>', all, i+1);
s2:=copy(all, i, j-i);
description:=RemoveTags(s2);
description:=description+'<br><br>';
end;
i:=pos('<p class="trama">', all);
if i>0 then begin
j:=MyPos('</p>', all, i+1);
s2:=copy(all, i, j-i);
s2:=RemoveTags(s2);
description:=description+s2;
end;
i:=pos('<p class="commento">', all);
if i>0 then begin
j:=MyPos('</p>', all, i+1);
s2:=copy(all, i, j-i);
s2:=RemoveTags(s2);
description:=description+'<br><br>';
description:=description+s2;
end;
description:=DecodeHTML(description);
//snapshots
frames_count:=0;
i:=pos('<div id="photogallery">', all);
if i>0 then begin
j:=MyPos('</div>', all, i+1);
s2:=copy(all, i, j-i);
i:=pos('http://www.film.tv.it/imgbank/THUMB/', s2);
while (i>0) and (frames_count<MaxPicturesCount) do begin
j:=MyPos('</a>', s2, i+1);
s3:=copy(s2, i, j-i);
if (pos('JPG', s3)>0) then
shot_ext:='JPG'
else
shot_ext:='jpg';
shot:=ParseString(s3, 'http://www.film.tv.it/imgbank/THUMB/.*?/(\d+).jpg', 1);
if shot='' then
shot:=ParseString(s3, 'http://www.film.tv.it/imgbank/THUMB/.*?/(\d+).JPG', 1);
shot_prefix:=ParseString(s3, 'http://www.film.tv.it/imgbank/THUMB/(.*?)/\d+.*?', 1);
if shot<>'' then begin
shot:='http://www.film.tv.it/imgbank/GALLERY/'+shot_prefix+'/'+shot+'.'+shot_ext;
SetImageName('', shot, '', 3);
if (shot<>front_cover_url) then
frames_count:=frames_count+1;
end;
delete(s2, 1, j+10);
i:=pos('http://www.film.tv.it/imgbank/THUMB/', s2);
end;
end;
end;
//returned images links
procedure GetImages;
begin
if ask_amazon then
GetAmazonImages;
end;
//get movie site url
function GetMovieSiteURL(code: string): string;
begin
if code='' then
result:=''
else
result:='http://www.film.tv.it/scheda.php/film/'+code+'/';
end;
//get person site url
function GetPersonSiteURL(code: string): string;
begin
if code='' then
result:=''
else
result:='http://www.film.tv.it/scheda.php/persona/'+code+'/';
end;
begin
prefixes[1]:='The';
prefixes[2]:='A';
prefixes[3]:='An';
prefixes[4]:='La';
prefixes[5]:='Les';
prefixes[6]:='Des';
prefixes[7]:='L''';
prefixes[8]:='Un';
prefixes[9]:='El';
prefixes[10]:='Il';
prefixes[11]:='Le';
prefixes[12]:='Uno';
end.
[/code]
edited code
[code]
const
script_name='Film.tv.it';
language='Italian';
version=15;
author='Vlad';
MinProgramBuild=2120;
PCount = 12;
//MaxPicturesCount = 3;
IMDBInfos=true; // Download (or not) IMDB infos (id, rating, mpaa, mpaa rating)
var
DownloadMovieBigCover, DownloadMovieShortCast, DownloadMovieFullCast,
DownloadMovieBigDescription, DownloadMovieComments,
DownloadMovieStudios, DownloadMovieAwards, DownloadMovieEarnings,
DownloadMovieAdditionalInfo, DownloadMovieSeasonsList: boolean;
MaxShotsCount: integer;
title, MovieName, s, s2, s3, s4, year, director, name, character, BasicURL, country, description, salary: string;
movie_code, movie_site_url, title_code, small_image, imdb_code: string;
titles: array of string;
titles_count, image_mode: integer;
i, j: integer;
director_code, code: string;
directors, writers, actors, characters, genres, imdb_codes: array of string;
duration: integer;
imdb_rating: double;
front_cover_url: string;
posters_exists, ask_amazon, pictures_exist: boolean;
original_title, mpaa, mpaa_rating: string;
prefixes: array [1..PCount] of string;
occurstart,txtpos: string;
//Get IMDB Infos (sets imdb_code, imdb_rating, mpaa, mpaa_rating) // 20090701-JeF
procedure GetIMDBInfos(MovieTitle, Year: string);
var
url,all,title,NakedMovieTitle: string;
matches_count, i, j, k: integer;
sl: TStringList;
begin
NakedMovieTitle:=ReplaceStr(MovieTitle,'?','',-1);
NakedMovieTitle:=ReplaceStr(NakedMovieTitle,'!','',-1);
NakedMovieTitle:=ReplaceStr(NakedMovieTitle,'.','',-1);
NakedMovieTitle:=ReplaceStr(NakedMovieTitle,',','',-1);
NakedMovieTitle:=ReplaceStr(NakedMovieTitle,' ',' ',-1);
// search for imdb_code
if (imdb_code='') and (year>'') then begin
// launch imdb movie search
url:='http://akas.imdb.com/'
+format('find?q=%%5E%s%%24&type=regexp&tv=both&from_year=1890&to_year=2009&sort=smart;tt=1', [MovieTitle]);
url:=ReplaceStr(url, ' ', '+', -1);
all:=DownloadURL(url);
if (all<>'-1') then begin
// imdb movie search result page analysis
s:='';
matches_count:=0;
i:=pos('<p><b>Titles (Approx Matches)</b> (Displaying', all);
if (i>0) then i:=MyPos('<table>', all, i+1);
if (i>0) then begin
j:=MyPos('</table>', all, i+1);
if j>0 then
s:=copy(all, i, j-i);
end;
if (s='') or (pos('<b>No Matches.</b>', all)>0) then
//Movie not found
else begin
i:=pos('</tr>', s);
while i>0 do begin
s2:=copy(s, 1, i-1);
j:=Pos('</td>', s2);
j:=MyPos('</td>', s2, j+1);
s2:=copy(s, j+5, length(s2)-j-4);
j:=Pos('<a href="/title/tt', s2);
k:=MyPos('"', s2, j+15); // 20091126-JeF
s3:=copy(s2, j, k-j+1); // 20091126-JeF
title:=RemoveTags(s2);
title:=DecodeHTML(title);
title:=ClearExtraSpaces(title);
title:=ReplaceStr(title,'?','',-1);
title:=ReplaceStr(title,'!','',-1);
title:=ReplaceStr(title,'.','',-1);
title:=ReplaceStr(title,',','',-1);
title:=ReplaceStr(title,' ',' ',-1);
if (pos('AKA "'+UpperCase(NakedMovieTitle)+'"',UpperCase(title))>0)
or (pos(' AKA ',UpperCase(title))=0) and (pos(UpperCase(NakedMovieTitle),UpperCase(title))=1)
or (pos(UpperCase(NakedMovieTitle),UpperCase(title))=1)
or (pos('"'+UpperCase(NakedMovieTitle)+'"',UpperCase(title))=1) then begin
if (pos(Year,title)>0)
or (pos(IntToStr(StrToInt(Year)+1),title)>0)
or (pos(IntToStr(StrToInt(Year)-1),title)>0) then begin
matches_count:=matches_count+1;
if (imdb_code='') then imdb_code:=ParseString(s3, '<a href="/title/tt(\d+)/"', 1);
end;
end;
delete(s, 1, i+4);
i:=pos('</tr>', s);
end;
end;
if (matches_count>1) then imdb_code:='';
end;
end;
// imdb_code already known or found by imdb search : retrieve IMDB infos
if (imdb_code>'') then begin
imdb_rating:=0;
mpaa:='';
mpaa_rating:='';
url:=format('http://www.imdb.com/title/tt%s', [imdb_code]);
all:=DownloadURL(url);
if (all<>'-1') then begin
//imdb rating
imdb_rating:=0;
i:=pos('<h5>User Rating:</h5>', all);
if i>0 then begin
i:=MyPos('<b>', all, i+1);
if i>0 then begin
j:=MyPos('</b>', all, i+1);
if j>0 then begin
s2:=copy(all, i, j-i);
if length(s2)>0 then begin
delete(s2, 1, 3);
i:=pos('/', s2);
if i>0 then begin
s2:=copy(s2, 1, i-1);
i:=pos('.', s2);
if i>0 then
s2[i]:=DecimalSeparator;
try
imdb_rating:=StrToFloat(s2);
except
end;
end;
end;
end;
end;
end;
//mpaa
mpaa:='';
mpaa_rating:='';
i:=pos('<h5><a href="/mpaa">MPAA</a>:</h5>', all);
if i>0 then begin
j:=MyPos('</div>', all, i+1);
if j>0 then begin
s2:=copy(all, i, j-i);
i:=pos('Rated ', s2);
if i>0 then begin
delete(s2, 1, i+5);
i:=pos(' ', s2);
if i>0 then begin
mpaa:=copy(s2, 1, i-1);
delete(s2, 1, i);
i:=pos('.', s2);
if i>0 then begin
mpaa_rating:=copy(s2, 1, i-1);
end;
end;
end;
end;
end;
end; // all <> -1
end; // imdb_code > ''
end;
// IMDB infos
if IMDBInfos then GetIMDBInfos(title,year);
function MovieSearch: integer;
var
i, j, k, l: integer;
title: string;
begin
s:='';
titles_count:=0;
//if the search is forwarded to the movie's page (only one result)
if (pos('<title>Ricerca ', all)<=0) then begin
title_code:=ParseString(all, '<li id="sel"><a href="/scheda.php/film/(\d+)/', 1);
if title_code<>'' then begin
SetSearchResult('movie', title_code);
titles_count:=1;
end;
end
//otherwise check seach results
else begin
i:=pos('<div id="ricerca">', all);
if i>0 then begin
j:=MyPos('<!-- fine ricerca -->', all, i+1);
if j>0 then
s:=copy(all, i+17, j-i-17);
end;
if (s='') or (pos('<h3>Non ho trovato nulla!</h3>', all)>0) then
//Movie not found
else begin
i := pos('<dt><a href="/scheda.php/film/',s);
while i>0 do begin
titles_count:=titles_count+1;
SetLength(titles, titles_count);
j := MyPos('</dd>', s, i+1);
if j<=0 then
j:=MyPos('</dt>', s, i+1);
s2 := copy(s, i, j-i);
title_code:=ParseString(s2, '<a href="/scheda.php/film/(\d+)/', 1);
title:=RemoveTags(s2);
title:=DecodeHTML(title);
title:=ClearExtraSpaces(title);
while (length(title)>0) and (title[1]=' ') do
delete(title, 1, 1);
titles[titles_count-1]:=title_code;
SetSearchResult(title, title_code);
delete(s, 1, j+20);
i:=pos('<dt><a href="/scheda.php/film/', s);
end;
end;
end;
result:=titles_count;
end;
//get movie name by barcode(UPC-12)
function GetMovieNameByUPC(barcode: string): string;
var
url, all, s2, s3, res: string;
i, j: integer;
begin
res:='';
url:=format('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=0J0N83PT9M72BYH98YR2&Operation=ItemSearch&Keywords=%s&SearchIndex=Video&ResponseGroup=Request,Images,Tracks,ItemAttributes', [barcode]);
url:=ReplaceStr(url, ' ', '+', -1);
all:=DownloadURL(url);
//search image by title
i:=pos('<Item>', all);
while (i>0) and (res='') do begin
j:=MyPos('</Item>', all, i+1);
if j>0 then begin
s2:=copy(all, i, j-i);
s3:=ParseString(s2, '<Title>(.*?) \(.*\)</Title>', 1);
if s3='' then
s3:=ParseString(s2, '<Title>(.*?)</Title>', 1);
if s3<>'' then
res:=s3;
end;
i:=MyPos('<Item>', all, i+1);
end;
i:=pos('[', res);
if i>0 then begin
j:=MyPos(']', res, i+1);
if j>0 then
delete(res, i, j-i+1);
end;
result:=res;
end;
//Get search URL by movie name
function GetSearchURLbyName(MovieName: string): string;
var
url: string;
begin
url:=format('http://www.film.tv.it/cerca.php?q=%s&x=0&y=0', [MovieName]);
url:=ReplaceStr(url, ' ', '+', -1);
result:=url;
end;
//Download search results from URL
function DownloadSearchURL(url: string): integer;
begin
all:=DownloadURL(url);
if all='-1' then
result:=-1
else
result:=MovieSearch;
end;
function GetMovieURL(code: string; images_only: boolean): string;
begin
result:=format('http://www.film.tv.it/scheda.php/film/%s/', [code]);
end;
//returned link to front cover
function GetAmazonImages: string;
var
res, all, url, s, s2, s3, amazon_url: string;
i, j: integer;
begin
//discard info in brackets
s:=original_title;
url:=format('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=0J0N83PT9M72BYH98YR2&Operation=ItemSearch&Keywords=%s&SearchIndex=Video&ResponseGroup=Request,Images,Tracks,ItemAttributes', [original_title]);
url:=ReplaceStr(url, ' ', '+', -1);
all:=DownloadURL(url);
//search image by title
amazon_url:='';
i:=pos('<Item>', all);
while (i>0) and (amazon_url='') do begin
j:=MyPos('</Item>', all, i+1);
if j>0 then begin
s2:=copy(all, i, j-i);
s3:=ParseString(s2, '<Title>(.*?) \(.*\)</Title>', 1);
if s3='' then
s3:=ParseString(s2, '<Title>(.*?)</Title>', 1);
s3:=DecodeHTML(s3);
if s3<>'' then
begin
//if title=s3 then begin //!!!
if pos(UpperCase(original_title), UpperCase(s3))=1 then
begin
amazon_url:=ParseString(s2, '<LargeImage><URL>(.*?)</URL>', 1);
end;
end;
end;
i:=MyPos('<Item>', all, i+1);
end;
if amazon_url<>'' then begin
SetImageName('', amazon_url, '', 1);
res:=amazon_url;
end;
result:=res;
end;
//save front cover to file
function SaveFrontCover(url, FileName: string): boolean;
var
fs: TFileStream;
s, referer: string;
i: integer;
begin
referer:='http://www.film.tv.it/gallery.php/film/';
s:=DownloadURLWithReferer(url, referer);
if (length(s)>0) and (s<>'-1') then begin
try
fs:=TFileStream.Create(FileName, fmCreate);
fs.Write(s, Length(s));
fs.Free;
result:=true;
except
result:=false;
end;
end
else
result:=false;
end;
function MovePrefixLeft(name: string): string;
var
i, j: integer;
begin
// replace "The", "A", "An"... to the left
for j:=1 to PCount do
begin
i:=pos(', '+Prefixes[j], name);
if i>0 then
if (i = length(name)-length(Prefixes[j])-1) or
(length(name) >= i+2+length(Prefixes[j])) and (name[i+2+length(Prefixes[j])]=':') then
begin
if Prefixes[j][length(Prefixes[j])] = '''' then
name := Prefixes[j] + copy(name, 1, i-1) + copy(name, i+length(Prefixes[j])+2, length(name)-i-length(Prefixes[j])-2+1)
else
name := Prefixes[j]+' ' + copy(name, 1, i-1) + copy(name, i+length(Prefixes[j])+2, length(name)-i-length(Prefixes[j])-2+1);
break;
end;
end;
Result := name;
end;
function ClearExtraQuotes(name: string): string;
begin
// Clears extra quotes «"»
if length(name)>0 then
if (name[1]='"') and (name[length(name)]='"') then
name := copy(name,2,length(name)-2);
Result := name;
end;
function GetInfo(url: string; images_only: boolean): string;
var
keyword, s, s2, s3, plot_outline, shot, shot_prefix, shot_ext: string;
i, j, k, frames_count: integer;
actors: boolean;
begin
result:='';
all:=DownloadURL(url);
if all='-1' then
result:='-1'
else
result:=all;
movie_code:=ParseString(url, 'http://www.film.tv.it/scheda.php/film/(\d+)/',1);
movie_site_url:=GetMovieSiteURL(movie_code);
//movie title
i:=pos('<h1>', all);
j:=MyPos('</h1>', all, i+1);
title:=copy(all, i+4, j-i-4);
title:=RemoveTags(title);
title:=DecodeHTML(title);
title:=ClearExtraSpaces(title);
i:=pos('>', title);
if i>0 then
delete(title, 1, i);
title := ClearExtraQuotes(title);
title := MovePrefixLeft(title);
if title='' then
exit;
duration:=0;
//original title
i:=pos('[<i>', all);
if i>0 then begin
j:=MyPos('</i>', all, i+1);
s2:=copy(all, i+4, j-i-4);
original_title:=DecodeHTML(s2);
original_title:=ClearExtraSpaces(original_title);
end;
//Countries
i:=pos('<a href="/cerca.php?nazione=', all);
if i>0 then begin
i:=MyPos('">', all, i+1);
j:=MyPos('</a>', all, i+1);
s:=copy(all, i+2, j-i-2);
k:=pos('/', s);
while k>0 do begin
name:=copy(s, 1, k-1);
if name<>'' then SetCountry(name);
if (name='USA') or (name='Gran Bretagna') or (name='Australia') then
ask_amazon:=true;
delete(s, 1, k);
k:=pos('/',s);
end;
if s<>'' then SetCountry(s);
if (s='USA') or (s='Gran Bretagna') or (s='Australia') then
ask_amazon:=true;
end;
//Year
i:=Pos('<a href="/cerca.php?anno=', all);
if i>0 then
year:=copy(all, i+25, 4);
//Genres
i:=Pos('<a href="/cerca.php?genere=', all);
if i>0 then begin
i:=MyPos('">', all, i+1);
j:=MyPos('</a>', all, i+1);
name:=copy(all, i+2, j-i-2);
if name<>'' then SetGenre(name);
end;
//Duration
i:=Pos('durata ', all);
if i>0 then begin
j:=MyPos('''', all, i+1);
s:=copy(all, i+7, j-i-7);
try
duration:=StrToInt(s);
except
end;
end;
//directors and actors
//directors
actors:=true;
i:=pos('Regia di', all);
if i>0 then begin
j:=MyPos('Con ', all, i+1);
k:=MyPos('</div>', all, i+1);
if (j>k) or (j=0) then begin
j:=k;
actors:=false;
end;
s:=copy(all, i, j-i);
i:=pos('<a href=', s);
while i>0 do begin
k:=MyPos('</a>', s, i+1);
s2:=copy(s, i, k-i);
code:=ParseString(s2, '<a href="/scheda.php/persona/(\d+)/', 1);
name:=RemoveTags(s2);
name:=DecodeHTML(name);
name:=ClearExtraSpaces(name);
if name<>'' then
SetPersonName(name, '', 1, code);
delete(s, 1, k+4);
i:=pos('<a href=', s);
end;
//actors
if actors then begin
i:=j+4; //j is taken from the previous
j:=MyPos('</div>', all, i+1);
s:=copy(all, i, j-i);
i:=pos('<a href=', s);
while i>0 do begin
j:=MyPos('</a>', s, i+1);
s2:=copy(s, i, j-i);
code:=ParseString(s2, '<a href="/scheda.php/persona/(\d+)/', 1);
name:=RemoveTags(s2);
name:=DecodeHTML(name);
name:=ClearExtraSpaces(name);
if name<>'' then
SetPersonName(name, '', 3, code);
delete(s, 1, j+4);
i:=pos('<a href=', s);
end;
end;
end;
//image
i:=pos('<img src="http://www.film.tv.it/imgbank/', all);
if i>0 then begin
j:=MyPos('"', all, i+11);
s2:=copy(all, i, j-i+1);
s3:=ParseString(s2, '<img src="(.*?)"', 1);
if s3='/imgbank/DUMMY/locandina.gif' then
s3:=''
else
front_cover_url:=s3;
end;
if front_cover_url<>'' then
SetImageName('', front_cover_url, '', 1);
//description
i:=pos('<p class="sommario">', all);
if i>0 then begin
j:=MyPos('</p>', all, i+1);
s2:=copy(all, i, j-i);
description:=RemoveTags(s2);
description:=description+'<br><br>';
end;
i:=pos('<p class="trama">', all);
if i>0 then begin
j:=MyPos('</p>', all, i+1);
s2:=copy(all, i, j-i);
s2:=RemoveTags(s2);
description:=description+s2;
end;
i:=pos('<p class="commento">', all);
if i>0 then begin
j:=MyPos('</p>', all, i+1);
s2:=copy(all, i, j-i);
s2:=RemoveTags(s2);
description:=description+'<br><br>';
description:=description+s2;
end;
description:=DecodeHTML(description);
//snapshots
frames_count:=0;
i:=pos('<div id="photogallery">', all);
if i>0 then begin
j:=MyPos('</div>', all, i+1);
s2:=copy(all, i, j-i);
i:=pos('http://www.film.tv.it/imgbank/THUMB/', s2);
while (i>0) and (frames_count<MaxPicturesCount) do begin
j:=MyPos('</a>', s2, i+1);
s3:=copy(s2, i, j-i);
if (pos('JPG', s3)>0) then
shot_ext:='JPG'
else
shot_ext:='jpg';
shot:=ParseString(s3, 'http://www.film.tv.it/imgbank/THUMB/.*?/(\d+).jpg', 1);
if shot='' then
shot:=ParseString(s3, 'http://www.film.tv.it/imgbank/THUMB/.*?/(\d+).JPG', 1);
shot_prefix:=ParseString(s3, 'http://www.film.tv.it/imgbank/THUMB/(.*?)/\d+.*?', 1);
if shot<>'' then begin
shot:='http://www.film.tv.it/imgbank/GALLERY/'+shot_prefix+'/'+shot+'.'+shot_ext;
SetImageName('', shot, '', 3);
if (shot<>front_cover_url) then
frames_count:=frames_count+1;
end;
delete(s2, 1, j+10);
i:=pos('http://www.film.tv.it/imgbank/THUMB/', s2);
end;
end;
end;
//returned images links
procedure GetImages;
begin
if ask_amazon then
GetAmazonImages;
end;
//get movie site url
function GetMovieSiteURL(code: string): string;
begin
if code='' then
result:=''
else
result:='http://www.film.tv.it/scheda.php/film/'+code+'/';
end;
//get person site url
function GetPersonSiteURL(code: string): string;
begin
if code='' then
result:=''
else
result:='http://www.film.tv.it/scheda.php/persona/'+code+'/';
end;
begin
prefixes[1]:='The';
prefixes[2]:='A';
prefixes[3]:='An';
prefixes[4]:='La';
prefixes[5]:='Les';
prefixes[6]:='Des';
prefixes[7]:='L''';
prefixes[8]:='Un';
prefixes[9]:='El';
prefixes[10]:='Il';
prefixes[11]:='Le';
prefixes[12]:='Uno';
end.
but not work.. i suppose that i miss something , is not loaded in program
