Search found 4 matches
- 2015-01-22 03:10:42
- Forum: Ant Movie Catalog > Scripts
- Topic: Help merging two scripts
- Replies: 3
- Views: 1970
//------------------------------------------------------------------------------------ function CINEOL_ListaBusqueda(Address, params: String): string; var Titulo, url, texto, resultados: string; cont: integer; encontradoParaBatch: boolean; begin resultados := GetPage(Address + '?' + params); result...
- 2015-01-22 03:02:00
- Forum: Ant Movie Catalog > Scripts
- Topic: Help merging two scripts
- Replies: 3
- Views: 1970
Thanks. Yes, that was the problem, I had changed the names using the search, but then I changed some of them back and I made a mistake.
Now, I have the script working. I have combined three scripts (IMDB,FIlmaffinity and CINeol) and I take specific data from that pages. I also use several custom fields.
It's not clean code and there are quite things I could delete. Anyway, I post the code here in case it could be useful for somebody (it's in two posts because it's too long) :
Now, I have the script working. I have combined three scripts (IMDB,FIlmaffinity and CINeol) and I take specific data from that pages. I also use several custom fields.
It's not clean code and there are quite things I could delete. Anyway, I post the code here in case it could be useful for somebody (it's in two posts because it's too long) :
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=VJSP + PeQuE, GlandeMan(CINeol) + aviloria (aviloria@yahoo.com) modded by: rodpedja (rodpedja@gmail.com), kreti (bisoft@hotmail.com), MrK, gilistico, juliojs, Albher, Arturo, jacqlittle(Filmaffinity) + Antoine Potten, KaraGarga, baffab, Thermal Ions, bad4u, Sancho, Joe, cage, Elman(IMDB)
Title=IMDB + Filmaffinity + Cineol (+Culturalia y/o Alpacine) (ES)
Description=Script que obtiene datos concretos de IMDB, FIlmaffinity y CINeol
Site=http://www.cineol.net + http://www.culturalianet.com + http://www.alpacine.com + http://www.filmaffinity.com + http://www.imdb.com
Language=ES
Version=1.0
Requires=4.2.0
Comments=En este script utilizo varios campos personalizados.
License=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.
GetInfo=1
RequiresMovies=1
[Options]
ModoBusquedaCaratula=1|1|0=Auto. Se recupera carátula de Cineol si es grande. Si es pequeña, se recupera de Alpacine.|1=Se recupera carátula de Cineol. Las películas más recientes tienen carátula grande. Las otras tiene carátula muy pequeña.|2=Se recupera carátula de Culturalianet. Son medianas.|3=Se recupera carátula de Alpacine. Son enormísimas. Algunas de más de 1 Mb.
ModoBatch=0|0|0=Modo normal|1=Modo automático (batch). No pregunta nada ni muestra mensajes
FiltradoAnyo=1|1|0=No se filtran las búsquedas de carátulas en Culturalianet y en Alpacine por año. Esto es especialmente interesante en el caso en que el año de estreno de una película en Cineol sea diferente al que aparece en Culturalianet o Alpacine (por ejemplo, 300).|1=Se filtran las búsquedas de carátulas en Culturalianet y Alpacine. Sólo se muestran las películas encontradas entre el año anterior y el siguiente al del estreno según Cineol.|2=Se filtran las búsquedas de carátulas en Culturalianet y Alpacine. Sólo se muestran las películas encontradas cuyo estreno es igual al de Cineol.
ActorsLayout=0|0|0=Only actor names, separated by commas|1=Only actor names, separated by linebreaks|2=Actors names with character names between parenthesis separated by commas|3=Actors names with character names between parenthesis separated by linebreaks|4=Actor names like on IMDB page, with "...." and separated by linebreaks
AllActors=0|0|0=Only import actors from main page (does not work if you import producer name)|1=Import all possible actors|2=Import 10 first actors (does not work with ActorLayout=4)
AspectRatio=1|1|0=Do not import picture aspect ratio|1=Import picture aspect ratio to video format field|2=Import picture aspect ratio to resolution field
Awards=0|0|0=Do not import awards|1=Import awards to Description field, after the summary|2=Import awards to Comments field, after comments
BatchMode=0|0|0=Normal working mode, prompts user when needed|1=Does not display any window, takes the first movie found|2=Same as 1, but it uses the URL field if available to update movie information
CommentType=0|0|0=Standard Type (Only one comment from main page)|1=Detailed Type (10 most useful comments from comments page)|2=No user comment, clear current field contents|3=No user comment, keep current field contents (may cause problem for multiple imports on the same movie if other options append text to the comment field)
ConvertToASCII=0|0|0=Do not change special characters and accents.|1=Replace special characters and accents by basic ASCII characters
DescriptionSelection=0|0|0=Take the short summary, from main page (faster)|1=Show a list of available summaries|2=Take the longest summary
EpisodeTitleSearch=0|0|0=Use "Find more" button on results list for next result pages if available (default)|1=Use "Find more" button on results list for episode title search instead
GetTagline=1|1|0=Do not get tagline|1=Put it in Description field, before the summary|2=Put it in the Comment field, before the comments
HideAkaTitles=0|0|0=Show 'aka' titles on result list (= other titles for the film)|1=Hide 'aka' titles on result list
ImageKind=3|3|0=No image|1=IMDB small image, from the main movie page, no image if none available|2=IMDB small image, from the main movie page, "No Poster Available" if none available|3=IMDB large image, from link on main movie page, else small image, else "No Poster Available"|4=Cover from "Merchandising Link" page, else "DVD detail" page, else small image|5=Cover from "DVD detail" page, else "Merchandising Link", else small image
MPAA=0|0|0=Do not import MPAA rating|1=Import MPAA rating to MediaType|2=Append MPAA rating and info to Comments
MultipleValuesAudioFormat=1|1|0=Only take first value for Audio Format|1=Take full list, separated by commas|2=Take full list, separated by slashes|3=Do not import Audio Format / Sound Mix
MultipleValuesCategory=1|1|0=Only take first value for Category|1=Take full list, separated by commas|2=Take full list, separated by slashes|3=Do not import Category
MultipleValuesCountry=1|1|0=Only take first value for Country|1=Take full list, separated by commas|2=Take full list, separated by slashes|3=Do not import Country
MultipleValuesLanguages=1|1|0=Only take first value for Languages|1=Take full list, separated by commas|2=Take full list, separated by slashes|3=Do not import Languages
PopularSearches=1|1|0=Do not use the popular searches page, directly show full search results|1=Show popular searches first, I'll click on "Find more" if needed (much faster)
RoundRating=0|0|0=Do not round Rating|1=Round Rating to whole number
Trivia=0|0|0=Do not import trivia|1=Import short trivia to Description field, after the summary|2=Import short trivia to Comments field, after the comments|3=Import full trivia to Description field, after the summary|4=Import full trivia to Comments field, after the comments
UserRatings=0|0|0=Import value to ratings field only (default)|1=Import value and number of votes to Media Type field|2=Import value and number of votes to comments field
DontAsk=0|0|1=Método rápido: No te pregunta el titulo al principio, ni te pide confirmar si sólo hay un resultado|0=Método lento: Confirmas la información manualmente
ActorsInALine=0|0|1=Actores en lineas independientes |0=Actores separados por comas
Force350=0|0|1=force the behavior of 3.5.0 version|0=Version auto
DontWantExtras=1|1|1=No se recopilan extras|0=Se recopilan extras: enlaces, imágenes
GroupImages=1|1|1=Agrupa todas las imagenes en una misnma categoría 'Imagenes'|0=Divide las imágenes por categorias
[Parameters]
***************************************************)
program IMDB_FA_CINeol;
uses
StringUtils1;
// ***** Manually set UserCountry to your required Classification Country below *****
const
//UserCountry = '';
{ Delete the line above and remove the "//" in front of one the
following lines, or add your country if it is not listed }
UserCountry = 'Spain';
//UserCountry = 'Canada';
//UserCountry = 'Mexico';
//UserCountry = 'Brazil';
//UserCountry = 'Argentina';
//UserCountry = 'Australia';
//UserCountry = 'India';
//UserCountry = 'Italy';
//UserCountry = 'USA';
//UserCountry = 'Portugal';
//UserCountry = 'France';
//UserCountry = 'Germany';
//UserCountry = 'Netherlands';
//UserCountry = 'UK';
//UserCountry = 'Ireland';
//UserCountry = 'Finland';
//UserCountry = 'Norway';
//UserCountry = 'Sweden';
//UserCountry = 'Switzerland';
BaseURL = 'http://www.filmaffinity.com';
BaseURLCineol = 'http://www.cineol.net/api/busquedapeliculas.php';
BaseURLAlpacine = 'http://www.alpacine.com/buscar/?buscar=';
BaseURLAlpacine_Caratula = 'http://www.alpacine.com/pelicula/';
BaseURLCulturalia = 'http://www.culturalianet.com/bus/resu.php?texto=';
PopularTitleSearchURL = 'http://www.imdb.com/find?s=tt&q=';
FullTitleSearchURL = 'http://www.imdb.com/find?s=tt&exact=true&q=';
EpisodeTitleSearchURL = 'http://www.imdb.com/find?s=ep&q=';
var
MovieName: string;
MovieURL: string;
MovieNumber: string;
UpdateFile: TStringList;
Title: string;
i, FiltradoAnyo, ModoBusquedaCaratula: integer;
s11: string;
ModoBatch: Boolean;
Page, Pagecur: TStringList;
Comments: string;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// IMDB
function ConvertToASCII(AText: string): string;
begin
Result := AText;
if GetOption('ConvertToASCII') = 1 then
Result := Cp1252ToASCII(AText);
end;
// ***** analyzes IMDB's results page that asks to select a movie from a list *****
procedure AnalyzeResultsPage(Address: string);
var
PageText: string;
Value: string;
begin
PageText := ConvertToASCII(GetPage(Address));
if pos('<title>Find - IMDb', PageText) = 0 then
begin
AnalyzeMoviePage2(PageText)
end else
begin
if Pos('<b>No Matches.</b>', PageText) > 0 then
begin
if GetOption('BatchMode') = 0 then
ShowMessage('No movie found for this search.');
Exit;
end;
if GetOption('BatchMode') = 0 then
begin
PickTreeClear;
Value := TextBetween(PageText, '<h1 class="findHeader">Displaying', '</h1>');
if Value <> '' then
begin
HTMLRemoveTags(Value);
HTMLDecode(Value);
PickTreeAdd(UTF8Decode(Value), '');
end;
Value := TextBetween(PageText, '<table class="findList">', '</table>');
PageText := RemainingText;
AddMovieTitles(Value);
{
Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
if Value <> '' then
PickTreeMoreLink('http://www.imdb.com' + Value);
if GetOption('EpisodeTitleSearch') > 0 then
PickTreeMoreLink(EpisodeTitleSearchURL + UrlEncode(MovieName));
}
if PickTreeExec(Address) then
AnalyzeResultsPage(Address);
end
else
begin
Value := TextBetween(PageText, '<td class="primary_photo">', '<img src');
if Value <> '' then
AnalyzeResultsPage('http://www.imdb.com' + TextBetween(Value, '<a href="', '"'));
end;
end;
end;
// ***** adds the movie titles found on IMDB's results page *****
function AddMovieTitles(List: string): Boolean;
var
Value: string;
Address: string;
begin
Result := False;
Value := TextBetween(List, '<td class="result_text">', '</td>');
if GetOption('HideAkaTitles') = 1 then
Value := StringReplace(Value, TextAfter(Value, '<br/>aka'), '')
else
Value := StringReplace(Value, 'aka', ' | aka');
List := RemainingText;
while Value <> '' do
begin
Address := TextBetween(Value, '<a href="/title/tt', '/');
Address := Address + '/combined';
HTMLRemoveTags(Value);
HTMLDecode(Value);
PickTreeAdd(UTF8Decode(Value), 'http://www.imdb.com/title/tt' + Address);
Result := True;
Value := TextBetween(List, '<td class="result_text">', '</td>');
if GetOption('HideAkaTitles') = 1 then
Value := StringReplace(Value, TextAfter(Value, '<br/>aka'), '')
else
Value := StringReplace(Value, 'aka', ' | aka');
List := RemainingText;
end;
end;
// ***** analyzes the page containing movie information *****
procedure AnalyzeMoviePage2(PageText: string);
var
Value, Value2, Value3, Value4, FullValue, originalTitle: string;
p, Count: Integer;
begin
MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/');
if MovieNumber = '' then
MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/combined"');
if MovieNumber = '' then
MovieNumber := TextBetween(PageText, '<link rel="canonical" href="http://www.imdb.com/title/tt', '/');
// #########
// if ((GetOption('AllActors') = 1) or (GetOption('Producer') = 1)) and (Pos('<div id="tn15" class="maindetails">', PageText) > 0) then
// PageText := ConvertToASCII(GetPage('http://www.imdb.com/title/tt' + MovieNumber + '/combined'));
if Pos('/combined"', TextBetween(PageText, '<link rel="canonical"', '/>')) = 0 then
PageText := ConvertToASCII(GetPage('http://www.imdb.com/title/tt' + MovieNumber + '/combined'));
// #########
MovieURL := 'http://imdb.com/title/tt' + MovieNumber;
// OriginalTitle & Year
if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
begin
originalTitle := TextBefore(PageText, '<i>(original title)', '<span class="title-extra">');
HTMLDecode(originalTitle);
Value := TextBetween(PageText, '<title>', '</title>');
// showmessage(originalTitle);
// showmessage(value);
if (originalTitle <> '') and CanSetField(fieldOriginalTitle) then
SetField(fieldOriginalTitle, FullTrim(originalTitle));
p := Pos(' (1', Value);
if p = 0 then
p := Pos(' (2', Value);
Value2 := Copy(Value, 0, p-1);
Value := Copy(Value, p+2, Length(Value));
HTMLDecode(Value2);
if (originalTitle = '') and CanSetField(fieldOriginalTitle) then
SetField(fieldOriginalTitle, FullTrim(Value2));
if Pos('/', Value) > 0 then
Value2 := TextBefore(Value, '/', '')
else
Value2 := TextBefore(Value, ')', '');
if CanSetField(fieldYear) then
SetField(fieldYear, Value2);
end;
// Director
if CanSetField(fieldDirector) then
begin
Value := TextBetween(PageText, 'Directed by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldDirector, FullValue);
end;
// Actors
if CanSetField(fieldActors) then
begin
Value := FullTrim(TextBetween(PageText, '<table class="cast">', '</table>'));
if Value <> '' then
begin
FullValue := '';
Count := 0;
case GetOption('ActorsLayout') of
0, 1:
while Pos('<tr', Value) > 0 do
begin
Value2 := TextBetween(Value, '<tr', '</tr>');
Value := RemainingText;
if Pos('rest of cast', Value2) > 0 then
Continue;
if FullValue <> '' then
FullValue := FullValue + #13#10;
TextBefore(Value2, '</td>', '');
Value4 := FullTrim(TextBetween(Value2, '<td class="char">', '</td>'));
Value2 := FullTrim(TextBetween(Value2, '<td class="nm">', '</td>'));
HTMLRemoveTags(Value4);
HTMLRemoveTags(Value2);
if POS('(as', Value4) > 0 then Value4 := TextBefore(Value4, ' (as',''); // deletes listed actors name from role
if POS('(uncredited', Value4) > 0 then Value4 := TextBefore(Value4, ' (uncredited','');
if Value2 <> '' then
begin
FullValue := FullValue + Value2 + ' (' +Value4 + ')';
Count := Count + 1;
end;
// ###
if (Count = 15) and (GetOption('AllActors') = 0) then
Break;
// ###
if (Count = 10) and (GetOption('AllActors') = 2) then
Break;
end;
2, 3:
while Pos('<tr', Value) > 0 do
begin
Value2 := TextBetween(Value, '<tr', '</tr>');
Value := RemainingText;
if Pos('rest of cast', Value2) > 0 then
Continue;
if FullValue <> '' then
FullValue := FullValue + #13#10;
TextBefore(Value2, '</td>', '');
Value4 := FullTrim(TextBetween(Value2, '<td class="char">', '</td>'));
Value2 := FullTrim(TextBetween(Value2, '<td class="nm">', '</td>'));
HTMLRemoveTags(Value4);
HTMLRemoveTags(Value2);
if POS('(as', Value4) > 0 then Value4 := TextBefore(Value4, ' (as',''); // deletes listed actors name from role
if POS('(uncredited', Value4) > 0 then Value4 := TextBefore(Value4, ' (uncredited','');
if Value2 <> '' then
begin
FullValue := FullValue + Value2;
Value2 := FullTrim(TextBetween(RemainingText, '"char">', '</td>'));
if Value2 <> '' then
FullValue := FullValue + ' (as ' + Value2 + ')';
Count := Count + 1;
// ###
if (Count = 15) and (GetOption('AllActors') = 0) then
Break;
// ###
if (Count = 10) and (GetOption('AllActors') = 2) then
Break;
end;
end;
4:
begin
FullValue := Value;
FullValue := StringReplace(FullValue, ' <tr><td align="center" colspan="4"><small>rest of cast listed alphabetically:</small></td></tr>', '');
FullValue := StringReplace(FullValue, '> <', '><');
FullValue := StringReplace(FullValue, '</tr>', #13#10);
end;
end;
HTMLRemoveTags(FullValue);
HTMLDecode(FullValue);
case GetOption('ActorsLayout') of
0, 2:
FullValue := StringReplace(FullValue, #13#10, ', ');
end;
SetField(fieldActors, FullValue);
end;
end;
// Composer
if CanSetField(fieldComposer) then
begin
Value := TextBetween(PageText, 'Music by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldComposer, FullValue);
end;
// Cinematography
begin
Value := TextBetween(PageText, 'Cinematography by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Fotografia', FullValue);
end;
// Costume Design
begin
Value := TextBetween(PageText, 'Costume Design by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Vestuario', FullValue);
end;
// Film Editing
begin
Value := TextBetween(PageText, 'Film Editing by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Montaje', FullValue);
end;
// Production Design
begin
Value := TextBetween(PageText, 'Production Design by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
Value := TextBetween(PageText, 'Set Decoration by</a></h5>', '</table>');
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Diseno', FullValue);
end;
// Producer
if CanSetField(fieldProducer) then
begin
Value := TextBetween(PageText, 'Produced by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldProducer, FullValue);
end;
// Writer
if CanSetField(fieldWriter) then
begin
Value := TextBetween(PageText, 'Writing credits</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldWriter, FullValue);
end;
// Production Companies
if CanSetCustomField('Productora') then
begin
Value := TextBetween(PageText, 'Production Companies</b><ul><li>', 'Distributors');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/company/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/company/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Productora', FullValue);
end;
// Distributors
if CanSetCustomField('Distribuidora') then
begin
Value := TextBetween(PageText, 'Distributors</b><ul><li>', '(Spain)');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/company/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
FullValue := Value2;
Value2 := TextBetween(Value, '<a href="/company/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Distribuidora', FullValue);
end;
// AKA Name
if CanSetField(fieldTranslatedTitle) then
begin
FullValue := ConvertToASCII(GetPage(MovieURL+'/releaseinfo#akas'));
FullValue := TextBetween(FullValue, '<a id="akas" name="akas">', '</table>');
FullValue := RemoveSpaces(FullValue, True);
FullValue := StringReplace(FullValue, #13, '');
FullValue := StringReplace(FullValue, #10, '');
FullValue := StringReplace(FullValue, '> <', '><');
FullValue := StringReplace(FullValue, '<tr class="even">', '<tr>');
FullValue := StringReplace(FullValue, '<tr class="odd">', '<tr>');
if RegExprSetExec('</td>\s*<tr>', FullValue) then
// removing the original title
FullValue := '<tr>'+TextAfter(FullValue, '</td><tr>');
while fullvalue <> '' do
begin
// showMessage('Analysing: '+FullValue);
// each line is a pair of translated title and country
// format: <tr><td>country</td><td>Translated title</td><tr>
value2 := TextBetween(FullValue, '<tr>', '</tr>');
// showMessage('Line: '+value2);
value := TextBetween(Value2, '<td>', '</td>');
value2 := TextAfter(Value2, '</td>');
value2 := TextBetween(Value2, '<td>', '</td>');
HTMLDecode(value2);
// showMessage('Translated: '+value+' into '+value2);
if pos(UserCountry, value) > 0 then
begin
HTMLDecode(Value2);
SetField(fieldTranslatedTitle, FullTrim(UTF8Decode(Value2)));
FullValue := '';
end
else FullValue := TextAfter(FullValue, '</tr>');
end;
{
if Value <> '' then
begin
Value := StringReplace(Value, 'See more', '');
Value := StringReplace(Value, '»', '');
Value := FullTrim(StringReplace(Value, '<br>', ', '));
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := FullTrim(Value);
if Value <> '' then
if StrGet(Value, Length(Value)) = ',' then
Delete(Value, Length(Value), 1);
SetField(fieldTranslatedTitle, Value)
end;
}
end;
end;
// ***** Imports lists like Genre, Country, etc. depending of the selected option *****
function ImportList(PageText: string; MultipleValues: Integer; StartTag: string): string;
var
Value, Value2: string;
begin
if MultipleValues = 0 then
begin
Value := TextBetween(PageText, StartTag, '</a>');
Value2 := TextAfter(Value, '">');
end
else
begin
Value := TextBetween(PageText, StartTag, '</div>');
Value2 := TextBefore(Value, '<a class="tn15more inline"', '');
if Value2 = '' then
Value2 := Value;
Value2 := TextAfter(Value2, '">');
HTMLRemoveTags(Value2);
if MultipleValues = 1 then
Value2 := StringReplace(Value2, ' | ', ', ');
if MultipleValues = 2 then
Value2 := StringReplace(Value2, ' | ', ' / ');
if MultipleValues = 3 then
Value2 := '';
end;
Value2 := StringReplace(Value2, #13#10, '');
Value2 := StringReplace(Value2, ' , ', ', ');
HTMLDecode(Value2);
Result := FullTrim(Value2);
end;
function MiTextBetween(var S: string; StartTag: string; EndTag: string): string;
var
InitialPos: Integer;
a,b: string;
begin
a := ansiLowerCase(StartTag);
b := AnsiLowerCase(S);
InitialPos := Pos(AnsiLowerCase(StartTag), AnsiLowerCase(S));
Delete(S, 1, InitialPos + Length(StartTag) - 1);
InitialPos := Pos(AnsiLowerCase(EndTag), AnsiLowerCase(S));
result := copy(S, 1, InitialPos - 1);
Delete(S, 1, InitialPos + 1);
end;
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Filmaffinity
function LineDecode(S: string):string;
begin
S:= UTF8Decode(S);
HTMLDecode(S);
Result := S;
end;
//------------------------------------------------------------------------------------
function FindLine2(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
i: Integer;
begin
Result := -1;
if StartAt < 0 then StartAt := 0;
for i := StartAt to List.Count-1 do
if Pos(Pattern, List.GetString(i)) <> 0 then
begin
Result := i;
Break;
end;
end;
//------------------------------------------------------------------------------------
//
// ConvertAlphaNum: Quita todo menos letras (mayusculas y minusculas) y numeros
//
Function ConvertAlphaNum(s: string) : string;
var
i: Integer;
s2, ch: string;
begin
s2 := '';
For i := 1 To Length(s) do
begin
ch := copy(s, i, 1);
if ((ch >= 'a') and (ch <= 'z')) or ((ch >= '0') and (ch <= '9')) or ((ch >= 'A') and (ch <= 'Z')) then
s2 := s2 + ch;
end;
result := s2;
end;
//------------------------------------------------------------------------------------
function TextBetween2(S: string; StartTag: string; EndTag: string): string;
var
ini, fin, lenS: Integer;
begin
Result := '';
lenS := Length(S);
ini := Pos(StartTag, S);
if ini <> 0 then
begin
ini := ini + Length(StartTag);
S:= Copy(S,ini,lenS-ini+1);
ini:=1;
fin := Pos(EndTag, S);
if (fin <> 0) and (fin > ini) then
Result := Copy(S, ini, fin - ini);
end;
end;
//------------------------------------------------------------------------------------
function TextAfter2(S: string; StartTag: string): string;
var
ini: Integer;
begin
ini := Pos(StartTag, S);
if ini <> 0 then
Result := Copy(S, ini + Length(StartTag), Length(S)-ini+1)
else
Result := '';
end;
//------------------------------------------------------------------------------------
function DeleteTags2(S: string): string;
var
n, len, tag: Integer;
c, p: char;
begin
len := Length(S);
tag := 0;
p := ' ';
Result := '';
for n := 1 to len do
begin
c := Copy(S,n,1);
// Eliminamos los tabuladores
if c = #9 then c := ' ';
// Los espacios redundantes no se procesan
if (c <> ' ') or (p <> ' ') then
begin
// Eliminamos los tags de HTML
if tag = 0 then
begin
if c <> '<' then
begin
Result := Result + c;
p := c;
end
else tag := 1;
end
else if c = '>' then tag := 0;
end;
end
if p = ' ' then Result := Copy(Result, 1, Length(Result) - 1);
end;
//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Count: Integer;
MovieTitle, MovieAddress: string;
begin
Count := 0;
Page := TStringList.Create;
Page.Text := GetPage(Address);
PickTreeClear;
// Get how much search results have been found
// No encuentra las palabras "Resultados por tÃtulo"¿?, busco la
// linea anterior, y cojo la siguiente linea, le quito los espacios
// y me quedo con el numerode peliculas.
LineNr := FindLine('<div class="sub-header-search">', Page, 0);
if LineNr <> -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Line:= DeleteTags2(Line);
Line:= ConvertAlphaNum(Line);
Count := StrToInt(Line,0);
end;
// Add the results to the PickTree
if Count = 0 then
ShowMessage('No se ha encontrado ningún registro')
else
begin
LineNr := 0;
while true do
begin
LineNr := FindLine('<div class="mc-title"><a href="', Page, LineNr + 1);
if LineNr = -1 then
begin
LineNr := FindLine('siguientes >>', Page, 0);
if LineNr = -1 then
break;
Line := Page.GetString(LineNr);
Page.Text := GetPage('http://www.filmaffinity.com/es/search.php' + TextBetween(Line, '<a href="search.php', '"><div class="'));
LineNr := 0;
continue;
end;
Line := Page.GetString(LineNr);
MovieAddress := TextBetween(Line, '<div class="mc-title"><a href="', '.html">') + '.html';
MovieTitle:= TextBetween(Line, '.html">', '<img src="');
MovieTitle:= DeleteTags2(MovieTitle);
MovieTitle:= LineDecode(MovieTitle);
if (Length(MovieAddress) <> 0) and (Length(MovieTitle) <> 0) then
PickTreeAdd(MovieTitle, BaseURL + MovieAddress);
end;
if ((Count = 1) and (GetOption('DontAsk') = 1)) then
AnalyzeMoviePage(BaseURL + MovieAddress)
else
begin
//
// PickTreeSort; // Si se quiere clasificar por orden alfabetico hay que activar el PickTreeSort, quitar las 2
// // las 2 barras "//" que hay a la izquierda la instrucción PickTreeSort y ya esta.
//
PickTreeExec(Address);
AnalyzeMoviePage(Address)
end
end;
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr, LineInc: Integer;
Line: string;
Item: string;
CharStar: string;
Premios: string;
i: Integer;
begin
//Comments := '';
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Rating
LineNr := FindLine2('<div id="movie-rat-avg" itemprop="ratingValue">', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags2(Line);
Item:= LineDecode(Item);
SetField(fieldRating, StringReplace(Item, ',', '.'));
end;
// Year
LineNr := FindLine2(UTF8Encode('<dt>Año</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags2(TextBetween2(Line, '<dd>', '</dd>'));
Item:= LineDecode(Item);
SetField(fieldYear, Item);
end;
// Length
LineNr := FindLine2(UTF8Encode('<dt>Duración</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags2(TextBetween2(Line, '<dd>', 'min.</dd>'));
Item:= LineDecode(Item);
SetField(fieldLength, Item);
end;
// Country
LineNr := FindLine2(UTF8Encode('<dt>País</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags2(TextBetween2(Line, 'title="', '"></span'));
Item:= LineDecode(Item);
SetField(fieldCountry, Item);
end;
// Productor
LineNr := FindLine2(UTF8Encode('<dt>Productora</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags2(TextBetween2(Line, '<dd>', '</dd>'));
Item:= LineDecode(Item);
Item := StringReplace(Item, ' / ', ', ');
SetCustomField('Productora', Item);
end;
// Category
LineNr := FindLine(UTF8Encode('<dt>Género</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 2);
Item := DeleteTags2(Line);
Item := LineDecode(Item);
Item := StringReplace(Item, '. ', ', ');
i := Pos('|', Item);
Item := Copy(Item, 1, i-1);
Item := Trim(Item);
SetField(fieldCategory, Item);
end;
// Theme
LineNr := FindLine(UTF8Encode('<dt>Género</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 2);
Item := DeleteTags2(Line);
Item := LineDecode(Item);
Item := StringReplace(Item, '. ', ', ');
i := Pos('|', Item);
Item := Copy(Item, i+1, Length(Item));
Item := Trim(Item);
SetCustomField('Tematica', Item);
end;
// Synopsis
LineNr := FindLine2(UTF8Encode('<dt>Sinopsis</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags2(Line);
Item:= LineDecode(Item);
SetField(fieldDescription, Item);
end;
// Awards
LineNr := FindLine(UTF8Encode('<dt>Premios</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
// Comments := Comments + 'Premios: ' + #13#10;
while Pos ('</dd>', Line) = 0 do
begin
if Pos ('<span id="show-all-awards">', Line) = 0 then
begin
Item := DeleteTags2(Line);
Item:= LineDecode(Item);
if (Length(Item) <> 0) then
begin
Premios := Premios + ' - ' + Item + #13#10;
//Comments := Comments + ' - ' + Item + #13#10;
end;
end;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
end;
Premios := Premios + #13#10;
//Comments := Comments + #13#10;
SetCustomField('Premios', Premios);
end;
// Critic
LineNr := FindLine2(UTF8Encode('<dt>Críticas</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
// El unico objeto de esta linea es poder presentar en el foro el listado
// del script sin que se produzca la conversión del caracter estrella
CharStar := '&'+'#9733;' ;
if Comments <> '' then Comments := Comments + #13#10 + #13#10 + '________________________________________' + #13#10 + '________________________________________' + #13#10 + #13#10;
Comments := Comments + 'CRÍTICAS: ' + #13#10 + #13#10;
LineNr := FindLine2('<div class="pro-review">', Page, LineNr + 1);
while LineNr <> -1 do
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if Pos (UTF8Encode('<a title="Leer crítica completa" href='), Line) <> 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
end;
Line:= StringReplace(Line, CharStar, '*');
Item := DeleteTags2(Line);
Item:= LineDecode(Item);
if (Length(Item) <> 0) then
begin
Comments := Comments + Item + #13#10;
LineNr := FindLine2('<div class="pro-crit-med">', Page, LineNr + 1);
Line := Page.GetString(LineNr);
Item := DeleteTags2(Line);
Item:= LineDecode(Item);
if (Length(Item) <> 0) then
begin
Comments := Comments + Item + #13#10;
end;
Comments := Comments + '----------------------------------------' + #13#10;
end;
LineNr := FindLine('<div class="pro-review">', Page, LineNr + 1);
end;
end;
HTMLDecode(Comments);
SetField(fieldComments, Comments);
if GetOption('DontWantExtras') = 0 then
AnalyzeExtras(Page,Address);
end;
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// CINeol + Culturalia
(* PeQuE: estas funciones no tocan la variable original donde se busca, y devuelven cadena vacía si alguno
de los tags no es encontrado *)
function MiTextBetween_2(var S: string; StartTag: string; EndTag: string): string;
var
InitialPos: Integer;
a: string;
begin
a := S;
InitialPos := Pos(AnsiLowerCase(StartTag), AnsiLowerCase(a));
if InitialPos = 0 then
begin
result := '';
exit;
end
Delete(a, 1, InitialPos + Length(StartTag) - 1);
InitialPos := Pos(AnsiLowerCase(EndTag), AnsiLowerCase(a));
if InitialPos = 0 then
begin
result := '';
exit;
end
result := copy(a, 1, InitialPos - 1);
end;
//------------------------------------------------------------------------------------
function MiTextAfter(var S: string; StartTag: string): string;
var
InitialPos: Integer;
a: string;
begin
a := S;
InitialPos := Pos(AnsiLowerCase(StartTag), AnsiLowerCase(a));
if InitialPos = 0 then
begin
result := '';
exit;
end
Delete(a, 1, InitialPos + Length(StartTag) - 1);
result := a;
end;
//------------------------------------------------------------------------------------
function EliminaInicio(S: string; CR: string): string;
begin
result := S;
while Pos(CR, result) = 1 do
begin
Delete(result, 1, Length(CR));
end;
end;
//------------------------------------------------------------------------------------
function Caracter(str1: string) :string;
begin
str1 := StringReplace(str1, 'á' , 'á');
str1 := StringReplace(str1, 'é' , 'é');
str1 := StringReplace(str1, 'Ã', 'í');
Str1 := StringReplace(Str1, 'ó', 'ó');
str1 := StringReplace(str1, 'ú' , 'ú');
str1 := StringReplace(str1, 'ñ' , 'ñ');
str1 := StringReplace(str1, 'Ã', 'Á');
str1 := StringReplace(str1, 'É', 'É');
str1 := StringReplace(str1, 'Ã', 'Í');
str1 := StringReplace(str1, 'Ó', 'Ó');
str1 := StringReplace(str1, 'Ú', 'Ú');
str1 := StringReplace(str1, 'Ñ', 'Ñ');
str1 := StringReplace(str1, 'Â', '');
//v 2.0beta3 - JXO
str1 := StringReplace(str1, '“', '"');
str1 := StringReplace(str1, 'â€', '"');
str1 := StringReplace(str1, '–', '"');
result := str1;
end;
//------------------------------------------------------------------------------------
function DeleteTags(var S: string): string;
var
n,len, tag: Integer;
c: char;
t: String;
begin
tag := 0;
t := '';
len := length(s);
for n :=1 to len do
begin
c := Copy(s,n,1);
if c = #9 then
c := ' ';
if(tag=1) then
begin
if(c='>') then tag := 0;
continue;
end
else
begin
if(c='<') then
begin
tag := 1;
continue;
end;
t := t + c;
end;
end
s := t;
result := t;
end;
//------------------------------------------------------------------------------------
function SansAccents(AvecAccent : String): String;
var
accent, noaccent : String;
i : integer;
begin
accent := 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿÑñÇç';
noaccent := 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuyNnCc';
for i := 1 to Length(accent) do
AvecAccent := StringReplace(AvecAccent,copy(accent, i, 1),copy(noaccent, i, 1)); // Supprime tous les accents pour la recherche cinéfil
result := AvecAccent;
end;
//------------------------------------------------------------------------------------
procedure BuscarCaratulaCulturalia;
var
strTemp: string;
Articles: array of string;
Index: integer;
begin
SetArrayLength(Articles,11);
Articles[0]:='Lo ';
Articles[1]:='La ';
Articles[2]:='Le ';
Articles[3]:='Uno ';
Articles[4]:='Una ';
Articles[5]:='Un ';
Articles[6]:='El ';
Articles[7]:='Los ';
Articles[8]:='Las ';
Articles[9]:='Unos ';
Articles[10]:='Unas ';
// Eliminate spanish article if exists
for Index := 0 to 10 do
begin
if Pos(Articles[Index], MovieName) <> 0 then
MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
end;
// Eliminate point(s) at final of MovieName before search
strTemp := MovieName;
if Copy(strTemp, Length(strTemp), Length(strTemp)) = '.' then
MovieName := Copy(strTemp, 1, Length(strTemp) -1);
AnalyzePageCulturalia(BaseURLCulturalia + UrlEncode(MovieName) + '&donde=1',0);
end;
//------------------------------------------------------------------------------------
procedure AnalyzePageCulturalia(Address: string; todas_pags: integer);
var
Page: TStringList;
LineNr, Fin, pags, curr_pag: Integer;
Code, Tit, Year, Linea: string;
TitleFound, multipagina: Boolean;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if Pos('No se ha encontrado ningún artículo por título', Page.Text) = 0 then
begin
if not ModoBatch then
begin
//PeQuE: Si tenemos que parsear todas las páginas de resultados, buscamos el número de páginas, si no, sólo parseamos la primera.
pags := 0;
LineNr := 0;
while LineNr > -1 do
begin
pags := pags + 1;
LineNr := FindLine('muestro=' + IntToStr(pags), Page, 0);
end
if pags > 1 then
begin
multipagina := true;
end else multipagina := false;
if todas_pags = 0 then pags := 1;
PickTreeClear;
PickTreeAdd('CULTURALIANET: Resultados de la búsqueda:', '');
//PeQuE: Analizamos todas las páginas de la búsqueda.
curr_pag := 1;
while curr_pag <= pags do
begin
//PeQuE: La primera página ya la hemos bajado antes. Nos ahorramos volverla a bajar.
if curr_pag > 1 then
begin
Page.Free;
Page := TStringList.Create;
Page.Text := GetPage(Address + '&muestro=' + IntToStr(curr_pag - 1));
end
//PeQuE: Buscamos la primera línea con resultados.
LineNr := FindLine('<b>RESULTADOS ', Page, 0);
//PeQuE: Buscamos la última línea con resultados.
Fin := FindLine('Se han encontrado', Page, 0);
Fin := FindLine('Se han encontrado', Page, Fin+1);
while LineNr < Fin do
begin
//PeQuE: Extraemos code, título y año. No hace falta nada más.
LineNr := FindLine(' (', Page, LineNr+1);
if LineNr <> -1 then
begin
Linea := Page.GetString(LineNr);
Year := MiTextBetween(Linea, ' (', ')');
Linea := Page.GetString(LineNr-1);
Code := MiTextBetween(Linea, '../art/ver.php?art=', '''');
Tit:= MiTextBetween(Linea, ' target=''_top''>', '.</a></b></td>');
//Sólo asociamos el "Code" a cada una de las opciones encontradas. No hace falta nada más.
//PickTreeAdd(Tit + ' (' + Year + ')', BaseURLCulturalia + '?catalogo=1&codigo=' + Code);
if FiltradoAnyo = 0 then PickTreeAdd(Tit + ' (' + Year + ')', Code);
if FiltradoAnyo = 1 then
begin
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) - 1 then PickTreeAdd(Tit + ' (' + Year + ')', Code);
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) then PickTreeAdd(Tit + ' (' + Year + ')', Code);
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) + 1 then PickTreeAdd(Tit + ' (' + Year + ')', Code);
end
if FiltradoAnyo = 2 then
if Year = getfield(fieldYear) then PickTreeAdd(Tit + ' (' + Year + ')', Code);
end else LineNr := Fin;
end;
curr_pag := curr_pag + 1;
end;
Page.Free;
// PeQuE: Si sólo mostramos la primera página pero hay más, añadimos la opción de mostrar todas.
if (todas_pags = 0) and (multipagina) then
begin
PickTreeAdd('Más resultados', '');
PickTreeAdd(' >> MOSTRAR TODOS LOS RESULTADOS >>', Address);
end
if PickTreeExec(Code) then
// PeQuE: Si la respuesta no es un "Code", volvemos a ejecutar esta función indicando el parseo de todas las páginas de resultados.
if Pos('culturalianet',Code) > 0 then
begin
AnalyzePageCulturalia(Address,1);
// PeQuE: Debemos usar la nueva función GetPicture2 del AMC 3.5.1 para poder configurar Culturalianet
// como Referrer al bajar la carátula. De otro modo, Culturalianet prohibe el acceso (error 403).
end else GetPicture2('http://www.culturalianet.com/imatges/articulos/' + Code + '-1.jpg','http://www.culturalianet.com');
end else
begin
//PeQuE: En caso de modobatch, buscamos la primera línea con resultados en que coincida el año y listos.
LineNr := FindLine('<b>RESULTADOS ', Page, 0);
TitleFound := True;
Linea := Page.GetString(LineNr);
Code := MiTextBetween(Linea, '../art/ver.php?art=', '''');
if TitleFound then
GetPicture2('http://www.culturalianet.com/imatges/articulos/' + Code + '-1.jpg','http://www.culturalianet.com');
Page.Free;
end;
end else
if not ModoBatch then
ShowError('CULTURALIANET: No se ha encontrado ninguna coincidencia para "'+ MovieName +'"');
end;
//------------------------------------------------------------------------------------
procedure AnalyzePage_Alpacine(Address: string);
var
MovieAddr, Year, Line,Item: string;
Page: TStringList;
LineNr: Integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<div class="titulo">Pel', Page, 0);
if(LineNr > -1)then
begin
Line := Page.GetString(LineNr);
Line := MiTextBetween_2(Line,'<ul>','</ul>');
if not ModoBatch then
begin
PickTreeClear;
PickTreeAdd('ALPACINE: Resultados de la búsqueda:', '');
end
repeat
Item := MiTextBetween_2(Line,'<li>','</li>');
if Item = '' then
begin
Item := MiTextBetween_2(Line,'<li class="mas">','</li>');
PickTreeAdd('Más resultados', '');
PickTreeAdd(' >> MOSTRAR TODOS LOS RESULTADOS >>', Address + '&todo=1&tipo=2');
Line := MiTextAfter(Line,'</li>');
end else
begin
MovieAddr := BaseURLAlpacine_Caratula + MiTextBetween_2(Line,'/pelicula/','/') + '/';
Year := MiTextAfter(Item,'</a>');
Year := MiTextBetween_2(Year,'(',')');
HTMLRemoveTags(Item);
Item := Caracter(Item);
if not ModoBatch then
begin
if FiltradoAnyo = 0 then PickTreeAdd(Item, MovieAddr);
if FiltradoAnyo = 1 then
begin
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) - 1 then PickTreeAdd(Item, MovieAddr);
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) then PickTreeAdd(Item, MovieAddr);
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) + 1 then PickTreeAdd(Item, MovieAddr);
end
if FiltradoAnyo = 2 then
if Year = getfield(fieldYear) then PickTreeAdd(Item, MovieAddr);
Line := MiTextAfter(Line,'</li>');
end else
begin
if Year = getfield(fieldYear) then
begin
AnalyzeMoviePage_Alpacine(MovieAddr);
Line := '';
end else Line := MiTextAfter(Line,'</li>');
end
end
Until Pos('<li',Line) = 0;
if not ModoBatch then
begin
PickTreeExec(Address);
if Pos('&todo=1&tipo=2',Address) > 0 then
begin
AnalyzePage_Alpacine(Address);
end else AnalyzeMoviePage_Alpacine(Address);
end
end else if not ModoBatch then ShowError('ALPACINE: No se ha encontrado ninguna coincidencia para "'+ MovieName +'"');
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage_Alpacine(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Item: string;
Busca: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Caratula
LineNr := FindLine('src="http://img.alpacine.com/carteles/', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Busca := FindLine('id="ampliar">', Page, 0);
if Busca <> -1 then
begin
Item := TextBetween (Line, 'src="', '.jpg');
Item := StringReplace(Item , '-150', '');
GetPicture (Item+'.jpg');
end
else
begin
Item := TextBetween (Line, 'src="', '" alt');
GetPicture (Item);
end
end;
end;
//------------------------------------------------------------------------------------
procedure CINEOL_BuscarInformacion;
var url: String;
Articles: array of string;
Index: integer;
begin
SetArrayLength(Articles,11);
Articles[0]:='Lo ';
Articles[1]:='La ';
Articles[2]:='Le ';
Articles[3]:='Uno ';
Articles[4]:='Una ';
Articles[5]:='Un ';
Articles[6]:='El ';
Articles[7]:='Los ';
Articles[8]:='Las ';
Articles[9]:='Unos ';
Articles[10]:='Unas ';
// Eliminate spanish article if exists
for Index := 0 to 10 do
begin
if Pos(Articles[Index], MovieName) = 1 then
MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
end;
MovieName := StringReplace(MovieName,'.',' ');
MovieName := StringReplace(MovieName,' - ',' ');
MovieName := SansAccents(MovieName);
url := CINEOL_ListaBusqueda(BaseURLCineol, URLEncode('apiKey=cfdvkFD&search=' + MovieName));
if url <> '' then
CINEOL_RecuperarInformacionPelicula(url + '&apiKey=cfdvkFD');
end;
- 2015-01-20 21:37:29
- Forum: Ant Movie Catalog > Scripts
- Topic: Help merging two scripts
- Replies: 3
- Views: 1970
Help merging two scripts
I'm tying to merge two scripts, one fom imdb and the other from fimaffinity, but I have a problem with the duplicated AnalyzeMoviePage. I've tried to change the name, but I get an error. How can I solve it?
Thanks.
Thanks.
Code: Select all
program IMDB;
uses
StringUtils1;
// ***** Manually set UserCountry to your required Classification Country below *****
const
//UserCountry = '';
{ Delete the line above and remove the "//" in front of one the
following lines, or add your country if it is not listed }
UserCountry = 'Spain';
//UserCountry = 'Canada';
//UserCountry = 'Mexico';
//UserCountry = 'Brazil';
//UserCountry = 'Argentina';
//UserCountry = 'Australia';
//UserCountry = 'India';
//UserCountry = 'Italy';
//UserCountry = 'USA';
//UserCountry = 'Portugal';
//UserCountry = 'France';
//UserCountry = 'Germany';
//UserCountry = 'Netherlands';
//UserCountry = 'UK';
//UserCountry = 'Ireland';
//UserCountry = 'Finland';
//UserCountry = 'Norway';
//UserCountry = 'Sweden';
//UserCountry = 'Switzerland';
BaseURL = 'http://www.filmaffinity.com';
PopularTitleSearchURL = 'http://www.imdb.com/find?s=tt&q=';
FullTitleSearchURL = 'http://www.imdb.com/find?s=tt&exact=true&q=';
EpisodeTitleSearchURL = 'http://www.imdb.com/find?s=ep&q=';
var
MovieName: string;
MovieURL: string;
MovieNumber: string;
UpdateFile: TStringList;
function ConvertToASCII(AText: string): string;
begin
Result := AText;
if GetOption('ConvertToASCII') = 1 then
Result := Cp1252ToASCII(AText);
end;
// ***** analyzes IMDB's results page that asks to select a movie from a list *****
procedure AnalyzeResultsPage(Address: string);
var
PageText: string;
Value: string;
begin
PageText := ConvertToASCII(GetPage(Address));
if pos('<title>Find - IMDb', PageText) = 0 then
begin
AnalyzeMoviePage(PageText)
end else
begin
if Pos('<b>No Matches.</b>', PageText) > 0 then
begin
if GetOption('BatchMode') = 0 then
ShowMessage('No movie found for this search.');
Exit;
end;
if GetOption('BatchMode') = 0 then
begin
PickTreeClear;
Value := TextBetween(PageText, '<h1 class="findHeader">Displaying', '</h1>');
if Value <> '' then
begin
HTMLRemoveTags(Value);
HTMLDecode(Value);
PickTreeAdd(UTF8Decode(Value), '');
end;
Value := TextBetween(PageText, '<table class="findList">', '</table>');
PageText := RemainingText;
AddMovieTitles(Value);
{
Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
if Value <> '' then
PickTreeMoreLink('http://www.imdb.com' + Value);
if GetOption('EpisodeTitleSearch') > 0 then
PickTreeMoreLink(EpisodeTitleSearchURL + UrlEncode(MovieName));
}
if PickTreeExec(Address) then
AnalyzeResultsPage(Address);
end
else
begin
Value := TextBetween(PageText, '<td class="primary_photo">', '<img src');
if Value <> '' then
AnalyzeResultsPage('http://www.imdb.com' + TextBetween(Value, '<a href="', '"'));
end;
end;
end;
// ***** adds the movie titles found on IMDB's results page *****
function AddMovieTitles(List: string): Boolean;
var
Value: string;
Address: string;
begin
Result := False;
Value := TextBetween(List, '<td class="result_text">', '</td>');
if GetOption('HideAkaTitles') = 1 then
Value := StringReplace(Value, TextAfter(Value, '<br/>aka'), '')
else
Value := StringReplace(Value, 'aka', ' | aka');
List := RemainingText;
while Value <> '' do
begin
Address := TextBetween(Value, '<a href="/title/tt', '/');
Address := Address + '/combined';
HTMLRemoveTags(Value);
HTMLDecode(Value);
PickTreeAdd(UTF8Decode(Value), 'http://www.imdb.com/title/tt' + Address);
Result := True;
Value := TextBetween(List, '<td class="result_text">', '</td>');
if GetOption('HideAkaTitles') = 1 then
Value := StringReplace(Value, TextAfter(Value, '<br/>aka'), '')
else
Value := StringReplace(Value, 'aka', ' | aka');
List := RemainingText;
end;
end;
// ***** analyzes the page containing movie information *****
procedure AnalyzeMoviePage2(PageText: string);
var
Value, Value2, Value3, FullValue, originalTitle: string;
p, Count: Integer;
begin
MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/');
if MovieNumber = '' then
MovieNumber := TextBetween(PageText, '<input type="hidden" name="auto" value="legacy/title/tt', '/combined"');
if MovieNumber = '' then
MovieNumber := TextBetween(PageText, '<link rel="canonical" href="http://www.imdb.com/title/tt', '/');
// #########
// if ((GetOption('AllActors') = 1) or (GetOption('Producer') = 1)) and (Pos('<div id="tn15" class="maindetails">', PageText) > 0) then
// PageText := ConvertToASCII(GetPage('http://www.imdb.com/title/tt' + MovieNumber + '/combined'));
if Pos('/combined"', TextBetween(PageText, '<link rel="canonical"', '/>')) = 0 then
PageText := ConvertToASCII(GetPage('http://www.imdb.com/title/tt' + MovieNumber + '/combined'));
// #########
MovieURL := 'http://imdb.com/title/tt' + MovieNumber;
// OriginalTitle & Year
if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
begin
originalTitle := TextBefore(PageText, '<i>(original title)', '<span class="title-extra">');
HTMLDecode(originalTitle);
Value := TextBetween(PageText, '<title>', '</title>');
// showmessage(originalTitle);
// showmessage(value);
if (originalTitle <> '') and CanSetField(fieldOriginalTitle) then
SetField(fieldOriginalTitle, FullTrim(originalTitle));
p := Pos(' (1', Value);
if p = 0 then
p := Pos(' (2', Value);
Value2 := Copy(Value, 0, p-1);
Value := Copy(Value, p+2, Length(Value));
HTMLDecode(Value2);
if (originalTitle = '') and CanSetField(fieldOriginalTitle) then
SetField(fieldOriginalTitle, FullTrim(Value2));
if Pos('/', Value) > 0 then
Value2 := TextBefore(Value, '/', '')
else
Value2 := TextBefore(Value, ')', '');
if CanSetField(fieldYear) then
SetField(fieldYear, Value2);
end;
// Director
if CanSetField(fieldDirector) then
begin
Value := TextBetween(PageText, 'Directed by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldDirector, FullValue);
end;
// Actors
if CanSetField(fieldActors) then
begin
Value := FullTrim(TextBetween(PageText, '<table class="cast">', '</table>'));
if Value <> '' then
begin
FullValue := '';
Count := 0;
case GetOption('ActorsLayout') of
0, 1:
while Pos('<tr', Value) > 0 do
begin
Value2 := TextBetween(Value, '<tr', '</tr>');
Value := RemainingText;
if Pos('rest of cast', Value2) > 0 then
Continue;
if FullValue <> '' then
FullValue := FullValue + #13#10;
TextBefore(Value2, '</td>', '');
Value2 := FullTrim(TextBetween(Value2, '<td class="nm">', '</td>'));
HTMLRemoveTags(Value2);
if Value2 <> '' then
begin
FullValue := FullValue + Value2;
Count := Count + 1;
end;
// ###
if (Count = 15) and (GetOption('AllActors') = 0) then
Break;
// ###
if (Count = 10) and (GetOption('AllActors') = 2) then
Break;
end;
2, 3:
while Pos('<tr', Value) > 0 do
begin
Value2 := TextBetween(Value, '<tr', '</tr>');
Value := RemainingText;
if Pos('rest of cast', Value2) > 0 then
Continue;
if FullValue <> '' then
FullValue := FullValue + #13#10;
TextBefore(Value2, '</td>', '');
Value2 := FullTrim(TextBetween(Value2, '<td class="nm">', '</td>'));
HTMLRemoveTags(Value2);
if Value2 <> '' then
begin
FullValue := FullValue + Value2;
Value2 := FullTrim(TextBetween(RemainingText, '"char">', '</td>'));
if Value2 <> '' then
FullValue := FullValue + ' (as ' + Value2 + ')';
Count := Count + 1;
// ###
if (Count = 15) and (GetOption('AllActors') = 0) then
Break;
// ###
if (Count = 10) and (GetOption('AllActors') = 2) then
Break;
end;
end;
4:
begin
FullValue := Value;
FullValue := StringReplace(FullValue, ' <tr><td align="center" colspan="4"><small>rest of cast listed alphabetically:</small></td></tr>', '');
FullValue := StringReplace(FullValue, '> <', '><');
FullValue := StringReplace(FullValue, '</tr>', #13#10);
end;
end;
HTMLRemoveTags(FullValue);
HTMLDecode(FullValue);
case GetOption('ActorsLayout') of
0, 2:
FullValue := StringReplace(FullValue, #13#10, ', ');
end;
SetField(fieldActors, FullValue);
end;
end;
// Composer
if CanSetField(fieldComposer) then
begin
Value := TextBetween(PageText, 'Music by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldComposer, FullValue);
end;
// Cinematography
begin
Value := TextBetween(PageText, 'Cinematography by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Fotografia', FullValue);
end;
// Costume Design
begin
Value := TextBetween(PageText, 'Costume Design by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Vestuario', FullValue);
end;
// Film Editing
begin
Value := TextBetween(PageText, 'Film Editing by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Montaje', FullValue);
end;
// Production Design
begin
Value := TextBetween(PageText, 'Production Design by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
Value := TextBetween(PageText, 'Set Decoration by</a></h5>', '</table>');
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetCustomField('Diseno', FullValue);
end;
// Producer
if CanSetField(fieldProducer) then
begin
Value := TextBetween(PageText, 'Produced by</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldProducer, FullValue);
end;
// Writer
if CanSetField(fieldWriter) then
begin
Value := TextBetween(PageText, 'Writing credits</a></h5>', '</table>');
FullValue := '';
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
while Value2 <> '' do
begin
Value := RemainingText;
Value2 := TextAfter(Value2, '">');
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value2;
Value2 := TextBetween(Value, '<a href="/name/', '</a>');
end;
HTMLDecode(FullValue);
SetField(fieldWriter, FullValue);
end;
// AKA Name
if CanSetField(fieldTranslatedTitle) then
begin
FullValue := ConvertToASCII(GetPage(MovieURL+'/releaseinfo#akas'));
FullValue := TextBetween(FullValue, '<a id="akas" name="akas">', '</table>');
FullValue := RemoveSpaces(FullValue, True);
FullValue := StringReplace(FullValue, #13, '');
FullValue := StringReplace(FullValue, #10, '');
FullValue := StringReplace(FullValue, '> <', '><');
FullValue := StringReplace(FullValue, '<tr class="even">', '<tr>');
FullValue := StringReplace(FullValue, '<tr class="odd">', '<tr>');
if RegExprSetExec('</td>\s*<tr>', FullValue) then
// removing the original title
FullValue := '<tr>'+TextAfter(FullValue, '</td><tr>');
while fullvalue <> '' do
begin
// showMessage('Analysing: '+FullValue);
// each line is a pair of translated title and country
// format: <tr><td>country</td><td>Translated title</td><tr>
value2 := TextBetween(FullValue, '<tr>', '</tr>');
// showMessage('Line: '+value2);
value := TextBetween(Value2, '<td>', '</td>');
value2 := TextAfter(Value2, '</td>');
value2 := TextBetween(Value2, '<td>', '</td>');
HTMLDecode(value2);
// showMessage('Translated: '+value+' into '+value2);
if pos(UserCountry, value) > 0 then
begin
HTMLDecode(Value2);
SetField(fieldTranslatedTitle, FullTrim(UTF8Decode(Value2)));
FullValue := '';
end
else FullValue := TextAfter(FullValue, '</tr>');
end;
{
if Value <> '' then
begin
Value := StringReplace(Value, 'See more', '');
Value := StringReplace(Value, '»', '');
Value := FullTrim(StringReplace(Value, '<br>', ', '));
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := FullTrim(Value);
if Value <> '' then
if StrGet(Value, Length(Value)) = ',' then
Delete(Value, Length(Value), 1);
SetField(fieldTranslatedTitle, Value)
end;
}
end;
end;
// ***** Imports lists like Genre, Country, etc. depending of the selected option *****
function ImportList(PageText: string; MultipleValues: Integer; StartTag: string): string;
var
Value, Value2: string;
begin
if MultipleValues = 0 then
begin
Value := TextBetween(PageText, StartTag, '</a>');
Value2 := TextAfter(Value, '">');
end
else
begin
Value := TextBetween(PageText, StartTag, '</div>');
Value2 := TextBefore(Value, '<a class="tn15more inline"', '');
if Value2 = '' then
Value2 := Value;
Value2 := TextAfter(Value2, '">');
HTMLRemoveTags(Value2);
if MultipleValues = 1 then
Value2 := StringReplace(Value2, ' | ', ', ');
if MultipleValues = 2 then
Value2 := StringReplace(Value2, ' | ', ' / ');
if MultipleValues = 3 then
Value2 := '';
end;
Value2 := StringReplace(Value2, #13#10, '');
Value2 := StringReplace(Value2, ' , ', ', ');
HTMLDecode(Value2);
Result := FullTrim(Value2);
end;
//------------------------------------------------------------------------------------
function LineDecode(S: string):string;
begin
S:= UTF8Decode(S);
HTMLDecode(S);
Result := S;
end;
//------------------------------------------------------------------------------------
function FindLine2(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
i: Integer;
begin
Result := -1;
if StartAt < 0 then StartAt := 0;
for i := StartAt to List.Count-1 do
if Pos(Pattern, List.GetString(i)) <> 0 then
begin
Result := i;
Break;
end;
end;
//------------------------------------------------------------------------------------
//
// ConvertAlphaNum: Quita todo menos letras (mayusculas y minusculas) y numeros
//
Function ConvertAlphaNum(s: string) : string;
var
i: Integer;
s2, ch: string;
begin
s2 := '';
For i := 1 To Length(s) do
begin
ch := copy(s, i, 1);
if ((ch >= 'a') and (ch <= 'z')) or ((ch >= '0') and (ch <= '9')) or ((ch >= 'A') and (ch <= 'Z')) then
s2 := s2 + ch;
end;
result := s2;
end;
//--------------------------------------
function TextBetween2(S: string; StartTag: string; EndTag: string): string;
var
ini, fin, lenS: Integer;
begin
Result := '';
lenS := Length(S);
ini := Pos(StartTag, S);
if ini <> 0 then
begin
ini := ini + Length(StartTag);
S:= Copy(S,ini,lenS-ini+1);
ini:=1;
fin := Pos(EndTag, S);
if (fin <> 0) and (fin > ini) then
Result := Copy(S, ini, fin - ini);
end;
end;
//------------------------------------------------------------------------------------
function TextAfter2(S: string; StartTag: string): string;
var
ini: Integer;
begin
ini := Pos(StartTag, S);
if ini <> 0 then
Result := Copy(S, ini + Length(StartTag), Length(S)-ini+1)
else
Result := '';
end;
//------------------------------------------------------------------------------------
function DeleteTags(S: string): string;
var
n, len, tag: Integer;
c, p: char;
begin
len := Length(S);
tag := 0;
p := ' ';
Result := '';
for n := 1 to len do
begin
c := Copy(S,n,1);
// Eliminamos los tabuladores
if c = #9 then c := ' ';
// Los espacios redundantes no se procesan
if (c <> ' ') or (p <> ' ') then
begin
// Eliminamos los tags de HTML
if tag = 0 then
begin
if c <> '<' then
begin
Result := Result + c;
p := c;
end
else tag := 1;
end
else if c = '>' then tag := 0;
end;
end
if p = ' ' then Result := Copy(Result, 1, Length(Result) - 1);
end;
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// FUNCIONES DE CARTELESPELICULAS
//
// Función que suprime los acentos
//
function Sinacento(Conacento : String): String;
var
Acento, Noacento : String;
i : integer;
begin
Acento := 'ÀÃÂÂÃÄÅàáâãäåÒÓÃâ€Ãƒâ€¢Ãƒâ€“ØòóôõöøÈÉÊËèéêëÌÃÂÃŽÃÂìÃÂîïÙÚÛÜùúûüÿ';
Noacento := 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuy';
for i := 1 to Length(Acento) do
Conacento := StringReplace(Conacento,copy(Acento, i, 1),copy(Noacento, i, 1));
result := Conacento;
end;
//
// Función para convertir a ascii
//
function Caracter(str1: string) : string;
begin
str1 := StringReplace(str1, 'á' , 'á');
str1 := StringReplace(str1, 'é' , 'é');
str1 := StringReplace(str1, 'ÃÂÂ' , 'ÃÂ');
str1 := StringReplace(Str1, 'ó' , 'ó');
str1 := StringReplace(str1, 'ú' , 'ú');
str1 := StringReplace(str1, 'ñ' , 'ñ');
str1 := StringReplace(str1, 'É' , 'É');
str1 := StringReplace(str1, 'Ã?' , 'ÃÂ');
str1 := StringReplace(str1, 'Ó' , 'Ó');
str1 := StringReplace(str1, 'Ú' , 'Ú');
str1 := StringReplace(str1, 'Ñ' , 'Ñ');
str1 := StringReplace(str1, 'Â' , '');
str1 := StringReplace(str1, 'â' , 'â');
str1 := StringReplace(str1, 'ê' , 'ê');
str1 := StringReplace(str1, 'î' , 'î');
str1 := StringReplace(str1, 'ô' , 'ô');
str1 := StringReplace(str1, 'û' , 'û');
str1 := StringReplace(str1, 'è' , 'è');
str1 := StringReplace(str1, 'ì' , 'ì');
str1 := StringReplace(str1, 'ò' , 'ò');
str1 := StringReplace(str1, 'ù' , 'ù');
str1 := StringReplace(str1, 'ä' , 'ä');
str1 := StringReplace(str1, 'ë' , 'ë');
str1 := StringReplace(str1, 'ï' , 'ï');
str1 := StringReplace(str1, 'ö' , 'ö');
str1 := StringReplace(str1, 'ü' , 'ü');
str1 := StringReplace(str1, 'ÃÂÂ' , 'ÃÂ');
str1 := StringReplace(str1, 'Ã' , 'à');
str1 := StringReplace(str1, 'Â¥' , 'Ã¥');
str1 := StringReplace(str1 , '“' , '"' );
str1 := StringReplace(str1 , 'â€Â' , '"' );
str1 := StringReplace(str1 , '’' , '''' );
str1 := StringReplace(str1 , '‘' , '''' );
str1 := StringReplace(str1 , '&' , '&' );
str1 := StringReplace(str1 , '–' , '-' );
str1 := StringReplace(str1 , '&' , '&' );
str1 := StringReplace(str1 , '″' , '"' );
str1 := StringReplace(str1 , '…' , '...');
str1 := StringReplace(str1 , ' ' , '');
// Str1 := Sinacento (Str1);
result := str1;
end;
//
// Funcion que borra signos y quita acentos
//
function PreparaTitulo(T: string): string;
var
i: Integer;
begin
HTMLDecode(result);
result := AnsiLowerCase(T);
result := StringReplace(result, chr(146), '');
result := StringReplace(result, chr(39), '');
result := StringReplace(result, '´', '');
result := StringReplace(result, '`', '');
result := StringReplace(result, '"', '');
result := StringReplace(result, '¿', '');
result := StringReplace(result, '?', '');
result := StringReplace(result, '¡', '');
result := StringReplace(result, '!', '');
result := StringReplace(result, '.', '');
result := StringReplace(result, ':', '');
result := StringReplace(result, ';', '');
//result := StringReplace(result, '-', '');
result := StringReplace(result, '/', '');
result := StringReplace(result, '\', '');
result := StringReplace(result, '_', '');
result := StringReplace(result, 'á', 'a');
result := StringReplace(result, 'ÃÂ', 'a');
result := StringReplace(result, 'À', 'a');
result := StringReplace(result, 'é', 'e');
result := StringReplace(result, 'ÃÂ', 'i');
result := StringReplace(result, 'ó', 'o');
result := StringReplace(result, 'ú', 'u');
result := StringReplace(result, 'ä', 'a');
result := StringReplace(result, 'ë', 'e');
result := StringReplace(result, 'ï', 'i');
result := StringReplace(result, 'ö', 'o');
result := StringReplace(result, 'ü', 'u');
result := StringReplace(result, '–', '-' );
result := StringReplace(result, '…', '...');
result := Caracter (result);
end;
// PROCEDIMIENTOS DE CARTELES PELICULAS
//
// Crea la lista de las peliculas que contengan el titulo introducido
//
procedure PaginasCartelesPeliculas (Titulo: string);
var
CPPage : TStringList;
Line, PageWeb, TitleWeb, Encontrado, SwFin, TitleWebSin, Any, PageWebList : string;
LineNr, ContPagina, i, j, PosAny : Integer;
begin
Encontrado := '0'; // Si encontrado = '0' es que no se encuentra la pelicula
PickTreeClear;
PickTreeAdd('Resultados de la búsqueda para "' + Titulo + '" (www.CartelesPeliculas.com):', '');
Titulo := UrlEncode (Titulo);
PageWeb := 'http://www.cartelespeliculas.com/wp/?s=' + titulo; // Se crea la URL para ver todas las peliculas que contengan el texto introducido
CPPage := TStringList.Create;
CPPage.Text := GetPage(PageWeb);
CPPage.Text := Caracter (CPPage.Text);
LineNr := 1;
SwFin := '0';
ContPagina := 1;
Repeat // Para cada pelicula que contenga el texto mira a ver si coincide con el titulo
If FindLine ('bookmark' , CPPage , LineNr) > 0 then // Puede haber coincidencias con otros campos de la web (Sinopsis, ...)
begin
LineNr := FindLine('bookmark', CPPage, LineNr);
Line := CPPage.GetString(LineNr);
TitleWeb := TextBetween (Line, 'bookmark">' , '<'); // Estrae el titulo
LineNr := LineNr + 1;
TitleWebSin := Sinacento(Titleweb);
Titulo := UrlDecode (Titulo);
TitleWebSin := PreparaTitulo(TitleWebSin);
PageWebList := TextBetween (Line, '<a href="' , '" rel="'); // Extrae la direccion Web
if Pos(AnsiLowerCase(Titulo), TitleWebSin) > 0 then // Verifica si el titulo de la web coincide con el texto
begin
LineNr := FindLine('quick-read-more', CPPage, LineNr);
Line := CPPage.GetString(LineNr);
Delete (Line, 1, 4);
For i := 1 to 5 do // Extrae el año para mostrar en la PickList
begin
PosAny := Pos(',' , Line);
Any := Copy (Line, PosAny - 4 , 4);
If (Any > '0000') and (Any < '9999') then
begin
Any:= ' (' + Any + ')';
break
end
else
begin
Any := '';
Delete (Line , PosAny, 1);
end;
end;
PickTreeAdd(TitleWeb + Any, PageWebList); // Añade el titulo, año y direccion Web
Encontrado := '1';
end
else //si no coincide el titulo miramos el primer AKAS
begin
LineNr := LineNr - 1;
LineNr := FindLine('akas', CPPage, LineNr);
Line := CPPage.GetString(LineNr);
TitleWeb := TextBetween (Line, 'alt="akas: ' , ','); // Estrae el titulo
LineNr := LineNr + 1;
TitleWebSin := Sinacento(Titleweb);
Titulo := UrlDecode (Titulo);
TitleWebSin := PreparaTitulo(TitleWebSin);
PageWebList := TextBetween (Line, '<a href="' , '" rel="'); // Extrae la direccion Web
if Pos(AnsiLowerCase(Titulo), TitleWebSin) > 0 then // Verifica si el titulo de la web coincide con el texto
begin
LineNr := FindLine('quick-read-more', CPPage, LineNr);
Line := CPPage.GetString(LineNr);
Delete (Line, 1, 4);
For i := 1 to 8 do // Extrae el año para mostrar en la PickList
begin
PosAny := Pos(',' , Line);
Any := Copy (Line, PosAny - 4 , 4);
If (Any > '0000') and (Any < '9999') then
begin
Any:= ' (' + Any + ')';
break
end
else
begin
Any := '';
Delete (Line , PosAny, 1);
end;
end;
PickTreeAdd(TitleWeb + Any, PageWebList); // Añade el titulo, año y direccion Web
Encontrado := '1';
end
else
begin
SwFin:= '1';
end
end
end
else
begin
If FindLine ('Entradas Anteriores' , CPpage, LineNr) > 0 then // Si 'Entradas Anteriores' es que hay mas paginas con coincidencia
begin
ContPagina := ContPagina + 1;
Titulo := UrlEncode (Titulo);
PageWeb := 'http://www.cartelespeliculas.com/wp/page/' + (inttostr(ContPagina)) + '/?s=' + titulo;
CPPage := TStringList.Create; // Lee las paginas con coincidencia
CPPage.Text := GetPage(PageWeb);
CPPage.Text := Caracter (CPPage.Text);
LineNr := 1;
end
else
begin
SwFin := '1';
end;
end;
until (SwFin = '1');
if (Encontrado = '1') then
begin
PickTreeSort;
if PickTreeExec(pageweb) then // Selecciona que nos interese y va a buscar la caratula
begin
AnalyzeCoverPage (PageWeb); // Muestra los carteles seleccionados
end
end
else
ShowMessage('Titulo ' + Titulo + ' no encontrado en CartelesPeliculas');
end;
//
// Caratula.
//
//Accede a la web para extraer la caratula, Primero va a una web intermedia y despues accede a la caratula
//
procedure AnalyzeCoverPage(PageWeb: string);
var
Page: TStringList;
LineNr : Integer;
Line : string;
begin
Page := TStringList.Create; // Accede a la Web donde están todas las caratulas y los datos de la pelicula
Page.Text := GetPage(PageWeb);
RemovePicture;
LineNr := 1;
If FindLine ('./../../pgrande3' , Page , LineNr) > 0 then
begin
LineNr := FindLine('./../../pgrande3', Page, LineNr);
Line := Page.GetString(LineNr);
PageWeb := TextBetween (Line, '<a href="./../../' , '" target'); // Forma la Web con la primera caratula que encuentra
PageWeb := 'http://www.cartelespeliculas.com/' + PageWeb;
PageWeb := StringReplace(pageWeb , 'amp;' , '&' );
Page.Free
Page := TStringList.Create; // Accede a la Web intermedia
Page.Text := GetPage(PageWeb);
LineNr := 1;
LineNr := FindLine('galeria/albums/', Page, LineNr);
If FindLine ('galeria/albums/' , Page , LineNr) > 0 then
begin
Line := Page.GetString(LineNr);
PageWeb := TextBetween (Line, 'id="imagen" src="' , '" width'); // Forma la Web donde esta la caratula
PageWeb := 'http://www.cartelespeliculas.com/' + PageWeb;
Getpicture (PageWeb); // EnvÃÂa la caratula al programa.
end
else
ShowMessage('Titulo no encontrado en CartelesPeliculas')
end
else
ShowMessage('Titulo no encontrado en CartelesPeliculas');
end;
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Count: Integer;
MovieTitle, MovieAddress, Title: string;
begin
Count := 0;
Page := TStringList.Create;
Page.Text := GetPage(Address);
PickTreeClear;
// Get how much search results have been found
// No encuentra las palabras "Resultados por tÃÂtulo"¿?, busco la
// linea anterior, y cojo la siguiente linea, le quito los espacios
// y me quedo con el numerode peliculas.
LineNr := FindLine('<div class="sub-header-search">', Page, 0);
if LineNr <> -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Line:= DeleteTags(Line);
Line:= ConvertAlphaNum(Line);
Count := StrToInt(Line,0);
end;
// Add the results to the PickTree
if Count = 0 then
ShowMessage('No se ha encontrado ningún registro')
else
begin
LineNr := 0;
while true do
begin
LineNr := FindLine('<div class="mc-title"><a href="', Page, LineNr + 1);
if LineNr = -1 then
begin
LineNr := FindLine('siguientes >>', Page, 0);
if LineNr = -1 then
break;
Line := Page.GetString(LineNr);
Page.Text := GetPage('http://www.filmaffinity.com/es/search.php' + TextBetween(Line, '<a href="search.php', '"><div class="'));
LineNr := 0;
continue;
end;
Line := Page.GetString(LineNr);
MovieAddress := TextBetween(Line, '<div class="mc-title"><a href="', '.html">') + '.html';
MovieTitle:= TextBetween(Line, '.html">', '<img src="');
MovieTitle:= DeleteTags(MovieTitle);
MovieTitle:= LineDecode(MovieTitle);
if (Length(MovieAddress) <> 0) and (Length(MovieTitle) <> 0) then
PickTreeAdd(MovieTitle, BaseURL + MovieAddress);
end;
if ((Count = 1) and (GetOption('DontAsk') = 1)) then
AnalyzeMoviePage(BaseURL + MovieAddress)
else
begin
//
// PickTreeSort; // Si se quiere clasificar por orden alfabetico hay que activar el PickTreeSort, quitar las 2
// // las 2 barras "//" que hay a la izquierda la instrucción PickTreeSort y ya esta.
//
PickTreeExec(Address);
AnalyzeMoviePage(Address);
Title := GetField(fieldTranslatedTitle);
if Title = '' then
Title := GetField(fieldOriginalTitle);
Title := PreparaTitulo(Title);
if Input('Importar de CartelesPeliculas', 'Por favor, introduce el titulo:', Title) then
PaginasCartelesPeliculas(Title);
end
end;
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr, LineInc: Integer;
Line: string;
Item: string;
Comments: string;
CharStar: string;
begin
Comments := '';
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Rating
LineNr := FindLine2('<div id="movie-rat-avg" itemprop="ratingValue">', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(Line);
Item:= LineDecode(Item);
SetField(fieldRating, StringReplace(Item, ',', '.'));
end;
// Year
LineNr := FindLine2(UTF8Encode('<dt>Año</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween2(Line, '<dd>', '</dd>'));
Item:= LineDecode(Item);
SetField(fieldYear, Item);
end;
// Length
LineNr := FindLine2(UTF8Encode('<dt>Duración</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween2(Line, '<dd>', 'min.</dd>'));
Item:= LineDecode(Item);
SetField(fieldLength, Item);
end;
// Country
LineNr := FindLine2(UTF8Encode('<dt>País</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween2(Line, 'title="', '"></span'));
Item:= LineDecode(Item);
SetField(fieldCountry, Item);
end;
// Productor
LineNr := FindLine2(UTF8Encode('<dt>Productora</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween2(Line, '<dd>', '</dd>'));
Item:= LineDecode(Item);
Item := StringReplace(Item, ' / ', ', ');
SetCustomField('Productora', Item);
end;
// Category
LineNr := FindLine2(UTF8Encode('<dt>Género</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 2);
Item := DeleteTags(Line);
Item := LineDecode(Item);
Item := StringReplace(Item, '. ', ', ');
SetField(fieldCategory, Item);
end;
// Synopsis
LineNr := FindLine2(UTF8Encode('<dt>Sinopsis</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(Line);
Item:= LineDecode(Item);
SetField(fieldDescription, Item);
end;
// Awards
LineNr := FindLine2(UTF8Encode('<dt>Premios</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if ((CheckVersion(4,2,0) = true) and (GetOption('Force350') = 0)) then SetCustomField('Premios', Item)
else Comments := Comments + 'Premios: ' + #13#10;
while Pos ('</dd>', Line) = 0 do
begin
if Pos ('<span id="show-all-awards">', Line) = 0 then
begin
Item := DeleteTags(Line);
Item:= LineDecode(Item);
if (Length(Item) <> 0) then
begin
if ((CheckVersion(4,2,0) = true) and (GetOption('Force350') = 0)) then SetCustomField('Premios', Item)
else Comments := Comments + ' - ' + Item + #13#10;
end;
end;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
end;
Comments := Comments + #13#10;
end;
// Critic
LineNr := FindLine2(UTF8Encode('<dt>CrÃticas</dt>'), Page, LineNr);
if LineNr <> -1 then
begin
// El unico objeto de esta linea es poder presentar en el foro el listado
// del script sin que se produzca la conversión del caracter estrella
CharStar := '&'+'#9733;' ;
Comments := Comments + 'CrÃticas: ' + #13#10 + #13#10;
LineNr := FindLine2('<div class="pro-review">', Page, LineNr + 1);
while LineNr <> -1 do
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if Pos (UTF8Encode('<a title="Leer crÃtica completa" href='), Line) <> 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
end;
Line:= StringReplace(Line, CharStar, '*');
Item := DeleteTags(Line);
Item:= LineDecode(Item);
if (Length(Item) <> 0) then
begin
Comments := Comments + Item + #13#10;
LineNr := FindLine2('<div class="pro-crit-med">', Page, LineNr + 1);
Line := Page.GetString(LineNr);
Item := DeleteTags(Line);
Item:= LineDecode(Item);
if (Length(Item) <> 0) then
begin
Comments := Comments + Item + #13#10;
end;
Comments := Comments + '________________________________________' + #13#10 + #13#10;
end;
LineNr := FindLine('<div class="pro-review">', Page, LineNr + 1);
end;
end;
HTMLDecode(Comments);
SetField(fieldComments, Comments);
if GetOption('DontWantExtras') = 0 then
AnalyzeExtras(Page,Address);
end;
//------------------------------------------------------------------------------------
begin
if (CheckVersion(4,1,2) = false) then
begin
ShowMessage('Se requiere Ant Movie Catalog versión 4.1.2 o superior');
exit;
end;
if (CheckVersion(4,2,0) = false) then
SetOption('DontWantExtras', 1);
MovieName := GetField(fieldOriginalTitle);
if Length(MovieName) = 0 then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('DontAsk') = 0 then
Input('FilmAffinity', 'Pelicula:', MovieName);
MovieName := UTF8Encode(MovieName);
if Pos('filmaffinity.com', MovieName) > 0 then
AnalyzeMoviePage(MovieName)
else
AnalyzePage(BaseURL +'/es/search.php?stext=' + UrlEncode(MovieName) + '&stype=Title');
// ***** beginning of the program *****
// Check for current AMC version
if CheckVersion(4,2,0) then
begin
MovieName := '';
if GetOption('BatchMode') = 2 then
begin
MovieName := GetField(fieldURL);
if Pos('imdb.com', MovieName) = 0 then
MovieName := '';
end;
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('BatchMode') = 0 then
begin
if not Input('IMDB Import', 'Enter the title or the IMDB URL of the movie:', MovieName) then
Exit;
end
else
Sleep(500);
if MovieName <> '' then
begin
if Pos('imdb.com', MovieName) > 0 then
AnalyzeResultsPage(MovieName)
else if RegExprSetExec('tt[0-9]+', moviename) then
AnalyzeResultsPage('http://www.imdb.com/title/' + MovieName)
else
begin
MovieName := UTF8Encode(StringReplace(MovieName, '&', 'and'));
if (GetOption('BatchMode') > 0) or (GetOption('PopularSearches') = 1) then
AnalyzeResultsPage(PopularTitleSearchURL + UrlEncode(MovieName))
else
AnalyzeResultsPage(FullTitleSearchURL + UrlEncode(MovieName));
end;
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 4.2)');
end.
- 2015-01-19 21:25:55
- Forum: Other programs
- Topic: ANT VIEWER
- Replies: 16
- Views: 26218