Downloading files from an Amcrest security camera with Python

I got a few Amcrest Wifi security cameras for my mom’s house at her request. They’re pretty nice overall (My only complaint is that the web-interface doesn’t fully support Linux). I set one up to save a jpg snapshot to memory every minute and then flew across the country. When I wanted to access them, I couldn’t just put the SD-card in a computer or anything, and clicking all 14,000 of them seemed like a pain, so I decided to figure out how to get them with a Python script.

Most of the information you need to know to do this is in the Amcrest CGI SDK API Documentation. With that, I was able to figure out how to list the file names of all the jpgs on the disk and then download them one by one to my local drive.

To get a listing of file names you have to first set up authentication, create a Media File Finder instance, and save the number that is returned

Then, you have to do a search for a bunch of files (optionally within a date range). Here I am looking for all jpgs made on July 15th:

The %20  things are just the code for a space. Note that we had to pass the number from the factory above here for this to work. Ok! Now we should be able to list the files found. At first I tried doing this without dealing with cookies and I was able to list files but I could not get them to download even though I was using the same commands used by the web interface. I decided to use the Firefox Developer tools to watch the network while downloading files from there. I noticed some authentication cookies that I thought might help, so I just copied and pasted them into the code (cheating a bit, but whatever).

Then, to list and download a file, I used this:

Totally worked! The loop over files.iter_lines just searches through the like 15 lines of information that come out for each file for the one that has the path on it. I did some name mangling in the open line to strip off the root folder names from the camera path so I just had a nice file name in my directory, such as: 17-07-10-001-jpg-17-48-07[R][0@0][0].jpg

So this got me all my files from my vacation. I transferred 2GB of photos by running this in a loop (with security provided by a VPN on the router). It would be better if I could grab those cookies directly from the script instead of cheating with the web browser so if you know how to do that with requests, let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *