Author Topic: FilmAffinity correction  (Read 49 times)

0 Members and 1 Guest are viewing this topic.

Offline afrocuban

  • Moderator
  • *****
  • Posts: 491
    • View Profile
FilmAffinity correction
« on: November 22, 2024, 09:13:35 pm »
At least recently, FilmAffinity script parses Movie title custom field "title1" together with movietype when the title is not movie, but series, documentary or so. For example, for https://www.filmaffinity.com/en/film348275.html for the result after <h1> we were getting


Quote
Orson Welles: The One-Man Band                documentary

Instead


Quote
Orson Welles: The One-Man Band

only.


So, using AI, I corrected this, because I confirmed that in such cases there are exactly 16 spaces between the title and movie type. So I changed this in the script. Instead of this


Code: [Select]

//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+'||');


I changed with this ( I choose to use >8 spaces just in case)
Code: [Select]

// 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 + '||');



It would be good Ivek to officially include it in FilmAffinity script if interested in, otherwise if someone is interested in, I can post my already customized script
« Last Edit: November 22, 2024, 09:15:41 pm by afrocuban »

Offline Ivek23

  • Global Moderator
  • *****
  • Posts: 2719
    • View Profile
Re: FilmAffinity correction
« Reply #1 on: November 23, 2024, 03:42:20 pm »
It would be good Ivek to officially include it in FilmAffinity script if interested in
No interested.

otherwise if someone is interested in, I can post my already customized script
You can post script.
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: 491
    • View Profile
Re: FilmAffinity correction
« Reply #2 on: November 23, 2024, 06:54:40 pm »
Thank you Ivek. Here is my script that corrects this.