@dukebot/instagram-scraper-api 0.1.0 → 0.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.
package/README.md CHANGED
@@ -21,6 +21,7 @@ const scraper = new InstagramScraperAPI({
21
21
  const user = await scraper.getUserInfo("instagram");
22
22
  const posts = await scraper.getUserPosts("instagram", 5);
23
23
 
24
+ console.log(user.id);
24
25
  console.log(user.username);
25
26
  console.log(posts.length);
26
27
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dukebot/instagram-scraper-api",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Reusable Instagram data scraper wrapper for RapidAPI with modern ESM imports.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -4,29 +4,11 @@
4
4
  export default class Location {
5
5
  /**
6
6
  * @param {Object} [data={}] Raw location data.
7
- * @param {string|number|null} [data.pk]
8
- * @param {string|null} [data.shortName]
9
- * @param {string|number|null} [data.facebookPlacesId]
10
- * @param {string|null} [data.externalSource]
11
- * @param {string|null} [data.name]
12
- * @param {string|null} [data.address]
13
- * @param {string|null} [data.city]
14
- * @param {boolean|null} [data.hasViewerSaved]
15
- * @param {number|null} [data.lng]
16
- * @param {number|null} [data.lat]
17
- * @param {boolean|null} [data.isEligibleForGuides]
18
7
  */
19
8
  constructor(data = {}) {
20
- this.pk = data.pk ?? null;
21
- this.shortName = data.shortName ?? null;
22
- this.facebookPlacesId = data.facebookPlacesId ?? null;
23
- this.externalSource = data.externalSource ?? null;
9
+ this.id = data.id ?? null;
24
10
  this.name = data.name ?? null;
25
- this.address = data.address ?? null;
26
- this.city = data.city ?? null;
27
- this.hasViewerSaved = data.hasViewerSaved ?? null;
28
11
  this.lng = data.lng ?? null;
29
12
  this.lat = data.lat ?? null;
30
- this.isEligibleForGuides = data.isEligibleForGuides ?? null;
31
13
  }
32
14
  }
@@ -1,4 +1,4 @@
1
- import Location from "./location.js";
1
+ import Location from './location.js';
2
2
 
3
3
  /**
4
4
  * Normalized Instagram post entity.
@@ -6,45 +6,24 @@ import Location from "./location.js";
6
6
  export default class Post {
7
7
  /**
8
8
  * @param {Object} [data={}] Raw post data.
9
- * @param {string|number|null} [data.pk]
10
- * @param {string|number|null} [data.id]
11
- * @param {string|number|null} [data.fbId]
12
- * @param {string|number|null} [data.mediaId]
13
- * @param {string|null} [data.code]
14
- * @param {string|null} [data.title]
15
- * @param {string|null} [data.text]
16
- * @param {string|null} [data.externalUrl]
17
- * @param {number|null} [data.takenAt]
18
- * @param {string|null} [data.date]
19
- * @param {string|null} [data.time]
20
- * @param {Object|Location|null} [data.location]
21
- * @param {string|null} [data.socialNetwork]
22
- * @param {string|null} [data.accountUsername]
23
- * @param {string|number|null} [data.accountId]
24
- * @param {number|null} [data.likeCount]
25
- * @param {number|null} [data.commentCount]
26
- * @param {{url: string, caption: string|null}[]} [data.images]
27
- * @param {{url: string, caption: string|null}[]} [data.videos]
28
9
  */
29
10
  constructor(data = {}) {
30
- this.pk = data.pk ?? null;
31
11
  this.id = data.id ?? null;
32
12
  this.fbId = data.fbId ?? null;
33
- this.mediaId = data.mediaId ?? null;
34
13
  this.code = data.code ?? null;
35
- this.title = data.title ?? null;
14
+
36
15
  this.text = data.text ?? null;
37
- this.externalUrl = data.externalUrl ?? null;
38
- this.takenAt = data.takenAt ?? null;
39
16
  this.date = data.date ?? null;
40
17
  this.time = data.time ?? null;
18
+ this.takenAt = data.takenAt ?? null;
19
+
20
+ this.user = data.user ? { id: data.user.id, username: data.user.username } : null;
41
21
  this.location = data.location ? new Location(data.location) : null;
42
- this.socialNetwork = data.socialNetwork ?? "Instagram";
43
- this.accountUsername = data.accountUsername ?? null;
44
- this.accountId = data.accountId ?? null;
45
- this.likeCount = data.likeCount ?? null;
46
- this.commentCount = data.commentCount ?? null;
22
+
47
23
  this.images = data.images ?? [];
48
24
  this.videos = data.videos ?? [];
25
+
26
+ this.likeCount = data.likeCount ?? null;
27
+ this.commentCount = data.commentCount ?? null;
49
28
  }
50
29
  }
@@ -6,21 +6,12 @@ import Post from "./post.js";
6
6
  export default class User {
7
7
  /**
8
8
  * @param {Object} [data={}] Raw user data.
9
- * @param {string|number|null} [data.otherId]
10
- * @param {string|null} [data.name]
11
- * @param {string|null} [data.username]
12
- * @param {string|null} [data.biography]
13
- * @param {string|null} [data.externalUrl]
14
- * @param {string|null} [data.socialNetwork]
15
- * @param {Object[]|Post[]} [data.posts]
16
9
  */
17
10
  constructor(data = {}) {
18
- this.otherId = data.otherId ?? null;
11
+ this.id = data.id ?? null;
19
12
  this.name = data.name ?? null;
20
13
  this.username = data.username ?? null;
21
14
  this.biography = data.biography ?? null;
22
15
  this.externalUrl = data.externalUrl ?? null;
23
- this.socialNetwork = data.socialNetwork ?? "Instagram";
24
- this.posts = (data.posts ?? []).map((post) => new Post(post));
25
16
  }
26
17
  }
@@ -27,7 +27,7 @@ export default class InstagramScraperAPI2ResponseProcessor {
27
27
  */
28
28
  function transformUser(user) {
29
29
  return new User({
30
- otherId: user.id,
30
+ id: user.id,
31
31
  name: user.full_name,
32
32
  username: user.username,
33
33
  biography: user.biography,
@@ -44,20 +44,6 @@ function transformPost(post) {
44
44
  const getVideoUrlFromVideoVersions = () => post.video_versions?.[0]?.url ?? null;
45
45
  const urlToMediaObject = (url) => ({ url, caption: null });
46
46
 
47
- function transformLocation() {
48
- const location = post.location;
49
- if (!location) {
50
- return null;
51
- }
52
-
53
- return {
54
- pk: location.id,
55
- name: location.name,
56
- lat: location.lat,
57
- lng: location.lng,
58
- };
59
- }
60
-
61
47
  function getDate() {
62
48
  if (!post.taken_at) return null;
63
49
  const dateTime = timestampToDateString(post.taken_at);
@@ -71,7 +57,6 @@ function transformPost(post) {
71
57
  }
72
58
 
73
59
  return new Post({
74
- pk: post.id,
75
60
  id: post.id,
76
61
  fbId: post.fbid,
77
62
  code: post.code,
@@ -79,9 +64,8 @@ function transformPost(post) {
79
64
  takenAt: post.taken_at ? Number(post.taken_at) : null,
80
65
  date: getDate(),
81
66
  time: getTime(),
82
- location: transformLocation(),
83
- accountUsername: post.user?.username ?? null,
84
- accountId: post.user?.id ?? null,
67
+ user: post.user,
68
+ location: post.location,
85
69
  likeCount: post.like_count ?? null,
86
70
  commentCount: post.comment_count ?? null,
87
71
  images: [getImageUrlFromImageVersions()].filter(Boolean).map(urlToMediaObject),