Skip to content

Commit

Permalink
feat: add onlyfans
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 1, 2024
1 parent bab8263 commit 0cfe669
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
6 changes: 6 additions & 0 deletions public/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion src/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions src/providers/onlyfans.js
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 11 additions & 5 deletions test/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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', {
Expand All @@ -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', {
Expand Down Expand Up @@ -171,12 +169,20 @@ 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
})
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'))
})

0 comments on commit 0cfe669

Please sign in to comment.