User: sempurnakan kode ini const yts = require('yt-search');

exports.run = {
usage: ['ytsearch'],
hidden: ['yts'],
use: 'judul lagu',
category: 'downloader',
async: async (m, { func, mecha }) => {
if (!m.text) return m.reply(func.example(m.cmd, 'legends never die'))
mecha.sendReact(m.chat, '🕒', m.key)
let search = await yts(m.text);
if (search.all.length == 0) return m.reply('Data empty.')
let data = search.all.filter(x => x.seconds < 3600);
if (!data) return m.reply('Video is longer than 1 hour!');
mecha.ytsearch = mecha.ytsearch || {};
mecha.ytsearch[m.sender] = {
jid: m.sender,
search: data,
}
let messageId = 'MECHA' + func.makeid(22).toUpperCase() + 'YTSEARCH'
let caption = `*Y O U T U B E - S E A R C H*

Result From : \`${m.text}\`

_reply message with \`1a\` to download audio_.
_reply message with \`1v\` to download video_.\n\n`
data.forEach((item, index) => {
caption += `${index + 1}. ${item.title}\n- Duration: ${item.timestamp}\n- Author: ${item.author.name}\n- Publish: ${item.ago}\n\n`;
});
mecha.sendMessage(m.chat, {
text: caption
},
{
quoted: m,
ephemeralExpiration: m.expiration,
messageId: messageId
});
},
main: async (m, { func, mecha, YT }) => {
mecha.ytsearch = mecha.ytsearch || {};
if (mecha.ytsearch[m.sender] && m.budy && m.quoted && m.quoted.fromMe && m.quoted.id.endsWith('YTSEARCH') && !m.isPrefix) {
let command = m.budy.trim();
let data = mecha.ytsearch[m.sender];
// Tambahin logika untuk ambil audio/video
let index = parseInt(command) - 1; // ambil index dari command
if (index >= 0 && index < data.search.length) {
if (command.endsWith('a')) {
// Logika untuk download audio
mecha.sendReact(m.chat, '🕒', m.key)
const result = await YT.detail(data.search[index].url)
if (!result.status) return m.reply(result.message)
let caption = `乂  *YOUTUBE DOWNLOADER MP3*\n`
caption += `\n◦ VideoId : ${result.id}`
caption += `\n◦ Title : ${result.title}`
caption += `\n◦ Duration : ${result.duration}`
caption += `\n◦ URL Video : ${result.url}`
caption += `\n◦ Key : ${result.access}`
caption += `\n\nPlease wait, the audio file is being sent...`
mecha.sendMessageModify(m.chat, caption, m, {
largeThumb: true,
thumbnail: await func.fetchBuffer(result.thumbnail)
}).then(async () => {
let audio = await YT.media('audio', '128', result.access);
if (!audio.status) return m.reply(audio.message);
mecha.sendMessage(m.chat, {
audio: {
url: audio.url
},
mimetype: 'audio/mpeg', 
}, {quoted: m, ephemeralExpiration: m.expiration})
})
} else if (command.endsWith('v')) {
// Logika untuk download video
mecha.sendReact(m.chat, '🕒', m.key)
const result = await YT.detail(data.search[index].url)
if (!result.status) return m.reply(result.message)
let caption = `乂  *YOUTUBE DOWNLOADER MP4*\n`
caption += `\n◦ VideoId : ${result.id}`
caption += `\n◦ Title : ${result.title}`
caption += `\n◦ Duration : ${result.duration}`
caption += `\n◦ URL Video : ${result.url}`
caption += `\n◦ Key : ${result.access}`
caption += `\n\nPlease wait, the video file is being sent...`
mecha.sendMessageModify(m.chat, caption, m, {
largeThumb: true,
thumbnail: await func.fetchBuffer(result.thumbnail)
}).then(async () => {
let video = await YT.media('video', '720', result.access);
if (!video.status) return m.reply(video.message);
mecha.sendMessage(m.chat, {
video: {
url: video.url
},
mimetype: 'video/mp4',
}, {quoted: m, ephemeralExpiration: m.expiration})
})
} else {
return m.reply('Command tidak valid!');
}
} else {
return m.reply('Index tidak valid!');
}
}
},
restrict: true,
limit: 3
} untuk resolusi sesuaikan yang ada di kode ini > const axios = require("axios");

async function SSVID(link) {
    try {
        // Regex untuk mendeteksi URL YouTube, termasuk shorts dan youtu.be
        const regex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/|.+\/|.+\/(?:\w+\/)?|(?:.*[?&]v=))|youtu\.be\/)([\w-]{11})/;
        const match = link.match(regex);
        if (!match) {
            return "Gk ada yg valid jir";
        }
        const id = match[1];

        const headers = {
            accept: "*/*",
            "accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            "sec-ch-ua": '"Not-A.Brand";v="99", "Chromium";v="124"',
            "sec-ch-ua-mobile": "?1",
            "sec-ch-ua-platform": '"Android"',
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-origin",
            "x-requested-with": "XMLHttpRequest",
            Referer: "https://ssvid.net/",
            Origin: "https://ssvid.net",
            Cookie: "_ga=GA1.1.123456789.1234567890; _gid=GA1.1.987654321.0987654"
        };

        const searchResponse = await axios.post(
            "https://ssvid.net/api/ajax/search",
            `query=${encodeURIComponent(link)}&vt=home`,
            { headers: headers }
        );

        if (!searchResponse.data || !searchResponse.data.vid) {
            throw new Error("Tidak dapat menemukan informasi video");
        }

        const videoData = searchResponse.data;

        const mp4ConvertKey =
            videoData.links.mp4.auto.k || videoData.links.mp4["18"].k;
        const mp4ConvertPayload = `vid=${id}&k=${encodeURIComponent(mp4ConvertKey)}`;
        const mp4ConvertResponse = await axios.post(
            "https://ssvid.net/api/ajax/convert",
            mp4ConvertPayload,
            { headers: headers }
        );

        const mp3ConvertKey = videoData.links.mp3.mp3128.k;
        const mp3ConvertPayload = `vid=${id}&k=${encodeURIComponent(mp3ConvertKey)}`;
        const mp3ConvertResponse = await axios.post(
            "https://ssvid.net/api/ajax/convert",
            mp3ConvertPayload,
            { headers: headers }
        );

        if (
            !mp4ConvertResponse.data ||
            mp4ConvertResponse.data.c_status !== "CONVERTED" ||
            !mp3ConvertResponse.data ||
            mp3ConvertResponse.data.c_status !== "CONVERTED"
        ) {
            throw new Error("Konversi video gagal");
        }

        return {
            title: videoData.title || "Judul Tidak Diketahui",
            mp4: {
                quality:
                    videoData.links.mp4.auto.q_text ||
                    videoData.links.mp4["18"].q_text,
                size:
                    videoData.links.mp4.auto.size ||
                    videoData.links.mp4["18"].size,
                downloadLink: mp4ConvertResponse.data.dlink
            },
            mp3: {
                quality: videoData.links.mp3.mp3128.q_text,
                size: videoData.links.mp3.mp3128.size,
                downloadLink: mp3ConvertResponse.data.dlink
            }
        };
    } catch (error) {
        return error;
    }
}

// Contoh penggunaan
return SSVID("https://youtu.be/aJxLZg_x51Y?si=aK4s_O4stEV5-hH9"); dan di satukan dan sesuaikan dari quailty atau resolusi nya
User: sempurnakan kode ini const yts = require('yt-search');

exports.run = {
usage: ['ytsearch'],
hidden: ['yts'],
use: 'judul lagu',
category: 'downloader',
async: async (m, { func, mecha }) => {
if (!m.text) return m.reply(func.example(m.cmd, 'legends never die'))
mecha.sendReact(m.chat, '🕒', m.key)
let search = await yts(m.text);
if (search.all.length == 0) return m.reply('Data empty.')
let data = search.all.filter(x => x.seconds < 3600);
if (!data) return m.reply('Video is longer than 1 hour!');
mecha.ytsearch = mecha.ytsearch || {};
mecha.ytsearch[m.sender] = {
jid: m.sender,
search: data,
}
let messageId = 'MECHA' + func.makeid(22).toUpperCase() + 'YTSEARCH'
let caption = `*Y O U T U B E - S E A R C H*

Result From : \`${m.text}\`

_reply message with \`1a\` to download audio_.
_reply message with \`1v\` to download video_.\n\n`
data.forEach((item, index) => {
caption += `${index + 1}. ${item.title}\n- Duration: ${item.timestamp}\n- Author: ${item.author.name}\n- Publish: ${item.ago}\n\n`;
});
mecha.sendMessage(m.chat, {
text: caption
},
{
quoted: m,
ephemeralExpiration: m.expiration,
messageId: messageId
});
},
main: async (m, { func, mecha, YT }) => {
mecha.ytsearch = mecha.ytsearch || {};
if (mecha.ytsearch[m.sender] && m.budy && m.quoted && m.quoted.fromMe && m.quoted.id.endsWith('YTSEARCH') && !m.isPrefix) {
let command = m.budy.trim();
let data = mecha.ytsearch[m.sender];
// Tambahin logika untuk ambil audio/video
let index = parseInt(command) - 1; // ambil index dari command
if (index >= 0 && index < data.search.length) {
if (command.endsWith('a')) {
// Logika untuk download audio
mecha.sendReact(m.chat, '🕒', m.key)
const result = await YT.detail(data.search[index].url)
if (!result.status) return m.reply(result.message)
let caption = `乂  *YOUTUBE DOWNLOADER MP3*\n`
caption += `\n◦ VideoId : ${result.id}`
caption += `\n◦ Title : ${result.title}`
caption += `\n◦ Duration : ${result.duration}`
caption += `\n◦ URL Video : ${result.url}`
caption += `\n◦ Key : ${result.access}`
caption += `\n\nPlease wait, the audio file is being sent...`
mecha.sendMessageModify(m.chat, caption, m, {
largeThumb: true,
thumbnail: await func.fetchBuffer(result.thumbnail)
}).then(async () => {
let audio = await YT.media('audio', '128', result.access);
if (!audio.status) return m.reply(audio.message);
mecha.sendMessage(m.chat, {
audio: {
url: audio.url
},
mimetype: 'audio/mpeg', 
}, {quoted: m, ephemeralExpiration: m.expiration})
})
} else if (command.endsWith('v')) {
// Logika untuk download video
mecha.sendReact(m.chat, '🕒', m.key)
const result = await YT.detail(data.search[index].url)
if (!result.status) return m.reply(result.message)
let caption = `乂  *YOUTUBE DOWNLOADER MP4*\n`
caption += `\n◦ VideoId : ${result.id}`
caption += `\n◦ Title : ${result.title}`
caption += `\n◦ Duration : ${result.duration}`
caption += `\n◦ URL Video : ${result.url}`
caption += `\n◦ Key : ${result.access}`
caption += `\n\nPlease wait, the video file is being sent...`
mecha.sendMessageModify(m.chat, caption, m, {
largeThumb: true,
thumbnail: await func.fetchBuffer(result.thumbnail)
}).then(async () => {
let video = await YT.media('video', '720', result.access);
if (!video.status) return m.reply(video.message);
mecha.sendMessage(m.chat, {
video: {
url: video.url
},
mimetype: 'video/mp4',
}, {quoted: m, ephemeralExpiration: m.expiration})
})
} else {
return m.reply('Command tidak valid!');
}
} else {
return m.reply('Index tidak valid!');
}
}
},
restrict: true,
limit: 3
} untuk resolusi sesuaikan yang ada di kode ini > const axios = require("axios");

async function SSVID(link) {
    try {
        // Regex untuk mendeteksi URL YouTube, termasuk shorts dan youtu.be
        const regex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/|.+\/|.+\/(?:\w+\/)?|(?:.*[?&]v=))|youtu\.be\/)([\w-]{11})/;
        const match = link.match(regex);
        if (!match) {
            return "Gk ada yg valid jir";
        }
        const id = match[1];

        const headers = {
            accept: "*/*",
            "accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            "sec-ch-ua": '"Not-A.Brand";v="99", "Chromium";v="124"',
            "sec-ch-ua-mobile": "?1",
            "sec-ch-ua-platform": '"Android"',
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-origin",
            "x-requested-with": "XMLHttpRequest",
            Referer: "https://ssvid.net/",
            Origin: "https://ssvid.net",
            Cookie: "_ga=GA1.1.123456789.1234567890; _gid=GA1.1.987654321.0987654"
        };

        const searchResponse = await axios.post(
            "https://ssvid.net/api/ajax/search",
            `query=${encodeURIComponent(link)}&vt=home`,
            { headers: headers }
        );

        if (!searchResponse.data || !searchResponse.data.vid) {
            throw new Error("Tidak dapat menemukan informasi video");
        }

        const videoData = searchResponse.data;

        const mp4ConvertKey =
            videoData.links.mp4.auto.k || videoData.links.mp4["18"].k;
        const mp4ConvertPayload = `vid=${id}&k=${encodeURIComponent(mp4ConvertKey)}`;
        const mp4ConvertResponse = await axios.post(
            "https://ssvid.net/api/ajax/convert",
            mp4ConvertPayload,
            { headers: headers }
        );

        const mp3ConvertKey = videoData.links.mp3.mp3128.k;
        const mp3ConvertPayload = `vid=${id}&k=${encodeURIComponent(mp3ConvertKey)}`;
        const mp3ConvertResponse = await axios.post(
            "https://ssvid.net/api/ajax/convert",
            mp3ConvertPayload,
            { headers: headers }
        );

        if (
            !mp4ConvertResponse.data ||
            mp4ConvertResponse.data.c_status !== "CONVERTED" ||
            !mp3ConvertResponse.data ||
            mp3ConvertResponse.data.c_status !== "CONVERTED"
        ) {
            throw new Error("Konversi video gagal");
        }

        return {
            title: videoData.title || "Judul Tidak Diketahui",
            mp4: {
                quality:
                    videoData.links.mp4.auto.q_text ||
                    videoData.links.mp4["18"].q_text,
                size:
                    videoData.links.mp4.auto.size ||
                    videoData.links.mp4["18"].size,
                downloadLink: mp4ConvertResponse.data.dlink
            },
            mp3: {
                quality: videoData.links.mp3.mp3128.q_text,
                size: videoData.links.mp3.mp3128.size,
                downloadLink: mp3ConvertResponse.data.dlink
            }
        };
    } catch (error) {
        return error;
    }
}

// Contoh penggunaan
return SSVID("https://youtu.be/aJxLZg_x51Y?si=aK4s_O4stEV5-hH9"); dan di satukan dan sesuaikan dari quailty atau resolusi nya
Assistant: