instauto 7.1.4 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +35 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -354,16 +354,12 @@ const Instauto = async (db, browser, options) => {
354
354
 
355
355
  const isLoggedIn = async () => (await page.$x('//*[@aria-label="Home"]')).length === 1;
356
356
 
357
- async function getFollowersOrFollowing({
358
- userId, getFollowers = false, maxPages, shouldProceed: shouldProceedArg,
359
- }) {
360
- const graphqlUrl = `${instagramBaseUrl}/graphql/query`;
361
- const followersUrl = `${graphqlUrl}/?query_hash=37479f2b8209594dde7facb0d904896a`;
362
- const followingUrl = `${graphqlUrl}/?query_hash=58712303d941c6855d4e888c5f0cd22f`;
357
+ async function graphqlQueryUsers({ queryHash, getResponseProp, maxPages, shouldProceed: shouldProceedArg, graphqlVariables: graphqlVariablesIn }) {
358
+ const graphqlUrl = `${instagramBaseUrl}/graphql/query/?query_hash=${queryHash}`;
363
359
 
364
360
  const graphqlVariables = {
365
- id: userId,
366
361
  first: 50,
362
+ ...graphqlVariablesIn,
367
363
  };
368
364
 
369
365
  const outUsers = [];
@@ -379,15 +375,14 @@ const Instauto = async (db, browser, options) => {
379
375
  };
380
376
 
381
377
  while (shouldProceed()) {
382
- const url = `${getFollowers ? followersUrl : followingUrl}&variables=${JSON.stringify(graphqlVariables)}`;
378
+ const url = `${graphqlUrl}&variables=${JSON.stringify(graphqlVariables)}`;
383
379
  // logger.log(url);
384
380
  await page.goto(url);
385
381
  const json = await getPageJson();
386
382
 
387
- const subPropName = getFollowers ? 'edge_followed_by' : 'edge_follow';
388
-
389
- const pageInfo = json.data.user[subPropName].page_info;
390
- const { edges } = json.data.user[subPropName];
383
+ const subProp = getResponseProp(json);
384
+ const pageInfo = subProp.page_info;
385
+ const { edges } = subProp;
391
386
 
392
387
  edges.forEach(e => outUsers.push(e.node.username));
393
388
 
@@ -404,6 +399,33 @@ const Instauto = async (db, browser, options) => {
404
399
  return outUsers;
405
400
  }
406
401
 
402
+ async function getFollowersOrFollowing({
403
+ userId, getFollowers = false, maxPages, shouldProceed,
404
+ }) {
405
+ return graphqlQueryUsers({
406
+ getResponseProp: (json) => json.data.user[getFollowers ? 'edge_followed_by' : 'edge_follow'],
407
+ graphqlVariables: { id: userId },
408
+ shouldProceed,
409
+ maxPages,
410
+ queryHash: getFollowers ? '37479f2b8209594dde7facb0d904896a' : '58712303d941c6855d4e888c5f0cd22f',
411
+ });
412
+ }
413
+
414
+ async function getUsersWhoLikedContent({
415
+ contentId, maxPages, shouldProceed,
416
+ }) {
417
+ return graphqlQueryUsers({
418
+ getResponseProp: (json) => json.data.shortcode_media.edge_liked_by,
419
+ graphqlVariables: {
420
+ shortcode: contentId,
421
+ include_reel: true,
422
+ },
423
+ shouldProceed,
424
+ maxPages,
425
+ queryHash: 'd5d763b1e2acf209d62d22d184488e57',
426
+ });
427
+ }
428
+
407
429
  /* eslint-disable no-undef */
408
430
  async function likeCurrentUserImagesPageCode({ dryRun: dryRunIn, likeImagesMin, likeImagesMax }) {
409
431
  const allImages = Array.from(document.getElementsByTagName('a')).filter(el => /instagram.com\/p\//.test(el.href));
@@ -901,6 +923,7 @@ const Instauto = async (db, browser, options) => {
901
923
  sleep,
902
924
  listManuallyFollowedUsers,
903
925
  getFollowersOrFollowing,
926
+ getUsersWhoLikedContent,
904
927
  safelyUnfollowUserList,
905
928
  getPage,
906
929
  followUsersFollowers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instauto",
3
- "version": "7.1.4",
3
+ "version": "7.2.0",
4
4
  "description": "Instagram automation library written in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {