Why apperantly, this script has an "add-on" file which I don't have???!
Startrek script problem
-
RIP
Startrek script problem
When I try to run the statrek script the following error apears: Cannot open file StarTrekScript_cache.txt
Why apperantly, this script has an "add-on" file which I don't have???!
Why apperantly, this script has an "add-on" file which I don't have???!
-
RIP
Update
I created an empty file whith the name of the one missing and it seems to work! You should have provided it with the scripts pack!!
Yet! that's not all! the script asks me for a site when I write www.startrek.com (guessed) it gives another error!
this time is: error in page
Yet! that's not all! the script asks me for a site when I write www.startrek.com (guessed) it gives another error!
The address you have to enter is one of the following :
http://www.startrek.com/library/episodes_TOS.asp
http://www.startrek.com/library/episodes_DS9.asp
http://www.startrek.com/library/episodes_TNG.asp
http://www.startrek.com/library/episodes_voy.asp
You can also have a "code" already in the Original Title field so select which address to use so you do not have to enter them:
TOS
DS9
TNG
VOY
or:
Original Series
Deep Space
Next Generation
Voyager
It's not me that made the script, but I'll maybe correct it so it asks to select from a list instead of entering the address...
http://www.startrek.com/library/episodes_TOS.asp
http://www.startrek.com/library/episodes_DS9.asp
http://www.startrek.com/library/episodes_TNG.asp
http://www.startrek.com/library/episodes_voy.asp
You can also have a "code" already in the Original Title field so select which address to use so you do not have to enter them:
TOS
DS9
TNG
VOY
or:
Original Series
Deep Space
Next Generation
Voyager
It's not me that made the script, but I'll maybe correct it so it asks to select from a list instead of entering the address...
I've improved the original script so you don't have to type
a URL .
Just select a series in case your episode title does NOT contain the series name or the script can't figure out the series.
Have fun with it 
a URL .
Just select a series in case your episode title does NOT contain the series name or the script can't figure out the series.
Code: Select all
// GETINFO SCRIPTING
// Paramount StarTrek.Com import Episode Info With picture
(***************************************************
* Episode Information importation script for: *
* StarTrek(US), http://www.startrek.Com *
* *
* (c) 2003 Trekkie asimov@hotmail.com *
* *
* For use with Ant Movie Catalog 3.4.0 *
* www.ant.be.tf/moviecatalog ··· www.buypin.com *
* *
* The source code of the script can be used in *
* another program only if full credits to *
* script author and a link to Ant Movie Catalog *
* website are given in the About box or in *
* the documentation of the program *
***************************************************)
program StarTrek;
const
ImportLongDescription = True; // True - All Episode Description.
// False - Only Short Synopsis
ImportLargePicture = True; // True - A Larger Pictures of the Episodes Will Be Imported
// False - A Small Thumbnail Picture Will be Imported
StorePictureInDatabase = True; // False - Will Store the Picture Externally
ImportComments = True; // Comment Will Contain : Writers & Teleplay Info,Production
// Number & Stardate
ImportGuestCast = True; // Add Info on Guest Cast to Actors field
OnErrorWholeList = True; // If Episode Title not found
// display a list of ALL episodes to choose from
VerboseMode = True; // True - Will Display Error messages
// Use Only ONE of the following Episode Titles Templetes:
// Uncomment only ONE template
TitleTemplate = 'Series - Episode Nr - Title'; // Example: Star Trek TOS - 1x01 - The Cage
// TitleTemplate = 'Title - Episode Nr - Series'; // Example: The Cage - 1x01 - Original Series
// TitleTemplate = 'Title - Series'; // Example: The Cage - TOS
// TitleTemplate = 'Series - Title'; // Example: DS9 - Dax
// TitleTemplate = 'Title'; // Example: The Cage
// If CacheMode is TRUE you should verify a file 'StarTrekScript_Cache.txt'
// Exists in the Scripts Directory Under Ant Movie Catalog Install Directory
// If not you MUST (at First Run ) create an EMPTY File and put it in that directory.
CacheMode = True; // True - Will Store A Series Listing in File and
// Use it to offload server queries
// False - Will Query Series Episode listing for every entry
var
EpisodeTitle,OriginalTitle: string;
TheEpisodesListing: string;
PickTreeSelected,TitleCorrected,CacheExists:Boolean;
CacheFile:TStringList;
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
begin
if Pos(Pattern, List.GetString(i)) <> 0 then
begin
result := i;
Break;
end;
end;
end;
Function GetEpisodeAddress(Line:String):String;
var
BeginPos,EndPos:Integer;
Begin
Result:='';
BeginPos:= Pos('a href=',Line);
BeginPos:= BeginPos +8;
EndPos:= Pos('">',Line);
Result:=Copy(Line,BeginPos, EndPos-BeginPos);
End;
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr,TitleLineNr: Integer;
BeginPos,EndPos:Integer;
Line:String;
Title,EpisodeAddress:String;
begin
Page := TStringList.Create;
if CacheMode Then
begin
if not CacheExists then
begin
Page.Text := GetPage(Address);
CacheFile.Free;
CacheFile:=TStringList.Create;
CacheFile.Add(Address);
For LineNr:=0 to Page.Count -1 do
Begin
CacheFile.Add(Page.GetString(LineNr));
End;
end
else
For LineNr:=0 to CacheFile.Count -1 do
Begin
Page.Add(CacheFile.GetString(LineNr));
End;
end
else
Page.Text := GetPage(Address);
// Find The Selected Episode in The Whole Episode Listings
LineNr := FindLine('<TABLE STYLE=',Page,0);
if LineNr > 0 Then
begin
Line :=Page.GetString(LineNr);
TitleLineNr := FindLine(EpisodeTitle, Page, LineNr);
if TitlelineNr > -1 then
begin
// Title
Line :=Page.GetString(TitleLineNr);
EndPos:=Pos('</A>',Line);
Title:=Copy(Line,1,EndPos-1);
// Address
Line :=Page.GetString(TitleLineNr-1);
EpisodeAddress:=GetEpisodeAddress(Line);
Address:='http://www.startrek.com' + EpisodeAddress;
EndPos:=Pos('Part I',EpisodeTitle);
if (EndPos <> 0) and (Length(EpisodeTitle) > 7) then
Title:=Title + ' ';
// Find Next Matching Titles
LineNr:= FindLine(Title,Page,TitleLineNr+1);
if LineNr > -1 then
begin
PickTreeClear;
PickTreeAdd('Matching Episode Titles for: ' + EpisodeTitle, '');
PickTreeAdd( Title, 'http://www.startrek.com' + EpisodeAddress);
AddEpisodesTitles(Page,LineNr);
PickTreeSelected:=PickTreeExec(Address);
if Not PickTreeSelected Then
Exit;
End;
End
Else
Begin
if OnErrorWholeList then
Begin
PickTreeClear;
PickTreeAdd('Select A Title Closest to: '+ EpisodeTitle, '');
DisplayAllTitles(Page,LineNr);
PickTreeSelected:=PickTreeExec(Address);
if Not PickTreeSelected Then
Exit;
End
else
begin
if VerboseMode then
Showmessage(' Episode ' + EpisodeTitle + ' Not Found');
Exit;
End;
End;
HTMLDecode(Address);
SetField(fieldURL, Address);
Page.Free;
Page:=TStringList.Create();
Page.Text := GetPage(Address);
// Handle Page redirection
LineNr:= FindLine('window.location.replace',Page,0);
if LineNr > -1 then
begin
Line:=Page.GetString(LineNr);
BeginPos:= Pos('replace',Line) + 9;
EndPos := Pos(')',Line) -1;
Address:=Copy(Line,BeginPos, EndPos-BeginPos);
Address:='http://www.startrek.com' + Address;
Page.Free;
Page:=TStringList.Create();
Page.Text := GetPage(Address);
End;
AnalyzeEpisodePage(Page);
end
else
if VerboseMode then
ShowMessage('Error In Page for ' + EpisodeTitle);
Page.Free;
end;
procedure DisplayAllTitles(Page: TStringList; var LineNr: Integer);
var
Line,Title,Address,Season: string;
BeginPos,EndPos,EndLine: Integer;
begin
LineNr:=LineNr +1;
EndLine := FindLine('</HTML>',Page,LineNr);
Line := Page.GetString(LineNr);
While (LineNr < EndLine) do
begin
BeginPos:=Pos('SEASON',Line);
if BeginPos <> 0 Then
Begin
EndPos:=Pos('</b>',Line);
Season:=Copy(Line,BeginPos,EndPos-BeginPos);
PickTreeAdd(Season,'');
End;
EndPos:= Pos('</A></TD>',Line);
if EndPos <> 0 then
Begin
// Title
Title:=Copy(Line,1,EndPos-1);
// Address
Line :=Page.GetString(LineNr-1);
Address:=GetEpisodeAddress(Line);
PickTreeAdd(Title, 'http://www.startrek.com' + Address);
End;
LineNr:=LineNr+1;
Line := Page.GetString(LineNr);
End; //while
end;
procedure AddEpisodesTitles(Page: TStringList; var LineNr: Integer);
var
Line,Title,Address: string;
EndPos: Integer;
begin
While (LineNr > -1) do
begin
Line := Page.GetString(LineNr);
// Title
Line :=Page.GetString(LineNr);
EndPos:=Pos('</A>',Line);
Title:=Copy(Line,1,EndPos-1);
// Address
Line :=Page.GetString(LineNr-1);
Address:=GetEpisodeAddress(Line);
PickTreeAdd(Title, 'http://www.startrek.com' + Address);
LineNr:= FindLine(EpisodeTitle,Page,LineNr+1);
End;
end;
function FindValue(BeginTag,EndTag:String; Page:TStringList; var LineNr:Integer):String;
var
BeginPos,EndPos:Integer;
Line,Value:String;
A:Char;
begin
Value:='';
BeginPos:=0;
Repeat
Line := Page.GetString(LineNr);
BeginPos := pos(BeginTag, Line);
LineNr:=LineNr+1;
Until ((BeginPos <> 0) or (LineNr > Page.Count-1 ));
if BeginPos > 0 then
begin
BeginPos := BeginPos + Length(BeginTag);
LineNr:=LineNr - 1;
end;
if BeginTag = EndTag then
begin
Delete(Line,1,BeginPos);
BeginPos:=1;
End;
EndPos := pos(EndTag, Line);
While ((EndPos = 0) and (LineNr < Page.Count-1 ) ) do
begin
Value := Value + copy(Line, BeginPos, Length(Line) - BeginPos);
// Next Lines
BeginPos:= 0;
LineNr:= LineNr+1;
Line:= Page.GetString(LineNr);
EndPos := Pos(EndTag,Line);
End;
Value:= Value + copy(Line, BeginPos, EndPos - BeginPos);
Result:=Value;
End;
procedure AnalyzeEpisodePage(Page: TStringList);
var
Line, Value, Value2, FullValue: string;
Production,StarDate,Year,PictureAddress:String;
LineNr,DirectorLine,StartLine: Integer;
BeginPos, EndPos: Integer;
PicturePage:TStringList;
begin
// Original Title & Year , Production Nr & Star Date
StartLine := FindLine('Begin Episodes List', Page, 0);
LineNr:=StartLine+1;
Line := Page.GetString(LineNr);
Value:=FindValue('<B>','</B>',Page,LineNr);
if Value <> '' Then
begin
HTMLDecode(Value);
SetField(fieldTranslatedTitle, Value);
if PickTreeSelected or TitleCorrected Then
Begin
Value2:=Getfield(fieldOriginalTitle);
FullValue:= StringReplace(Value2,OriginalTitle,Value);
SetField(fieldOriginalTitle,FullValue);
End;
Line := Page.GetString(LineNr);
Year:='';
// Concatenate Next 2 Lines
BeginPos := Pos(EpisodeTitle,Line);
Delete(Line,1,BeginPos);
Value:=Line;
Line:=Page.GetString(LineNr+1);
Value:=Value + Line;
HTMLRemoveTags(Value);
BeginPos:= Pos('Production',Value);
if BeginPos > 0 then
Begin
Production:= Copy(Value,BeginPos,14);
EndPos := Pos('Stardate',Value);
StarDate := copy(Value,EndPos,Length(Value) - EndPos);
Year:=Copy(Value,BeginPos + 14,EndPos -BeginPos -14);
EndPos:=Length(Year);
Year:=Copy(Year,EndPos-3,4);
End;
SetField(fieldYear, Year);
end
else
begin
if VerboseMode then
ShowMessage('Could Not Find Episode Title')
exit;
end;
// Picture
if not ImportLargePicture then
begin
LineNr := FindLine('<IMG SRC=/content/Photo/', Page, StartLine);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('Photo', Line) + 5;
Delete(Line, 1, BeginPos);
EndPos := pos('ALIGN', Line) -1;
Value := copy(Line, 1, EndPos);
PictureAddress:='http://www.startrek.com/content/Photo/'+ Value;
GetPicture(PictureAddress, not StorePictureInDatabase); // False = do not store picture // externally ; store it in the catalog file
end;
end
else
Begin
LineNr := FindLine('/art/tinyicons/PHOTO.gif', Page, StartLine);
if LineNr > -1 then
begin
Line:=Page.GetString(LineNr-2);
BeginPos:=Pos('href="',Line) + 6;
EndPos:=Pos('">',Line);
Value:= Copy(Line,BeginPos,EndPos-BeginPos);
PictureAddress:='http://www.startrek.com'+ Value;
PicturePage:=TStringList.Create();
PicturePage.Text := GetPage(PictureAddress);
LineNr:=FindLine('/content/PHOTO/',PicturePage,0);
if LineNr > -1 then
Begin
Line:=PicturePage.GetString(LineNr);
BeginPos:=Pos('PHOTO',Line) + 5;
EndPos:= Pos('">',Line);
Value:= Copy(Line,BeginPos,EndPos-BeginPos);
PictureAddress:='http://www.startrek.com/content/PHOTO'+ Value;
GetPicture(PictureAddress, not StorePictureInDatabase); // False = do not store
// externally ; store it in the catalog file
End
PicturePage.Free;
End;
End;
// Director
DirectorLine:=0;
LineNr := FindLine('Director:', Page, StartLine);
if LineNr > -1 then
begin
DirectorLine:=LineNr;
Value:=FindValue('<B>','</B>',Page,LineNr);
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldDirector, Value);
end
else
if VerboseMode then
ShowMessage('Could Not Find Director Paragraph');
// Actors
LineNr := FindLine('Cast:', Page, StartLine);
if LineNr > -1 then
begin
FullValue := '';
LineNr:=LineNr+1;
Line := Page.GetString(LineNr);
Value2:='Guest Cast';
if ImportGuestCast then
Value2:='Creative staff';
While (Pos(Value2,Line) = 0) do
begin
HTMLRemoveTags(Line);
if (FullValue <> '') and (Length(Line) > 1 ) then
FullValue := FullValue + ', ';
FullValue := FullValue + Line;
LineNr:=LineNr+1;
Line := Page.GetString(LineNr);
end;
HTMLDecode(FullValue);
SetField(fieldActors, FullValue);
end
else
if VerboseMode then
ShowMessage('Could Not Find Cast Paragraph');
//Country
Value := 'United States';
SetField(fieldCountry, Value);
//Category
Value := 'Science Fiction';
SetField(fieldCategory, Value);
// Language
Value := 'English';
SetField(fieldLanguages, Value);
// Producer
Value := 'Paramount Pictures';
SetField(fieldProducer, Value);
//Description
LineNr := FindLine('Synopsis:', Page, StartLine);
if LineNr > -1 then
begin
LineNr:=LineNr +1;
if ImportLongDescription Then
begin
FullValue := '';
Line := Page.GetString(LineNr);
While ( Pos('Related Links',Line) = 0 ) do
begin
HTMLRemoveTags(Line);
Line:=StringReplace(Line,#11,' ');
Line:=StringReplace(Line,'—',' ');
FullValue := FullValue + Line;
LineNr:=LineNr +1;
Line := Page.GetString(LineNr);
End;
end
else
FullValue:=FindValue('<B>','</B>',Page,LineNr);
HTMLRemoveTags(FullValue);
SetField(fieldDescription, FullValue);
end;
// Comments
if ImportComments then
begin
FullValue := '';
LineNr :=DirectorLine +1;
Line:= Page.GetString(LineNr);
While(Pos('p class',Line) = 0 ) do
begin
HTMLRemoveTags(Line);
if FullValue <> '' then
FullValue := FullValue + #13#10;
FullValue := FullValue + Line;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
End;
FullValue:=FullValue + #13#10 + Production + ' ' + Stardate;
SetField(fieldComments, FullValue);
End;
DisplayResults;
end;
function CorrectEpisodeTitle (Title:string):string;
var Words:Array of string;
Replace,Original:String;
Index:Integer;
begin
Title := AnsiMixedCase(Title,' ');
TitleCorrected:=False;
Setarraylength(Words,10);
Words[0]:=' In ';
Words[1]:=' On ';
Words[2]:=' Of ';
Words[3]:=' As ';
Words[4]:=' The ';
Words[5]:=' At ';
Words[6]:=' And ';
Words[7]:=' A ';
Words[8]:=' An ';
Words[9]:=' To ';
for Index:=0 to 9 do
begin
if Pos(Words[Index],Title) <> 0 then
begin
Original:=Words[Index];
Replace:=AnsiLowerCase(Original);
Title:=StringReplace(Title,Original,Replace);
TitleCorrected:=True;
End;
End;
Result:=Title;
End;
var
BeginPos,EndPos,Len:Integer;
Template,BaseAddress:String;
begin
if CheckVersion(3,4,0) then
begin
TheEpisodesListing:='';
if CacheMode Then
begin
CacheFile:=TStringList.Create;
CacheFile.LoadFromFile('StarTrekScript_Cache.txt')
End;
EpisodeTitle := GetField(fieldOriginalTitle);
if EpisodeTitle = '' then
EpisodeTitle := GetField(fieldTranslatedTitle);
PickTreeClear;
PickTreeAdd('Select A Star Trek Series','');
BaseAddress:='http://www.startrek.com/library/';
if (Pos('TOS',EpisodeTitle) > 0) or (Pos('Original Series',EpisodeTitle) > 0 ) Then
Begin
TheEpisodesListing:= BaseAddress+'episodes_TOS.asp';
End;
PickTreeAdd('The Original Series',BaseAddress +'episodes_TOS.asp');
if (Pos('DS9',EpisodeTitle) > 0) or (Pos('Deep Space',EpisodeTitle) > 0 ) then
Begin
TheEpisodesListing:= BaseAddress + 'episodes_DS9.asp';
End;
PickTreeAdd('Deep Space Nine',BaseAddress+'episodes_DS9.asp');
if (Pos('TNG',EpisodeTitle) > 0) or ( Pos('Next Generation',EpisodeTitle) > 0 ) then
Begin
TheEpisodesListing:= BaseAddress+'episodes_TNG.asp';
End;
PickTreeAdd('The Next Generation',BaseAddress+'episodes_TNG.asp');
if ( Pos('VOY',EpisodeTitle) > 0) or (Pos('Voyager',EpisodeTitle) > 0 ) then
Begin
TheEpisodesListing:= BaseAddress+ 'episodes_voy.asp';
End;
PickTreeAdd('Voyager',BaseAddress+'episodes_voy.asp');
if TheEpisodesListing = '' then
Begin
if not PickTreeExec(TheEpisodesListing) Then
Begin
ShowMessage('You Must Select A Series');
Exit;
End;
End;
CacheExists:=False;
if CacheMode Then
Begin
if CacheFile.Count > 0 Then
Begin
// verify the Cache is for the same star trek series
CacheExists:= (FindLine(TheEpisodesListing,CacheFile,0) > -1 );
End;
End;
// Extract Episode Title from template
Template:= TitleTemplate;
BeginPos:=Pos('-',EpisodeTitle);
Len:= Length(EpisodeTitle);
case Template of
'Series - Episode Nr - Title':
Begin
Delete(EpisodeTitle, 1, BeginPos);
BeginPos:=Pos('-',EpisodeTitle);
Delete(EpisodeTitle, 1, BeginPos);
End
'Title - Series':
Begin
BeginPos:=Pos('-',EpisodeTitle);
Delete(EpisodeTitle, BeginPos, Len);
End
'Title - Episode Nr - Series':
Begin
BeginPos:=Pos('-',EpisodeTitle);
Delete(EpisodeTitle, BeginPos, Len);
End
'Series - Title':
Begin
Delete(EpisodeTitle, 1, BeginPos);
End
'Title':
;
Else
Begin
if VerboseMode then
ShowMessage('Episode Title does not match the template: ' + Template);
Input('Star Trek Episode Guide Import', 'Enter Episode Title', EpisodeTitle);
End;
End; // Case
EpisodeTitle := Trim(EpisodeTitle);
OriginalTitle:= EpisodeTitle;
EpisodeTitle:=CorrectEpisodeTitle(EpisodeTitle);
AnalyzePage(TheEpisodesListing);
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
if CacheMode Then
begin
CacheFile.SaveToFile('StarTrekScript_Cache.Txt');
CacheFile.Free;
end;
end.