Author Topic: Suggestion for Ivek23  (Read 77918 times)

0 Members and 5 Guests are viewing this topic.

Offline deazo

  • Older Power User
  • *****
  • Posts: 283
    • View Profile
Re: Suggestion for Ivek23
« Reply #20 on: August 30, 2013, 07:34:51 am »

 Thanks A LOT Ivek23 for this update.
 I use this script regularly.

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #21 on: August 30, 2013, 03:26:41 pm »

 Thanks A LOT Ivek23 for this update.
 I use this script regularly.

Welcome and thanks.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline sunspot

  • Member
  • *
  • Posts: 13
    • View Profile
Re: Suggestion for Ivek23
« Reply #22 on: September 05, 2013, 05:13:23 pm »
Please also accept my thanks! :-)

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #23 on: September 05, 2013, 05:59:05 pm »
Please also accept my thanks!

Welcome and accepted.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Legin76

  • Member
  • *
  • Posts: 1
    • View Profile
Re: Suggestion for Ivek23
« Reply #24 on: January 31, 2014, 10:19:00 pm »
Hi.. This is a great script. Thankyou.

I may have found bug however.

If it is not sure which is the correct movie and brings up the list to select. It adds the rating correctly, but then creates a new listing for the movie with the name and its date exactly as it is on Rotten Tomatos,  but no other content. So for example with Blade the second listing has the title "Blade (1998)" but has no date in the date field.

Also would it be possibe to also add the Audiance rating from RT as I often go by an average of the two.

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #25 on: February 01, 2014, 08:27:56 am »
Welcome on the forum, Legin76.

In which Rottentomatoes script version of this is happening and which version of PVD program is being used. Then it will be easier to answer.

Also a screenshot would be welcome to see what actually happens.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #26 on: February 09, 2014, 10:58:10 am »
Question:

How to could be two different ratings for a one movie be combined into one movie rating or how to get to the average rating for one movie from for two different movie ratings.

Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #27 on: March 04, 2014, 03:18:26 pm »
Also would it be possibe to also add the Audiance rating from RT as I often go by an average of the two.

Audiance rating

It is possible, but there is a small problem that can be seen only one rating in PVD database:
Tomatometer rating or Audiance rating.

Recommendation or advice:

First of all, Tomatometer rating info you download with Rottentomatoes script. If Tomatometer rating not stand it now, but whoever wants you Audiance rating may be transferred to Rottentomatoes (a) script. If it was not yet the transfer, then they use Rottentomatoes (a1) script for Audiance rating, this script will Audiance rating surely passed if, of course, is added to the movies web sites.


One warning:

Rottentomatoes (a) or Rottentomatoes (a1) script will overwrite Tomatometer rating information.


Rottentomatoes (a) script
v 0.1.0.5.a

Rottentomatoes (a1) script
v 0.1.0.5.a




Rottentomatoes (a) script and Rottentomatoes (a1) script is attached.
« Last Edit: March 05, 2014, 07:07:18 am by Ivek23 »
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #28 on: March 04, 2014, 03:28:05 pm »
For unregistered users:

Rottentomatoes script
v 0.1.0.1

Rottentomatoes.psf

Code: [Select]
(*
SCRIPT INFO:

---------------------------------------------

SCRIPT: Rottentomatoes Script
AUTHOR: Ivek23
VERSION: 0.1.0.1
DATE: 25/08/2013

---------------------------------------------
*)

//SCRIPT BEGINS HERE...

//Some useful constants

const

//Script types
stMovies = 0;
stPeople = 1;
stPoster = 2;

///Script modes
smSearch = 0;
smNormal = 1;
smCast = 2;
smReview = 3;
smCredits = 4;
smDVDReleases = 5;
smBiography = 6;
smGenreindex = 7;
smAwards = 8;
smMiscellaneous = 9;
smPoster = 10;
smFinished = 11;

//Parse results
prError = 0;
prFinished = 1;
prList = 2;
prListImage = 3;
prDownload = 4;

//Prefix modes
pmNone = 0;
pmEnd = 1;
pmBegin = 2;
pmRemove = 3;

//Download methods
dmGET = 0;
dmPOST = 1;

//Movie fields
mfURL = 0;
mfTitle = 1;
mfOrigTitle = 2;
mfAka = 3;
mfYear = 4;
mfGenre = 5;
mfCategory = 6;
mfCountry = 7;
mfStudio = 8;
mfMPAA = 9;
mfRating = 10;
mfTags = 11;
mfTagline = 12;
mfDescription = 13;
mfDuration = 14;
mfFeatures = 15;

//People fields
    pfURL        = 0;
pfName        = 1;
pfTransName  = 2;
pfAltNames    = 3;
pfBirthday    = 4;
pfBirthplace = 5;
pfGenre      = 6;
pfBio        = 7;
pfDeathDate  = 8; 
pfComment    = 9;
pfBookmark    = 10;
pfPid        = 11;
pfCareer      = 12;

//Credits types
ctActors = 0;
ctDirectors = 1;
ctWriters = 2;
ctComposers = 3;
ctProducers = 4;

//Script data
SCRIPT_VERSION = '0.1.0.1';
SCRIPT_NAME = 'Rottentomatoes Script';
SCRIPT_DESC = '[EN] Get Movie Information about from Rottentomatoes.com';
SCRIPT_LANG = $09; //English
SCRIPT_TYPE = stMovies;

BASE_URL = 'http://www.rottentomatoes.com';
RATING_NAME = 'Rottentomatoes';
SEARCH_STR = 'http://www.rottentomatoes.com/search/?search=%s&sitesearch=rt';
CODE_PAGE = 65001; //Use 0 for Autodetect

//Global variables
var
ELI : Integer;
Mode : Byte;
ExtraLinks : array [smCast..smPoster] of String;

//Functions
function GetScriptVersion : String;
begin
Result := SCRIPT_VERSION;
end;

function GetScriptName : String;
begin
Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : String;
begin
Result := SCRIPT_DESC;
end;

function GetRatingName : String;
begin
Result := RATING_NAME;
end;

function GetScriptLang: Cardinal;
begin
Result := SCRIPT_LANG;
end;

function GetCodePage : Cardinal;
begin
Result := CODE_PAGE;
end;

function GetBaseURL : AnsiString;
begin
Result := BASE_URL;
end;

function GetDownloadURL : AnsiString;
begin
if (Mode = smSearch) then
Result := SEARCH_STR
else
Result := ExtraLinks[Mode];
end;

function GetDownloadMethod : Byte;
begin
Result := dmGET;
end;

function GetPrefixMode : Byte;
begin
Result := pmBegin;
end;

function GetScriptType : Byte;
begin
Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte;
begin
Result := Mode;
end;

procedure ParseMovie(MovieURL : String; HTML : String);
var
curPos, endPos : Integer;
TmpStr : String;
begin

//Get ~mfURL~ or ~RT Url~
endPos := Pos('" itemprop="url"/>', HTML);
if endPos > 0 then begin
curPos := PrevPos('"canonical" href="', HTML, endPos);
AddFieldValue(mfURL, Copy(HTML, curPos + 18, endPos - curPos - 18));
end else
AddFieldValue(mfURL, MovieURL);

//~Rating~ or ~RT Rating~
curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, 'Average Rating: <span>', '/10</span>', True, curPos);
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
curPos := Pos('<ul id="movie_results_ul" class="results_ul" ', HTML);
if curPos < 1 then
Exit;

LogMessage('Parsing search results...');

curPos  := PosFrom('<img src="', HTML, curPos)+10;
endPos  := PosFrom('" width=', HTML, curPos);
Preview := Trim(Copy(HTML, curPos, endPos - curPos));

curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
while (curPos > 0) AND (curPos < PosFrom('<a id="more_movies" href="#results_movies_tab">More Movies...</a>', HTML, endPos)) do begin
endPos := PosFrom('"  class=', HTML, curPos);
URL := 'http://www.rottentomatoes.com'+Trim(Copy(HTML, curPos+23, endPos - curPos-23));

curPos := PosFrom('"  class="" >', HTML, curPos);
endPos := PosFrom('</a>', HTML, curPos);
Title := TextBetween(HTML, '"  class="" >', '</a>', True, curPos);

curPos := PosFrom('<span class="movie_year">', HTML, curPos);
endPos := PosFrom('</span></h3>', HTML, curPos);
Year := TextBetween(HTML, '<span class="movie_year">', '</span></h3>', True, curPos);

curPos  := PosFrom('<img src="', HTML, curPos)+10;
endPos  := PosFrom('" width=', HTML, curPos);
Preview := Trim(Copy(HTML, curPos, endPos - curPos));

AddSearchResult(Title+' '+Year, '', '', URL, '');

curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
  end;
end;

function NextMode(curMode : Integer) : Integer;
var
I : Integer;
begin
Result := smFinished;
if curMode < Low(ExtraLinks) - 1 then
curMode := Low(ExtraLinks) - 1;

for I := curMode + 1 to High(ExtraLinks) do
if ExtraLinks[I] <> '' then begin
Result := I;
Break;
end;
end;

function ParsePage(HTML : String; URL : AnsiString) : Cardinal;
begin
HTML := HTMLToText(HTML);
HTML := StringReplace (HTML, 'http://rottentomatoes.com', 'http://www.rottentomatoes.com', True, True, False);

if Pos('Search Results - Rotten Tomatoes', HTML) > 0 then begin
ParseSearchResults(HTML);
Result := prList;
Exit;

end else
 if Pos(' - Rotten Tomatoes</title>', HTML) > 0 then
    ParseMovie(URL, HTML);

Mode := NextMode(Mode);
if Mode <> smFinished then
Result := prDownload
else
Result := prFinished;
end;

begin
Mode := smSearch;
for ELI := Low(ExtraLinks) to High(ExtraLinks) do
ExtraLinks[ELI] := '';
end.
« Last Edit: July 27, 2014, 01:32:23 pm by Ivek23 »
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #29 on: March 04, 2014, 03:28:54 pm »
For unregistered users:

Rottentomatoes(1) script
v 0.1.0.1

Rottentomatoes(1).psf


Code: [Select]
(*
SCRIPT INFO:

---------------------------------------------

SCRIPT: Rottentomatoes Script 1
AUTHOR: Ivek23
VERSION: 0.1.0.1
DATE: 25/08/2013

---------------------------------------------
*)

//SCRIPT BEGINS HERE...

//Some useful constants

const

//Script types
stMovies = 0;
stPeople = 1;
stPoster = 2;

///Script modes
smSearch = 0;
smNormal = 1;
smCast = 2;
smReview = 3;
smCredits = 4;
smDVDReleases = 5;
smBiography = 6;
smGenreindex = 7;
smAwards = 8;
smMiscellaneous = 9;
smPoster = 10;
smFinished = 11;

//Parse results
prError = 0;
prFinished = 1;
prList = 2;
prListImage = 3;
prDownload = 4;

//Prefix modes
pmNone = 0;
pmEnd = 1;
pmBegin = 2;
pmRemove = 3;

//Download methods
dmGET = 0;
dmPOST = 1;

//Movie fields
mfURL = 0;
mfTitle = 1;
mfOrigTitle = 2;
mfAka = 3;
mfYear = 4;
mfGenre = 5;
mfCategory = 6;
mfCountry = 7;
mfStudio = 8;
mfMPAA = 9;
mfRating = 10;
mfTags = 11;
mfTagline = 12;
mfDescription = 13;
mfDuration = 14;
mfFeatures = 15;

//People fields
    pfURL        = 0;
pfName        = 1;
pfTransName  = 2;
pfAltNames    = 3;
pfBirthday    = 4;
pfBirthplace = 5;
pfGenre      = 6;
pfBio        = 7;
pfDeathDate  = 8; 
pfComment    = 9;
pfBookmark    = 10;
pfPid        = 11;
pfCareer      = 12;

//Credits types
ctActors = 0;
ctDirectors = 1;
ctWriters = 2;
ctComposers = 3;
ctProducers = 4;

//Script data
SCRIPT_VERSION = '0.1.0.1';
SCRIPT_NAME = 'Rottentomatoes Script1';
SCRIPT_DESC = '[EN] Get Movie Information about from Rottentomatoes.com1';
SCRIPT_LANG = $09; //English
SCRIPT_TYPE = stMovies;

BASE_URL = 'http://www.rottentomatoes.com';
RATING_NAME = 'Rottentomatoes';
SEARCH_STR = 'http://www.rottentomatoes.com/search/?search=%s&sitesearch=rt';
CODE_PAGE = 65001; //Use 0 for Autodetect

//Global variables
var
ELI : Integer;
Mode : Byte;
ExtraLinks : array [smCast..smPoster] of String;

//Functions
function GetScriptVersion : String;
begin
Result := SCRIPT_VERSION;
end;

function GetScriptName : String;
begin
Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : String;
begin
Result := SCRIPT_DESC;
end;

function GetRatingName : String;
begin
Result := RATING_NAME;
end;

function GetScriptLang: Cardinal;
begin
Result := SCRIPT_LANG;
end;

function GetCodePage : Cardinal;
begin
Result := CODE_PAGE;
end;

function GetBaseURL : AnsiString;
begin
Result := BASE_URL;
end;

function GetDownloadURL : AnsiString;
begin
if (Mode = smSearch) then
Result := SEARCH_STR
else
Result := ExtraLinks[Mode];
end;

function GetDownloadMethod : Byte;
begin
Result := dmGET;
end;

function GetPrefixMode : Byte;
begin
Result := pmBegin;
end;

function GetScriptType : Byte;
begin
Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte;
begin
Result := Mode;
end;

procedure ParseMovie(MovieURL : String; HTML : String);
var
curPos, endPos : Integer;
TmpStr : String;
begin

//Get ~mfURL~ or ~RT Url~
endPos := Pos('" itemprop="url"/>', HTML);
if endPos > 0 then begin
curPos := PrevPos('"canonical" href="', HTML, endPos);
AddFieldValue(mfURL, Copy(HTML, curPos + 18, endPos - curPos - 18));
end else
AddFieldValue(mfURL, MovieURL);

//~Rating~ or ~RT Rating~
curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, 'Average Rating: <span>', '/10</span>', True, curPos);
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
curPos := Pos('<ul id="movie_results_ul" class="results_ul" ', HTML);
if curPos < 1 then
Exit;

LogMessage('Parsing search results...');

curPos  := PosFrom('<img src="', HTML, curPos)+10;
endPos  := PosFrom('" width=', HTML, curPos);
Preview := Trim(Copy(HTML, curPos, endPos - curPos));

curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
while curPos > 0 do begin
endPos := PosFrom('"  class=', HTML, curPos);
URL := 'http://www.rottentomatoes.com'+Trim(Copy(HTML, curPos+23, endPos - curPos-23));

curPos := PosFrom('"  class="" >', HTML, curPos);
endPos := PosFrom('</a>', HTML, curPos);
Title := TextBetween(HTML, '"  class="" >', '</a>', True, curPos);

curPos := PosFrom('</a>', HTML, curPos);
endPos := PosFrom('</span></h3>', HTML, curPos);
Year := TextBetween(HTML, '</a>', '</span></h3>', True, curPos);

curPos  := PosFrom('<img src="', HTML, curPos)+10;
endPos  := PosFrom('" width=', HTML, curPos);
Preview := Trim(Copy(HTML, curPos, endPos - curPos));

AddSearchResult(Title+' '+Year, '', '', URL, '');

curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
  end;
end;

function NextMode(curMode : Integer) : Integer;
var
I : Integer;
begin
Result := smFinished;
if curMode < Low(ExtraLinks) - 1 then
curMode := Low(ExtraLinks) - 1;

for I := curMode + 1 to High(ExtraLinks) do
if ExtraLinks[I] <> '' then begin
Result := I;
Break;
end;
end;

function ParsePage(HTML : String; URL : AnsiString) : Cardinal;
begin
HTML := HTMLToText(HTML);
HTML := StringReplace (HTML, 'http://rottentomatoes.com', 'http://www.rottentomatoes.com', True, True, False);

if Pos('Search Results - Rotten Tomatoes', HTML) > 0 then begin
ParseSearchResults(HTML);
Result := prList;
Exit;

end else
 if Pos(' - Rotten Tomatoes</title>', HTML) > 0 then
    ParseMovie(URL, HTML);

Mode := NextMode(Mode);
if Mode <> smFinished then
Result := prDownload
else
Result := prFinished;
end;

begin
Mode := smSearch;
for ELI := Low(ExtraLinks) to High(ExtraLinks) do
ExtraLinks[ELI] := '';
end.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #30 on: March 04, 2014, 03:29:32 pm »
For unregistered users:

Rottentomatoes (a) script
v 0.1.0.5.a

Rottentomatoes (a).psf


Code: [Select]
(*
SCRIPT INFO:

Following until 'SCRIPT BEGINS HERE...' is documentation.
Please see 'USER OPTIONS' in the body of the script.

---------------------------------------------

SCRIPT: Rottentomatoes (a) Script
AUTHOR: Ivek23
VERSION: 0.1.0.5.a
DATE: 04/03/2014

---------------------------------------------

TYPES AND FUNCTIONS
Additional types and functions that can be used in scripts:

Types
TWIDEARRAY : array of String

Field functions
procedure AddSearchResult(Title1, Title2, Year, URL, PreviewURL : String)
procedure AddFieldValue(AField: Integer; AValue : String)
procedure AddMoviePerson(Name, TransName, Role, URL : String; AType : Byte)
procedure AddPersonMovie(Title, OrigTitle, Role, Year, URL : String; AType : Byte)
procedure AddAward(Event, Award, Category, Recipient, Year: String; const Won : Boolean)
procedure AddAwardEx(Event, Award, Category, RecipientVal1, RecipientVal2, Year : String; const Won : Boolean);
procedure AddConnection(Title, OrigTitle, Category, URL, Year: String)
procedure AddEpisode(Title, OrigTitle, Description, URL, Year, Season, Episode : String)

String functions
function Pos(Substr : String; Str: String): Integer
function PosFrom(const SubStr, Str : String; FromIndex : Integer) : Integer
function LastPos(const SubStr, Str : String) : Integer
function PrevPos(const SubStr, Str : String; APos : Integer) : Integer
function RemoveTags(AText : String; doLineBreaks : Boolean) : String
function ExplodeString(AText : String; var Items : TWideArray; Delimiters : String) : Integer
function Copy(S: String; Index, Count: Integer): String
procedure Delete(var S: String; Index, Count: Integer)
procedure Insert(Source: String; var Dest: String; Index: Integer)
function Length(S: String): Integer
function Trim(S: String): String
function CompareText(S1, S2: String): Integer
function CompareStr(S1, S2: String): Integer
function UpperCase(S: String): String
function LowerCase(S: String): String
function AnsiString(S, OldPattern, NewPattern: String; All : Boolean; IgnoreCase : Boolean; WholeWord: Boolean): String
function StrToInt(const S: String): Integer
function IntToStr(const Value: Integer): String
function StrToFloat(const S: String): Extended
function FloatToStr(const Value: Extended): String
function CurrentDateTime : Extended
function DateToStr(Value : Extended) : String
function TimeToStr(Value : Extended) : String
function HTMLValues(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String
function HTMLValues2(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String
function TextBetween(const HTML : String; ABegin, AEnd : String; doLineBreaks : Boolean; var Pos : Integer) : String
function HTMLToText(const HTML : String) : String

  procedure ShowMessage(const Msg, Head : String)
*)

//SCRIPT BEGINS HERE...

//Some useful constants

const

//Script types
stMovies = 0;
stPeople = 1;
stPoster = 2;

///Script modes
smSearch = 0;
smNormal = 1;
smCast = 2;
smReview = 3;
smCredits = 4;
smDVDReleases = 5;
smBiography = 6;
smGenreindex = 7;
smAwards = 8;
smMiscellaneous = 9;
smPoster = 10;
smFinished = 11;

//Parse results
prError = 0;
prFinished = 1;
prList = 2;
prListImage = 3;
prDownload = 4;

//Prefix modes
pmNone = 0;
pmEnd = 1;
pmBegin = 2;
pmRemove = 3;

//Download methods
dmGET = 0;
dmPOST = 1;

//Movie fields
mfURL = 0;
mfTitle = 1;
mfOrigTitle = 2;
mfAka = 3;
mfYear = 4;
mfGenre = 5;
mfCategory = 6;
mfCountry = 7;
mfStudio = 8;
mfMPAA = 9;
mfRating = 10;
mfTags = 11;
mfTagline = 12;
mfDescription = 13;
mfDuration = 14;
mfFeatures = 15;

//People fields
    pfURL        = 0;
pfName        = 1;
pfTransName  = 2;
pfAltNames    = 3;
pfBirthday    = 4;
pfBirthplace = 5;
pfGenre      = 6;
pfBio        = 7;
pfDeathDate  = 8; 
pfComment    = 9;
pfBookmark    = 10;
pfPid        = 11;
pfCareer      = 12;

//Credits types
ctActors = 0;
ctDirectors = 1;
ctWriters = 2;
ctComposers = 3;
ctProducers = 4;

//Script data
SCRIPT_VERSION = '0.1.0.5.a';
SCRIPT_NAME = 'Rottentomatoes(a) Script';
SCRIPT_DESC = '[EN] Get Movie Information(a) from Rottentomatoes.com';
SCRIPT_LANG = $09; //English
SCRIPT_TYPE = stMovies;

BASE_URL = 'http://www.rottentomatoes.com';
RATING_NAME = 'Rottentomatoes';
SEARCH_STR = 'http://www.rottentomatoes.com/search/?search=%s&sitesearch=rt';
CODE_PAGE = 65001; //Use 0 for Autodetect

//User Options
GET_THEMES = True; //Set to False to ensure ~mfCategory~ not added even if 'Overwrite fields' setting allows
    GET_POSTER  = False; //Set to False or True
GET_RATING = True; //Set to False to ensure ~mfRating~ not set even if 'Overwrite setting' fields setting allows

//Global variables
var
ELI : Integer;
fullinfo, fullinfo1, fullinfo2 : String;
Mode : Byte;
ExtraLinks : array [smCast..smPoster] of String;

//Functions
function GetScriptVersion : String;
begin
Result := SCRIPT_VERSION;
end;

function GetScriptName : String;
begin
Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : String;
begin
Result := SCRIPT_DESC;
end;

function GetRatingName : String;
begin
Result := RATING_NAME;
end;

function GetScriptLang: Cardinal;
begin
Result := SCRIPT_LANG;
end;

function GetCodePage : Cardinal;
begin
Result := CODE_PAGE;
end;

function GetBaseURL : AnsiString;
begin
Result := BASE_URL;
end;

function GetDownloadURL : AnsiString;
begin
if (Mode = smSearch) then
Result := SEARCH_STR
else
Result := ExtraLinks[Mode];
end;

function GetDownloadMethod : Byte;
begin
Result := dmGET;
end;

function GetPrefixMode : Byte;
begin
Result := pmBegin;
end;

function GetScriptType : Byte;
begin
Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte;
begin
Result := Mode;
end;


procedure ParseMovie(MovieURL : String; HTML : String);
var
curPos, endPos : Integer;
Date, Title, URL, Month, TmpStr, TmpStr0, TmpStr1, TmpStr2, TmpStr3, TmpStr4, TmpStr5, TmpStr6: String;
DateParts : TWideArray;
begin

//Date ~Updated~ (choose simple or verbose version)
Date := DateToStr(CurrentDateTime);
if Date <> '' then
  begin
    ExplodeString(Date, DateParts, '-');
Date := DateParts[2] +'.'+ DateParts[1] +'.'+ DateParts[0];
AddCustomFieldValueByName('RTUpdated', Date + ' at ' + TimeToStr(CurrentDateTime) + ' • ' + SCRIPT_NAME + ' ' + SCRIPT_VERSION); // Annoying
  end else
    LogMessage('date not found');


//Get ~mfURL~ or ~RT Url~
endPos := Pos('" itemprop="url"/>', HTML);
if endPos > 0 then begin
curPos := PrevPos('"canonical" href="', HTML, endPos);
AddFieldValue(mfURL, Copy(HTML, curPos + 18, endPos - curPos - 18));
end else
AddFieldValue(mfURL, MovieURL);


//~Rating~ or ~RT Rating~
curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, 'Average Rating: <span>', '/10</span>', True, curPos);
// //TmpStr := StringReplace(TmpStr, ',', '', True, True, False);
 if TmpStr = '0' then
TmpStr := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr);
    AddCustomFieldValueByName('RT Rating', TmpStr);
 if TmpStr = '' then
TmpStr := 'rating unknown';
//end;
end else
//~Rating~
curPos := PosFrom('<span class="meter popcorn numeric ">', HTML, EndPos);
if curPos > 0 then begin
// EndPos := curPos;
curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
if curPos > 0 then begin
curPos := PosFrom('Average Rating: ', HTML, curPos);
endPos := PosFrom('/5', HTML, curPos);
    TmpStr1 :=  FloatToStr((StrToFloat(Copy(HTML, curPos + 16, endPos - curPos - 16)) * 2));
 if TmpStr1 = '0' then
TmpStr1 := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr1);
    AddCustomFieldValueByName('RT Rating', TmpStr1);
 if TmpStr1 = '' then
TmpStr1 := 'rating unknown';
 end;
  EndPos := curPos;
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
curPos := Pos('<ul id="movie_results_ul" class="results_ul" ', HTML);
if curPos < 1 then
Exit;

LogMessage('Parsing search results...');

EndPos := PosFrom('<span class="movieposter">', HTML, EndPos);
curPos := PosFrom('<img src="', HTML, EndPos);
endPos := PosFrom('" width="', HTML, curPos);
Preview := Copy(HTML, curPos+10, EndPos - curPos-10);
curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
while (curPos > 0) AND (curPos < PosFrom('<a id="more_movies" href="#results_movies_tab">More Movies...</a>', HTML, endPos)) do begin
endPos := PosFrom('"  class=', HTML, curPos);
URL := 'http://www.rottentomatoes.com/'+Trim(Copy(HTML, curPos+23, endPos - curPos-23));
curPos := PosFrom('"  class="" >', HTML, curPos);
endPos := PosFrom('</a>', HTML, curPos);
Title := TextBetween(HTML, '"  class="" >', '</a>', True, curPos);
curPos := PosFrom('<span class="movie_year">', HTML, curPos);
endPos := PosFrom('</span></h3>', HTML, curPos);
Year := RemoveTags(TextBetween(HTML, '<span class="movie_year">', '</span></h3>', True, curPos), false);
AddSearchResult(Title+' '+Year, '', '', URL, Preview);
EndPos := PosFrom('<span class="movieposter">', HTML, EndPos);
curPos := PosFrom('<img src="', HTML, EndPos);
endPos := PosFrom('" width="', HTML, curPos);
Preview := Copy(HTML, curPos+10, EndPos - curPos-10);
curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
 end;
end;

function NextMode(curMode : Integer) : Integer;
var
I : Integer;
begin
Result := smFinished;
if curMode < Low(ExtraLinks) - 1 then
curMode := Low(ExtraLinks) - 1;

for I := curMode + 1 to High(ExtraLinks) do
if ExtraLinks[I] <> '' then begin
Result := I;
Break;
end;
end;

function ParsePage(HTML : String; URL : AnsiString) : Cardinal;
begin
HTML := HTMLToText(HTML);
HTML := StringReplace (HTML, 'http://rottentomatoes.com', 'http://www.rottentomatoes.com', True, True, False);

if Pos('Search Results - Rotten Tomatoes', HTML) > 0 then begin
ParseSearchResults(HTML);
Result := prList;
Exit;

end else
 if Pos(' - Rotten Tomatoes</title>', HTML) > 0 then
    ParseMovie(URL, HTML);

Mode := NextMode(Mode);
if Mode <> smFinished then
Result := prDownload
else
Result := prFinished;
end;

begin
Mode := smSearch;
for ELI := Low(ExtraLinks) to High(ExtraLinks) do
ExtraLinks[ELI] := '';
end.

« Last Edit: March 05, 2014, 07:02:29 am by Ivek23 »
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #31 on: March 04, 2014, 03:30:32 pm »
For unregistered users:

Rottentomatoes (a1) script
v 0.1.0.5.a

Rottentomatoes (a1).psf


Code: [Select]
(*
SCRIPT INFO:

Following until 'SCRIPT BEGINS HERE...' is documentation.
Please see 'USER OPTIONS' in the body of the script.

---------------------------------------------

SCRIPT: Rottentomatoes (a1) Script
AUTHOR: Ivek23
VERSION: 0.1.0.5.a1
DATE: 04/03/2014

---------------------------------------------

TYPES AND FUNCTIONS
Additional types and functions that can be used in scripts:

Types
TWIDEARRAY : array of String

Field functions
procedure AddSearchResult(Title1, Title2, Year, URL, PreviewURL : String)
procedure AddFieldValue(AField: Integer; AValue : String)
procedure AddMoviePerson(Name, TransName, Role, URL : String; AType : Byte)
procedure AddPersonMovie(Title, OrigTitle, Role, Year, URL : String; AType : Byte)
procedure AddAward(Event, Award, Category, Recipient, Year: String; const Won : Boolean)
procedure AddAwardEx(Event, Award, Category, RecipientVal1, RecipientVal2, Year : String; const Won : Boolean);
procedure AddConnection(Title, OrigTitle, Category, URL, Year: String)
procedure AddEpisode(Title, OrigTitle, Description, URL, Year, Season, Episode : String)

String functions
function Pos(Substr : String; Str: String): Integer
function PosFrom(const SubStr, Str : String; FromIndex : Integer) : Integer
function LastPos(const SubStr, Str : String) : Integer
function PrevPos(const SubStr, Str : String; APos : Integer) : Integer
function RemoveTags(AText : String; doLineBreaks : Boolean) : String
function ExplodeString(AText : String; var Items : TWideArray; Delimiters : String) : Integer
function Copy(S: String; Index, Count: Integer): String
procedure Delete(var S: String; Index, Count: Integer)
procedure Insert(Source: String; var Dest: String; Index: Integer)
function Length(S: String): Integer
function Trim(S: String): String
function CompareText(S1, S2: String): Integer
function CompareStr(S1, S2: String): Integer
function UpperCase(S: String): String
function LowerCase(S: String): String
function AnsiString(S, OldPattern, NewPattern: String; All : Boolean; IgnoreCase : Boolean; WholeWord: Boolean): String
function StrToInt(const S: String): Integer
function IntToStr(const Value: Integer): String
function StrToFloat(const S: String): Extended
function FloatToStr(const Value: Extended): String
function CurrentDateTime : Extended
function DateToStr(Value : Extended) : String
function TimeToStr(Value : Extended) : String
function HTMLValues(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String
function HTMLValues2(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String
function TextBetween(const HTML : String; ABegin, AEnd : String; doLineBreaks : Boolean; var Pos : Integer) : String
function HTMLToText(const HTML : String) : String

  procedure ShowMessage(const Msg, Head : String)
*)

//SCRIPT BEGINS HERE...

//Some useful constants

const

//Script types
stMovies = 0;
stPeople = 1;
stPoster = 2;

///Script modes
smSearch = 0;
smNormal = 1;
smCast = 2;
smReview = 3;
smCredits = 4;
smDVDReleases = 5;
smBiography = 6;
smGenreindex = 7;
smAwards = 8;
smMiscellaneous = 9;
smPoster = 10;
smFinished = 11;

//Parse results
prError = 0;
prFinished = 1;
prList = 2;
prListImage = 3;
prDownload = 4;

//Prefix modes
pmNone = 0;
pmEnd = 1;
pmBegin = 2;
pmRemove = 3;

//Download methods
dmGET = 0;
dmPOST = 1;

//Movie fields
mfURL = 0;
mfTitle = 1;
mfOrigTitle = 2;
mfAka = 3;
mfYear = 4;
mfGenre = 5;
mfCategory = 6;
mfCountry = 7;
mfStudio = 8;
mfMPAA = 9;
mfRating = 10;
mfTags = 11;
mfTagline = 12;
mfDescription = 13;
mfDuration = 14;
mfFeatures = 15;

//People fields
    pfURL        = 0;
pfName        = 1;
pfTransName  = 2;
pfAltNames    = 3;
pfBirthday    = 4;
pfBirthplace = 5;
pfGenre      = 6;
pfBio        = 7;
pfDeathDate  = 8; 
pfComment    = 9;
pfBookmark    = 10;
pfPid        = 11;
pfCareer      = 12;

//Credits types
ctActors = 0;
ctDirectors = 1;
ctWriters = 2;
ctComposers = 3;
ctProducers = 4;

//Script data
SCRIPT_VERSION = '0.1.0.5.a1';
SCRIPT_NAME = 'Rottentomatoes(a1) Script';
SCRIPT_DESC = '[EN] Get Movie Information(a1) from Rottentomatoes.com';
SCRIPT_LANG = $09; //English
SCRIPT_TYPE = stMovies;

BASE_URL = 'http://www.rottentomatoes.com';
RATING_NAME = 'Rottentomatoes';
SEARCH_STR = 'http://www.rottentomatoes.com/search/?search=%s&sitesearch=rt';
CODE_PAGE = 65001; //Use 0 for Autodetect

//User Options
GET_THEMES = True; //Set to False to ensure ~mfCategory~ not added even if 'Overwrite fields' setting allows
    GET_POSTER  = False; //Set to False or True
GET_RATING = True; //Set to False to ensure ~mfRating~ not set even if 'Overwrite setting' fields setting allows

//Global variables
var
ELI : Integer;
fullinfo, fullinfo1, fullinfo2 : String;
Mode : Byte;
ExtraLinks : array [smCast..smPoster] of String;

//Functions
function GetScriptVersion : String;
begin
Result := SCRIPT_VERSION;
end;

function GetScriptName : String;
begin
Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : String;
begin
Result := SCRIPT_DESC;
end;

function GetRatingName : String;
begin
Result := RATING_NAME;
end;

function GetScriptLang: Cardinal;
begin
Result := SCRIPT_LANG;
end;

function GetCodePage : Cardinal;
begin
Result := CODE_PAGE;
end;

function GetBaseURL : AnsiString;
begin
Result := BASE_URL;
end;

function GetDownloadURL : AnsiString;
begin
if (Mode = smSearch) then
Result := SEARCH_STR
else
Result := ExtraLinks[Mode];
end;

function GetDownloadMethod : Byte;
begin
Result := dmGET;
end;

function GetPrefixMode : Byte;
begin
Result := pmBegin;
end;

function GetScriptType : Byte;
begin
Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte;
begin
Result := Mode;
end;


procedure ParseMovie(MovieURL : String; HTML : String);
var
curPos, endPos : Integer;
Date, Title, URL, Month, TmpStr, TmpStr0, TmpStr1, TmpStr2, TmpStr3, TmpStr4, TmpStr5, TmpStr6: String;
DateParts : TWideArray;
begin

//Date ~Updated~ (choose simple or verbose version)
Date := DateToStr(CurrentDateTime);
if Date <> '' then
  begin
    ExplodeString(Date, DateParts, '-');
Date := DateParts[2] +'.'+ DateParts[1] +'.'+ DateParts[0];
AddCustomFieldValueByName('RTUpdated', Date + ' at ' + TimeToStr(CurrentDateTime) + ' • ' + SCRIPT_NAME + ' ' + SCRIPT_VERSION); // Annoying
  end else
    LogMessage('date not found');


//Get ~mfURL~ or ~RT Url~
endPos := Pos('" itemprop="url"/>', HTML);
if endPos > 0 then begin
curPos := PrevPos('"canonical" href="', HTML, endPos);
AddFieldValue(mfURL, Copy(HTML, curPos + 18, endPos - curPos - 18));
end else
AddFieldValue(mfURL, MovieURL);


//~Rating~ or ~RT Rating~
//curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
//if curPos > 0 then begin
// EndPos := curPos;
// TmpStr :=  TextBetween(HTML, 'Average Rating: <span>', '/10</span>', True, curPos);
// //TmpStr := StringReplace(TmpStr, ',', '', True, True, False);
// if TmpStr = '0' then
// TmpStr := '';
//    AddCustomFieldValueByName('RT Rating', TmpStr);
//if TmpStr = '' then
// TmpStr := 'rating unknown';
//end;
//~Rating~
//If Pos('audience', HTML) > 0 then begin
//If Pos('<span class="meter popcorn numeric ">', HTML) > 0 then begin
curPos := PosFrom('<span class="meter popcorn numeric ">', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
if curPos > 0 then begin
    curPos := PosFrom('Average Rating: ', HTML, curPos);
endPos := PosFrom('/5', HTML, curPos);
    TmpStr3 :=  StringReplace(FloatToStr((StrToFloat(Copy(HTML, curPos + 16, endPos - curPos - 16)) * 2)), '/5', '', True, True, False);
 if TmpStr3 = '0' then
TmpStr3 := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr3);
    AddCustomFieldValueByName('RT Rating', TmpStr3);
 if TmpStr3 = '' then
TmpStr3 := 'rating unknown';
//  end;
 end;
end else
//~Rating~
//If Pos('audience', HTML) > 0 then begin
//If Pos('<span class="meter spilled numeric ">', HTML) > 0 then begin
curPos := PosFrom('<span class="meter spilled numeric ">', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
if curPos > 0 then begin
    curPos := PosFrom('Average Rating: ', HTML, curPos);
endPos := PosFrom('/5', HTML, curPos);
    TmpStr4 :=  StringReplace(FloatToStr((StrToFloat(Copy(HTML, curPos + 16, endPos - curPos - 16)) * 2)), '/5', '', True, True, False);
 if TmpStr4 = '0' then
TmpStr4 := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr4);
    AddCustomFieldValueByName('RT Rating', TmpStr4);
 if TmpStr4 = '' then
TmpStr4 := 'rating unknown';
//  end;
 end;
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
curPos := Pos('<ul id="movie_results_ul" class="results_ul" ', HTML);
if curPos < 1 then
Exit;

LogMessage('Parsing search results...');

EndPos := PosFrom('<span class="movieposter">', HTML, EndPos);
curPos := PosFrom('<img src="', HTML, EndPos);
endPos := PosFrom('" width="', HTML, curPos);
Preview := Copy(HTML, curPos+10, EndPos - curPos-10);
curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
while (curPos > 0) AND (curPos < PosFrom('<a id="more_movies" href="#results_movies_tab">More Movies...</a>', HTML, endPos)) do begin
endPos := PosFrom('"  class=', HTML, curPos);
URL := 'http://www.rottentomatoes.com/'+Trim(Copy(HTML, curPos+23, endPos - curPos-23));
curPos := PosFrom('"  class="" >', HTML, curPos);
endPos := PosFrom('</a>', HTML, curPos);
Title := TextBetween(HTML, '"  class="" >', '</a>', True, curPos);
curPos := PosFrom('<span class="movie_year">', HTML, curPos);
endPos := PosFrom('</span></h3>', HTML, curPos);
Year := RemoveTags(TextBetween(HTML, '<span class="movie_year">', '</span></h3>', True, curPos), false);
AddSearchResult(Title+' '+Year, '', '', URL, Preview);
EndPos := PosFrom('<span class="movieposter">', HTML, EndPos);
curPos := PosFrom('<img src="', HTML, EndPos);
endPos := PosFrom('" width="', HTML, curPos);
Preview := Copy(HTML, curPos+10, EndPos - curPos-10);
curPos := PosFrom('<a target="_top" href="/m/', HTML, curPos);
 end;
end;

function NextMode(curMode : Integer) : Integer;
var
I : Integer;
begin
Result := smFinished;
if curMode < Low(ExtraLinks) - 1 then
curMode := Low(ExtraLinks) - 1;

for I := curMode + 1 to High(ExtraLinks) do
if ExtraLinks[I] <> '' then begin
Result := I;
Break;
end;
end;

function ParsePage(HTML : String; URL : AnsiString) : Cardinal;
begin
HTML := HTMLToText(HTML);
HTML := StringReplace (HTML, 'http://rottentomatoes.com', 'http://www.rottentomatoes.com', True, True, False);

if Pos('Search Results - Rotten Tomatoes', HTML) > 0 then begin
ParseSearchResults(HTML);
Result := prList;
Exit;

end else
 if Pos(' - Rotten Tomatoes</title>', HTML) > 0 then
    ParseMovie(URL, HTML);

Mode := NextMode(Mode);
if Mode <> smFinished then
Result := prDownload
else
Result := prFinished;
end;

begin
Mode := smSearch;
for ELI := Low(ExtraLinks) to High(ExtraLinks) do
ExtraLinks[ELI] := '';
end.
« Last Edit: March 05, 2014, 07:03:29 am by Ivek23 »
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #32 on: March 30, 2014, 02:10:18 pm »
Preparing Imdb Movie Script and Imdb Movie(1) Script with additional information, which data are Imdb plugin is not transferred.

I wonder what additional information is added to the script, so you can write your suggestions here for additional information, which should be added to the script.

Then I'll see how and what I can do and which of the proposals the can be added to the script.

Solutions, comprehensive information and more scripts now in Imdb Movie Script for Additional Information topic described.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #33 on: July 27, 2014, 02:12:59 pm »
I fixed it procedure ParseSearchResults to re-presentation of search results.

Rottentomatoes script
v 0.1.0.6


The source code for the search results on Rottentomatoes web pages there have been some changes, which is now very important influence in modifying and correcting the Rottentomatoes script.

This problem is removed, no more present.
There is a small cosmetic problem, namely to the first five results (one until five hits - depending on how many are on the All Search Results page) these results again repeat with all the other results in Movies Search Results page
Now this is no longer a cosmetic fault.

Rottentomatoes(1) script is no longer necessary because now it's all in one script.



Rottentomatoes script is attached.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #34 on: July 27, 2014, 02:13:35 pm »
For unregistered users:

Rottentomatoes script
v 0.1.0.6

Rottentomatoes.psf


Code: [Select]
(*
SCRIPT INFO:

---------------------------------------------

SCRIPT: Rottentomatoes Script
AUTHOR: Ivek23
VERSION: 0.1.0.6
DATE: 27/07/2014

---------------------------------------------
*)

//SCRIPT BEGINS HERE...

//Some useful constants

const

//Script types
stMovies = 0;
stPeople = 1;
stPoster = 2;

//Script modes
smSearch = 0;
smNormal = 1;
smCast = 2;
smReview = 3;
//smCredits = 4;
//smDVDReleases = 5;
//smBiography = 6;
//smGenreindex = 7;
//smAwards = 8;
//smMiscellaneous = 9;
smPoster = 10;
smFinished = 11;

//Parse results
prError = 0;
prFinished = 1;
prList = 2;
prListImage = 3;
prDownload = 4;

//Prefix modes
pmNone = 0;
pmEnd = 1;
pmBegin = 2;
pmRemove = 3;

//Download methods
dmGET = 0;
dmPOST = 1;

//Movie fields
mfURL = 0;
mfTitle = 1;
mfOrigTitle = 2;
mfAka = 3;
mfYear = 4;
mfGenre = 5;
mfCategory = 6;
mfCountry = 7;
mfStudio = 8;
mfMPAA = 9;
mfRating = 10;
mfTags = 11;
mfTagline = 12;
mfDescription = 13;
mfDuration = 14;
mfFeatures = 15;

//People fields
    pfURL        = 0;
pfName        = 1;
pfTransName  = 2;
pfAltNames    = 3;
pfBirthday    = 4;
pfBirthplace = 5;
pfGenre      = 6;
pfBio        = 7;
pfDeathDate  = 8; 
//pfComment    = 9;
//pfBookmark    = 10;
//pfPid        = 11;
//pfCareer      = 12;

//Credits types
ctActors = 0;
ctDirectors = 1;
ctWriters = 2;
ctComposers = 3;
ctProducers = 4;

//Script data
SCRIPT_VERSION = '0.1.0.6';
SCRIPT_NAME = 'Rottentomatoes Script';
SCRIPT_DESC = '[EN] Get Movie Information about from Rottentomatoes.com';
SCRIPT_LANG = $09; //English
SCRIPT_TYPE = stMovies;

BASE_URL = 'http://www.rottentomatoes.com';
RATING_NAME = 'Rottentomatoes';
SEARCH_STR = 'http://www.rottentomatoes.com/search/?search=%s&sitesearch=rt';
CODE_PAGE = 65001; //Use 0 for Autodetect

//Global variables
var
ELI : Integer;
Mode : Byte;
ExtraLinks : array [smCast..smPoster] of String;

//Functions
function GetScriptVersion : String;
begin
Result := SCRIPT_VERSION;
end;

function GetScriptName : String;
begin
Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : String;
begin
Result := SCRIPT_DESC;
end;

function GetRatingName : String;
begin
Result := RATING_NAME;
end;

function GetScriptLang: Cardinal;
begin
Result := SCRIPT_LANG;
end;

function GetCodePage : Cardinal;
begin
Result := CODE_PAGE;
end;

function GetBaseURL : AnsiString;
begin
Result := BASE_URL;
end;

function GetDownloadURL : AnsiString;
begin
if (Mode = smSearch) then
Result := SEARCH_STR
else
Result := ExtraLinks[Mode];
end;

function GetDownloadMethod : Byte;
begin
Result := dmGET;
end;

function GetPrefixMode : Byte;
begin
Result := pmBegin;
end;

function GetScriptType : Byte;
begin
Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte;
begin
Result := Mode;
end;

procedure ParseMovie(MovieURL : String; HTML : String);
var
curPos, endPos : Integer;
TmpStr : String;
begin

//Get ~mfURL~ or ~RT Url~
endPos := Pos('" itemprop="url"/>', HTML);
if endPos > 0 then begin
curPos := PrevPos('"canonical" href="', HTML, endPos);
AddFieldValue(mfURL, Copy(HTML, curPos + 18, endPos - curPos - 18));
end else
AddFieldValue(mfURL, MovieURL);

//~Rating~ or ~RT Rating~
curPos := PosFrom('<p class="critic_stats">', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, 'Average Rating: <span>', '/10</span>', True, curPos);
 if TmpStr = '0' then
TmpStr := '';
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
 if TmpStr = '' then
TmpStr := 'rating unknown';
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
// curPos := Pos('<ul id="movie_results_ul" class="results_ul" ', HTML);
curPos := Pos('<div id="results_movies_tab" class="ui-tabs-hide">', HTML);
if curPos < 1 then
Exit;

LogMessage('Parsing search results...');

curPos  := PosFrom('<img src="', HTML, curPos)+10;
endPos  := PosFrom('" width=', HTML, curPos);
Preview := Trim(Copy(HTML, curPos, endPos - curPos));

curPos := PosFrom('<a target="_top" data-pageheader="" href="/m/', HTML, curPos);
//while (curPos > 0) AND (curPos < PosFrom('<a id="more_movies" href="#results_movies_tab">More Movies...</a>', HTML, endPos)) do begin
while curPos > 0 do begin
endPos := PosFrom('"  class=', HTML, curPos);
URL := 'http://www.rottentomatoes.com'+Trim(Copy(HTML, curPos+42, endPos - curPos-42));

curPos := PosFrom('"  class="" >', HTML, curPos);
endPos := PosFrom('</a>', HTML, curPos);
Title := TextBetween(HTML, '"  class="" >', '</a>', True, curPos);

curPos := PosFrom('</a>', HTML, curPos);
endPos := PosFrom('</span></h3>', HTML, curPos);
Year := TextBetween(HTML, '</a>', '</span></h3>', True, curPos);

curPos  := PosFrom('<img src="', HTML, curPos)+10;
endPos  := PosFrom('" width=', HTML, curPos);
Preview := Trim(Copy(HTML, curPos, endPos - curPos));

AddSearchResult(Title+' '+Year, '', '', URL, '');

curPos := PosFrom('<a target="_top" data-pageheader="" href="/m/', HTML, curPos);
  end;
end;

function NextMode(curMode : Integer) : Integer;
var
I : Integer;
begin
Result := smFinished;
if curMode < Low(ExtraLinks) - 1 then
curMode := Low(ExtraLinks) - 1;

for I := curMode + 1 to High(ExtraLinks) do
if ExtraLinks[I] <> '' then begin
Result := I;
Break;
end;
end;

function ParsePage(HTML : String; URL : AnsiString) : Cardinal;
begin
HTML := HTMLToText(HTML);
HTML := StringReplace (HTML, 'http://rottentomatoes.com', 'http://www.rottentomatoes.com', True, True, False);

if Pos('Search Results - Rotten Tomatoes', HTML) > 0 then begin
ParseSearchResults(HTML);
Result := prList;
Exit;

end else
 if Pos(' - Rotten Tomatoes</title>', HTML) > 0 then
    ParseMovie(URL, HTML);

Mode := NextMode(Mode);
if Mode <> smFinished then
Result := prDownload
else
Result := prFinished;
end;

begin
Mode := smSearch;
for ELI := Low(ExtraLinks) to High(ExtraLinks) do
ExtraLinks[ELI] := '';
end.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #35 on: July 27, 2014, 03:16:36 pm »
Also would it be possibe to also add the Audiance rating from RT as I often go by an average of the two.

Audiance rating

It is possible, but there is a small problem that can be seen only one rating in PVD database:
Tomatometer rating or Audiance rating.

Recommendation or advice:

First of all, Tomatometer rating info you download with Rottentomatoes script. If Tomatometer rating not stand it now, but whoever wants you Audiance rating may be transferred to Rottentomatoes (a) script. If it was not yet the transfer, then they use Rottentomatoes (a1) script for Audiance rating, this script will Audiance rating surely passed if, of course, is added to the movies web sites.


One warning:

Rottentomatoes (a) or Rottentomatoes (a1) script will overwrite Tomatometer rating information.


Rottentomatoes (a) script
v 0.1.0.5.a

Rottentomatoes (a1) script
v 0.1.0.5.a


These Rottentomatoes scripts still work as before.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline deazo

  • Older Power User
  • *****
  • Posts: 283
    • View Profile
Re: Suggestion for Ivek23
« Reply #36 on: August 06, 2014, 01:28:44 am »
Thanks a lot Ivek, working GREAT!

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #37 on: August 06, 2014, 04:40:26 am »
Thanks a lot Ivek, working GREAT!

Welcome and thank you for feedback.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #38 on: October 04, 2014, 11:53:14 am »
Rottentomatoes script
v 0.1.1.0


Due to changes in the source code on Rottentomatoes pages, it was necessary that I again had to fix "process ParseSearchResults" to restore the functioning of the search results. The good side of these changes is, that it will now transfer rating data using only one Rottentomatoes script. Up to now, for the transmission of rating data were in many cases required two or even three script that was made a successful transfer of data for TOMATOMETER rating or AUDIENCE SCORE rating. Now for the transmission of data over rating requires only one script namely Rottentomatoes script, because I added code for TOMATOMETER rating and AUDIENCE SCORE rating.
In addition, Average Rating for All Critics,  the yet added Average Rating for Top Critics and Average Rating for Audience Score.


Custom field:

RT data:                                           custom field:
---------------                                       -------------------

Rating for All Critics                                     RT Rating      
Rating for Top Critics                                   RT Top Rating
Rating for Audience Score                           RT Audience Rating



Notice:

Rottentomatoes (a) script
v 0.1.0.5.a

Rottentomatoes (a1) script
v 0.1.0.5.a

is no longer necessary because now it's all in one script.




Rottentomatoes script is attached.
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD


Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2711
    • View Profile
Re: Suggestion for Ivek23
« Reply #39 on: October 04, 2014, 12:12:35 pm »
In Average Rating for All Critics also features such possibility in the code

Code: [Select]
//  ~Rating for All Critics~
//~Average Rating~ or ~RT Rating~ for All Critics
.
.
.
if GET_RATING then
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
 if TmpStr = '' then
TmpStr := 'rating unknown';
end;

it is possible to do this
Code: [Select]
GET_RATING = True; //Set to False to ensure ~mfRating~ not set even if 'Overwrite setting' fields setting allows
Ivek23
Win 10 64bit (32bit)   PVD v0.9.9.21, PVD v1.0.2.7, PVD v1.0.2.7 + MOD