metascraper-telegram 5.29.3 → 5.29.7
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 +29 -8
- package/index.js +41 -31
- package/package.json +10 -18
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
> Metascraper integration with Telegram
|
|
1
|
+
<div align="center">
|
|
2
|
+
<br>
|
|
3
|
+
<img style="width: 500px; margin:3rem 0 1.5rem;" src="https://metascraper.js.org/static/logo-banner.png" alt="metascraper">
|
|
4
|
+
<br>
|
|
5
|
+
<br>
|
|
6
|
+
<p align="center"><strong>metascraper-telegram</strong>: Metascraper integration with Telegram.</p>
|
|
7
|
+
<p align="center">See our <a href="https://metascraper.js.org" target='_blank' rel='noopener noreferrer'>website</a> for more information.</p>
|
|
8
|
+
<br>
|
|
9
|
+
</div>
|
|
7
10
|
|
|
8
11
|
## Install
|
|
9
12
|
|
|
@@ -11,9 +14,27 @@
|
|
|
11
14
|
$ npm install metascraper-telegram --save
|
|
12
15
|
```
|
|
13
16
|
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
### metascraper-telegram([options])
|
|
20
|
+
|
|
21
|
+
#### options
|
|
22
|
+
|
|
23
|
+
##### gotOpts
|
|
24
|
+
|
|
25
|
+
Type: `object`
|
|
26
|
+
|
|
27
|
+
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
|
|
28
|
+
|
|
29
|
+
##### keyvOpts
|
|
30
|
+
|
|
31
|
+
Type: `object`
|
|
32
|
+
|
|
33
|
+
Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).
|
|
34
|
+
|
|
14
35
|
## License
|
|
15
36
|
|
|
16
|
-
**metascraper-telegram** © [Microlink](https://microlink.io),
|
|
37
|
+
**metascraper-telegram** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
|
|
17
38
|
Authored and maintained by [Microlink](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/metascraper/contributors).
|
|
18
39
|
|
|
19
|
-
> [microlink.io](https://microlink.io) · GitHub [
|
|
40
|
+
> [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
|
package/index.js
CHANGED
|
@@ -4,16 +4,15 @@ const {
|
|
|
4
4
|
author,
|
|
5
5
|
date,
|
|
6
6
|
image,
|
|
7
|
-
loadIframe,
|
|
8
7
|
memoizeOne,
|
|
9
8
|
toRule
|
|
10
9
|
} = require('@metascraper/helpers')
|
|
11
10
|
|
|
12
|
-
const
|
|
11
|
+
const memoize = require('@keyvhq/memoize')
|
|
13
12
|
const { getDomain } = require('tldts')
|
|
13
|
+
const pReflect = require('p-reflect')
|
|
14
14
|
const cssUrls = require('css-urls')
|
|
15
|
-
|
|
16
|
-
const fromIframe = asyncMemoizeOne((url, $) => loadIframe(url, $.html()))
|
|
15
|
+
const got = require('got')
|
|
17
16
|
|
|
18
17
|
const toAuthor = toRule(author)
|
|
19
18
|
const toImage = toRule(image)
|
|
@@ -21,44 +20,55 @@ const toDate = toRule(date)
|
|
|
21
20
|
|
|
22
21
|
const TELEGRAM_DOMAINS = ['telegram.me', 't.me']
|
|
23
22
|
|
|
24
|
-
const
|
|
23
|
+
const test = memoizeOne(url => TELEGRAM_DOMAINS.includes(getDomain(url)))
|
|
24
|
+
|
|
25
|
+
const createGetIframe = gotOpts => async (url, $) => {
|
|
26
|
+
const iframe = $('iframe')
|
|
27
|
+
if (iframe.length === 0) return ''
|
|
28
|
+
|
|
29
|
+
const src = iframe.attr('src')
|
|
30
|
+
if (!src) return ''
|
|
31
|
+
|
|
32
|
+
const { value: response } = await pReflect(got(src, gotOpts))
|
|
33
|
+
if (!response) return ''
|
|
34
|
+
|
|
35
|
+
return response.body
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = ({ gotOpts, keyvOpts } = {}) => {
|
|
39
|
+
const getIframe = memoize(createGetIframe(gotOpts), keyvOpts, {
|
|
40
|
+
key: url => url
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const loadIframe = fn => async ($, url) => {
|
|
44
|
+
const html = await getIframe(url, $)
|
|
45
|
+
return html.length ? fn($.load(html), url) : undefined
|
|
46
|
+
}
|
|
25
47
|
|
|
26
|
-
module.exports = () => {
|
|
27
48
|
const rules = {
|
|
28
49
|
author: [toAuthor($ => $('meta[property="og:title"]').attr('content'))],
|
|
29
50
|
logo: [toImage($ => $('meta[property="og:image"]').attr('content'))],
|
|
30
51
|
image: [
|
|
31
|
-
toImage(
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
toImage(
|
|
53
|
+
loadIframe(($iframe, url) => {
|
|
54
|
+
const el = $iframe(
|
|
55
|
+
'.link_preview_image, .link_preview_right_image, .tgme_widget_message_photo_wrap'
|
|
56
|
+
)
|
|
34
57
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
if (el.length === 0) return
|
|
59
|
+
const [{ normalizedUrl: cssUrl }] = cssUrls({
|
|
60
|
+
text: el.css('background-image'),
|
|
61
|
+
url
|
|
62
|
+
})
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const [{ normalizedUrl: cssUrl }] = cssUrls({
|
|
43
|
-
text: el.style['background-image'],
|
|
44
|
-
url
|
|
64
|
+
return cssUrl
|
|
45
65
|
})
|
|
46
|
-
|
|
47
|
-
return cssUrl
|
|
48
|
-
})
|
|
66
|
+
)
|
|
49
67
|
],
|
|
50
|
-
date: [
|
|
51
|
-
toDate(async ($, url) => {
|
|
52
|
-
const iframe = await fromIframe(url, $)
|
|
53
|
-
if (!iframe) return
|
|
54
|
-
|
|
55
|
-
const el = iframe.document.querySelector('.datetime')
|
|
56
|
-
return el ? el.getAttribute('datetime') : undefined
|
|
57
|
-
})
|
|
58
|
-
]
|
|
68
|
+
date: [toDate(loadIframe($iframe => $iframe('.datetime').attr('datetime')))]
|
|
59
69
|
}
|
|
60
70
|
|
|
61
|
-
rules.test = ({ url }) =>
|
|
71
|
+
rules.test = ({ url }) => test(url)
|
|
62
72
|
|
|
63
73
|
return rules
|
|
64
74
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-telegram",
|
|
3
3
|
"description": "Metascraper integration with Telegram",
|
|
4
4
|
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-telegram",
|
|
5
|
-
"version": "5.29.
|
|
5
|
+
"version": "5.29.7",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"telegram"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"css-urls": "~2.0.
|
|
28
|
-
"
|
|
25
|
+
"@keyvhq/memoize": "~1.6.13",
|
|
26
|
+
"@metascraper/helpers": "^5.29.7",
|
|
27
|
+
"css-urls": "~2.0.27",
|
|
28
|
+
"got": "~11.8.3",
|
|
29
|
+
"p-reflect": "~2.1.0",
|
|
30
|
+
"tldts": "~5.7.80"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"should": "latest",
|
|
33
|
-
"snap-shot": "latest"
|
|
33
|
+
"ava": "latest"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">= 12"
|
|
@@ -39,16 +39,8 @@
|
|
|
39
39
|
"index.js"
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
|
-
"test": "NODE_PATH=.. TZ=UTC
|
|
42
|
+
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
43
43
|
},
|
|
44
44
|
"license": "MIT",
|
|
45
|
-
"
|
|
46
|
-
"bail": true,
|
|
47
|
-
"exit": true,
|
|
48
|
-
"recursive": true,
|
|
49
|
-
"reporter": "spec",
|
|
50
|
-
"slow": 300,
|
|
51
|
-
"timeout": "120000"
|
|
52
|
-
},
|
|
53
|
-
"gitHead": "e3d5ef5add6fec690b1234e6aaa273e1a658c256"
|
|
45
|
+
"gitHead": "78434709c910cca5d8df3871c0b06131cce5df45"
|
|
54
46
|
}
|