[UPD ES] Filmaffinity 4.0

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Garada
Posts: 7
Joined: 2025-08-10 12:39:21

Re: [UPD ES] Filmaffinity 4.0

Post by Garada »

Me alegro que haya aparecido la solución. 🙂
Nadie se iba a imaginar que se había cambiado la aplicación por defecto del archivo VBS 😀

No te olvides de dejar la línea como estaba para que al terminar borre ese archivo temporal.
MrObama2022
Posts: 135
Joined: 2022-02-02 00:03:55

Re: [UPD ES] Filmaffinity 4.0

Post by MrObama2022 »

Ok, so ... vbs works.

For Garada, test this parameter in curl:

Code: Select all

w '%output{' + InstallerPath + curlOutputTmp + '}Download completed with response code %{http_code}\n' 
This is how the code should look now (I DON'T HAVE TESTED IT!)

Code: Select all

  if (fileExists(InstallerPath + curlOutput)) then
    DeleteFile(InstallerPath + curlOutput);  
  curlOutputTmp := curlOutput + '.tmp';
  if (fileExists(InstallerPath + curlOutputTmp)) then
    DeleteFile(InstallerPath + curlOutputTmp);  
    
  sCommand := '-L -w "%output{' + InstallerPath + curlOutputTmp + '}Download completed with response code %{http_code}\n" --output "' + InstallerPath + curlOutput + '" --url "' + address + '" ' + '-H "Accept: text/html, */*" -H "Accept-Language: it" -H "DNT: 1" -H "Priority: u=0, i" -H "Sec-Ch-Ua: \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"" -H "Sec-Ch-Ua-Mobile: ?0" -H "Sec-Ch-Ua-Platform: \"Windows\"" -H "Sec-Fetch-Dest: Document" -H "Sec-Fetch-Mode: Navigate" -H "Sec-Fetch-Site: None" -H "Sec-Fetch-User: ?1" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: ' + curlUserAgent + '"';

  Sleep(delayBetweenRequest);
  Launch(curlPath, sCommand); 
    
  cnt := 0;
  while ((not FileExists(InstallerPath + curlOutputTmp)) AND (cnt < 200)) Do
  begin
    cnt := cnt + 1;
    Sleep(50);
  end;  
  DeleteFile(InstallerPath + curlOutputTmp);
  if (fileExists(InstallerPath + curlOutput)) then
  begin  
    fileContent := TStringList.Create;
    fileContent.LoadFromFile(InstallerPath + curlOutput);
    [...]
How all this should work: Curl create InstallerPath + curlOutput file and SLOWLY it writes html in the file. Only AFTER the file is closed, Curl create another file, InstallerPath + curlOutputTmp and it writes something inside (Download completed with response code 200). When this file is created you can be 100% sure InstallerPath + curlOutput is closed and ready so you can use it.

Remember: this should work, I tested it but I deleted all the code so maybe you have to fix something with escaping, ', ", % or ... I don't remember now.

I did other test at your curl-only version but I don't like the prompt window (I got the same problem in mine curl-only version, that's why I deleted it). For a curl-only option I think we should wait for a new version of AMC where @antp will add an option to Launch command to hide its window.
Garada
Posts: 7
Joined: 2025-08-10 12:39:21

Re: [UPD ES] Filmaffinity 4.0

Post by Garada »

Good idea but I'm not sure it's necessary.

CURL should create/open the file for writing and keep it locked until it is closed.
While the file is locked it can't be renamed (MoveFile function), so wait for MoveFile function return success should be a good indicator that the process is complete.

Have you had trimmed results with the HTML file generated by CURL? If so, then all previous paragraph is useless. 😅

But I've made some tests checking the result is complete (looking for the end tag "</html>") and all of them were correct.


And yes, +1 for an udpated version of Launch function with a parameter to hide the program executed. 👍

BTW, on my system, the terminal icon briefly appears in the taskbar but not the entire window on the desktop. I mean, it runs minimized, Is that the case for you?
Garada
Posts: 7
Joined: 2025-08-10 12:39:21

Re: [UPD ES] Filmaffinity 4.0

Post by Garada »

NOTE 2: 😅

To avoid problems such as PACOIRIPO's, I would change the way the VBS file is executed.

Try this (not tested):

Code: Select all

Launch('wscript.exe', InstallerPath + vbsScript);
MrObama2022
Posts: 135
Joined: 2022-02-02 00:03:55

Re: [UPD ES] Filmaffinity 4.0

Post by MrObama2022 »

Garada wrote: 2025-08-16 18:55:25 Good idea but I'm not sure it's necessary.

CURL should create/open the file for writing and keep it locked until it is closed.
While the file is locked it can't be renamed (MoveFile function), so wait for MoveFile function return success should be a good indicator that the process is complete.

Have you had trimmed results with the HTML file generated by CURL? If so, then all previous paragraph is useless. 😅
I'm not 100% sure curl lock the file (we should double check), that's why I created tmp file. Before the tmp file, my ifs was something like this:

Code: Select all

while ((not FileExists(InstallerPath + curlOutput)) do Sleep(50);
fileContent := TStringList.Create;
fileContent.LoadFromFile(InstallerPath + curlOutput);
and this worked randomly, sometime this worked, sometime I got a blank response (without any pascal/amc error).

Have a look at this or try this powerscript file:

Code: Select all

# USE A HUGE FILE TO DOWNLOAD
# CHANGE X:\C.ts WITH YOUR PATH

$job = Start-Job {
    curl.exe -L 'http://PUT HERE A URL FOR A BIG FILE' --output 'X:\C.ts'
}

# CHANGE X:\C.ts WITH YOUR PATH
while (-not (Test-Path "X:\C.ts")) {
    Start-Sleep -Milliseconds 50
}

# CHANGE X:\C.ts WITH YOUR PATH
if ($job.State -eq 'Running') {
    try {
        $fs = [System.IO.File]::Open("X:\C.ts", 'Open', 'Read', 'ReadWrite')
        Write-Host "File Not Locked."
        $fs.Close()
    }
    catch {
        Write-Host "File Locked."
    }
}

$job | Wait-Job | Remove-Job
Garada wrote: 2025-08-16 18:55:25 But I've made some tests checking the result is complete (looking for the end tag "</html>") and all of them were correct.
It's up to your connection, your pc and how busy is the server. With a slow connection you could have problems and get a blank page.

Garada wrote: 2025-08-16 18:55:25 And yes, +1 for an udpated version of Launch function with a parameter to hide the program executed. 👍

BTW, on my system, the terminal icon briefly appears in the taskbar but not the entire window on the desktop. I mean, it runs minimized, Is that the case for you?
In my first test with your script it worked as you said. But in other tests it starts opening and closing dozens of time and every time I cannot minimize or put another window upon. I don't know why.
MrObama2022
Posts: 135
Joined: 2022-02-02 00:03:55

Re: [UPD ES] Filmaffinity 4.0

Post by MrObama2022 »

Garada wrote: 2025-08-16 19:05:03 NOTE 2: 😅

To avoid problems such as PACOIRIPO's, I would change the way the VBS file is executed.

Try this (not tested):

Code: Select all

Launch('wscript.exe', InstallerPath + vbsScript);
Great!

By the way, I'll be away for two weeks (holydays), so we can chat again at september. Love working with you :grinking:
Garada
Posts: 7
Joined: 2025-08-10 12:39:21

Re: [UPD ES] Filmaffinity 4.0

Post by Garada »

Have a great holiday!

When you get back, I will have a script ready with all the ideas that have been contributed. 👍
Radagast
Posts: 48
Joined: 2016-04-22 16:07:15

Re: [UPD ES] Filmaffinity 4.0

Post by Radagast »

Garada wrote: 2025-08-10 13:02:13 First, I would like to thank Antoine and Mickaël for many years of using AMC. 👍

Second, also to thank MrObama2022 for the new scripts, great. 🙂

I've made some changes to simplify the code and eliminate the dependency on Powershell and VS.
The following code calls CURL directly and use the pascal script MoveFile to handle the result.
No need to call the function setupScript.

Code: Select all

unit ExternalCurlHandler;

uses StringUtils7552;

const
  tmpDir = ''; // (optional) if you want get your scripts directory clean, set here your tmp working dir, example C:\Users\YOURWINDOWSUSER\AppData\Local\Temp\ . Remember to add \ at the end of the directory
  delayBetweenRequest = 2001;
  curlPath = 'curl.exe'; // if you use Windows 7 or 8 download curl.exe for Windows (it's free) and set here the right path
  curlOutput = 'curlOutput.html';
  curlUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36';

var
  InstallerPath: string;
  
function GetPage5Advanced(address: string; referer: string; cookies: string; content: string; headers: string): string;
var
  cnt: integer;
  fileContent: TStringList;
  curlOutputTmp: string;
  sCommand: string;
begin
  Result := '';

  if (tmpDir <> '') then
    InstallerPath := tmpDir
  else  
    InstallerPath := dirScripts;

  if (fileExists(InstallerPath + curlOutput)) then
    DeleteFile(InstallerPath + curlOutput);  
  curlOutputTmp := curlOutput + '.tmp';
  if (fileExists(InstallerPath + curlOutputTmp)) then
    DeleteFile(InstallerPath + curlOutputTmp);  
    
  sCommand := '-L --output "' + InstallerPath + curlOutputTmp + '" --url "' + address + '" ' + '-H "Accept: text/html, */*" -H "Accept-Language: it" -H "DNT: 1" -H "Priority: u=0, i" -H "Sec-Ch-Ua: \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"" -H "Sec-Ch-Ua-Mobile: ?0" -H "Sec-Ch-Ua-Platform: \"Windows\"" -H "Sec-Fetch-Dest: Document" -H "Sec-Fetch-Mode: Navigate" -H "Sec-Fetch-Site: None" -H "Sec-Fetch-User: ?1" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: ' + curlUserAgent + '"';

  Sleep(delayBetweenRequest);
  Launch(curlPath, sCommand); 
    
  cnt := 0;
  while ((not MoveFile(InstallerPath + curlOutputTmp, InstallerPath + curlOutput)) AND (cnt < 200)) Do
  begin
    cnt := cnt + 1;
    Sleep(50);
  end;  
  if (fileExists(InstallerPath + curlOutput)) then
  begin
    // wait until file is ready (you don't really need this)
    Sleep(5);    
    fileContent := TStringList.Create;
    fileContent.LoadFromFile(InstallerPath + curlOutput);
    Result := fileContent.Text;
    fileContent.Free;
    DeleteFile(InstallerPath + curlOutput);
  end;
end;

end.
Me voy de vacaciones y a la vuelta veo que hay movimiento, ¡¡fantástico :clapping: !!
Muchas gracias Garada, da tranquilidad que haya alguien más implicado del nivel de Antp, MrObama2022, etc...

He probado tú código y va bien, aunque en mi caso como comenta MrObama2022 se ve durante unos instantes la ventana CMD. Ningún problema por mi parte que se vea, lo que decidáis me parece bien.

Muchas gracias a todos!!!
Radagast
Posts: 48
Joined: 2016-04-22 16:07:15

Re: [UPD ES] Filmaffinity 4.0

Post by Radagast »

Si a alguien por casualidad le deja de funcionar el script en estas 2 situaciones.
Con la versión portable de AMC en un pendrive y al conectarlo cambia la letra de unidad asignada la última vez, o cambia la ubicación de la carpeta scripts en un AMC instalado.
Para que vuelva a funcionar es necesario borrar el archivo ExternalCurlHandler.vbs ubicado en la carpeta scripts para que se vuelva a generar.

Esto es para la versión de MrObama2022, a la versión de Garada no le afecta al llamar directamente a curl.
Last edited by Radagast on 2025-08-22 22:26:38, edited 1 time in total.
Radagast
Posts: 48
Joined: 2016-04-22 16:07:15

Re: [UPD ES] Filmaffinity 4.0

Post by Radagast »

Garada wrote: 2025-08-16 19:05:03 NOTE 2: 😅

To avoid problems such as PACOIRIPO's, I would change the way the VBS file is executed.

Try this (not tested):

Code: Select all

Launch('wscript.exe', InstallerPath + vbsScript);
He probado a cambiar la linea

Code: Select all

Launch(InstallerPath + vbsScript, '');
por la que comentas.
En la versión instalada de AMC funciona bien.
En la versión portable solo me funciona bien si el path donde está AMCportable no contiene espacios.
Si contiene espacios sale una ventana de error Windows Script Host que dice No existe ninguna extension de archivo en "I:\Ant", el path donde está AMCportable es I:\Ant Movie Catalog (portable)\. Es como si los espacios evitaran que se cogiera el path completo, pero solo en la versión portable.
Si utilizo la linea original de MrObama2022 o elimino los espacios del path de AMCportable funciona bien
Post Reply