From 0cfe669ed2c090915846069781aead93ff4f20fc 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 ++++++++++++++++++++++++++ test/endpoints.js | 16 +++++++++++----- 4 files changed, 45 insertions(+), 6 deletions(-) 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 +} diff --git a/test/endpoints.js b/test/endpoints.js index ea3c836..66af174 100644 --- a/test/endpoints.js +++ b/test/endpoints.js @@ -61,7 +61,7 @@ test('soundcloud', async t => { t.is(statusCode, 200) t.true(body.url.includes('images.weserv.nl')) }) -// + test('deviantart', async t => { const serverUrl = await runServer(t) const { body, statusCode } = await got('deviantart/spyed?json', { @@ -126,7 +126,6 @@ test('telegram', async t => { t.is(statusCode, 200) t.true(body.url.includes('images.weserv.nl')) }) -// ;(isCI ? test.skip : test)('reddit', async t => { const serverUrl = await runServer(t) const { body, statusCode } = await got('reddit/kikobeats?json', { @@ -135,7 +134,6 @@ test('telegram', async t => { t.is(statusCode, 200) t.true(body.url.includes('images.weserv.nl')) }) -// ;(isCI ? test.skip : test)('instagram', async t => { const serverUrl = await runServer(t) const { body, statusCode } = await got('instagram/willsmith?json', { @@ -171,8 +169,7 @@ test('readcv', async t => { t.is(statusCode, 200) t.true(body.url.includes('images.weserv.nl')) }) -// -test.skip('tiktok', async t => { +;(isCI ? test.skip : test)('tiktok', async t => { const serverUrl = await runServer(t) const { body, statusCode } = await got('tiktok/carlosazaustre?json', { prefixUrl: serverUrl @@ -180,3 +177,12 @@ test.skip('tiktok', async t => { t.is(statusCode, 200) t.true(body.url.includes('images.weserv.nl')) }) + +test('onlyfans', async t => { + const serverUrl = await runServer(t) + const { body, statusCode } = await got('onlyfans/amandaribas?json', { + prefixUrl: serverUrl + }) + t.is(statusCode, 200) + t.true(body.url.includes('images.weserv.nl')) +})