Skip to content

Commit 57262e7

Browse files
committed
Add video download functionality and update video info
- Updated `Program.cs` in `Blink.ConsoleTest` to iterate over videos and print byte array lengths. - Added `GetVideoAsync(BlinkVideoInfo video)` method in `BlinkClient.cs` to download video clips. - Modified `GetVideosAsync` in `BlinkClient.cs` to set `NetworkId`, `ModuleId`, and `ManifestId` for each video. - Added `NetworkId`, `ModuleId`, and `ManifestId` properties to `BlinkVideoInfo.cs` with `[JsonIgnore]` attribute.
1 parent 5f8b34a commit 57262e7

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Sources/Blink.ConsoleTest/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ private static async Task Start()
3535
int count = videos.Count();
3636

3737
Console.WriteLine("Videos count: " + count);
38+
39+
foreach (var video in videos)
40+
{
41+
byte[] bytes = await client.GetVideoAsync(video);
42+
Console.WriteLine($"Video {video.Id} bytes: {bytes.Length}");
43+
}
3844
}
3945
}
4046
}

Sources/Blink/BlinkClient.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,35 @@ public async Task<IEnumerable<BlinkVideoInfo>> GetVideosAsync()
204204
var response = await _http.GetAsync(url);
205205
var videoResponse = await response.Content.ReadFromJsonAsync<VideoResponse>()
206206
?? throw new BlinkClientException("Failed to get videos - no content");
207+
foreach (var video in videoResponse.Videos)
208+
{
209+
video.NetworkId = module.NetworkId;
210+
video.ModuleId = module.Id;
211+
video.ManifestId = videoResponse.ManifestId;
212+
}
207213
return videoResponse.Videos;
208214
}
215+
216+
/// <summary>
217+
/// Get video from Blink camera.
218+
/// </summary>
219+
/// <param name="video"><see cref="BlinkVideoInfo"/> object with video data</param>
220+
/// <returns>Video as byte array</returns>
221+
public async Task<byte[]> GetVideoAsync(BlinkVideoInfo video)
222+
{
223+
string url = $"/api/v1/accounts/{_accountId}/networks/{video.NetworkId}/" +
224+
$"sync_modules/{video.ModuleId}/local_storage/manifest/{video.ManifestId}/clip/request/{video.Id}";
225+
226+
await _http.PostAsync(url, null);
227+
await Task.Delay(2500);
228+
229+
var response = await _http.GetAsync(url);
230+
string contentType = response.Content.Headers.ContentType?.MediaType ?? string.Empty;
231+
if (contentType != "video/mp4")
232+
{
233+
throw new BlinkClientException("Failed to get video - " + response.ReasonPhrase);
234+
}
235+
return await response.Content.ReadAsByteArrayAsync();
236+
}
209237
}
210238
}

Sources/Blink/Models/BlinkVideoInfo.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,23 @@ public class BlinkVideoInfo
3131
/// </summary>
3232
[JsonPropertyName("created_at")]
3333
public DateTime CreatedAt { get; set; }
34+
35+
/// <summary>
36+
/// Network ID
37+
/// </summary>
38+
[JsonIgnore]
39+
public int NetworkId { get; set; }
40+
41+
/// <summary>
42+
/// Sync module ID
43+
/// </summary>
44+
[JsonIgnore]
45+
public int ModuleId { get; set; }
46+
47+
/// <summary>
48+
/// Video Manifest ID
49+
/// </summary>
50+
[JsonIgnore]
51+
public string ManifestId { get; set; } = string.Empty;
3452
}
3553
}

0 commit comments

Comments
 (0)