From 17866572ed6ae20469a38e5c2aebe41f8ade1c97 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Mon, 30 Sep 2024 23:54:28 +0200 Subject: [PATCH] feat: add onlyfans --- public/README.md | 6 ++++++ src/providers/index.js | 3 ++- src/providers/onlyfans.js | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/providers/onlyfans.js diff --git a/public/README.md b/public/README.md index 9b55743..7f9d577 100644 --- a/public/README.md +++ b/public/README.md @@ -158,6 +158,12 @@ It resolves user avatar using **microlink.io**. e.g., https://unavatar.io/microlink/microlink.io +### OnlyFans + +It resolves user avatar using **onlyfans.com**. + +e.g., https://unavatar.io/onlyfans/amandaribas + ### Read.cv Type: `username` diff --git a/src/providers/index.js b/src/providers/index.js index 338ec3d..4aca0e4 100644 --- a/src/providers/index.js +++ b/src/providers/index.js @@ -20,7 +20,8 @@ const providers = { // tiktok: require('./tiktok'), twitch: require('./twitch'), x: require('./x'), - youtube: require('./youtube') + youtube: require('./youtube'), + onlyfans: require('./onlyfans') } const providersBy = reduce( diff --git a/src/providers/onlyfans.js b/src/providers/onlyfans.js new file mode 100644 index 0000000..cf42fee --- /dev/null +++ b/src/providers/onlyfans.js @@ -0,0 +1,26 @@ +'use strict' + +const PCancelable = require('p-cancelable') +const cheerio = require('cheerio') + +const getHTML = require('../util/html-get') + +module.exports = PCancelable.fn(async function onlyfans ({ input }, onCancel) { + const promise = getHTML(`https://onlyfans.com/${input}`, { + prerender: true, + puppeteerOpts: { abortTypes: ['other', 'image', 'font'] } + }) + onCancel(() => promise.onCancel()) + const { html } = await promise + const $ = cheerio.load(html) + const json = JSON.parse( + $('script[type="application/ld+json"]').contents().text() + ) + return json.mainEntity.image +}) + +module.exports.supported = { + email: false, + username: true, + domain: false +}