KoenZomers / RingRecordingDownload

Console Application for Windows, Raspberry Pi, Linux and macOS which allows for downloading of Ring recorded events
Apache License 2.0
20 stars 9 forks source link

Download Fails after some time #17

Closed kstst closed 2 months ago

kstst commented 1 year ago

Describe the bug Using the command to download files, download starts and completes sucessfully for many files but then stops downloading and displays the folowing type of error. 28 - 2023-08-04 11-19-53 (7263502632197942188).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 2/3. Downloads can only be restarted with a new list and sms re authentication. Increasing the retries to seems to allow it to recover at times. The list command must be issued twice before the sms authentication will be requested.

To Reproduce Steps to reproduce the behavior: Using a ring camera creating almost continuous files of approx 1 minute video.

  1. Use command with -startdate "08-04-2023 11:00:00" -enddate "08-04-2023 12:00:00" -deviceid 155xxxxxx
  2. Watch files sucessfully download until error
  3. Subsequent reissue of exact command displays the following error. Unhandled exception. KoenZomers.Ring.Api.Exceptions.SessionNotAuthenticatedException: This session has not yet been authenticated. Please call Authenticate() first. at KoenZomers.Ring.Api.Session.EnsureSessionValid() at KoenZomers.Ring.Api.Session.GetDoorbotsHistory(DateTime startDate, Nullable1 endDate, Nullable1 doorbotId) at KoenZomers.Ring.RecordingDownload.Program.Main(String[] args) at KoenZomers.Ring.RecordingDownload.Program.
    (String[] args)
  4. Issuing list command initiates request for authentication code and new session. Connecting to Ring services Authenticating using provided username and password Two factor authentication enabled on this account, please enter the Ring token from the e-mail, text message or authenticator app: 800xxx Retrieving all devices... 4 found Connecting to Ring services Authenticating using refresh token from previous session Downloading all historical events between Friday 4 August 2023 11:00:00 and Friday 4 August 2023 12:00:00 for Ring device 15xxxx

Expected behavior Download to continue - without having to reauthenticate via sms

Screenshots If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

BudGreen commented 1 year ago

I can confirm same. Sometimes the auth key lasts for up to 15 minutes, other times it times out in less than 5 minutes. Issue a new key and you can continue but will get knocked off soon after.

Versions (please complete the following information): OS: Windows 10 22H2 Ringrecordingdownload: 3.1.0.0 authissue

AndrewRathbun commented 10 months ago

I've been running this a lot lately, and I've noticed that pretty consistently it fails on or right before 75 videos, if it doesn't fail prior to that. Not sure if that's a limit on RIng's side or not 🤷

dfliss commented 10 months ago

I'm encountering the same issue, but the length of time before the session expires appears to be inconsistent.

5E7EN commented 8 months ago

Any update on this issue? @KoenZomers 🔔 😉 Curious if perhaps it only involves a small change in the auth / refresh token logic?

5E7EN commented 8 months ago

After some research, it appears that the issue is caused by an oversight in the OAuthToken assignment.

The logic that checks for token expiry is not using a valid datetime (since the initial assignment is broken) and thinks the token has expired each time the EnsureSessionValid() is called, thus spamming the API unnecessarily - for every video download. After enough requests, the auth API gives way with the error below.

I will be making a PR to address this bug shortly.


Error ``` {"error":"too-many-token-request","error_description":"request not allowed"} ```
danespinosa commented 6 months ago

@5E7EN I have made some comments in your PR, your changes should fix the issue.

5E7EN commented 6 months ago

@5E7EN I have made some comments in your PR, your changes should fix the issue.

I don't see any comments

danespinosa commented 6 months ago

https://github.com/KoenZomers/RingRecordingDownload/pull/20#pullrequestreview-1985252565

@5E7EN here the direct link.

Thanks for the PR

5E7EN commented 6 months ago

#20 (review)

@5E7EN here the direct link.

Thanks for the PR

I may be seeing things (or lack thereof) but I cannot see your review / comments. Is it still a draft?

danespinosa commented 6 months ago

#20 (review) @5E7EN here the direct link. Thanks for the PR

I may be seeing things (or lack thereof) but I cannot see your review / comments. Is it still a draft?

Thanks @5E7EN I have published it as a single comment, my comment is if you can update the code to be the same as the Ring API to keep things consistent.

        private int _expiresInSeconds;
        /// <summary>
        /// Gets the amount of seconds after creation of this OAuth token after which it expires
        /// </summary>
        [JsonPropertyName("expires_in")]
        public int ExpiresInSeconds
        {
            get { return _expiresInSeconds; }
            set { _expiresInSeconds = value; ExpiresAt = DateTime.Now.AddSeconds(value); }
        }

        /// <summary>
        /// Gets a DateTime with when this token expires
        /// </summary>
        public DateTime ExpiresAt { get; private set; }

https://github.com/KoenZomers/RingApi/blob/master/Api/Entities/OAuthToken.cs#L28

danespinosa commented 4 months ago

@5E7EN were you abel to look at my comments in your PR?

abulsme commented 3 months ago

Just a note, since this fix hadn't been put into a release yet, and this problem has been actively blocking me, I merged the patch and compiled to binary myself. It did get rid of the previous error, but I am getting a new error and in the end have the same result, which is that after downloading successfully for awhile, it stops succeeding until I remove my config file and re-authenticate with two factor authentication.

I'm using a command like:

RingRecordingDownload -out RingDriveBUP -retries 10 -startdate "04-01-2024 00:00:00" -enddate "04-01-2024 23:59:59" -deviceid XXXXXX -username XXX@XXXX.XXX -password "XXXXXXXX";

The old errors looked like this:

Ring Recordings Download Tool v3.1.1.0 by Koen Zomers

Connecting to Ring services Authenticating using refresh token from previous session Downloading all historical events between Monday 1 April 2024 00:00:00 and Monday 1 April 2024 23:59:59 for Ring device XXXXXX 35 items found, downloading to /home/abulsme/RingPorchBUP 1 - 2024-04-01 21-52-39 (7353128145762781599).mp4... done (4 MB) 2 - 2024-04-01 21-22-48 (7353120453476354463).mp4... done (7 MB) 3 - 2024-04-01 20-48-22 (7353111580073920927).mp4... done (4 MB) ... 18 - 2024-04-01 14-52-08 (7353019779442936223).mp4... done (4 MB) 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 2/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 3/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 4/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 5/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 6/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 7/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 8/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 9/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Retrying 10/10. 19 - 2024-04-01 14-43-17 (7353017498815302047).mp4... failed (This session has not yet been authenticated. Please call Authenticate() first.). Giving up.

From then on every attempt fails until reauthentication.

Now it looks like:

Ring Recordings Download Tool v3.1.1.0 by Koen Zomers

Connecting to Ring services Authenticating using provided username and password Two factor authentication enabled on this account, please enter the Ring token from the e-mail, text message or authenticator app: XXXXXX Downloading all historical events between Monday 1 April 2024 00:00:00 and Monday 1 April 2024 23:59:59 for Ring device XXXXXX 35 items found, downloading to /home/abulsme/RingPorchBUP 1 - 2024-04-01 21-52-39 (7353128145762781599).mp4... done (4 MB) 2 - 2024-04-01 21-22-48 (7353120453476354463).mp4... done (7 MB) 3 - 2024-04-01 20-48-22 (7353111580073920927).mp4... done (4 MB) 4 - 2024-04-01 20-24-29 (7353105425385785759).mp4... done (4 MB) 5 - 2024-04-01 17-31-26 (7353060830740351391).mp4... done (4 MB) ... 30 - 2024-04-01 12-15-03 (7352979299376171423).mp4... done (4 MB) 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 2/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 3/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 4/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 5/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 6/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 7/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 8/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 9/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Retrying 10/10. 31 - 2024-04-01 11-06-15 (7352961569751173535).mp4... failed (Downloading of the recorded Ring event from '(no URL was created)' failed). Giving up.

Again failing on every request until I do the 2-factor authentication again.

It seems like it will succeed for longer now than it did before (130+ instead of more like 80), but still eventually stops working until re-authenticated.

I'm trying to run this unsupervised via cron to just download all my videos routinely, but with it needing to be re-authenticated regularly, I currently have to do it manually.

danespinosa commented 3 months ago

Hi @abulsme, I have merged the changes that fix the authentication issue to the main branch, here is the new release. https://github.com/KoenZomers/RingRecordingDownload/releases/tag/3.2.0.0

Regarding the new problem, I believe your issue could be more than authentication issue, I have created a branch that adds some verbose logging, can you pull this branch and run your job see if we get mor insights?

https://github.com/KoenZomers/RingRecordingDownload/tree/verboseResponse

abulsme commented 3 months ago

OK, downloaded and compiled the Verbose response version and ran it.

It didn't actually last very long the first time before it started erroring. I attached the output.

FirstRunRingVerbose.txt

I stopped it after awhile rather than letting it continue to fail.

I then ran the same command again without removing the config file and got:

Ring Recordings Download Tool v3.2.0.0 by Koen Zomers

Connecting to Ring services Authenticating using refresh token from previous session Unhandled exception. System.AggregateException: One or more errors occurred. (Authentication of the session failed) ---> KoenZomers.Ring.Api.Exceptions.AuthenticationFailedException: Authentication of the session failed at KoenZomers.Ring.Api.HttpUtility.FormPost(Uri url, Dictionary`2 formFields, NameValueCollection headerFields) at KoenZomers.Ring.Api.Session.RefreshSession(String refreshToken) at KoenZomers.Ring.Api.Session.GetSessionByRefreshToken(String refreshToken) --- End of inner exception stack trace --- at KoenZomers.Ring.RecordingDownload.Program.Main(String[] args) at KoenZomers.Ring.RecordingDownload.Program.

(String[] args) Aborted (core dumped)

I then removed the config file and ran it again. This time it finished downloading all the videos from the first date I gave it to download, so I gave it the next day, and then the next, etc until I got errors again. It actually took a really long time to fail again this time. This time it failed in completely different ways though.

Output attached:

SecondRunRingVerbose.txt

I just repeated this several times, one of the videos failed the same way each time. The other one that had failed initially worked the other attempts.

ThirdRunRingVerbose.txt

Since I still hadn't had the same kind of failure, I figured I'd continue further with more days though.

FourthRunRingVerbose.txt

It finally had the original failure type again. I let it run for two or three minutes before doing a Control-C and stopping it.

And running it again at that point once again gets:

[vps40378]$ /home/abulsme/RingRecordingDownloadVerbose -out /home/abulsme/RingDriveBUP -retries 10 -startdate "04-11-2024 00:00:00" -enddate "04-11-2024 23:59:59" -deviceid XXXXXX -username XXXXXX -password "XXXXXX"

Ring Recordings Download Tool v3.2.0.0 by Koen Zomers

Connecting to Ring services Authenticating using refresh token from previous session Unhandled exception. System.AggregateException: One or more errors occurred. (Authentication of the session failed) ---> KoenZomers.Ring.Api.Exceptions.AuthenticationFailedException: Authentication of the session failed at KoenZomers.Ring.Api.HttpUtility.FormPost(Uri url, Dictionary`2 formFields, NameValueCollection headerFields) at KoenZomers.Ring.Api.Session.RefreshSession(String refreshToken) at KoenZomers.Ring.Api.Session.GetSessionByRefreshToken(String refreshToken) --- End of inner exception stack trace --- at KoenZomers.Ring.RecordingDownload.Program.Main(String[] args) at KoenZomers.Ring.RecordingDownload.Program.

(String[] args) Aborted (core dumped)

I swear other times it has always failed much more quickly, but this time it lasted quite some time.

Anyway, hope all the output above is helpful to diagnose. Let me know if you need more or different.

Thanks!

danespinosa commented 3 months ago

Thanks @abulsme, these files give me enough data to fix the issue, by the way, some files contain your user and pass, make sure you update your password!

I'll work on a fix in the verbose branch and let you know once it's ready so we can test it before releasing the fix

abulsme commented 3 months ago

Drat, I thought I had caught all of them and made them XXXXXX before uploading the final versions. Guess I missed some. Oh well! :-)

danespinosa commented 3 months ago

@abulsme, I pushed new changes to the verbose branch, can you give it a try, please?

The change allows the program to re-authenticate using the RefreshToken if an API call returns 401, I also added a new line that logs the ExpiresAt before trying to renew the token. https://github.com/KoenZomers/RingRecordingDownload/tree/verboseResponse

abulsme commented 3 months ago

OK. Did that. Started running it asking for a day at a time of videos again. Did April 18 and 19, then stepped away from the computer for an hour or so before trying the 20th, and it had an unhandled exception right away. Removed the config file and started again. Did the 20th to 25th successfully. It errored out 64 downloads into the 26th.

Log attached. Hopefully I got all the IDs and PWs this time. :-)

FirstRunRingVerbose2.txt

danespinosa commented 3 months ago

@abulsme, I updated the code, the refresh token should only be updated if the refresh token is null in the app.config, can you please delete the RefreshToken from your app.config, download and run the verboseBranch exe again with user and password? I hope this should fix the unauthorized issue when renewing the access token.

abulsme commented 3 months ago

OK. Here goes after downloading and recompiling it again. Since I renamed to RingRecordingDownloadVerbose3 I started out with no config file at all. I started one day at a time from April 26 to April 30th, then just asked for all of May at once. It got to the 82nd video in the May batch before failing.

Here is the output:

FirstRunRingVerbose3.txt

Another question while I have you here... Notice on my run for all of May it starts at May 31st, then goes back in time, eventually getting to midway through May 29th before failing.

If I now were to use the -resumefromlastdownload option, where would it start from? It seems like if in situations like this it would always start from the OLDEST video and move toward the newest, then this would have a clear result. After a failure it would pick up where it left off and continue marching toward the present. But since it starts at the newest and works back, if it really started with the last successful, then it would just repeat the part of the 29th it already had, then repeat the 30th and 31st, never realizing it has missed most of that month. Or does it use the date of the most recent video, but only if it had successfully completed every video in the batch? So in this case, since my last fully successful command was the one where I got April 30th, it would just go with everything May 1st and beyond?

Checking the config file, in this case it has:

<add key="LastdownloadedRecordingId" value="7375407622890828964" />

So neither of the options I mentioned above. Instead this corresponds to the very first video it downloaded in the May batch, which was the last video on May 31st, so looks like if I tried resume, it would start working on June through the present, and never realize it had in fact missed lots of videos in May.

Because of this when I had automation going in the past, I'd have it run very frequently (hourly) with the resumefromlastdownload flag, so it would be harder for it to get interrupted and miss anything.

Seems like to be more robust in this situation you'd want to start with the oldest video and work your way forward in time rather than the other way around. That way if you fail, you just pick up where you left off next time. (Another possibility, having an option to just tell it to grab any video you don't already have in your destination folder, optionally subject to start and end time constraints.)

(I also ran a separate copy for each camera, so it would keep track of the last downloaded separately for each one.)

Sorry to diverge to something separate, this probably should be its own thread. But watching the failures here made me think of this again. Even if this issue gets fixed completely, there are all sorts of reasons you could fail mid-download (server reboots, internet connection goes down, etc) so being able to pick up again from the right spot ends up being important.

Thanks for all your help here!

danespinosa commented 3 months ago

@abulsme , would you mind creating a new discussion/issue for the new topic please?

Regarding the current issue, it seems the AccessToken and RefreshToken become invalid for an uknown reason, from the logs it seems they are not expired time-wise but still become unauthorized, can you think of any reason this can happen? Why would your tokens would lose validity? Also, I updated the branch with some missing headers and form fields when getting an access token to make sure that's not the root cause of the issue, can you try again please?

abulsme commented 3 months ago

Started a new thread on the LastdownloadedRecordingId and resumefromlastdownload thing.

I don't have any ideas on why they might lose validity. The server I am running on is on Pacific time in case time zones are an issue. (Sometimes things get screwed up if time zone assumptions are different, not that I have anything indicating that is the issue here, just giving more info.)

I downloaded and recompiled the newest verbose version and am running it on May 2024 now. 200+ videos in and hasn't failed yet. I'll report back once I get a failure. (Or I suppose if I run out of videos to download and it hasn't failed. :-) )

abulsme commented 3 months ago

And here it is:

FirstRunRingVerbose4.txt

Failed on the 477th video. (The 232rd also had an issue, but it gave up after 10 tries and continued with the next one, the 477th one was fatal.)

abulsme commented 3 months ago

Could it be some sort of rate limiting with Ring just rejecting if it gets too many requests within some time frame or some such? I'm not sure I have seen a consistent pattern on how quickly it fails though. But wondering if throttling the requests to just come in slower might make a difference if it is something like that.

danespinosa commented 3 months ago

I am suspecting is some sort of rate-limiting DoS mechanism, I would expect a 429 response, but the reality is that I don't know the internal implementation of the Ring API. For now I think we have a few options, let me know your thoughts.

1.- If program throws unauthorized try to re-authenticate with user/password at that point the user receives a 2FA SMS and the users needs to input it manually. This should be a last resort because you want this to be a background process. 2.- the applicaiton allows the user to specify a back-off/cool-down time between API calls in case Ring is expiring the token, not ideal since it can take a long time to download all videos. 3.- After unauthorized is thrown, back off/cool-down for 5/10 seconds, then retry to refresh token again in case the Unauthorized error is transient.

Let me know your thoughts.

abulsme commented 3 months ago

If you can get one of these errors, wait a while, and then recover (#3), that would be best of course. It seems like in order to recover you have to do the 2FA again though, so this may not work.

In that case, #2 would be next. I "fell behind" because there was a period where I couldn't get this to work at all, so I've got months of videos from two cameras to catch up on. But "normally" I'd just be running an hourly job to pick up new videos from the last hour or some such, which might not hit a rate limit.

But when downloading a lot of history, the delay could indeed be annoying. But in the end, as long as I'm downloading videos faster than they get created, I can still catch up. So even a 30 second or a minute delay between videos would still eventually catch up. I guess unless you had a camera in a place that never didn't trigger. That long a delay might be frustrating when trying to catch up and download months of videos though. But I could just set it to go in the background and forget about it until it caught up if it wasn't failing regularly.

So having this configurable makes sense. If it is a DoS protection, it would take some experimenting to determine how slow it needs to go to not set it off.

As you mentioned, #1 doesn't really work for a fully automated use case. Now that it can do a few hundred without a failure, for my personal case I can probably manually catch up and then set it back to automated hourly grabs, and maybe it won't fail in that case. But presumably if a solution can be found that handles the "please download all my videos from the last year" case smoothly, that would be preferable, even if the process ended up being slower than one might like to keep from DoSing Ring.

danespinosa commented 3 months ago

Let's try #3, I have updated the code it retries 3 times to renew the token backing off 30, 60, 90 seconds before failing. I have pushed the changes.

abulsme commented 2 months ago

Hmm. Waited until I was going to be home awhile to try this again anticipating it would run awhile and I would want to watch it, but this version just failed outright instantly for me. Output attached.

Tried a couple times, removed the config, tried again.

FirstRunRingVerbose5.txt

danespinosa commented 2 months ago

@abulsme, I am running the latest version of the verbose branch without problems, would you mind making sure the device id is correct please? also, I just added a new line that logs the json or response if the response fails to be deserialized so we can understand what's failing with this new version for you.

abulsme commented 2 months ago

I literally just used my command history and changed the number from 4 to 5 to run the command on the new version of the executable. So the command including the device id and such was identical. I'll download the latest and try again shortly.

abulsme commented 2 months ago

This time it is running fine. I'll send the output if/when it fails (including any retries), or I run out of stuff to download.

danespinosa commented 2 months ago

Thanks @abulsme, fingers crossed!

abulsme commented 2 months ago

OK. It completely finished all 694 of my May videos, although it had a number of errors along the way that didn't stop it.

I started it on June, and it it errored out and core dumped on the 7th video.

Output attached as usual.

FirstRunRingVerbose6.txt

danespinosa commented 2 months ago

@abulsme, I just pushed a new version I missed adding a catch when retrying and backing off after creating a new token would fail, that's why there was a fatal error when you were downloading June. Btw, can you try to run the code again with the prior refresh token, see if that works? I think that if the program runs with the old refresh token that could help us proof that the error is transient.

abulsme commented 2 months ago

OK, downloaded the new one, and copied the old config over to try to run with the old RefreshToken:

[vps40378]$ cat RingRecordingDownloadVerbose6.dll.config 
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <appSettings>
        <add key="RefreshToken" value="eyJhbGciOiJSUzI1NiIsImprdSI6Ii9vYXV0aC9pbnRlcm5hbC9qd2tzIiwia2lkIjoiZDc0YjNhMWUiLCJ0eXAiOiJKV1QifQ.eyJpYXQiOjE3MjI0MDUxNjAsImlzcyI6IlJpbmdPYXV0aFNlcnZpY2UtcHJvZDp1cy1lYXN0LTE6MWVjNDZiNmYiLCJvaWF0IjoxNzIyNDA1MTYwLCJyZWZyZXNoX2NpZCI6InJpbmdfb2ZmaWNpYWxfYW5kcm9pZCIsInJlZnJlc2hfc2NvcGVzIjpbImNsaWVudCJdLCJyZWZyZXNoX3VzZXJfaWQiOjgyOTIwMDY0LCJybmQiOiJESUhnRUJGbjFaIiwic2Vzc2lvbl9pZCI6ImZmYzA5ZDQ0LTc4YTYtNGRiYy05MmM0LTY4YmJjZjQ1Njk5OSIsInR5cGUiOiJyZWZyZXNoLXRva2VuIn0.GG0A3TttE9z8dHiaXhVIbJvwFSj3bBKR5kxRRhlVkSxaajJ_ynQmswqCaGc4782oOOUH6p7NuYeWzHlhgRvGEjczn2BuBeJgqt0ySLPkGiaFtkVTy8TfZPzeq4N-QDGv_HJSoX2qvqFQ5JeE9lNg0jML8LGjj150qNjPnkCd5zfYnkuaIWpx0Uy2TC6YRvGX7RqbhWSyie7XKFx2wS8V7HieaNxK9u7bt6SD0NBreAo6C0l1jTA6NhXp6GwfIio6dCyfJ4O3MZhH3ty4XDaqij23QpwYYkpnioviD4ixm0UfQ4l_Qs33AvhP4glkUp5j2Gde6Rqw3acaIJWQJpSA8w" />
        <add key="LastdownloadedRecordingId" value="7386533937534579876" />
    </appSettings>
</configuration>

[vps40378]$ cp RingRecordingDownloadVerbose6.dll.config RingRecordingDownloadVerbose7.dll.config 

[vps40378]$ /home/abulsme/RingRecordingDownloadVerbose7 -out /home/abulsme/RingDriveBUP -retries 10 -startdate "06-01-2024 00:00:00" -enddate "06-30-2024 23:59:59" -deviceid XXXXXX -username XXXXXX -password "XXXXXX"

Ring Recordings Download Tool v3.2.0.0 by Koen Zomers

Connecting to Ring services
Got Refresh token at 07/31/2024 18:22:07
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:22:07
Unhandled exception. KoenZomers.Ring.Api.Exceptions.AuthenticationFailedException: Authentication of the session failed
   at KoenZomers.Ring.Api.HttpUtility.FormPost(Uri url, Dictionary`2 formFields, NameValueCollection headerFields)
   at KoenZomers.Ring.Api.Session.RefreshSession(String refreshToken)
   at KoenZomers.Ring.Api.Session.GetSessionByRefreshToken(String refreshToken)
   at KoenZomers.Ring.RecordingDownload.Program.CreateSessionAsync(Configuration configuration)
   at KoenZomers.Ring.RecordingDownload.Program.Main(String[] args)
   at KoenZomers.Ring.RecordingDownload.Program.<Main>(String[] args)
Aborted (core dumped)

So that didn't work.

I then deleted the config file and repeated the command, did the 2FA, and it is on its way. I'll report back as usual once it finishes or I run out of stuff to download.

abulsme commented 2 months ago

It hasn't died yet, but it is erroring. Here is where it is so far. I'll let it keep running, but doesn't look like this approach is working.

[vps40378]$ rm RingRecordingDownloadVerbose7.dll.config 

[vps40378]$ /home/abulsme/RingRecordingDownloadVerbose7 -out /home/abulsme/RingDriveBUP -retries 10 -startdate "06-01-2024 00:00:00" -enddate "06-30-2024 23:59:59" -deviceid XXXXXX -username XXXXXX -password "XXXXXX"

Ring Recordings Download Tool v3.2.0.0 by Koen Zomers

Connecting to Ring services
Got Refresh token at 07/31/2024 18:22:45
Authenticating using provided username and password
Two factor authentication enabled on this account, please enter the Ring token from the e-mail, text message or authenticator app:
605972
Got Refresh token at 07/31/2024 18:23:00
Refresh token refreshed at 07/31/2024 18:23:00
Downloading all historical events between Saturday 1 June 2024 00:00:00 and Sunday 30 June 2024 23:59:59 for Ring device XXXXXX
1183 items found, downloading to /home/abulsme/RingDriveBUP
1 - 2024-06-30 22-24-11 (7386533937534579876).mp4... done (2 MB)
2 - 2024-06-30 22-23-30 (7386533761440920740).mp4... done (2 MB)
3 - 2024-06-30 22-21-50 (7386533331944191140).mp4... done (9 MB)
4 - 2024-06-30 21-29-29 (7386519841451914404).mp4... done (19 MB)
5 - 2024-06-30 21-29-01 (7386519721192830116).mp4... done (4 MB)
6 - 2024-06-30 21-01-39 (7386512668856530084).mp4... done (19 MB)
7 - 2024-06-30 20-59-25 (7386512093330912420).mp4... done (22 MB)
8 - 2024-06-30 20-15-13 (7386500703077643428).mp4... done (4 MB)
9 - 2024-06-30 19-55-34 (7386495639311201444).mp4... done (22 MB)
10 - 2024-06-30 19-53-26 (7386495089555387556).mp4... done (22 MB)
11 - 2024-06-30 19-50-32 (7386494342231078052).mp4... done (7 MB)
12 - 2024-06-30 15-45-44 (7386431257751434404).mp4... done (10 MB)
13 - 2024-06-30 13-43-08 (7386399663972005028).mp4... done (8 MB)
14 - 2024-06-30 13-42-20 (7386399457813574820).mp4... done (4 MB)
15 - 2024-06-30 13-39-26 (7386398710489265316).mp4... done (8 MB)
16 - 2024-06-30 13-38-20 (7386398427021423780).mp4... done (4 MB)
17 - 2024-06-30 13-36-47 (7386398027589465252).mp4... done (4 MB)
18 - 2024-06-30 13-25-48 (7386395197206017188).mp4... done (5 MB)
19 - 2024-06-30 13-23-35 (7386394625975366820).mp4... done (21 MB)
20 - 2024-06-30 13-08-33 (7386390751914865828).mp4... done (19 MB)
21 - 2024-06-30 12-37-53 (7386382849175041188).mp4... done (5 MB)
22 - 2024-06-30 10-31-14 (7386350211718558884).mp4... done (3 MB)
23 - 2024-06-30 10-30-51 (7386350112934311076).mp4... done (4 MB)
24 - 2024-06-30 10-29-39 (7386349803696665764).mp4... done (4 MB)
25 - 2024-06-30 10-06-47 (7386343911001535652).mp4... done (0 MB)
26 - 2024-06-30 10-04-58 (7386343442850100388).mp4... done (13 MB)
27 - 2024-06-30 09-06-50 (7386328462004171940).mp4... done (4 MB)
28 - 2024-06-30 07-28-57 (7386303237661242532).mp4... done (9 MB)
29 - 2024-06-30 05-30-20 (7386272670378996900).mp4... done (4 MB)
30 - 2024-06-30 04-32-40 (7386257809792152740).mp4... done (3 MB)
31 - 2024-06-30 04-17-34 (7386253918551782564).mp4... done (1 MB)
32 - 2024-06-30 04-13-43 (7386252926414337188).mp4... done (2 MB)
33 - 2024-06-30 04-08-03 (7386251479010358436).mp4... done (14 MB)
34 - 2024-06-30 02-01-19 (7386218807194137764).mp4... done (2 MB)
35 - 2024-06-30 00-33-05 (7386196069637272740).mp4... done (2 MB)
36 - 2024-06-29 23-02-25 (7386172705015182500).mp4... done (3 MB)
37 - 2024-06-29 22-57-09 (7386171347805516964).mp4... done (4 MB)
38 - 2024-06-29 22-53-00 (7386170278358660260).mp4... done (4 MB)
39 - 2024-06-29 22-43-02 (7386167709968217252).mp4... done (13 MB)
40 - 2024-06-29 22-23-10 (7386162590367200420).mp4... done (3 MB)
41 - 2024-06-29 20-38-25 (7386135596497745060).mp4... done (9 MB)
42 - 2024-06-29 20-05-25 (7386127092462498980).mp4... done (4 MB)
43 - 2024-06-29 20-02-57 (7386126456807339172).mp4... done (13 MB)
44 - 2024-06-29 18-51-03 (7386107928318424228).mp4... done (6 MB)
45 - 2024-06-29 18-47-47 (7386107086504834212).mp4... done (19 MB)
46 - 2024-06-29 17-38-27 (7386089219440882852).mp4... done (21 MB)
47 - 2024-06-29 17-34-39 (7386088240188339364).mp4... done (22 MB)
48 - 2024-06-29 15-54-39 (7386062470384563364).mp4... Response to get contents was not successful.
Response Status: Unauthorized
Response: {"error":"Unauthorized","status_code":401}
Got Refresh token at 07/31/2024 18:30:26
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:30:26
Failed to create session, re-try 1 out of 3, retrying after 30...
Got Refresh token at 07/31/2024 18:31:26
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:31:26
Failed to create session, re-try 2 out of 3, retrying after 60...
Got Refresh token at 07/31/2024 18:32:56
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:32:56
Failed to create session, re-try 3 out of 3, retrying after 90...
Got Refresh token at 07/31/2024 18:34:56
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:34:56
Failed to create session, re-try 4 out of 3, retrying after 120...
. Retrying 2/10.
48 - 2024-06-29 15-54-39 (7386062470384563364).mp4... Response to get contents was not successful.
Response Status: Unauthorized
Response: {"error":"Unauthorized","status_code":401}
Got Refresh token at 07/31/2024 18:35:27
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:35:27
Failed to create session, re-try 1 out of 3, retrying after 30...
Got Refresh token at 07/31/2024 18:36:27
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:36:27
Failed to create session, re-try 2 out of 3, retrying after 60...
Got Refresh token at 07/31/2024 18:37:57
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:37:57
Failed to create session, re-try 3 out of 3, retrying after 90...
Got Refresh token at 07/31/2024 18:39:57
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:39:57
Failed to create session, re-try 4 out of 3, retrying after 120...
. Retrying 3/10.
48 - 2024-06-29 15-54-39 (7386062470384563364).mp4... Response to get contents was not successful.
Response Status: Unauthorized
Response: {"error":"Unauthorized","status_code":401}
Got Refresh token at 07/31/2024 18:40:27
Authenticating using refresh token from previous session
Got Refresh token at 07/31/2024 18:40:27
Failed to create session, re-try 1 out of 3, retrying after 30...
danespinosa commented 2 months ago

It seems once the RefreshToken is invalid the program can't recover, at this point I think the only thing that we have left to try is

2.- the applicaiton allows the user to specify a back-off/cool-down time between API calls in case Ring is expiring the token, not ideal since it can take a long time to download all videos.

danespinosa commented 2 months ago

@abulsme I pushed the new changes that allow you to specify a time between downloads, the new param is -timeBetweenCalls and it accepts a timespan string, e.g. If you want to wait 5 seconds you would specify the string "00:00:05", see example below.

-startdate \"07-01-2024 00:00:00\" -enddate \"07-29-2024 23:59:59\" -deviceid xxxxxxx -timeBetweenCalls 00:00:05

abulsme commented 2 months ago

OK. Downloaded. Started it on June again. With a 10 second timeBetweenCalls. I'll check how it did in the morning. :-)

abulsme commented 2 months ago

Failed overnight.

FirstRunRingVerbose8.txt

I'll try it again with a 30 second delay.

abulsme commented 2 months ago

The 30 second version failed eventually too. I started it again with 60 seconds. Will send logs for the 30 and 60 second versions when I get home this evening.

abulsme commented 2 months ago

Here are the logs failing at both 30 and 60.

SecondRunRingVerbose8.txt

Stopping it now since it clearly isn't going to start working again on its own.

Going to try again at a 2 minute pause.

abulsme commented 2 months ago

Failed at 2 minutes and 5 minutes as well. Going to start it again with 10 minutes before I leave for work.

ThirdRunRingVerbose8.txt

abulsme commented 2 months ago

Failed pretty soon after I left for work. Here is the log:

FourthRunRingVerbose8.txt

I guess I'll try it at 15 minutes, but looks like whatever is happening, this doesn't solve it.

Any other ideas? Or are we stumped?

danespinosa commented 2 months ago

hi @abulsme, I was noticing that the way the library is creating a new session is not specifying the latest api version, which could be causing the token to become invalid, also I added a new logic so when you create a new session the program assigns a device id to your application, that device id will be stored on the .config file with the key DeviceId, once you log in you should be able to look at the device logged in in the Ring Control Center https://account.ring.com/account/control-center/authorized-devices in the page you should see a device like the one in the screenshot.

image

Hopefully that wll do the trick, if this doesn't do it I am out of ideas :)

abulsme commented 2 months ago

I started the new version (with the delay set to 60s). I'll report back when I have a result.

And I do indeed have the device listed.

Screenshot 2024-08-04 at 00 24 22

(It says 8/4 because my desktop computer I took the screenshot from is on UTC, but the server I am running the script on is on Pacific.)

abulsme commented 2 months ago

It is still going, but noticed this bit:

415 - 2024-06-18 16-09-52 (7381984454771586212).mp4... done (14 MB) Waiting for 60 seconds before continuing... 416 - 2024-06-18 14-14-00 (7381954596158944420).mp4... done (25 MB) Waiting for 60 seconds before continuing... 417 - 2024-06-18 14-11-24 (7381953926144046244).mp4... Response to get contents was not successful. Response Status: Unauthorized Response: {"error":"Unauthorized","status_code":401} failed (Response status code does not indicate success: 401 (Unauthorized).). Retrying 2/10. 417 - 2024-06-18 14-11-24 (7381953926144046244).mp4... Refreshing session, Token expired at 08/04/2024 01:11:20 done (15 MB) Waiting for 60 seconds before continuing... 418 - 2024-06-18 13-20-43 (7381940865148499108).mp4... done (5 MB) Waiting for 60 seconds before continuing... 419 - 2024-06-18 13-07-20 (7381937416289760420).mp4... done (12 MB) Waiting for 60 seconds before continuing... 420 - 2024-06-18 12-56-32 (7381934633150952612).mp4... done (4 MB) Waiting for 60 seconds before continuing...

This is the first time I have seen it recover after a 401, so... looking good!

abulsme commented 2 months ago

Seeing a few of these as well, where there is a refresh without an error first:

835 - 2024-06-09 18-20-09 (7378678261961569444).mp4... done (22 MB) Waiting for 60 seconds before continuing... 836 - 2024-06-09 17-48-34 (7378670122998543524).mp4... Refreshing session, Token expired at 08/04/2024 09:12:20 done (22 MB) Waiting for 60 seconds before continuing... 837 - 2024-06-09 17-38-43 (7378667584672871588).mp4... done (22 MB) Waiting for 60 seconds before continuing...

Still going.

danespinosa commented 2 months ago

@abulsme These are great news! Fingers crossed🤞!

abulsme commented 2 months ago

It successfully completed all my June videos. Here is the log so you can see the places it recovered and kept going:

FirstRunRingVerbose9.txt

Looks like tokens are expiring every 4 hours, but it is now recovering by refreshing. Going to kick off July now, but without the 60 second delay, to see if that is even necessary at this point.