foxt / icloud.js

Library for accessing iCloud in Node.js

Home Page:https://npmjs.com/icloudjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

status and apple-icloud

costa opened this issue · comments

Just a quick question, given the nature of this package, is it supposed to replace https://www.npmjs.com/package/apple-icloud (not sure if it's alive at the moment)?

Is this one fit for integration at the moment?

Thanks a lot.

commented

I wasn't aware of that package until now, this package is it's own work, but I assume in many cases it could be used in place of that library.

Hi @foxt!
First, thanks again for your work on this package, I've just managed to get it working... mostly... for my modest purposes, more on this below.

FYI, the project in question: https://medium.com/@costa/lively-video-reporting-project-248fe01283e3

Now, at the tech shopping stage, after trying (successfully) to use Selenium to access my media at iCloud, I decided to also take a look in the TypeScript direction, since I don't care too much about a non-critical component's platform, TS is popular with the relevant community, and I've found two "node" packages with an appearance of the required functionality (this package and an older one I've mentioned above).

I always prefer integrating tech of other people's adequate and active projects, so I performed a kind of evaluation of my options:

  • the older package (iCloud-API) didn't seem to work, did seem abandoned: MauriceConrad/iCloud-API#84
  • this package (icloud.js) needed a little help to work, there are (apparently workaround-able) issues with the code and the docs, see below
  • my original idea of rolling my own with Selenium ([easier] reverse-engineering icloud.com web page instead of [harder] reverse-engineering unofficial [web-client] iCloud API like with the two options above)... is a fallback for now I suppose

The gist of my usage of this package after working around (in $ docker run --rm -it node:20.8 bash, in $$ node after $$ npm i icloudjs):

const fs = require('fs');
const iCloud = require('icloudjs');  // NOTE README is outdated or something
// NOTE getting userName and passWord from the user before this, of course
const icloud = new iCloud.default({  // NOTE README is outdated or something
    username: userName,
    password: passWord,
    saveCredentials: true,
    trustDevice: true,
    authMethod: "srp"
});
await icloud.authenticate();  // NOTE a possibility of "confusing" errors here...
if (icloud.status === "MfaRequested") {
   var otp = "123456";  // TODO getting the OTP from the user instead, of course
   await icloud.provideMfaCode(otp);  // NOTE ...and here
}
const iphotos = icloud.getService('photos');
var ialbums = await iphotos.getAlbums();
var vidAlbum = ialbums.get('Videos');
await vidAlbum.getPhotos();  // NOTE this is a "good enough for me" workaround here
vidAlbum.album.direction = 'DESCENDING';
var vids = await vidAlbum.getPhotos();  // NOTE this looks like the last page only is fetched
// NOTE (destination for DL) vidPath must be defined somewhere before this
fs.appendFile(vidPath, Buffer.from(await vids[0].download()), function (err) {
  console.log(err || "OK");  // NOTE some real error handling should be here, of course
});  // NOTE this does seem download the latest video, hooray!

So, I'm leaning towards integrating this package at the moment — as I see the project is active, the code looks fine, and the maintainer is responsive (I hope I won't have to fall back to the rolling-my-own option), but any timely advice is highly appreciated.

commented

Thanks for the feedback - I've pushed up some fixes to the docs & readme.