Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloading recordings #12

Open
danielkucera opened this issue Nov 1, 2023 · 1 comment
Open

Downloading recordings #12

danielkucera opened this issue Nov 1, 2023 · 1 comment

Comments

@danielkucera
Copy link

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?

@danielkucera
Copy link
Author

I have found that #10 detects the freezes very good, the question is how to avoid them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant