Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Weird issue with downloading files from a GoPro.

$
0
0

I have a Sketch that is intended to download the files from a WiFi attached GoPro. The GoPro runs a Web server so the only way to download the files is to scrape the filenames from the webpage and download them which is mostly working. In this case though the GoPro currently has files from "GOPR00302.JPG" to "GOPR0509.JPG" on it's SD card. The sketch below works fine until it gets to one particular file "GOPR0335.JPG" and then it just locks up, no errors or anything if I artificially create "GOPR0335.JPG" in the download directory then as designed the code skips it as already downloaded and downloads the rest of the files with no issues. The file doesn't appear to be obviously corrupt as I can view and download it from a web browser but even if it was corrupt without any sort of trappable error I can't skip it. If I force the sketch to always download a specific file (E.G. GOPR0334 or 0336) by inserting the line "LastFIle="GOPR0334"; etc. before the line "img = loadImage(URL_BASE +LastFile+".JPG");" then it download those images fine and if I set it to LastFIle="GOPR0335" it locks up so it only seems to have an issue with that one particular file with no obvious way to trap the problem.

import processing.net.*;

Client c;
String URL_BASE = "http://" + "10.5.5.9:8080/DCIM/100GOPRO/";  // Where the Gopro stores it's images
String LastFile=".";
int LastSavedFile=0;
String NewFile=".";
PImage GoProImage;

void draw() {
  background(220, 220, 255);
  //
  {
    ScanGoProDisk(URL_BASE);
    println(LastFile);
  }
}

//Scan Gopro and return last file saved as "LastFile"
String ScanGoProDisk(String URL)
{
  String lines[] = loadStrings(URL);

  for (int i = 0; i < lines.length; i++)
  {
    String[] m=match(lines[i], "href=\"(.*?).JPG\">GO");
    String[] mn=match(lines[i], "href=\"GOPR(.*?).JPG\">GO");
    if (m != null)
    {
      println(m[1]);
      LastFile=m[1];
      println(mn[1]);

      if (int(mn[1])>LastSavedFile)
      {
        PImage img = loadImage(LastFile+"B.JPG");
        if (img == null) // Not downloaded yet
        {
          img = loadImage(URL_BASE +LastFile+".JPG");
          if (img != null)
          {
            img.save(LastFile+"B.JPG"); // Cache of the file
            LastSavedFile=int(mn[1]); //store last downloaded image to speed up scanning
          } else
          {
            println("Unable to load the image from " + URL_BASE + LastFile+".JPG");
            exit();
          }
        }
      }
    }
  }

  return LastFile;
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles