21
Support / Re: FilmAffinity correction
« Last post by afrocuban on November 23, 2024, 06:54:40 pm »Thank you Ivek. Here is my script that corrects this.
It would be good Ivek to officially include it in FilmAffinity script if interested inNo interested.
otherwise if someone is interested in, I can post my already customized scriptYou can post script.
Orson Welles: The One-Man Band documentary
Orson Welles: The One-Man Band
//Get ~title~
curPos:=1
ItemValue:=TextBetWeen(HTML,'<h1 id="main-title">','</h1>',false,curPos); //Strings which opens/closes the data. WEB_SPECIFIC
AddCustomFieldValueByName('title1',ItemValue);
LogMessage(' Get result title:'+ItemValue+'||');
// Get ~title~
curPos := 1;
// Extract the section within <h1 id="main-title"> and </h1>
ItemValue := TextBetWeen(HTML, '<h1 id="main-title">', '</h1>', false, curPos);
LogMessage('Intermediate result after <h1>: ' + ItemValue + '||');
// Check and clean up any trailing content with 8 or more spaces
curPos := Pos(' ', ItemValue); // 8 spaces here between single quotes
if curPos > 0 then
begin
// Move the cursor to cover any additional spaces
// This loop handles any number of trailing spaces greater than or equal to 8
while (curPos <= Length(ItemValue)) and (ItemValue[curPos] = ' ') do // 8 spaces here between single quotes
begin
curPos := curPos + 1;
end;
// Extract the title up to the first non-space character after the spaces
ItemValue := Copy(ItemValue, 1, curPos - 1);
LogMessage('Cleaned title result: ' + ItemValue + '||');
end
else
begin
LogMessage('No extra trailing content found.');
end;
// Trim any leading or trailing whitespace
ItemValue := Trim(ItemValue);
// Add the title to the custom field
AddCustomFieldValueByName('title1', ItemValue);
// Log the final cleaned title for verification
LogMessage('Get result title: ' + ItemValue + '||');
Here's the most comprehensive list of both original and custom fields through many active and obsolete scripts, I have managed to gather.
If you want me to add fields from any other script please do not post links to the script, upload script here, or I won't be able to add it to the list. That is how we will easier track which additional scripts are added.
Probably very interesting column is column D which shows if script field is active or inactive ("hidden") in the script, so you might want to change the script if you find some inactive field in active script for yourself, and you even didn't know it's there. Not every hidden field will import data when activated, be aware, so if you're not sure, better ask Ivek.
List of my custom films is in column H. Yours is different so change it carefully if you want to know which custom fields from scripts you don't have added to your PVD. For this filter either column B or G for "No Custom Field Added in PVD for This Field".
There are many formulas in the file in order to help automation of future adding, as well as for better visibility inside the file, so be careful with any customization especially because of array formulas and conditional formatting.
It would be nice someone to change exclusively in column B what types of PVD fields are those in column A, with "No Custom Field Added in PVD for This Field" in column B. Please do not change this in column G. I added column B intentionally for this change only.
If you have any question, I'll do my best to respond.
Hi afrocuban,
PVD can handle multiple images for the same type (poster, disk cover, etc..) but from scripts I have never been able to upload more than 1 per type.
Hmmm, yes, me too. I'm trying but what ever I try, script won't compile, and it should. For example, this:Code: [Select]
type
TPosterInfo = record
ImageURL: string;
Caption: string;
Height: Integer; // Included height in the record for clarity
end;
Function ParsePage_IMDBMovieBASE(HTML: String): Cardinal; //BlockOpen
//Returns:
// Result:=prFinished; Script has finished gathering data
// Result:=prError; If ¿any big problem? with exit;
// Retrieve: ~title~, ~year~, ~origtitle~, ~poster~ / ~imdbrating~, ~IMDB_Votes~ (Custom Field) / ~TOP_250~ (Custom Field) /
// If Not(GET_FULL_CREDIT): ~crew~ ctDirectors, ctWriters, ctComposers, ctProducers (Not in base page), ctActors
// ~description~ / ~category~ "keywords" / ~tagline~ / ~genre~
// If Not(GET_FULL_MPAA) ~mpaa~
// ~country~ / ~rdate~ in contry provider local IP geolocation
// If Not(GET_FULL_AKA) ~aka~.
// ~budget~ / ~money~ / ~studio~ "Production Co"
Var
curPos, endPos, index, debug_pos1: Integer;
StartPos, Hours, Minutes: Integer;
ItemValue, ItemValue0, ItemValue1, ItemValue2, ItemValue99, ItemList, ImageFile: String;
MovieURL, titleValue, yearValue, yearsValue: String;
Name, Role, PersonURL: String;
ItemList2, ItemList12, day_s, month_s, year_s: String;
ItemList1, ItemList11: String;
ItemArray: TWideArray;
Posters: array of TPosterInfo; // Declared Posters here
PosterURL, TempURL: String; // Added for poster handling
TempHeight: Integer; // Added for poster handling
Begin
LogMessage('Function ParsePage_IMDBMovieBASE BEGIN======================|');
Result := prFinished; // It will change to prError if any big problem with exit;
//Because the script doesn't retrieve the data in order, a token search for the first curPos position or block select is mandatory
//Get ~title~, ~year~, ~origtitle~, ~poster~
//Get all "raw" title summary (in raw because we need the hidden links, we avoid "complete" token in strings which opens/closes) // (* *)
//Get ~MID ID:~ and ~NUM ID::~
AddCustomFieldValueByName('MID ID:', GetFieldValueXML('mid'));
LogMessage(' ** Movie MID ID: ' + GetFieldValueXML('mid') + ' **');
if GetFieldValueXML('num') <> '0' then AddCustomFieldValueByName('NUM ID:', GetFieldValueXML('num'));
if GetFieldValueXML('num') <> '0' then LogMessage(' * Movie NUM ID: ' + GetFieldValueXML('num') + ' ||');
//Get ~script info~
//Get ~rdate~ in country provider local IP geolocation. See: http://sobizarre-en.blogspot.fr/2014/12/how-to-easily-defeat-imdb-geolocation.html
//Get ~imdbrating~, ~IMDB_Votes~ (Two tries)
ItemList := TextBetWeenFirst(HTML, '<script type="application/ld+json"', '}</script>'); //WEB_SPECIFIC.
//LogMessage(' Parse results (' + IntToStr(curPos) + ',' + IntToStr(endPos) + ') complex ItemList: ' + '<script type="application/ld+json"' + ItemList + '}</script>' + '||');
If (Length(ItemList) > 0) Then Begin
//Get ~IMDb Url~
//MovieURL:='http://www.imdb.com' + TextBetWeenFirst(ItemList, '","url":"', '","name":"');
MovieURL := TextBetWeenFirst(ItemList, '","url":"', '","name":"');
MovieURL := StringReplace(MovieURL, 'https://', 'http://', True, False, True);
AddFieldValueXML('url', MovieURL);
LogMessage(' * Get result url 1:' + MovieURL + ' ||');
LogMessage(' * Get result MovieURL: ' + MovieURL);
// IMDB_FIELD = 'IMDB';
if PosFrom('imdb', MovieURL, 1) > 0 then AddCustomFieldValueByName(IMDB_FIELD, '-1');
//Get ~title~
titleValue := TextBetWeenFirst(ItemList, '","name":"', '","'); //Strings which opens/closes the data. WEB_SPECIFIC
If titleValue = '0' then titleValue := '';
//If titleValue = '' then titleValue := TextBetWeenFirst(ItemList, '<h1 class="long">', '<'); //Strings which opens/closes the data. WEB_SPECIFIC
if GET_ORIGINAL_TITLE then AddFieldValueXML('title', titleValue);
AddCustomFieldValueByName('Title', titleValue);
AddCustomFieldValueByName('Localized title', titleValue);
LogMessage(' Get result title:' + titleValue + '||');
//Get ~origtitle~
ItemValue := TextBetWeenFirst(ItemList, '","name":"', '","'); //Strings which opens/closes the data. WEB_SPECIFIC
If (Length(ItemValue) = 0) Then ItemValue := titleValue; //Provider hides the original title if same as title. WEB_SPECIFIC
AddFieldValueXML('origtitle', ItemValue);
AddCustomFieldValueByName('Origtitle', ItemValue);
LogMessage(' Get result origtitle:' + ItemValue + '||');
//Get ~alternatetitle~
ItemValue := TextBetWeenFirst(ItemList, '","alternateName":"', '","'); //Strings which opens/closes the data. WEB_SPECIFIC
AddCustomFieldValueByName('Localized title', ItemValue);
if GET_LOCAL_TITLE then AddFieldValueXML('title', ItemValue);
if ItemValue <> '' then LogMessage(' Get result alternatetitle:' + ItemValue + '||');
If ItemValue <> '' then AddCustomFieldValueByName('Imdb_Title', ItemValue + #13 + titleValue + ' (original title)')
Else AddCustomFieldValueByName('Imdb_Title', titleValue);
//Get ~IMDB_Movietype~
ItemValue := TextBetWeenFirst(ItemList, '","@type":"', '","'); //Strings which opens/closes the data. WEB_SPECIFIC
MediaType := ItemValue;
MediaType := StringReplace(MediaType, 'TVEpisode', 'TV Episode', True, False, True);
MediaType := StringReplace(MediaType, 'TVSeries', 'TV Series', True, False, True);
AddCustomFieldValueByName('IMDB_Movietype', MediaType);
AddCustomFieldValueByName('Tv 0', MediaType);
if ItemValue <> '' then LogMessage(' Get result MediaType (CF~IMDB_Movietype~):' + MediaType + '||');
//Get ~IMDB_MPAA~
ItemValue := TextBetWeenFirst(ItemList, ',"contentRating":"', '","'); //Strings which opens/closes the data. WEB_SPECIFIC
AddCustomFieldValueByName('IMDB_MPAA', ItemValue);
if ItemValue <> '' then LogMessage(' Get result ContentRating (CF~IMDB_MPAA~):' + ItemValue + '||');
// Start of the new poster-related code
procedure AddPoster(const URL: string; Height: Integer);
begin
SetLength(Posters, Length(Posters) + 1);
Posters[High(Posters)].ImageURL := URL;
Posters[High(Posters)].Caption := 'Poster'; // Adjust this as needed
Posters[High(Posters)].Height := Height; // Added to ensure height is stored
end;
repeat
PosterURL := TextBetWeenFirst(ItemList, BASE_URL_IMAGE_PRE_TRUE, '.'); // Adjust this to match actual URLs
if PosterURL <> '' then
begin
TempURL := BASE_URL_IMAGE_PRE_TRUE + PosterURL + '.jpg';
TempHeight := StrToIntDef(TextBetWeenFirst(PosterURL, '_V1_UY', '_'), 0);
AddPoster(TempURL, TempHeight);
end;
until (PosterURL = '');
// Import the posters up to the specified limit
PosterCount := Min(5, Length(Posters)); // Up to 5 posters
for index := 0 to PosterCount - 1 do
begin
ImageFile := GetAppPath + 'Scripts\' + BASE_DOWNLOAD_FILE_IMAGE_NAME + '-Poster-' + IntToStr(index + 1) + '.jpg';
if (1 = DownloadImage(Posters[index].ImageURL + '._V1_UY' + IntToStr(Posters[index].Height) + '_.jpg', ImageFile)) then
begin
AddImageURL(itPoster, ImageFile);
LogMessage('Imported poster: ' + Posters[index].ImageURL + '._V1_UY' + IntToStr(Posters[index].Height) + '_.jpg' + ' || Height: ' + IntToStr(Posters[index].Height));
end
else if (1 = DownloadImage(Posters[index].ImageURL + '.jpg', ImageFile)) then
begin
AddImageURL(itPoster, ImageFile);
LogMessage('Imported poster: ' + Posters[index].ImageURL + '.jpg' + ' || Height: ' + IntToStr(Posters[index].Height));
end;
end;
// End of the new poster-related code
End;
Begin
LoadPosters;
// Additional code to integrate with PVD if needed
End.
//~description~
The log complains with thisQuote
(11/16/2024 1:17:20 PM) Could not compile script: IMDB_2c_afro-Custom Cast + more.psf
[Error] (731:5): Identifier expected
Line 731 is procedure AddPoster(const URL: string; Height: Integer);
procedure AddPoster(const URL: string; Height: Integer);
Hello again, Ivek. I'm further customizing your script. I've got that custom director's field, but I will not post the script until some point when I will be satisfied with the level of customization.
Now I'm working on a possibility to import more than one poster at once from the site (let's say, IMDb site). Do you by any chance know if database or PVD itself allows that, so with the proper script coding, multiple posters would be parsed and populated to poster field?
Hi afrocuban,
PVD can handle multiple images for the same type (poster, disk cover, etc..) but from scripts I have never been able to upload more than 1 per type.
<tab shape="true" space="1">
<caption>&Images</caption>
<color>$E0ECFE</color>
<row>
<column valign="top" space="1">
<imagelist valign="top" halign="left" cheight="100" cwidth="75" autosize="true" space="7">
<border shape="none" />
<color>$CCDDEE</color>
</imagelist>
</column>
</row>
</tab>