Page 8 of 8

Re: [UPD ES] Filmaffinity 4.0

Posted: 2025-08-15 21:54:52
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.

Re: [UPD ES] Filmaffinity 4.0

Posted: 2025-08-15 22:01:47
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.

Re: [UPD ES] Filmaffinity 4.0

Posted: 2025-08-16 18:55:25
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?

Re: [UPD ES] Filmaffinity 4.0

Posted: 2025-08-16 19:05:03
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);

Re: [UPD ES] Filmaffinity 4.0

Posted: 2025-08-16 23:55:58
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.

Re: [UPD ES] Filmaffinity 4.0

Posted: 2025-08-17 00:03:15
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: