Code Monkey home page Code Monkey logo

dahua.api's Introduction

Dahua.Api

  • Available as nuget

  • dotnet add package Dahua.Api --version 1.0.1

  • NuGet Downloads

  • Wrapper over Dahua SDK. It allows login, fetch videos list, download videos, get config list and more.

  • Or just run console app sample

Initialization

DahuaApi.Init();

Login. Returns DahuaApi

var session = DahuaApi.Login("192.168.1.63", 37777, "admin", "pass");

Logout

session.Logout();
DahuaApi.Cleanup();

Print list of IP channels for NVR (IP Camera use hikapi.DefaultIpChannel)

Console.WriteLine("Channel:" + string.Join(",", session.AllChannels.Select(t => $"Channel{t.Id}_{t.Name}")));

Get machine name.

session.ConfigService.GetMachineName();

Get device serial number.

session.ConfigService.GetDeviceSerialNumber();

Get device type.

session.ConfigService.GetDeviceType();

Get device current time

session.ConfigService.GetTime();

Set device time

var currentTime = DateTime.Now;
session.ConfigService.SetTime(currentTime);

Video service

Get videos list from IP Camera (default IP channel). Returns IReadOnlyCollection<RemoteFile>

var videos = session.VideoService.FindFiles(DateTime.Today, DateTime.Now);

Get videos list from IP Camera (specific IP channel)

int channel = 2;
var videos = session.VideoService.FindFiles(DateTime.Today, DateTime.Now, channel);

Download video

foreach (var video in videos)
{
    Console.WriteLine(video.Name);
    var name = $"{video.Date.ToString(DateFormat)}_{video.Duration}.mp4";
    var destinationPath = Path.Combine(@$"C:\Users\{Environment.UserName}\Desktop", name);
    var downloadId = session.VideoService.StartDownloadFile(video, destinationPath);
    if (downloadId > 0)
    {
        Console.WriteLine($"Downloading {destinationPath}");
        do
        {
            await Task.Delay(5000);
            var downloadProgress = session.VideoService.GetDownloadPosition(downloadId);
            Console.WriteLine($"Downloading {downloadProgress} %");
            if (downloadProgress.downloadSize == downloadProgress.totalSize)
            {
                session.VideoService.StopDownloadFile(downloadId);
                break;
            }
            else if (!downloadProgress.success)
            {
                throw new InvalidOperationException($"UpdateDownloadProgress failed, progress value = {downloadProgress}");
            }
        }
        while (true);
        Console.WriteLine($"Downloaded {destinationPath}");
    }
}

dahua.api's People

Contributors

vov4uk avatar aaasoft avatar

Stargazers

Kurt-0x99b8f2 avatar  avatar Galli Davide Francesco Maria avatar

Watchers

 avatar

Forkers

kravitzmc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.