Skip to content

Commit

Permalink
feat: add tiktok support (#230)
Browse files Browse the repository at this point in the history
closes #225
  • Loading branch information
Kikobeats committed Mar 11, 2023
1 parent 44ab191 commit 02750a8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
9 changes: 9 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ <h3>Telegram</h3>
<a target="_blank" rel="noopener noreferrer"
href="https://unavatar.io/telegram/drsdavidsoft">https://unavatar.io/telegram/drsdavidsoft</a>
</p>
<h3>TikTok</h3>
<p>
<code>&lt;img src="https://unavatar.io/tiktok/:username" /&gt;</code>
</p>
<p>
e.g.,
<a target="_blank" rel="noopener noreferrer"
href="https://unavatar.io/tiktok/carlosazaustre">https://unavatar.io/tiktok/carlosazaustre</a>
</p>
<h3>Twitter</h3>
<p>
<code>&lt;img src="https://unavatar.io/twitter/:username" /&gt;</code>
Expand Down
1 change: 1 addition & 0 deletions src/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const providers = {
soundcloud: require('./soundcloud'),
substack: require('./substack'),
telegram: require('./telegram'),
tiktok: require('./tiktok'),
twitter: require('./twitter'),
youtube: require('./youtube')
}
Expand Down
1 change: 0 additions & 1 deletion src/providers/readcv.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = async function readcv (username) {
const images = $('main > div > div > div > div > img').attr('srcset')
if (!images) return
const parsedImages = srcset.parse(images)
if (parsedImages.length === 0) return
return parsedImages[parsedImages.length - 1].url
}

Expand Down
5 changes: 1 addition & 4 deletions src/providers/reddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ const getHTML = require('../util/html-get')

module.exports = async function reddit (username) {
const { html } = await getHTML(`https://www.reddit.com/user/${username}`, {
headers: { 'accept-language': 'en' },
puppeteerOpts: {
abortTypes: ['image', 'stylesheet', 'font', 'script']
}
headers: { 'accept-language': 'en' }
})
const $ = cheerio.load(html)
return $('img[alt="User avatar"]').attr('src')
Expand Down
17 changes: 17 additions & 0 deletions src/providers/tiktok.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const cheerio = require('cheerio')

const getHTML = require('../util/html-get')

module.exports = async function tiktok (username) {
const { html } = await getHTML(`https://www.tiktok.com/@${username}`)
const $ = cheerio.load(html)
return $('meta[property="og:image"]').attr('content')
}

module.exports.supported = {
email: false,
username: true,
domain: false
}
9 changes: 9 additions & 0 deletions test/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,12 @@ test('readcv', async t => {
})
t.true(body.url.includes('images.weserv.nl'))
})

test('tiktok', async t => {
const serverUrl = await createServer(t)
const { body } = await got('tiktok/carlosazaustre?json', {
prefixUrl: serverUrl,
responseType: 'json'
})
t.true(body.url.includes('images.weserv.nl'))
})

0 comments on commit 02750a8

Please sign in to comment.