JurajNyiri / pytapo

Python library for communication with Tapo Cameras
MIT License
290 stars 59 forks source link

The downloader gets a wrong video file #116

Closed t-yrka closed 4 months ago

t-yrka commented 4 months ago

I'm not sure if the camera or the library causes this behavior. It seems like it cannot download a video outside of the day it was searching last time.

I'm using pytapo in version pytapo==3.3.21 with camera model C310 (1.3.9).

How to reproduce:

import asyncio
import os

from pytapo import Tapo
from pytapo.media_stream.downloader import Downloader

ip = "CAMERA_IP"
password = "CLOUD_PASSWORD"

download_dir = "./"
file_name = "video.mp4"
assert not os.path.exists(os.path.join(download_dir, file_name))

t = Tapo(ip, "admin", password, password)

recordings = t.getRecordings("20240610")
target_info = next(iter(recordings[0].values()))
start_time = target_info["startTime"]
end_time = target_info["endTime"]

# === trigger list for a different date ===
t.getRecordings("20240611")
# =========================================

time_correction = t.getTimeCorrection()
print(f"Downloading video for {start_time=}->{end_time=}")
d = Downloader(t, start_time, end_time, time_correction, download_dir, fileName=file_name)

asyncio.run(d.downloadFile())

start_time points to the correct video timestamp, but as a result, a video from 2024.06.11 is downloaded instead. Removing the line t.getRecordings("20240611") makes the issue disappear. When the second getRecordings refers to an older date then the download fails to get anything.

Is it a bug, or a known behavior?

JurajNyiri commented 4 months ago
recordings = t.getRecordings("20240610")
t.getRecordings("20240611")

You need to ensure the date is the same.

t-yrka commented 4 months ago
recordings = t.getRecordings("20240610")
t.getRecordings("20240611")

You need to ensure the date is the same.

But it does not make any sense. The second getRecordings should NOT impact the downloader. I'm not using anything it returned.

JurajNyiri commented 4 months ago

Oh I see, sorry I missed that.

The script is intended to be used just for a one date, it tells the camera in the background which date it needs to start the stream off of.

t-yrka commented 4 months ago

Oh I see, sorry I missed that.

The script is intended to be used just for a one date, it tells the camera in the background which date it needs to start the stream off of.

I'm not using the script - I was hoping to use the Tapo and the Downloader classes directly. It's really weird some calls may affect the behavior of others in such a way. You call the Downloader to get the video for timestamp X and you may get something completely different without any info/warning.