Author Topic: Suggestion for Ivek23  (Read 78137 times)

0 Members and 1 Guest are viewing this topic.

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #40 on: October 04, 2014, 12:14:02 pm »
For unregistered users:

Rottentomatoes script
v 0.1.1.0

Rottentomatoes.psf


Code: [Select]
(*
SCRIPT INFO:

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

SCRIPT: Rottentomatoes Script
AUTHOR: Ivek23
VERSION: 0.1.1.0
DATE: 04/10/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.1.0';
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

//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;
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, TmpStr1, TmpStr2 : 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);


//  ~TOMATOMETER~

//  ~Rating for All Critics~
//~Average Rating~ or ~RT Rating~ for All Critics
curPos := PosFrom('<div id="all-critics-numbers" class="tab-pane active"', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, 'Average Rating: ', '/10</div>', True, curPos);
 if TmpStr = '0' then
TmpStr := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
 if TmpStr = '' then
TmpStr := 'rating unknown';
end;

//  ~Rating for Top Critics~
//~Average Rating~ or ~RT Top Rating~ for Top Critics
curPos := PosFrom('<div id="top-critics-numbers" class="tab-pane">', HTML, EndPos);
if curPos > 0 then begin
// EndPos := curPos;
TmpStr1 :=  TextBetween(HTML, 'Average Rating: ', '/10</div>', True, curPos);
 if TmpStr1 = '0' then
TmpStr1 := '';
    AddCustomFieldValueByName('RT Top Rating', TmpStr1);
 if TmpStr1 = '' then
TmpStr1 := 'rating unknown';
  EndPos := curPos;
end;
 
 
//  ~AUDIENCE SCORE~ 

//~Audience: Average Rating~ or ~RT Audience Rating~ for Audience Score
curPos := PosFrom('<h3 style="padding:10px">AUDIENCE SCORE', HTML, EndPos);
if curPos > 0 then begin
// EndPos := curPos;
curPos := PosFrom('<div class="audience-info" style="padding-bottom:10px">', HTML, EndPos);
if curPos > 0 then begin
    curPos := PosFrom('Average Rating: ', HTML, curPos);
endPos := PosFrom('/5', HTML, curPos);
    TmpStr2 :=  StringReplace(FloatToStr((StrToFloat(Copy(HTML, curPos + 16, endPos - curPos - 16)) * 2)), '/5', '', True, True, False);
 if TmpStr2 = '0' then
TmpStr2 := '';
    AddCustomFieldValueByName('RT Audience Rating', TmpStr2);
 if TmpStr2 = '' then
TmpStr2 := 'rating unknown';
  end;
  EndPos := curPos;
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
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 class="unstyled articleLink" target="_top" data-pageheader="" href="/m/', HTML, curPos);
while curPos > 0 do begin
endPos := PosFrom('"  >', HTML, curPos);
URL := 'http://www.rottentomatoes.com'+Trim(Copy(HTML, curPos+71, endPos - curPos-71));

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

curPos := PosFrom('</a>', HTML, curPos);
endPos := PosFrom('</span></div>', HTML, curPos);
Year := TextBetween(HTML, '</a>', '</span></div>', 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 class="unstyled articleLink" 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 deazo

  • Older Power User
  • *****
  • Posts: 283
    • View Profile
Re: Suggestion for Ivek23
« Reply #41 on: October 05, 2014, 09:38:45 am »
Again Ivek: THANKS A LOT for the hard work!

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #42 on: October 05, 2014, 09:55:17 am »
Again Ivek: THANKS A LOT for the hard work!

deazo, thanks.
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 #43 on: October 09, 2014, 10:13:13 am »

 Hi Ivek,

 For some reason the new script does not grab the rating anymore.
 I have even tried with the previous script and ratings are not taken either.
 Would you know what the problem is by any chance?

Thanks

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #44 on: October 10, 2014, 11:37:02 am »

 Hi Ivek,

 For some reason the new script does not grab the rating anymore.
 I have even tried with the previous script and ratings are not taken either.
 Would you know what the problem is by any chance?

Thanks

Yeah, I noticed that the rating does not work anymore.
Reason: again the changes in the source code on rottentomatoes pages.



Rottentomatoes script
v 0.1.1.4


I fixed the rating code that now the problem is solved.
I hope that will not change in the source code on rottentomatoes pages in the near future - at least for some time not.

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: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #45 on: October 10, 2014, 11:37:35 am »
For unregistered users:

Rottentomatoes script
v 0.1.1.4

Rottentomatoes.psf


Code: [Select]
(*
SCRIPT INFO:

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

SCRIPT: Rottentomatoes Script
AUTHOR: Ivek23
VERSION: 0.1.1.4
DATE: 10/10/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.1.4';
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

//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;
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, TmpStr1, TmpStr2 : 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);


//  ~TOMATOMETER~

//  ~Rating for All Critics~
//~Average Rating~ or ~RT Rating~ for All Critics
curPos := PosFrom('<div id="all-critics-numbers" class="tab-pane active"', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, '<span class="subtle">Average Rating: </span>', '/10', True, curPos);
 if TmpStr = '0' then
TmpStr := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
 if TmpStr = '' then
TmpStr := 'rating unknown';
end;

//  ~Rating for Top Critics~
//~Average Rating~ or ~RT Top Rating~ for Top Critics
curPos := PosFrom('<div id="top-critics-numbers" class="tab-pane', HTML, EndPos);
if curPos > 0 then begin
// EndPos := curPos;
TmpStr1 :=  TextBetween(HTML, '<span class="subtle">Average Rating: </span>', '/10', True, curPos);
 if TmpStr1 = '0' then
TmpStr1 := '';
    AddCustomFieldValueByName('RT Top Rating', TmpStr1);
 if TmpStr1 = '' then
TmpStr1 := 'rating unknown';
  EndPos := curPos;
end;
 
 
//  ~AUDIENCE SCORE~ 

//~Audience: Average Rating~ or ~RT Audience Rating~ for Audience Score
//curPos := PosFrom('<div class="audience-info">', HTML, EndPos);
curPos := Pos('<div class="audience-info">', HTML);
if curPos > 0 then begin
// EndPos := curPos;
TmpStr2 :=  FloatToStr(StrToFloat(TextBetween(HTML, '<span class="subtle">Average Rating:</span>', '/5', True, curPos)) * 2);
 if TmpStr2 = '0' then
TmpStr2 := '';
    AddCustomFieldValueByName('RT Audience Rating', TmpStr2);
 if TmpStr2 = '' then
TmpStr2 := 'rating unknown';
  EndPos := curPos;
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
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 class="unstyled articleLink" target="_top" data-pageheader="" href="/m/', HTML, curPos);
while curPos > 0 do begin
endPos := PosFrom('"  >', HTML, curPos);
URL := 'http://www.rottentomatoes.com'+Trim(Copy(HTML, curPos+71, endPos - curPos-71));

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

curPos := PosFrom('</a>', HTML, curPos);
endPos := PosFrom('</span></div>', HTML, curPos);
Year := TextBetween(HTML, '</a>', '</span></div>', 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 class="unstyled articleLink" 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 deazo

  • Older Power User
  • *****
  • Posts: 283
    • View Profile
Re: Suggestion for Ivek23
« Reply #46 on: October 10, 2014, 01:20:36 pm »

 Works perfectly.
 Thanks again!
  ;D ;D ;D ;D ;D

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #47 on: October 10, 2014, 03:19:39 pm »

 Works perfectly.
 Thanks again!
  ;D ;D ;D ;D ;D

Thank you, we'll see how long it will work because they are so far were daily changes in the source code on rottentomatoes pages.
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: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #48 on: November 01, 2014, 07:08:18 pm »
Again, it was corrected procedure ParseSearchResults for the re-presentation of search results.

Rottentomatoes script
v 0.1.1.5


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: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #49 on: November 01, 2014, 07:09:31 pm »
For unregistered users:

Rottentomatoes script
v 0.1.1.5

Rottentomatoes.psf


Code: [Select]
(*
SCRIPT INFO:

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

SCRIPT: Rottentomatoes Script
AUTHOR: Ivek23
VERSION: 0.1.1.5
DATE: 1/11/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.1.5';
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

//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;
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, TmpStr1, TmpStr2 : 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);


//  ~TOMATOMETER~

//  ~Rating for All Critics~
//~Average Rating~ or ~RT Rating~ for All Critics
curPos := PosFrom('<div id="all-critics-numbers" class="tab-pane active"', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, '<span class="subtle">Average Rating: </span>', '/10', True, curPos);
 if TmpStr = '0' then
TmpStr := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
 if TmpStr = '' then
TmpStr := 'rating unknown';
end;

//  ~Rating for Top Critics~
//~Average Rating~ or ~RT Top Rating~ for Top Critics
curPos := PosFrom('<div id="top-critics-numbers" class="tab-pane', HTML, EndPos);
if curPos > 0 then begin
// EndPos := curPos;
TmpStr1 :=  TextBetween(HTML, '<span class="subtle">Average Rating: </span>', '/10', True, curPos);
 if TmpStr1 = '0' then
TmpStr1 := '';
    AddCustomFieldValueByName('RT Top Rating', TmpStr1);
 if TmpStr1 = '' then
TmpStr1 := 'rating unknown';
  EndPos := curPos;
end;
 
 
//  ~AUDIENCE SCORE~ 

//~Audience: Average Rating~ or ~RT Audience Rating~ for Audience Score
//curPos := PosFrom('<div class="audience-info">', HTML, EndPos);
curPos := Pos('<div class="audience-info">', HTML);
if curPos > 0 then begin
// EndPos := curPos;
TmpStr2 :=  FloatToStr(StrToFloat(TextBetween(HTML, '<span class="subtle">Average Rating:</span>', '/5', True, curPos)) * 2);
 if TmpStr2 = '0' then
TmpStr2 := '';
    AddCustomFieldValueByName('RT Audience Rating', TmpStr2);
 if TmpStr2 = '' then
TmpStr2 := 'rating unknown';
  EndPos := curPos;
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
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 class="unstyled articleLink" target="_top" data-pageheader="" href="/m/', HTML, curPos);
while curPos > 0 do begin
endPos := PosFrom('"  >', HTML, curPos);
URL := 'http://www.rottentomatoes.com'+Trim(Copy(HTML, curPos+71, endPos - curPos-71));

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

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

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

curPos := PosFrom('<a class="unstyled articleLink" 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 deazo

  • Older Power User
  • *****
  • Posts: 283
    • View Profile
Re: Suggestion for Ivek23
« Reply #50 on: November 09, 2014, 01:10:54 am »

 THANKS again!

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #51 on: November 09, 2014, 06:32:51 am »
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 #52 on: April 28, 2015, 08:14:54 am »

 Hi Ivek,
I think the script is broken (RT has probably changed again...)
I cannot get ratings and also the script will download a bunch of codes in the URL field...
Let us know if you can take a look when you have time please?
No rush.
Thank you in advance.

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #53 on: April 28, 2015, 10:38:07 am »

 Hi Ivek,
I think the script is broken (RT has probably changed again...)
I cannot get ratings and also the script will download a bunch of codes in the URL field...
Let us know if you can take a look when you have time please?
No rush.
Thank you in advance.

Thank you for your feedback, deazo.

I'll see what the problem is, when I have more time. Certainly, this will be when I updated and added new movie titles in my movie database. Then will AllMovie.com_new script, which is also currently does not work, it will also
then updated.
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 #54 on: April 28, 2015, 08:03:50 pm »

 Ok thanks take your time.

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #55 on: May 23, 2015, 07:14:48 pm »
Again, it was corrected procedure ParseSearchResults for the re-presentation of search results. I also fixed all rating information transmission.

Rottentomatoes script
v 0.1.1.6


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: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #56 on: May 23, 2015, 07:16:31 pm »
For unregistered users:

Rottentomatoes script
v 0.1.1.6

Rottentomatoes.psf


Code: [Select]
(*
SCRIPT INFO:

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

SCRIPT: Rottentomatoes Script
AUTHOR: Ivek23
VERSION: 0.1.1.6
DATE: 23/05/2015

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

//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.1.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';
SEARCH_STR = 'http://www.rottentomatoes.com/search/?search=%s';
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;
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, TmpStr1, TmpStr2 : String;
begin

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


//  ~TOMATOMETER~

//  ~Rating for All Critics~
//~Average Rating~ or ~RT Rating~ for All Critics
curPos := PosFrom('<div id="all-critics-numbers" class="tab-pane active"', HTML, EndPos);
//curPos := PosFrom('<<meta itemprop="name" content="All Critic Tomatometer"/>', HTML, EndPos);
if curPos > 0 then begin
EndPos := curPos;
TmpStr :=  TextBetween(HTML, '<span class="subtle superPageFontColor">Average Rating: </span>', '/10 </div>', True, curPos);
 if TmpStr = '0' then
TmpStr := '';
if GET_RATING then
AddFieldValue(mfRating, TmpStr);
AddCustomFieldValueByName('RT Rating', TmpStr);
 if TmpStr = '' then
TmpStr := 'rating unknown';
end;

//  ~Rating for Top Critics~
//~Average Rating~ or ~RT Top Rating~ for Top Critics
curPos := PosFrom('<div id="top-critics-numbers" class="tab-pane', HTML, EndPos);
if curPos > 0 then begin
// EndPos := curPos;
TmpStr1 :=  TextBetween(HTML, '<span class="subtle superPageFontColor">Average Rating: </span>', '/10 </div>', True, curPos);
 if TmpStr1 = '0' then
TmpStr1 := '';
    AddCustomFieldValueByName('RT Top Rating', TmpStr1);
 if TmpStr1 = '' then
TmpStr1 := 'rating unknown';
  EndPos := curPos;
end;
 
 
//  ~AUDIENCE SCORE~ 

//~Audience: Average Rating~ or ~RT Audience Rating~ for Audience Score
//curPos := PosFrom('<div class="audience-info">', HTML, EndPos);
curPos := Pos('<div class="audience-score meter">', HTML);
if curPos > 0 then begin
// EndPos := curPos;
TmpStr2 :=  FloatToStr(StrToFloat(TextBetween(HTML, '<div> <span class="subtle superPageFontColor">Average Rating:</span>', '/5 </div>', True, curPos)) * 2);
 if TmpStr2 = '0' then
TmpStr2 := '';
    AddCustomFieldValueByName('RT Audience Rating', TmpStr2);
 if TmpStr2 = '' then
TmpStr2 := 'rating unknown';
  EndPos := curPos;
end;
 
end;


procedure ParseSearchResults(HTML : String);
var
curPos, endPos : Integer;
Title, Year, URL, Preview : String;
begin
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 class="unstyled articleLink" target="_top" data-pageheader="" href="/m/', HTML, curPos);
while curPos > 0 do begin
endPos := PosFrom('">', HTML, curPos);
URL := 'http://www.rottentomatoes.com'+Trim(Copy(HTML, curPos+71, endPos - curPos-71));

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

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

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

curPos := PosFrom('<a class="unstyled articleLink" 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 deazo

  • Older Power User
  • *****
  • Posts: 283
    • View Profile
Re: Suggestion for Ivek23
« Reply #57 on: May 26, 2015, 11:22:49 pm »
NICE ONE
Thank you Ivek it works perfectly!

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2713
    • View Profile
Re: Suggestion for Ivek23
« Reply #58 on: May 27, 2015, 05:22:48 am »
NICE ONE
Thank you Ivek it works perfectly!

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


Offline afrocuban

  • Moderator
  • *****
  • Posts: 475
    • View Profile
Re: Suggestion for Ivek23
« Reply #59 on: October 26, 2015, 11:29:36 pm »
Hello Ivek,

Is it possible with this script to import Title to a Custom Field also named "Title"? What piece of code it would be? Thanks in advance.

I have already added this piece of code
AddCustomFieldValueByName('Rottentomatoes.com', '<link url="' + MovieURL + '">Rottentomatoes.com</link>');
:
Code: [Select]
//Get ~mfURL~ or ~RT Url~
endPos := Pos('" rel="canonical" itemprop="url"/>', HTML);
if endPos > 0 then begin
curPos := PrevPos('</title> <link href="', HTML, endPos);
AddFieldValue(mfURL, Copy(HTML, curPos + 21, endPos - curPos - 21));
end else
AddFieldValue(mfURL, MovieURL);
AddCustomFieldValueByName('Rottentomatoes.com', '<link url="' + MovieURL + '">Rottentomatoes.com</link>');