metascraper-instagram 5.45.22 → 5.45.28
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/package.json +4 -5
- package/src/index.d.ts +2 -2
- package/src/index.js +38 -69
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-instagram",
|
|
3
3
|
"description": "Metascraper integration for Instagram",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-instagram",
|
|
5
|
-
"version": "5.45.
|
|
5
|
+
"version": "5.45.28",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"author": {
|
|
@@ -23,9 +23,8 @@
|
|
|
23
23
|
"metascraper"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@metascraper/helpers": "
|
|
27
|
-
"
|
|
28
|
-
"lodash": "~4.17.21"
|
|
26
|
+
"@metascraper/helpers": "5.45.28",
|
|
27
|
+
"franc": "~5.0.0"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"ava": "5"
|
|
@@ -40,5 +39,5 @@
|
|
|
40
39
|
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
41
40
|
},
|
|
42
41
|
"license": "MIT",
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "a3ca157491003cd78000a3c5c6d1bf038937b1c7"
|
|
44
43
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function rules(): import('metascraper').Rules
|
|
2
|
-
export = rules
|
|
1
|
+
declare function rules (): import('metascraper').Rules
|
|
2
|
+
export = rules
|
package/src/index.js
CHANGED
|
@@ -1,82 +1,51 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const { JSDOM, VirtualConsole } = require('jsdom')
|
|
5
|
-
const { keys, first, get } = require('lodash')
|
|
3
|
+
const franc = require('franc')
|
|
6
4
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
virtualConsole: new VirtualConsole(),
|
|
17
|
-
runScripts: 'dangerously'
|
|
18
|
-
})
|
|
19
|
-
const sharedData = get(dom, 'window._sharedData')
|
|
20
|
-
|
|
21
|
-
const page = getPage(sharedData)
|
|
22
|
-
|
|
23
|
-
const getTitle = ({ author, username }) =>
|
|
24
|
-
author
|
|
25
|
-
? `${author} (@${username}) on Instagram`
|
|
26
|
-
: `@${username} on Instagram`
|
|
5
|
+
const {
|
|
6
|
+
author,
|
|
7
|
+
date,
|
|
8
|
+
iso6393,
|
|
9
|
+
lang,
|
|
10
|
+
memoizeOne,
|
|
11
|
+
parseUrl,
|
|
12
|
+
title
|
|
13
|
+
} = require('@metascraper/helpers')
|
|
27
14
|
|
|
28
|
-
|
|
29
|
-
case 'PostPage': {
|
|
30
|
-
const media = get(
|
|
31
|
-
sharedData,
|
|
32
|
-
`entry_data.${page}[0].graphql.shortcode_media`
|
|
33
|
-
)
|
|
15
|
+
console.log('iso6393', iso6393)
|
|
34
16
|
|
|
35
|
-
|
|
36
|
-
const username = get(media, 'owner.username')
|
|
17
|
+
const detectLang = input => lang(iso6393[franc(input)])
|
|
37
18
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
image: get(media, 'display_url'),
|
|
42
|
-
date: get(media, 'taken_at_timestamp'),
|
|
43
|
-
title: getTitle({ author, username }),
|
|
44
|
-
description: get(media, 'edge_media_to_caption.edges[0].node.text')
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
case 'ProfilePage': {
|
|
48
|
-
const user = get(sharedData, `entry_data.${page}[0].graphql.user`)
|
|
49
|
-
const author = get(user, 'full_name')
|
|
50
|
-
const username = get(user, 'username')
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
author,
|
|
54
|
-
title: getTitle({ author, username }),
|
|
55
|
-
description: get(user, 'biography')
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
case 'StoriesPage': {
|
|
59
|
-
const user = get(sharedData, `entry_data.${page}[0].user`)
|
|
60
|
-
const username = get(user, 'username')
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
title: getTitle({ username })
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
19
|
+
const test = memoizeOne(
|
|
20
|
+
url => parseUrl(url).domainWithoutSuffix === 'instagram'
|
|
21
|
+
)
|
|
68
22
|
|
|
69
|
-
const
|
|
23
|
+
const getDescription = memoizeOne(
|
|
24
|
+
(_, $) => $('meta[property="og:description"]').attr('content'),
|
|
25
|
+
memoizeOne.EqualityFirstArgument
|
|
26
|
+
)
|
|
70
27
|
|
|
71
28
|
module.exports = () => {
|
|
72
29
|
const rules = {
|
|
73
|
-
author:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
30
|
+
author: ({ htmlDom: $ }) => {
|
|
31
|
+
const title = $('meta[property="og:title"]').attr('content')
|
|
32
|
+
const value = title.split(' on Instagram')[0]
|
|
33
|
+
return author(value)
|
|
34
|
+
},
|
|
35
|
+
date: ({ htmlDom: $, url }) => {
|
|
36
|
+
const description = getDescription(url, $)
|
|
37
|
+
const dateMatch = description.match(/on ([^,]+, \d{4})/)
|
|
38
|
+
if (dateMatch === null) return
|
|
39
|
+
const dateString = `${dateMatch[1]} GMT`
|
|
40
|
+
return date(new Date(dateString))
|
|
41
|
+
},
|
|
42
|
+
lang: ({ htmlDom: $, url }) => {
|
|
43
|
+
const description = getDescription(url, $)
|
|
44
|
+
const input = description.split(': ').pop().split(' - ').pop()
|
|
45
|
+
return detectLang(input)
|
|
46
|
+
},
|
|
47
|
+
title: ({ htmlDom: $ }) =>
|
|
48
|
+
title($('meta[name="twitter:title"]').attr('content'))
|
|
80
49
|
}
|
|
81
50
|
|
|
82
51
|
rules.test = ({ url }) => test(url)
|