Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //By: π§ πππππ πππ ππππππ π§
- //Canal: https://whatsapp.com/channel/0029Vb69bDnAe5VmzSMwBH11
- const axios = require('axios');
- const cheerio = require('cheerio');
- async function baixarTikTok(url) {
- try {
- if (!url.includes('tiktok.com')) throw new Error('URL invΓ‘lida.');
- const { data: html, headers } = await axios.get('https://musicaldown.com/en');
- const $ = cheerio.load(html);
- const dadosFormulario = {};
- $('#submit-form input').each((i, elemento) => {
- const nome = $(elemento).attr('name');
- const valor = $(elemento).attr('value');
- if (nome) dadosFormulario[nome] = valor || '';
- });
- const campoUrl = Object.keys(dadosFormulario).find(chave => !dadosFormulario[chave]);
- if (campoUrl) dadosFormulario[campoUrl] = url;
- const { data } = await axios.post('https://musicaldown.com/download', new URLSearchParams(dadosFormulario).toString(), {
- headers: {
- 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
- cookie: headers['set-cookie'].join('; '),
- origin: 'https://musicaldown.com',
- referer: 'https://musicaldown.com/',
- 'user-agent': 'Mozilla/5.0 (Linux; Android 15; SM-F958 Build/AP3A.240905.015) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.86 Mobile Safari/537.36'
- }
- });
- const $$ = cheerio.load(data);
- const cabecalhoVideo = $$('.video-header');
- const imagemFundo = cabecalhoVideo.attr('style');
- const capaMatch = imagemFundo?.match(/url\((.*?)\)/);
- const downloads = [];
- $$('a.download').each((i, elemento) => {
- const $elemento = $$(elemento);
- const tipo = $elemento.data('event')?.replace('_download_click', '');
- const rotulo = $elemento.text().trim();
- downloads.push({
- tipo: tipo,
- rotulo: rotulo,
- url: $elemento.attr('href')
- });
- });
- return {
- titulo: $$('.video-desc').text().trim(),
- autor: {
- usuario: $$('.video-author b').text().trim(),
- avatar: $$('.img-area img').attr('src')
- },
- capa: capaMatch ? capaMatch[1] : null,
- downloads: downloads
- };
- } catch (erro) {
- throw new Error(erro.message);
- }
- }
- module.exports = baixarTikTok;
- // Exemplo de uso:
- // baixarTikTok('https://vm.tiktok.com/ZSH3eSA7UTts9-FK9xz/')
- // .then(console.log)
- // .catch(console.error);
Advertisement
Add Comment
Please, Sign In to add comment