davglass / doorbot

Ring.com Doorbell API
Other
317 stars 55 forks source link

Installed; nothing happens. Newbie help needed please. #54

Open Stavrak2 opened 4 years ago

Stavrak2 commented 4 years ago

So I've installed node and I believe, this package. I go into the doorbot folder and edit downloads.js and links.js to have my username and password. I've turned off 2fa to keep things simple.

MacBook-Pro:downloads mac$ node /Users/mac/node_modules/doorbot/examples/download.js done MacBook-Pro:downloads mac$

This creates a 'Downloads' folder with nothing in it.

Similarly, links.js just opens and closes (if I run it as node /folder/links.js which I assume is the way to do these things)

I am new to node and scripts generally so don't know if I'm missing anything obvious. Please help?

gbolcer commented 4 years ago

Same. This was working at of 12/16/2019, but I think Ring changed something on their side. Same behavior. No generation of links to download anymore. download-all.js succeeds, but doesn't identify any files to download.

joeyberkovitz commented 4 years ago

You're likely running into the authentication issue mentioned here: https://github.com/davglass/doorbot/issues/52

The main code hasn't been updated to support oauth yet, so you'll need to switch to a version that has been updated.

Stavrak2 commented 4 years ago

So that way works, but it only downloads 100 videos. I have many more videos than this, and am approaching the point at which they all get cleared off Ring’s server. I really need urgent help in getting more than 100 videos before they go entirely

On 7 Jan 2020, at 22:52, joeyberkovitz notifications@github.com wrote:



You're likely running into the authentication issue mentioned here: #52https://github.com/davglass/doorbot/issues/52

The main code hasn't been updated to support oauth yet, so you'll need to switch to a version that has been updated.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/davglass/doorbot/issues/54?email_source=notifications&email_token=ABDIBARPBPYOM7NCAYNBH63Q4UBTHA5CNFSM4KBLWPF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIKSEJQ#issuecomment-571810342, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABDIBATWHGNOUIB7UVSLZSDQ4UBTHANCNFSM4KBLWPFQ.

joeyberkovitz commented 4 years ago

Not sure about the details, but if you're using my fork, it doesn't have the latest download code, so you should probably download the contents of the example folder from here and try to use those

Stavrak2 commented 4 years ago

I’m just using the changed file for authentication from yours, everything else as stock. It pulls down the 100 most recent videos only.

The links one doesn’t do anything :(

On 8 Jan 2020, at 12:01, joeyberkovitz notifications@github.com<mailto:notifications@github.com> wrote:

Not sure about the details, but if you're using my fork, it doesn't have the latest download code, so you should probably download the contents of the example folder from here and try to use those

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/davglass/doorbot/issues/54?email_source=notifications&email_token=ABDIBAV3UQPFCBNB5OMTTPLQ4W573A5CNFSM4KBLWPF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIME6HA#issuecomment-572018460, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABDIBAUGHALMMVOQH5P6DDTQ4W573ANCNFSM4KBLWPFQ.

joeyberkovitz commented 4 years ago

The history function in doorbot.js also changed, try copying that too

Stavrak2 commented 4 years ago

Correction - it works but I just get a few links in the console window

I’m in a real bind because I need to pull down an entire day of video (one video every 1 minute) that is days away from being cleared down by Ring themselves and I can’t for the life of me find anything that will just let me download that many videos :(

On 8 Jan 2020, at 13:42, joeyberkovitz notifications@github.com<mailto:notifications@github.com> wrote:

The history function in doorbot.js also changed, try copying that too

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/davglass/doorbot/issues/54?email_source=notifications&email_token=ABDIBAVA33YBXG3MINAHOO3Q4XJ5HA5CNFSM4KBLWPF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIMOOHY#issuecomment-572057375, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABDIBAQ5EY2PDYMSPHDE6UDQ4XJ5HANCNFSM4KBLWPFQ.

SysErr23 commented 4 years ago

Not sure about the details, but if you're using my fork, it doesn't have the latest download code, so you should probably download the contents of the example folder from here and try to use those

I understand, that the authentification changed and OAuth is required now. I have the donwload-all.js from https://github.com/davglass/doorbot/issues/48#issuecomment-533138657 that worked fine until mid of December 2019. From then on the DEBUG tells me that doorbot can not handle the token.

Now i downloaded the doorbot.js from your fork but now i get the error of "Callback not defined" in doorbot:50:15, that has to do something with the Doorbot.history at doorbot.js:371:9

Can you give me the hint, what to do to make it run again?

gbolcer commented 4 years ago

Here's where I got to. I checked both davglass and joey's projects out into two separate directories. git clone https://github.com/davglass/doorbot git clone https://github.com/joeyberkovitz/doorbot.git doorbotj

I think merged everything in doorbotj/doorbot.js into doorbot/doorbot.js except the history() function which I kept from the davglass version.

In all the example files, I edited the username and password. I also added the retries and userAgent and api version variables.

Not being that familiar w/ node, I then did a couple extra things. I made sure that instead of loading from the npm archive, it installed the local code. 'npm install' and then 'npm link doorbot'. This second command makes sure that the local copy of doorbot code is the one that is installed.

I had to add a few requirements by also doing the npm install. When you run node download-all.js it'll just tell you what package it's missing. I think I needed requests, dateformat, and some oauth one.

From there it ran and downloaded about the last 100 or so videos from 1/7-1/8 2020. I'm stuck trying to figure out how to force it to go back further as I'd like to fill in the missing gaps from further back.j

joeyberkovitz commented 4 years ago

I updated download-all.js and doorbot.js in my fork. I tested the fix for download-all.js and it did a few loops before I stopped it, so it looks like it's working now.

gbolcer commented 4 years ago

Thank you very much!

Stavrak2 commented 4 years ago

oh my god that works! THANK YOU JOEY BERKOVITZ you've saved me a ton of bother!

I especially like how in download-all you're able to set the ID of the 'newest' file from the series you want (tip - get it from the 'share' URL generated in RIng). By doing this you can then watch the terminal as it downloads and then cancel the process when you get to the start of the series.

Thank you so much all for your help on this - I've never used Node before!

gbolcer commented 4 years ago

Confirmed: Joey's fork works perfectly.

SysErr23 commented 4 years ago

For me it did not work. Installed it with 'npm i joeyberkovitz/doorbot' but the execution of download-all.js leds to a 'Cannot find module 'doorbot.js''. So in the donwload-all.js i changed the require('doorbot.js') to require('doorbot').

Now it works also for me. Thank you Mr Berkovitz!

gbolcer commented 4 years ago

It's looking for doorbot.js instead of doorbot in download-all.js. I think you can copy the file into the directory you are executing from or use npm link and then change it to the package name.

diff --git a/examples/download-all.js b/examples/download-all.js index 0e46da5..f087604 100644 --- a/examples/download-all.js +++ b/examples/download-all.js @@ -11,7 +11,8 @@

//Includes const dateFormat = require('dateformat'); -const RingAPI = require('doorbot.js'); +//const RingAPI = require('doorbot.js'); +const RingAPI = require('doorbot'); const async = require('async'); const mkdirp = require('mkdirp'); const fs = require('fs');

itadministrator-bhab commented 4 years ago

After updating the files with joeyberkovitz's branch and following the recommendations above, when I run node download-all.js, the terminal returns : "Done, Oldest File: 999999999999999999999999 Getting more, older than: 999999999999999999999999" A download folder is created but it's empty.

Stavrak2 commented 4 years ago

After updating the files with joeyberkovitz's branch and following the recommendations above, when I run node download-all.js, the terminal returns : "Done, Oldest File: 999999999999999999999999 Getting more, older than: 999999999999999999999999" A download folder is created but it's empty.

Same - @joeyberkovitz would you mind having a look at it please? I'm assuming Ring changed something and it's just stuck on 9999999 (etc) now

Thanks all

joeyberkovitz commented 4 years ago

Is this possibly related to the fact that you can't disable 2FA anymore? This module doesn't support 2FA logins, but if you have an auth and refresh token, it'll work fine.

Can you try the following and see if you get an error. There's no point in even filling in the correct username and password since you'll have to rely on the auth token. const RingAPI = require('doorbot.js');

const ring = RingAPI({ email: 'your@email.com', password: '12345' });

ring.devices((e, devices) => { console.log(e, devices); });

If you do get an error, you'll need to use a separate script to obtain the auth and refresh tokens and then update it in the ".ringAlarmCache" file in your home directory.

Stavrak2 commented 4 years ago

Is this possibly related to the fact that you can't disable 2FA anymore? This module doesn't support 2FA logins, but if you have an auth and refresh token, it'll work fine.

Can you try the following and see if you get an error. There's no point in even filling in the correct username and password since you'll have to rely on the auth token. const RingAPI = require('doorbot.js');

const ring = RingAPI({ email: 'your@email.com', password: '12345' });

ring.devices((e, devices) => { console.log(e, devices); });

If you do get an error, you'll need to use a separate script to obtain the auth and refresh tokens and then update it in the ".ringAlarmCache" file in your home directory.

Thanks @joeyberkovitz - actually I was able to disable 2FA just fine before getting this problem. Do you still want me to try something? I may need some help with getting the tokens if so

joeyberkovitz commented 4 years ago

Yes. Try that script I sent and see if you get an error. At least on my account there's no way to disable 2FA, just switch it to email as a second factor.

Stavrak2 commented 4 years ago

This is what I get, after changing the reference to 'doorbot' (removing the '.js')

Error: API failed to return an authentication_token at IncomingMessage. (/Users/UEF2/node_modules/doorbot/doorbot.js:244:30) at IncomingMessage.emit (events.js:215:7) at endReadableNT (_stream_readable.js:1184:12) at processTicksAndRejections (internal/process/task_queues.js:80:21) undefined

And you're right - it attempts to verify access via email every time you run the download script, so there's no way to satisfy it (by entering the code online, you re-run the script and it generates another pseudo-2fa code)

I'm stumped :(

joeyberkovitz commented 4 years ago

Maybe try running the ring-auth-cli from somewhere like here: https://github.com/dgreif/ring/wiki/Refresh-Tokens to get a refresh token

After that, put your refresh token in your .ringAlarmCache file in the "refreshToken" key:

{"oauthToken":"BLANK","refreshToken":"REFRESHTOKEN","hardware_id":"ID"}

If that doesn't work, I'll have to write a similar script to generate a refresh token

jamenlang commented 4 years ago

Maybe try running the ring-auth-cli from somewhere like here: https://github.com/dgreif/ring/wiki/Refresh-Tokens to get a refresh token

After that, put your refresh token in your .ringAlarmCache file in the "refreshToken" key:

{"oauthToken":"BLANK","refreshToken":"REFRESHTOKEN","hardware_id":"ID"}

If that doesn't work, I'll have to write a similar script to generate a refresh token

I managed to create a refresh token, but where is .ringAlarmCache? I tried placing this file everywhere i can think of but get this.

Error: Api failed to return an authentication_token

joeyberkovitz commented 4 years ago

It should be in your home directory - /home/USER on Linux, C:\Users\USER\ on Windows.

Also, this functionality is only included in my fork.

jamenlang commented 4 years ago

installed your fork with "npm install https://github.com/joeyberkovitz/doorbot.git --save"

replaced REFRESHTOKEN in {"oauthToken":"BLANK","refreshToken":"REFRESHTOKEN","hardware_id":"ID"} with my refresh token and it's getting real data now.

thank you so much everyone!

gbolcer commented 4 years ago

I had to remove the old doorbot package. Also after my Ubuntu upgrade, I had to npm install async and npm install dateformat. From there I copied the old examples directory and ran node download-all.js

It appears to have grabbed them all. I'm going to look into the homebridge-ring next as I manually put the refresh token into my /home/greg/.ringAlarmCache file. I assume it times out after some short period of time.

habhabhabs commented 4 years ago

@joeyberkovitz Thanks for the constant contribution to this API. I'd tried reinstalling via your fork and refreshing tokens, however I'm stuck with the following codeblock

[alexkm@homebase examples]$ node download-all.js 
/home/alexkm/node_modules/doorbot/node_modules/mkdirp/lib/opts-arg.js:13
    throw new TypeError('invalid options argument')
    ^

TypeError: invalid options argument
    at optsArg (/home/alexkm/node_modules/doorbot/node_modules/mkdirp/lib/opts-arg.js:13:11)
    at mkdirp (/home/alexkm/node_modules/doorbot/node_modules/mkdirp/index.js:11:10)
    at ring.recording (/home/alexkm/node_modules/doorbot/examples/download-all.js:78:21)
    at simpleRequest (/home/alexkm/node_modules/doorbot/doorbot.js:427:13)
    at fetch (/home/alexkm/node_modules/doorbot/doorbot.js:315:17)
    at IncomingMessage.res.on (/home/alexkm/node_modules/doorbot/doorbot.js:144:17)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
[alexkm@homebase examples]$ 

Any idea if I've missed any args that might be required? Thanks!

joeyberkovitz commented 4 years ago

Sounds like maybe there's something wrong work your save directory, variable called base.

Otherwise will need some more logging to figure out your specific issue

habhabhabs commented 4 years ago

Thanks @joeyberkovitz for your prompt reply.

Looks like mkdirp is attempting to check for the folder, which was created prior. Then it proceeds to fetch the video.

//Make sure the directory exists
const dirname = path.dirname(file);

console.log(dirname); // to check whether path is constructed properly
mkdirp(dirname, () => {
        //Tracking variable
        var writeFile = true;

        //Test if the file we are about to write already exists
        try {
            fs.accessSync(file);
            console.log('File Exists, Skipping: ', file);
            writeFile = false;
        } catch (err) {
            writeFile = true;
        }

        //If we aren't skipping existing files, we write them regardless of the write-file value
        if (skipExistingFiles && !writeFile) {
            return callback();
        }

        console.log('Fetching file', file);
        const writer = fs.createWriteStream(file);
        writer.on('close', () => {
            console.log('Done writing', file);
            callback();
        });
        request(recording).pipe(writer);
    });

Doing console.log before the mkdirp function correctly shows the directory the video will be saved in.

I tried downgrading to mkdirp@1.0.3, the minimum version required to operate, to no success.


Update: Removing the mkdirp function works, leaving with this chunk

//Make sure the directory exists
const dirname = path.dirname(file);

//Tracking variable
var writeFile = true;

//Test if the file we are about to write already exists
try {
    fs.accessSync(file);
    console.log('File Exists, Skipping: ', file);
    writeFile = false;
} catch (err) {
    writeFile = true;
}

//If we aren't skipping existing files, we write them regardless of the write-file value
if (skipExistingFiles && !writeFile) {
    return callback();
}

console.log('Fetching file', file);
const writer = fs.createWriteStream(file);
writer.on('close', () => {
    console.log('Done writing', file);
    callback();
});
request(recording).pipe(writer);

This excludes videos marked as shared/favorites (under share.ring.com) and only focuses on fetching ALL videos. Not sure how sustainable will this solution be but it works for now. I've commented out the first code block in the file until a fix comes along.

gbolcer commented 4 years ago

I was going to try to recreate the error. npm install mkdirp installed mkdirp@1.0.4

node download-all.js Same error.

npm uninstall mkdirp

All good including skipping and looping.

var loopForOlder = true; var skipExistingFiles = true;

For some reason, I did have to remove my old package-lock.json file to get it working the day before. I don't completely understand it, but at least it's working!