Canon ccapi contents` returns 100 images only

459 Views Asked by At

I am using Canon ccapi to download the last image taken. I am trying to find it by getting the list of all the photos from contents request and then download the last one

http://<camera-ip>:8080/ccapi/ver100/contents/sd/100CANON

but actually it returns the first 100 cameras only, although there are 100 cameras inside 100CANON folder. Is there any parameter to pass to contents request? Is there any normal documentation that describes behavior of each request avaliable?

2

There are 2 best solutions below

0
ekatz On

In summary, what you want is /ccapi/ver100/event/polling?continue=off, and poll that to find the latest file added under addedcontents. Python info below, but if you're working with a more basic URL setup, just refresh your query shortly after hitting the shutter.

Canon CCAPI documentation is for some reason nonexistent. I found a helpful open source library to scour the endpoints here: Canomate.

The repo has this python file with a function called pollForNewFilesOnCamera. Here's a dumbed down version of that function for a python script.

# returns the number of seconds that have elapsed since
# the specified anchor time. if the anchor time is None
# then this routine returns the current time, which
# the caller can use for a subsequent call to get elapsed
# time. time values are floats
#
def secondsElapsed(timeAnchor):
    timeCurrent = time.time()
    if timeAnchor == None:
        return timeCurrent
    return timeCurrent - timeAnchor

#
# Waits for camera to indicate new file(s) are available on the camera (ie, a photo or video has
# been taken since the last time the camera was polled).
# @param maxWaitTimeSecs - Maximum time to wait for new file(s) before giving up. If this value is
# zero then the camera will only be polled once
# @return  An array of CCAPI URLs to the new file(s) or None if no new files were indicated
#
def pollForNewFilesOnCamera(maxWaitTimeSecs=10, pollIntervalSecs=0.5):
    timeStart = secondsElapsed(None)
    while True:
        updates = requests.get(config.BASE_URL+endpoint_new_files)
        data = updates.json()
        if 'addedcontents' in data:
            print(data['addedcontents'])  # sample return value: 'http://192.168.1.142:8080/ccapi/ver100/contents/sd/100CANON/IMG_0327.JPG'
        if maxWaitTimeSecs == 0 or secondsElapsed(timeStart) >= maxWaitTimeSecs:
            return None
        print("Delaying {:.2f} on poll for new files".format(pollIntervalSecs))
        time.sleep(pollIntervalSecs)

pollForNewFilesOnCamera()
0
Gregor von Laszewski On

As CCAPI is limited to 100 images per page, you can request the number of pages and then repeat to get all images. or you can just get the last image from the last page, or you use polling in the previous answer.

If you like to have a python library that does all images in a list, you can use

https://github.com/laszewsk/canon-r7-ccapi

camera = CCAPI(ip=<your IP>)
images = camera.contents()
print (images)

here is a jupyter notebook showcasing some features

https://github.com/laszewsk/canon-r7-ccapi/blob/main/examples/notebook.ipynb