61
PVD Python Scripts / Re: PVD Selenium MOD v4 IMDb Movie Script Confusion
« Last post by Ivek23 on March 31, 2025, 09:43:19 am »Function ParsePage_IMDBMovieREFERENCE
Custom field to remove.
Removing unnecessary parts of the code.
Custom field to remove.
Quote
//(*
// Get (CF~Year~) and ~year~
If Pos('<div id="content-2-wide" class="redesign">', HTML)>0 Then Begin
curPos := PosFrom('<h3 itemprop="name">', HTML, EndPos);
EndPos := PosFrom('<section class="titlereference-section-overview">', HTML, curPos);
ItemList := Copy(HTML, curPos, endPos-curPos);
ItemValue10 := TextBetWeenFirst(ItemList, 'itemprop="url">', '</a>');
//if ItemValue10 <> '' then AddCustomFieldValueByName('IMDB_year', ItemValue10);
if ItemValue10 <> '' then AddCustomFieldValueByName('Year', ItemValue10);
//If Not (USE_SAVED_PVDCONFIG And (ConfigOptions[4] = '0')) Then Begin
if ItemValue10 <> '' then AddFieldValueXML('year', ItemValue10); //It looks like there is a bug in PVD. Year will be populated even if set to "None" in PVD)
//End;
Quote
// Get ~imdbrating~ (CF~IMDB Rating~), (~IMDBRating~)
ItemValue2 := TextBetWeenFirst(ItemList, '<span class="ipl-rating-star__rating">', '</span>');
//ItemValue2 := StringReplace(ItemValue2, ',', '.', True, False, False);
If ItemValue2 = '0' then ItemValue2 := '';
if ItemValue2 <> '' then LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemValue2: ' + ItemValue2 + ' | |');
//if ItemValue2 <> '' then ItemList2 := ItemList2 + ItemValue2;
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemList2 + ItemValue: ' + ItemList2 + ItemValue2 + ' | |');
AddFieldValueXML('imdbrating',ItemValue2);
LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ratingValue ~imdbrating~ (CF~IMDB Rating~), (~IMDBRating~): ' + ItemValue2 + ' | |');
Quote
// Get IMDb Votes (CF~IMDB_Votes~), (CF~IMDB Votes~), (CF~IMDB Votes:~)
ItemValue12 := TextBetWeenFirst(ItemList, '<span class="ipl-rating-star__total-votes">(', ')</span>');
ItemValue12 := StringReplace(ItemValue12, '.', '', True, False, False);
AddCustomFieldValueByName('IMDB Votes', ItemValue12);
AddCustomFieldValueByName('IMDB Votes:', ItemValue12);
if ItemValue12 <> '' then LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ratingCount (CF~IMDB_Votes~): ' + ItemValue12 + ' | |');
if ItemValue12 <> '' then LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemValue12: ' + ItemValue12 + ' | |');
//if ItemValue12 <> '' then ItemList2 := ItemList2 + ' ' + #8226 + ' ' + ItemValue12;
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemList2: ' + ItemList2 + ' | |');
Quote
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Value of ReleaseInfoPageDownloaded: ' + BoolToStr(ReleaseInfoPageDownloaded))
// Get Imdb Release Date ~rdate~, (CF~IMDB Release Date~), (CF~IMDB Release Dates~)
ItemValue120 := TextBetWeenFirst(ItemList, '/releaseinfo">', '</a>');
if ItemValue120 <> '' then LogMessage('Function - Get result ItemValue120: ' + ItemValue120 + ' | |');
if ItemValue120 <> '' then AddCustomFieldValueByName('Imdb Release Date', ItemValue120);
LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result DatePublished (CF~IMDB Release Date~): ' + ItemValue120 + ' | |');
//End;
Quote
// Get ~studio~ and (CF~IMDb Studio2~) "Production Co" (multiple values in a comma separated list)
curPos := Pos('">Production compan', HTML); // WEB_SPECIFIC.
//curPos := Pos('<a href="/company/co', HTML) + Length('<a href="/company/co'); // WEB_SPECIFIC.
If 0 < curPos Then Begin
EndPos := curPos;
ItemValue := HTMLValues(HTML, '">Production compan', '</ul>', '<li>', '</a>', ', ', endPos);
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get ItemValue Studio/Production Co multiple: ' + ItemValue + ' | |');
AddFieldValueXML('studio', ItemValue);
LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get results Studio/Production Co: ' + ItemValue + ' | |');
End;
Quote
If Not(TechnicalPageDownloaded) then Begin
//If Not (USE_SAVED_PVDCONFIG And (ConfigOptions[23] = '0')) Then Begin
// Get the original "Runtime" (in minutes) as ~length~ (in seconds), CF~Run time1~), and (CF~Imdb Runtime1~) instead of the duration of the user movie copy
curPos := Pos('</li>', ItemList) + Length('</li>');
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result curPos for ~length~: ' + IntToStr(curPos) + ' | |');
ItemList := Copy(ItemList, curPos, endPos - curPos);
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemList for ~length~: ' + ItemList + ' | |');
ItemValue := TextBetWeenFirst(ItemList, '<li class="ipl-inline-list__item">', '</li>');
LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemValue for ~length~: ' + ItemValue + ' | |');
if curPos > 0 then
begin
// Extract hours and minutes
Hours := 0;
Minutes := 0;
if Pos('h', ItemValue) > 0 then
begin
Hours := StrToIntDef(Copy(ItemValue, 1, Pos('h', ItemValue) - 1), 0);
ItemValue := Copy(ItemValue, Pos('h', ItemValue) + 1, Length(ItemValue));
end;
if Pos('min', ItemValue) > 0 then
begin
Minutes := StrToIntDef(Copy(ItemValue, 1, Pos('min', ItemValue) - 1), 0);
end;
ItemValue := IntToStr(Hours * 60 + Minutes);
if ItemValue = '0' then ItemValue := '';
if ItemValue <> '' then
begin
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result Original Runtime: ' + ItemValue + ' | |');
AddFieldValueXML('length', IntToStr(60 * StrToInt(ItemValue))); //~length~ Value in seconds.
AddCustomFieldValueByName('Run time 1', ItemValue);
AddCustomFieldValueByName('Imdb Runtime 1', IntToStr(Hours) + 'h' + ' ' + IntToStr(Minutes) + 'm (' + ItemValue + ' minutes)');
LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result "Runtime" (in minutes) ~length~, (CF~Run time1~), and (CF~Imdb Runtime1~) : ' + ItemValue + ' | |');
end;
end
else
begin
LogMessage('Function ParsePage_IMDBMovieREFERENCE - duration/length not found');
end;
//End;
End; // If Not(TechnicalPageDownloaded) then Begin should end here
Quote
If Not (MainPageDownloaded) And Not (TechnicalPageDownloaded) Then Begin
//Get "Color" (CF~Color :~) & (CF~'Imdb Color :~) (multiple values in a comma separated list)
curPos := Pos('<td class="ipl-zebra-list__label">Color</td>', HTML);
//LogMessage('Function ParsePage_IMDBMovieBASE - Get result curPos (CF~Color~) & (CF~Imdb Color~): ' + IntToStr(curPos) + ' | |');
if 0<curPos then begin
EndPos := curPos;
ItemValue := HTMLValues2(HTML, '<td class="ipl-zebra-list__label">Color</td>', '</ul>', '<li class="ipl-inline-list__item">', '</li>', ', ', EndPos);
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemValue after HTMLValues2 (CF~Color~) & (CF~Imdb Color~): ' + ItemValue + ' | |');
//ItemValue := StringReplace(ItemValue, '| ', ', ', True, True, False); //WEB_SPECIFIC.
ItemValue := StringReplace(ItemValue, '(', ' (', True, True, False); //WEB_SPECIFIC.
if ItemValue <> '' then ItemList := ItemList + 'Color: ' + ItemValue + '<br>';
if ItemValue <> '' then AddCustomFieldValueByName('Color :', ItemValue);
if ItemValue <> '' then AddCustomFieldValueByName('Imdb Color :', ItemValue);
if ItemValue <> '' then LogMessage('Function ParsePage_IMDBMovieBASE - Get result (CF~Color :~) and (CF~Imdb Color :~): ' + ItemValue + ' | |');
End;
End; //If Not (MainPageDownloaded) And Not (TechnicalPageDownloaded) Then Begin should end here
Removing unnecessary parts of the code.
Quote
(*
If Not (MainPageDownloaded) Then Begin
// Go to "Connections" (CF~Conect~) (CF~MiniConnections~) (CF~FOLLOWEDBY_FIELD~)
// Initialize the string to collect all entries
allItemValues := '';
StartPos := Pos('<td class="ipl-zebra-list__label">Movie Connections</td>', HTML);
If StartPos > 0 Then Begin
// Define the end marker for the "Connections" section
EndPos := PosFrom('</tr>', HTML, StartPos);
If EndPos > StartPos Then Begin
// Extract the relevant HTML section
ItemValue := Copy(HTML, StartPos, EndPos - StartPos);
//LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result ItemValue for (CF~Conect~) (CF~MiniConnections~) (CF~FOLLOWEDBY_FIELD~) : ' + #13 + ItemValue + ' | |' + #13);
// Initialize connections container
Connections := '';
// Define connection types
connectionTypes := ['Featured in', 'Follows', 'Followed by', 'Referenced in', 'Remade as', 'Remake of', 'Spin-off', 'Spoofed in', 'Edited into', 'Edited from', 'Version of', 'Features', 'References', 'Spoofs', 'Spin-off from'];
// Iterate through each type of connection using an indexed loop
For i := Low(connectionTypes) To High(connectionTypes) Do Begin
connType := connectionTypes;
connStartPos := PosFrom(connType, ItemValue, 1);
While connStartPos > 0 Do Begin
connEndPos := PosFrom('</a>', ItemValue, connStartPos) + Length('</a>') - 1;
If connEndPos > connStartPos Then Begin
connHTML := Copy(ItemValue, connStartPos, connEndPos - connStartPos + 1);
// Extract the link URL
linkStartPos := PosFrom('<a href="', connHTML, 1) + Length('<a href="');
linkEndPos := PosFrom('">', connHTML, linkStartPos);
linkURL := Copy(connHTML, linkStartPos, linkEndPos - linkStartPos);
// Extract the link text
textStartPos := linkEndPos + Length('">');
textEndPos := PosFrom('</a>', connHTML, textStartPos);
linkText := Copy(connHTML, textStartPos, textEndPos - textStartPos);
// Build the custom format
connHTML := connType + ' <link url="https://www.imdb.com' + linkURL + '">' + linkText + '</link>';
// Append to connections container
If Length(Connections) > 0 Then
Connections := Connections + ', ' + connHTML
Else
Connections := connHTML;
End;
connStartPos := PosFrom(connType, ItemValue, connStartPos + Length(connHTML));
End;
End;
LogMessage('Function ParsePage_IMDBMovieREFERENCE - Final processed Connections: ' + Connections + ' | |' + #13);
// Add custom field values
AddCustomFieldValueByName('Conect', Connections);
AddCustomFieldValueByName('MiniConnections', Connections);
// Add condition to check "Followed By" presence and add custom field value
If PosFrom('Followed By', Connections, 1) > 0 Then
AddCustomFieldValueByName(FOLLOWEDBY_FIELD, '-1');
End;
End Else
LogMessage('Function ParsePage_IMDBMovieREFERENCE - (CF~Conect~) (CF~MiniConnections~) (CF~FOLLOWEDBY_FIELD~) not found');
*)
(*
//Go to "Soundtracks" (CF~MiniSoundtracks~)
StartPos := Pos('<td class="ipl-zebra-list__label">Soundtracks</td>', HTML);
if StartPos>0 then begin
//ItemValue := HTMLValue(HTML, StartPos, 0, '<div><span class="soundtrack-', '</div>');
ItemValue := TextBetWeen(HTML, '<td>', '<a href=', False, StartPos);
AddCustomFieldValueByName('MiniSoundtracks', ItemValue);
if ItemValue <> '' then LogMessage('Function ParsePage_IMDBMovieREFERENCE - Get result Soundtracks (CF~MiniSoundtracks~): ' + #13 + ItemValue + #13);
end else
LogMessage('Function ParsePage_IMDBMovieREFERENCE - (CF~MiniSoundtracks~) not found');
End; //If Not (MainPageDownloaded) Then Begin should end here
*)