0

This question is similar to this one: Is it possible to download using the Windows command line?, but with the small difference that, since the browser is the only program allowed to access the internet, it is the only option available. As far as I understand, I would say that the answer is "no way". I tried something like:

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"  http://website.com/remotepicture.jpg > ./localfile.jpg

but, unsurprisingly, I got just an empty file.

Then I tried using a local html file, but I got to another dead end related to CORS: still getting an empty file.

<!DOCTYPE html>
<html>
  <head>
    <META HTTP-EQUIV="Refresh" CONTENT="600">
  </head>
<body>
  <script>
  function forceDownload(blob, filename) {
    var a = document.createElement('a');
    a.download = filename;
    a.href = blob;
    document.body.appendChild(a);
    a.click();
    a.remove();
   }
   // Current blob size limit is around 500MB for browsers
   function downloadResource(url, filename) {
     if (!filename) filename = url.split('\\').pop().split('/').pop();
     fetch(url, {
       headers: new Headers({
         'Origin': location.origin
       }),
       mode: 'no-cors'
     })
     .then(response => response.blob())
     .then(blob => {
       let blobUrl = window.URL.createObjectURL(blob);
       forceDownload(blobUrl, filename);
     })
     .catch(e => console.error(e));
   }
   downloadResource('http://www.klevischer-verein.de/webcam/schwanenturm.jpg');
  </script>
</body>
</html>

1 Answers1

1

At this point, I think there's no solution in the way I wanted it (directly through the browser). So, I thank everyone for the tips and in particular DrMoishe Pippik for suggesting me to look into the browser cache. In the end, I wrote a short VBScript file to find the picture I'm looking for based on its characteristics (file size and age, and picture size). It is not very reliable, but it seems effective. Then I used a (pretty straightforward) local html file to cache the resource every n minutes. Here is the vbs code for future reference:

On Error Resume Next
sOrigin = "C:\Users\xxxxxxxxx\AppData\Local\Microsoft\Edge\User Data\Default\Cache"           'Path to check for files
repeattime = 10                                                                                     'check again every n minutes
maxage = 5
minsize = 50                                                                                       'minimum file size in kB
maxsize = 150                                                                                       'maximum file size in kB
width = 640   
height = 480

Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject") Set objImage = WScript.CreateObject("WIA.ImageFile") Set objShell = WScript.CreateObject( "WScript.Shell" ) objShell.Run("cmd.exe /C peek.html") 'launch the browser Set oFolder = oFileSys.GetFolder(sOrigin)

lastcheck = Now Do For Each oFile In oFolder.Files 'only files not older than [maxage] minutes If (DateDiff("n", oFile.DateLastModified,lastcheck) < maxage) Then ' Or use DateCreated, if you wish 'only files between the limits If (oFile.Size > minsize1024 And oFile.Size < maxsize1024) Then 'check if it is an image oFileSys.CopyFile oFile.Path, ".\pictures\image.jpg", True objImage.LoadFile ".\pictures\image.jpg" If (Err.Number <> 0 Or objImage.Width <> width Or objImage.Height <> height) Then oFileSys.DeleteFile ".\pictures\image.jpg" Err.Clear Else Exit For End If End If End If Next

lastcheck = Now
WScript.Sleep 1000*60*repeattime

Loop