[REL][US]AnimeNfo.com
Posted: 2005-03-03 21:42:03
Here is a quick script i wrote.
its pretty sloppy but enjoy.
if there is any suggestions or problems please post them here.
Be gentle, this is my first time.
Mrknife
its pretty sloppy but enjoy.
if there is any suggestions or problems please post them here.
Be gentle, this is my first time.
Mrknife
Code: Select all
// GETINFO SCRIPTING
// AnimeNfo (US) By Mrknife
{* This was slapped together from the script
* IMDB that was included with version 3.4.3
*
* !! Country and Language are always set to Japan/Japanese
* !! Only the First Category will be used
* !! You will always have to select a title, even when the list is only 1 option
*
* Acknoledgements...
* Based on the script rewritten for version 3.5 *
* Which was based on the script made for *
* version 3.3.x / 3.4.x by *
* Antoine Potten, Danny Falkov, Kai Blankenhorn, *
* lboregard, Ork, Trekkie, Youri Heijnen
}
program AnimeNfo;
// ***** Here you can change the options of the script *****
function GetOption(OptName: string): Integer;
begin
case OptName of
'BatchMode': Result := 0;
{
0=Normal working mode, prompts user when needed
1=Does not display any window, takes the first movie found
}
'PopularSearches': Result := 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
}
'ActorsLayout': Result := 3;
{
3=Actors names with character names between parenthesis separated by linebreaks
}
'DescriptionSelection': Result := 2;
{
0=Take the short summary, from main page (faster)
1=Show a list of available summaries
2=Take the longest summary
}
'GetTagline': Result := 0;
{
0=Do not get tagline
1=Put it in Description field, before the summary
2=Put it in the Comment field, before the comments
}
end;
end;
// Here you can specify which fields can be modified.
// Simply remove a field from the list if it cannot be modified
function CanSetField(fieldID: Integer): Boolean;
begin
case fieldID of
fieldNumber,
fieldMedia,
fieldMediaType,
fieldSource,
fieldDate,
fieldBorrower,
fieldRating,
fieldOriginalTitle,
fieldTranslatedTitle,
fieldDirector,
fieldProducer,
fieldCountry,
fieldCategory,
fieldYear,
fieldLength,
fieldActors,
fieldURL,
fieldDescription,
fieldComments,
fieldVideoFormat,
fieldVideoBitrate,
fieldAudioFormat,
fieldAudioBitrate,
fieldResolution,
fieldFrameRate,
fieldLanguages,
fieldSubtitles,
fieldSize,
fieldDisks: Result := True;
else
Result := False;
end;
end;
var
MovieName: string;
MovieURL: string;
MovieNumber: string;
var
RemainingText: string;
{
when calling... this variable contains...
TextBefore the text after SearchText
TextBetween the text after AfterText
}
// ***** Like the Pos function, but returns the last occurence instead of the first one *****
function LastPos(ASearch: string; AText: string): Integer;
var
CurPos, PrevPos: Integer;
begin
PrevPos := 0;
CurPos := Pos(ASearch, AText);
while CurPos > 0 do
begin
if PrevPos = 0 then
PrevPos := CurPos
else
PrevPos := PrevPos + CurPos + Length(ASearch) - 1;
Delete(AText, 1, CurPos + Length(ASearch) - 1);
CurPos := Pos(ASearch, AText);
end;
Result := PrevPos;
end;
// *****
{ Returns the text before SearchText, but not before BeginLimit (if it is not empty),
It takes the last occurence of BeginLimit found before the position of SearchText }
function TextBefore(WholeText: string; SearchText: string; BeginLimit: string): string;
var
FoundPos, PrevPos: Integer;
WorkText: string;
begin
Result := '';
FoundPos := Pos(SearchText, WholeText);
if FoundPos = 0 then
Exit;
WorkText := Copy(WholeText, 1, FoundPos - 1);
RemainingText := Copy(WholeText, FoundPos + Length(SearchText), Length(WholeText));
if BeginLimit <> '' then
begin
FoundPos := LastPos(BeginLimit, WorkText);
if FoundPos = 0 then
Exit
else
FoundPos := FoundPos + Length(BeginLimit);
end
else
FoundPos := 1;
Result := Copy(WorkText, FoundPos, Length(WorkText));
end;
// ***** Returns the text after SearchText *****
function TextAfter(WholeText: string; SearchText: string): string;
var
FoundPos: Integer;
begin
Result := '';
FoundPos := Pos(SearchText, WholeText);
if FoundPos = 0 then
Exit;
Result := Copy(WholeText, FoundPos + Length(SearchText), Length(WholeText));
end;
// *****
{ Returns the text between BeforeText and AfterText (without these two strings),
It takes the first AfterText occurence found after the position of BeforeText }
function TextBetween(WholeText: string; BeforeText: string; AfterText: string): string;
var
FoundPos: Integer;
WorkText: string;
begin
Result := '';
FoundPos := Pos(BeforeText, WholeText);
if FoundPos = 0 then
Exit;
WorkText := Copy(WholeText, FoundPos + Length(BeforeText), Length(WholeText));
FoundPos := Pos(AfterText, WorkText);
if FoundPos = 0 then
Exit;
Result := Copy(WorkText, 1, FoundPos - 1);
RemainingText := Copy(WorkText, FoundPos + Length(AfterText), Length(WorkText));
end;
// ***** analyzes the results page that asks to select a movie from a list *****
procedure AnalyzeResultsPage(Address: string);
var
PageText: string;
Value: string;
begin
PageText := GetPage(Address);
if pos('<font color=''#FFFFFF''><b> Search Result', PageText) = 0 then
begin
AnalyzeMoviePage(PageText)
end else
begin
PickTreeClear;
repeat
Value := 'results:';
if Value <> '' then
begin
HTMLRemoveTags(Value);
HTMLDecode(Value);
PickTreeAdd(Value, '');
end;
Value := TextBetween(PageText, 'Search Result', 'End Contents');
PageText := RemainingText;
until not AddMovieTitles(Value);
Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
if Value <> '' then
PickTreeMoreLink('http://www.animenfo.com/animetitle' + Value );
if PickTreeExec(Address) then
AnalyzeResultsPage(Address);
end;
end;
// ***** adds the titles contained in <ol>'s items *****
function AddMovieTitles(List: string): Boolean;
var
Value: string;
Name: String;
Address: string;
begin
Result := False;
Value := TextBetween(List, 'href=''animetitle', 'html''>');
Name := TextBetween(List, 'html''>', '</a>');
List := RemainingText;
while Value <> '' do
begin
Address := Value+'html';
HTMLRemoveTags(Value);
HTMLDecode(Value);
PickTreeAdd(Name, 'http://www.animenfo.com/animetitle' + Address);
Result := True;
Value := TextBetween(List, 'href=''animetitle', 'html''>');
Name := TextBetween(List, 'html''>', '</a>');
List := RemainingText;
end;
end;
// ***** analyzes the page containing movie information *****
procedure AnalyzeMoviePage(PageText: string);
var
Value, Value2, Value3, FullValue, MovieT, MovieTitle_Html,CHar11 ,SEiyu : string;
begin
MovieNumber := TextBetween(PageText, '/anime/episode/display.php?id=', '&n=');
MovieT := TextBetween(PageText, '&n=', '&t=');
MovieTitle_Html := TextBetween(PageText, '&t=', '''>');
MovieURL := 'http://www.animenfo.com/animetitle,' + MovieNumber + ',' + MovieT + ',' + MovieTitle_Html + '.html';
// URL
if CanSetField(fieldURL) then
SetField(fieldURL, MovieURL);
// Original Title & Year
if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
begin
Value := TextBetween(PageText, '<title>AnimeNfo.Com : Anime : ', '</title>');
// Value2 := TextBefore(Value, ' (', '');
// Value := RemainingText;
// HTMLDecode(Value2);
if CanSetField(fieldOriginalTitle) then
SetField(fieldOriginalTitle, Value);
Value2 := TextBetween(PageText, 'animebyyear.php?year=', '''>');
if CanSetField(fieldYear) then
SetField(fieldYear, Value2);
end;
// Rating
if CanSetField(fieldRating) then
begin
Value := TextBetween(PageText, 'User Rating</font></td><td valign=''top'' bgcolor=''#F0F0F0''><font class=''DefaultFont''', '/10.0');
Value2 := TextBetween(Value, '>', '.');
if StrToInt(Copy(RemainingText, 1, 1), 0) >= 5 then
Value2 := IntToStr(StrToInt(Value2, 0) + 1);
SetField(fieldRating, Value2);
end;
// Picture NOT WORKING RIGHT NOW
ImportSmallPicture(PageText);
// Director
if CanSetField(fieldProducer) then
begin
Value := TextBetween(PageText, 'Studio</font></td>', '<br></font></td></tr>');
Value2 := TextBefore(Value, '</a>','</script>');
SetField(fieldProducer, Value2);
end;
// Actors working
if CanSetField(fieldActors) then
begin
SEiyu := 'garbage';
Value := TextBetween(PageText, 'Seiyuu (Voice Talent)</font>', 'Explanation');
//SetField(fieldActors, Value);
if Value <> '' then
begin
FullValue := '';
while Value <> '' do
begin
CHar11 := TextBefore(Value, '</a></td><td valign', '>');
Value := RemainingText;
if CHar11 = '' then
Break;
SEiyu := TextBefore(Value, '</a></td><td valign', '>');
Value := RemainingText;
FullValue := FullValue + SEiyu + ' (as ' + CHar11 + ')' + #13#10;
end;
HTMLRemoveTags(FullValue);
HTMLDecode(FullValue);
SetField(fieldActors, FullValue);
end;
end;
//Country Set to Japan
if CanSetField(fieldCountry) then
begin
SetField(fieldCountry, 'Japan');
end;
//Category Can only get the First Catagory
if CanSetField(fieldCategory) then
begin
Value := TextBetween(PageText, '<font class=''DefaultFont''>Genres', ', <a');
Value2 := TextBefore(Value, '</a>','>');
SetField(fieldCategory, Value2);
end;
// Language Set to Japanese
if CanSetField(fieldLanguages) then
begin
SetField(fieldLanguages, 'Japanese');
end;
//Description
if CanSetField(fieldDescription) then
begin
Value := TextBetween(PageText, 'Description </b></font>', '</font></td></tr></table><br><table border=');
Value2 := TextAfter(Value, '<font class=''DefaultFont''>');
HTMLRemoveTags(Value2);
HTMLDecode(Value2);
SetField(fieldDescription, Value2);
end;
// Comments
if CanSetField(fieldComments) then
begin
Value := TextBetween(PageText, 'Total Episodes</font></td><td valign=''top'' bgcolor=''#F0F0F0''><font class=''DefaultFont''>', '</font>');
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldComments, 'Total Episodes: '+Value);
end;
// Length
if CanSetField(fieldLength) then
begin
{ Value := TextBetween(PageText, '<b class="ch">Runtime:</b>' + #13#10, ' ');
if Value <> '' then
begin
if Pos(':', Value) > 0 then
SetField(fieldLength, TextAfter(Value, ':'))
else
SetField(fieldLength, Value);
end;
}
end;
// TagLine
if GetOption('GetTagline') > 0 then
begin
{ Value := TextBetween(PageText, 'Tagline:</b>', #13);
if Pos('<a', Value) > 0 then
Value := TextBefore(Value, '<a', '');
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := Trim(Value);
if Value <> '' then
begin
Value := '"' + Value + '"';
case GetOption('GetTagline') of
1:
if CanSetField(fieldDescription) then
SetField(fieldDescription, Value + #13#10 + GetField(fieldDescription));
2:
if CanSetField(fieldComments) then
SetField(fieldComments, Value + #13#10 + GetField(fieldComments));
end;
end;
}
end;
end;
// ***** functions to import the different pictures kinds, depending of the option selected by user *****
function ImportSmallPicture(PageText: string): Boolean;
var
Value: string;
begin
Result := False;
Value := TextBetween(PageText, '<img border=''0'' ', 'font class=''DefaultFont''>Title');
Value := TextBetween(Value, 'Src=''', ''' width');
if Value <> '' then
begin
GetPicture(Value, False);
Result := True;
end;
end;
// ***** beginning of the program *****
begin
if CheckVersion(3,4,3) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('BatchMode') = 0 then
begin
if not Input('AnimeNfo Import', 'Enter the name of the anime Series :', MovieName) then
Exit;
end;
if MovieName <> '' then
begin
if Pos('AnimeNfo.com', MovieName) > 0 then
AnalyzeResultsPage(MovieName)
else
begin
MovieName := StringReplace(MovieName, '&', 'and');
AnalyzeResultsPage('http://www.animenfo.com/search.php?query='+UrlEncode(MovieName)+'&action=Go&queryin=anime_titles&option=keywords')
end;
DisplayResults;
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.3)');
end.