Created
February 15, 2015 01:57
-
-
Save vmichnowicz/15ea0d19e832fccee287 to your computer and use it in GitHub Desktop.
D-Link DCS-2330L Backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
import time | |
import os.path | |
username = "admin" | |
password = "password" | |
ip = "192.168.0.14" | |
mac = "" | |
url = "http://{}/config/sdcard_list.cgi?type=video&page=1&pagesize=999&path=/".format(ip) | |
# Get all daily folders | |
h = httplib2.Http(".cache") | |
h.add_credentials(username, password) | |
resp, content = h.request(url) | |
lines = content.splitlines() | |
items = lines[8] | |
items = items.replace("items=", "") | |
rows = items.rsplit(":") | |
days = {} | |
counter = 0 | |
# Loop through each row | |
for row in rows: | |
cells = row.rsplit("|") # date, "d", "n", number of files | |
days[ cells[0] ] = {} | |
# Loop through each day | |
for day in days: | |
url = "http://{}/config/sdcard_list.cgi?type=video&page=1&pagesize=999&path=/{}/".format(ip, day) | |
h = httplib2.Http(".cache") | |
h.add_credentials(username, password) | |
resp, content = h.request(url) | |
lines = content.splitlines() | |
items = lines[8] | |
items = items.replace("items=", "") | |
rows = items.rsplit(":") | |
times = [] # Array of hours ("19", "20", etc...) | |
# Loop through each row | |
for row in rows: | |
cells = row.rsplit("|") # hour, "d", "n", number of files | |
days[day][ cells[0] ] = [] | |
# Loop through each hour in this day | |
for hour in days[day]: | |
url = "http://{}/config/sdcard_list.cgi?type=video&page=1&pagesize=999&path=/{}/{}/".format(ip, day, hour) | |
h = httplib2.Http(".cache") | |
h.add_credentials(username, password) | |
resp, content = h.request(url) | |
lines = content.splitlines() | |
rows = [] | |
#raise Exception("Invalid data. URL: {}, content: {}".format(url, content)) | |
# If content is valid | |
if len(lines) >= 8: | |
items = lines[8] | |
items = items.replace("items=", "") | |
rows = items.rsplit(":") | |
# Loop through each row | |
for row in rows: | |
cells = row.rsplit("|") # file name, "f", "n", file size | |
file_name = cells[0] | |
# If image and file does not already exist (File will either be a .jpg or a .mp4 file) | |
if file_name.find(".jpg") > 0 and os.path.exists(file_name) == False: | |
print "Downloading {}".format(file_name) | |
url = "http://{}/cgi-bin/sddownload.cgi?file=/video/{}/{}/{}".format(ip, day, hour, file_name) | |
h = httplib2.Http(".cache") | |
h.add_credentials(username, password) | |
resp, content = h.request(url) | |
file_handle = open(file_name, "w") | |
file_handle.write(content) | |
file_handle.close() | |
counter = counter + 1 | |
# Nap time, camera turned off because of too many requests? | |
time.sleep(5) | |
print "Downloaded {} images".format(counter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script!
I have extended it a little bit and migrated it to Python 3 (print, str.decode).
Sincerely Torsten