Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Downloading recordings #12

Description

@danielkucera

Hi,
thank you for the project.

I am trying to download all video files which I list with conn.files()

This is the function I am using:

def download(file):
    socket = Socket(AF_INET, SOCK_STREAM)

    conn = DVRIPClient(socket)
    conn.connect((argv[1], DVRIP_PORT), argv[2], argv[3])

    sock = Socket(AF_INET, SOCK_STREAM)
    sock.connect((argv[1], DVRIP_PORT))


    namepart = file.name.split('/')
    print(namepart)

    newname = "{}-{}".format(namepart[2], namepart[4])

    if os.path.exists(newname):
        have = os.path.getsize(newname)

        if have == file.length*1024:
            print("file complete")
            return

    sz = 0
    lastping = 0

    rdr = conn.download(sock, file.name)

    with open(newname, 'wb') as out:
        while True:
            chunk = rdr.read(16)
            sz += len(chunk)
            #print(sz)
            if not chunk: break
            out.write(chunk)
            out.flush()

            if time.time() > lastping + 10:
                lastping = time.time()
                print(conn.storageinfo())
    sock.close()

this only started working after I patched playback like this:

diff --git a/dvrip/playback.py b/dvrip/playback.py
index 6668ce5..4ad296f 100644
--- a/dvrip/playback.py
+++ b/dvrip/playback.py
@@ -26,6 +26,7 @@ class PlaybackParams(Object):
        # TODO there are more
        name:      member[str] = member('FileName')
        transport: fixedmember = fixedmember('TransMode', 'TCP')  # TODO
+       playmode:  fixedmember = fixedmember('PlayMode', 'ByName')
 
 class Playback(Object):
        action: member[PlaybackAction] = member('Action')

I took the parameter from a capture I made during download using the original activeX plugin:

 "Name" : "OPPlayBack", "OPPlayBack" : { "Action" : "Claim", "EndTime" : "2023-10-26 08:28:41", "Parameter" : { "FileName" : "/idea0/2023-10-26/001/08.25.00-08.28.41[R][@355c][0].h264", "IntelligentPlayBackEvent" : "", "IntelligentPlayBackSpeed" : -1, "PlayMode" : "ByName", "StreamType" : 0, "TransMode" : "TCP", "Value" : 0 }, "StartTime" : "2023-10-26 08:25:00" }, "SessionID" : "0x763" }

Before this, the downloaded file didn't match the FileSize parameter (maybe related to #9 ?)

There is one weird thing though, I need to keep "pinging" the api using some command (see conn.storageinfo() in my code) to prevent the download from freezing. This helps but it still freezes sometimes.

Do you have some idea how to make this flawless?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions