(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=aviloria (aviloria@yahoo.com) modded by: rodpedja (rodpedja@gmail.com), kreti (bisoft@hotmail.com), MrK, gilistico, juliojs, Albher, Arturo, jacqlittle, AgustinG Title=FilmAffinity (ES) Description=Movie importation script for FilmAffinity Spain Site=https://www.filmaffinity.com Language=ES Version=3.16 Requires=4.2.2 Comments=adaptation for compatibility with 4.2 version. Added Extras capture. Changed Charset ISO-> utf8 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] 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=1|0|1=Actores separados por comas|0=Actores en lineas independientes 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 SortByYear=0|0|1=Ordena lista de busqueda por año|0=Ordena lista de busqueda por relevancia SearchByFromToYears=0|0|0=No buscar por año|1=Buscar dentro de un período de años SearchByTitle=1|1|0=No buscar por título|1=Buscar por título SearchByDirector=0|0|0=No buscar por director|1=Buscar por director SearchByCast=0|0|0=No buscar por reparto|1=Buscar por reparto SearchByScript=0|0|0=No buscar por guión|1=Buscar por guión SearchByPhoto=0|0|0=No buscar por fotografía|1=Buscar por fotografía SearchByMusic=0|0|0=No buscar por música|1=Buscar por música SearchByProducer=0|0|0=No buscar por productor|1=Buscar por productor [Parameters] ExtraCriticsLimit=|99|Límite de criticas en Extras ExtraImagesLimit=|99|Límite de imágenes en Extras ExtraTrailersLimit=|99|Límite de Trailers en Extras ***************************************************) program FilmAffinity; const BaseURL = 'https://www.filmaffinity.com'; var MovieName : string; MovieURL : string; MovieYear : string; YearFrom : string; YearTo : string; AdvQuery : string; //------------------------------------------------------------------------------------ function LineDecode(S: string):string; begin S:= UTF8Decode(S); HTMLDecode(S); Result := S; end; function FindLine(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 TextBetween(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 TextAfter(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; //------------------------------------------------------------------------------------ function Occurrences(Subtext: string; Text: string): integer; var offset: Integer; begin result := 0; while true do begin offset := Pos(Subtext, Text); if offset = 0 then break; Result := Result + 1; Text := TextAfter(Text, Subtext); end; end; //------------------------------------------------------------------------------------ procedure AnalyzeAdvPage(Address: string); var Page: TStringList; LineNr,LineNrax,NextPageNr,Pages: Integer; Line, PageNr: string; Count: Integer; MovieTitle, MovieAddress, MovieDirector: string; YearAnt: string; PagSig:String; begin Count := 0; Page := TStringList.Create; Page.Text := GetPage(Address); PickTreeClear; // Get how much search results have been found LineNr := FindLine('
', Page, 0); Count := StrToInt(TextBetween(Page.GetString(LineNr),'
','' ),0); if LineNr <> -1 then // Add the results to the PickTree if Count = 0 then ShowMessage('No se ha encontrado ningún registro') else begin PageNr := ''; LineNr := 0; while true do begin LineNr := FindLine('
', Page, 0); if LineNr = -1 then break; Line := Page.GetString(LineNr); Pages := Occurrences('', ''); if StrToInt(PageNr, 0) = Pages then break; NextPageNr := StrToInt(PageNr, 0) + 1; PagSig:= 'https://www.filmaffinity.com/es/advsearch.php?page=' + IntToStr(NextPageNr) + '&stext=' + TextBetween(Line, '&stext=', '">'); PagSig:=StringReplace(PagSig,'&','&'); Page.Text := GetPage(PagSig); LineNr := 0; continue; end; Line := Page.GetString(LineNr); MovieAddress := TextBetween(Line, 'href="', '.html"') + '.html'; MovieTitle := TextBetween(Line, 'title="', '"'); MovieTitle := DeleteTags(MovieTitle); MovieTitle := LineDecode(MovieTitle); //------------------------------------- LineNrax := FindLine('">', Page, LineNr); if LineNrax <> -1 then begin Line:= Page.GetString(LineNrax); MovieYear := TextBetween(Line, '">', ''); MovieYear := DeleteTags(MovieYear); MovieYear:= LineDecode(MovieYear); end; if MovieYear = '' Then MovieYear := YearAnt else YearAnt := MovieYear; //------------------------------------ LineNrax := FindLine('div class="mc-director">', Page, LineNr); if LineNrax <> -1 then begin Line:= Page.GetString(LineNrax+1); MovieDirector:= TextBetween(Line, 'title="', '"'); MovieDirector:= DeleteTags(MovieDirector); MovieDirector:= LineDecode(MovieDirector); end; //------------------------------------ if (Length(MovieAddress) <> 0) and (Length(MovieTitle) <> 0) then PickTreeAdd(MovieTitle+' ('+MovieYear+')'+' -<'+MovieDirector+'>-', MovieAddress); end; if ((Count = 1) and (GetOption('DontAsk') = 1)) then AnalyzeMoviePage(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 AnalyzePage(Address: string); var Page: TStringList; LineNr,LineNrax: Integer; Line: string; Count: Integer; MovieTitle, MovieAddress, MovieDirector, MovieYear: string; YearAnt: string; PagSig: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(''); Item := LineDecode(Item); Item := DeleteTags(Item); Comments := Comments + 'Fotografía: ' + Item + #13#10 + #13#10; end; // Productor LineNr := FindLine(UTF8Encode('
Compañías
'), Page, LineNr); if LineNr <> -1 then begin Line := Page.GetString(LineNr + 2); Item := TextBetween(Line, '', '
'); Item := LineDecode(Item); Item := DeleteTags(Item); SetField(fieldProducer, Item); end; // Category LineNr := FindLine(UTF8Encode('
Género
'), Page, LineNr); if LineNr <> -1 then begin Line := Page.GetString(LineNr + 2); Item := DeleteTags(Line); Item := LineDecode(Item); Item := StringReplace(Item, ' | ', ', '); Item := StringReplace(Item, '. ', ', '); SetField(fieldCategory, Item); end; // Official Webpage LineNr := FindLine(UTF8Encode('
Web oficial
'), Page, LineNr); if LineNr <> -1 then begin Line := Page.GetString(LineNr + 1); Item := DeleteTags(TextBetween(Line, ' href="', '">')); Item := LineDecode(Item); Comments := Comments + 'Web oficial: ' + Item + #13#10 + #13#10; end; // Synopsis LineNr := FindLine(UTF8Encode('
Sinopsis
'), Page, LineNr); if LineNr <> -1 then begin Line := Page.GetString(LineNr + 1); Item := DeleteTags(Line); Item := LineDecode(Item); SetField(fieldDescription, Item); end; // Awards LineNr := FindLine(UTF8Encode('
Premios
'), Page, LineNr); if LineNr <> -1 then begin LineNr := LineNr + 1; Line := Page.GetString(LineNr); Comments := Comments + 'Premios: ' + #13#10; while Pos ('', Line) = 0 do begin if Pos ('', Line) = 0 then begin Item := DeleteTags(Line); Item := LineDecode(Item); if (Length(Item) <> 0) then begin Comments := Comments + ' - ' + Item + #13#10; end; end; LineNr := LineNr + 1; Line := Page.GetString(LineNr); end; Comments := Comments + #13#10; end; // Critic LineNr := FindLine(UTF8Encode('
Críticas
'), 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 := FindLine('
-1 do begin LineNr := LineNr + 2; Line := Page.GetString(LineNr); if Pos (UTF8Encode(' 0) then begin Comments := Comments + Item + #13#10; LineNr := FindLine('div class="pro-crit-med"', Page, LineNr + 1); Line := Page.GetString(LineNr); Item := DeleteTags(TextBetween(Line, ' itemprop="author">', ' 0) then begin Comments := Comments + Item + #13#10; end; Comments := Comments + '________________________________________' + #13#10 + #13#10; end; LineNr := FindLine('
Críticas'), Page, LineNr); CountC := 0; if LineNr <> -1 then begin LineNr := FindLine('
-1 do begin LineNr := LineNr + 2; Line := Page.GetString(LineNr); if Pos (UTF8Encode('0 then begin ExtraIndex := AddExtra(); SetExtraField(ExtraIndex, extraFieldURL, ExtraURL); SetExtraField(ExtraIndex, extraFieldCategory, 'Críticas'); SetExtraField(ExtraIndex, extraFieldTitle, TextBetween(ExtraURL, '//', '/')); SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'C'+IntToStr(ExtraIndex)); end; LineNr := LineNr + 1; Line := Page.GetString(LineNr); end; LineNr := FindLine(''); ExtraIndex := AddExtra(); if GetOption('GroupImages') = 1 then begin SetExtraField(ExtraIndex, extraFieldCategory, 'Imágenes'); SetExtraField(ExtraIndex, extraFieldTitle, ImageTitle); end else begin SetExtraField(ExtraIndex, extraFieldCategory, ImageTitle); SetExtraField(ExtraIndex, extraFieldTitle, 'Imágenes') end; SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'I'+IntToStr(ExtraIndex)); GetExtraPicture(ExtraIndex, ExtraString); end; end; end; end; If NumTrailers > LimitTrailers then NumTrailers := LimitTrailers; if NumTrailers > 0 then begin Page.Text := GetPage(TrailersAddress); LineNr := FindLine(UTF8Encode('>Mostrar video<'),Page,0); if LineNr <> -1 then begin Line := Page.GetString(LineNr); for i:= 1 to NumTrailers do begin LineNr := FindLine('src="', Page,LineNr + 1); if LineNr <> -1 then begin Line := Page.GetString(LineNr); ExtraString := TextBetween(Line, 'src="', '"'); ExtraURL := TextAfter(ExtraString, '//'); ExtraIndex := AddExtra(); SetExtraField(ExtraIndex, extraFieldURL, ExtraURL); SetExtraField(ExtraIndex, extraFieldCategory, 'Trailers'); SetExtraField(ExtraIndex, extraFieldTitle, TextBetween(ExtraString, '//', '/')) SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'T'+IntToStr(ExtraIndex)); LineNr := FindLine(UTF8Encode('Mostrar video'), Page,LineNr + 1); end; end; end; end; end; //------------------------------------------------------------------------------------ begin if (CheckVersion(4,2,2) = false) then begin if ShowWarning('This script requires a newer version of Ant Movie Catalog, at least the version 4.2.2, currently available as beta - do you wish to open the link to download it?)') = true then begin Launch('https://forum.antp.be/phpbb3/viewtopic.php?f=6&t=6862', ''); end; exit; end; MovieName := GetField(fieldOriginalTitle); MovieYear := GetField(fieldYear); YearFrom := MovieYear; YearTo := MovieYear; AdvQuery := '/es/advsearch.php'; if Length(MovieName) = 0 then MovieName := GetField(fieldTranslatedTitle); if GetOption('DontAsk') = 0 then Input('FilmAffinity', 'Título: ' + GetField(fieldFilePath), MovieName); if Pos('filmaffinity.com', MovieName) > 0 then AnalyzeMoviePage(MovieName) else begin //MovieName := UTF8Encode(MovieName); AdvQuery := AdvQuery + '?stext=' + UrlEncode(MovieName); if GetOption('SearchByFromToYears') = 1 then begin if GetOption('DontAsk') = 0 then begin Input('FilmAffinity', 'Desde el año: ', YearFrom); Input('FilmAffinity', 'Hasta el año: ', YearTo); end; AdvQuery := AdvQuery + '&fromyear=' + YearFrom; AdvQuery := AdvQuery + '&toyear=' + YearTo; end; { stype[]=title Título stype[]=director Director stype[]=cast Reparto stype[]=script Guión stype[]=photo Fotografía stype[]=music Música stype[]=producer Productor } if GetOption('SearchByTitle') = 1 then AdvQuery := AdvQuery + '&stype[]=title'; if GetOption('SearchByDirector') = 1 then AdvQuery := AdvQuery + '&stype[]=director'; if GetOption('SearchByCast') = 1 then AdvQuery := AdvQuery + '&stype[]=cast'; if GetOption('SearchByScript') = 1 then AdvQuery := AdvQuery + '&stype[]=script'; if GetOption('SearchByPhoto') = 1 then AdvQuery := AdvQuery + '&stype[]=photo'; if GetOption('SearchByMusic') = 1 then AdvQuery := AdvQuery + '&stype[]=music'; if GetOption('SearchByProducer') = 1 then AdvQuery := AdvQuery + '&stype[]=producer'; if GetOption('SortByYear') = 1 then AdvQuery := AdvQuery + '&orderby=year'; AnalyzeAdvPage(BaseURL + AdvQuery); end; end.