Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Stavrak2 opened this issue Dec 30, 2019 · 30 comments
Open

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

Stavrak2 opened this issue Dec 30, 2019 · 30 comments

Comments

@Stavrak2
Copy link

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
Copy link

gbolcer commented Jan 6, 2020

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
Copy link

You're likely running into the authentication issue mentioned here: #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
Copy link
Author

Stavrak2 commented Jan 8, 2020 via email

@joeyberkovitz
Copy link

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
Copy link
Author

Stavrak2 commented Jan 8, 2020 via email

@joeyberkovitz
Copy link

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

@Stavrak2
Copy link
Author

Stavrak2 commented Jan 8, 2020 via email

@SysErr23
Copy link

SysErr23 commented Jan 8, 2020

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 #48 (comment) 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
Copy link

gbolcer commented Jan 8, 2020

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
Copy link

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
Copy link

gbolcer commented Jan 9, 2020

Thank you very much!

@Stavrak2
Copy link
Author

Stavrak2 commented Jan 9, 2020

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
Copy link

gbolcer commented Jan 9, 2020

Confirmed: Joey's fork works perfectly.

@SysErr23
Copy link

SysErr23 commented Jan 9, 2020

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
Copy link

gbolcer commented Jan 9, 2020

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
Copy link

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
Copy link
Author

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
Copy link

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: '[email protected]',
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
Copy link
Author

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: '[email protected]',
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
Copy link

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
Copy link
Author

Stavrak2 commented Apr 12, 2020

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

gbolcer commented Jun 5, 2020

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
Copy link

@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
Copy link

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
Copy link

habhabhabs commented Jun 8, 2020

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 [email protected], 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
Copy link

gbolcer commented Jun 8, 2020

I was going to try to recreate the error.
npm install mkdirp installed [email protected]

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants