ShahriarAbidbd/SmartifyXBotPublic · Bot Template

Do Tasks Smartly with SmartifyX 😎

Utilitydownloaderyoutubeinstagramfacebookspoilercontent-protection
ProfileTelegram
25 commands2 envUpdated 1d agoCreated Jul 28, 2026
Back to folder

commands/Downloader/_yt.js

javascript · 139 lines

Raw
1/**#command2name: /yt3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12function cleanYTTitle(rawTitle) {13  if (!rawTitle) return {};14 15  let parts = rawTitle.split("|").map(p => p.trim());16  let title = parts[1] || rawTitle;17  return {18    title19  };20}21 22async function getYTVideo(link) {23 24  let a = await Bot.sendMessage("⏳ Downloading")25  let mid = a.result.message_id26 27  await Api.editMessageText({28    chat_id: chat.id,29    message_id: mid,30    text: "⏳ Downloading."31  })32 33  // validate YT link34  if (35    link.indexOf("youtube.com") === -1 &&36    link.indexOf("yt.watch") === -1 &&37    link.indexOf("youtu.be") === -138  ) {39    Api.editMessageText({40      chat_id: chat.id,41      message_id: mid,42      text: "❗ Only Youtube URLs are supported."43    })44    return45  }46 47  let headers = {48    "Accept": "application/json",49    "Content-Type": "application/json",50    "Origin": "https://ytdownload.in",51    "Referer": "https://ytdownload.in/",52    "User-Agent": "Mozilla/5.0 (Android)"53  }54 55  // warmup56  await HTTP.get({57    url: "https://ytdownload.in",58    headers: headers59  })60 61  let res = await HTTP.post({62    url: Bot.get("downloader_api"),63    headers: headers,64    body: {65      url: link,66      format: "mp4",67      quality: "1080p"68    }69  })70 71  await Api.editMessageText({72    chat_id: chat.id,73    message_id: mid,74    text: "⏳ Downloading.."75  })76 77  if (!res.ok || !res.data?.responseFinal) {78    Api.editMessageText({79      chat_id: chat.id,80      message_id: mid,81      text: "❌ Video not found or private."82    })83    return84  }85 86  await Api.editMessageText({87    chat_id: chat.id,88    message_id: mid,89    text: "⏳ Downloading..."90  })91 92  let r = res.data.responseFinal93 94  // HD video priority95  let video =96    r.videoUrl || r.formats?.find(v => v.qualityLabel?.includes("HD"))?.url ||97    r.formats?.[0]?.url98 99  if (!video) {100    Api.editMessageText({101      chat_id: chat.id,102      message_id: mid,103      text: "❌ HD video not available."104    })105    return106  }107 108  let info = cleanYTTitle(r.title)109 110  let caption =111    "<b>" + (info.title || "Youtube Video") + "</b>"112 113  let name = user.first_name + (user.last_name ? " " + user.last_name : "")114 115  let res_yt = await Api.editMessageMedia({116    chat_id: chat.id,117    message_id: mid,118    media: {119      type: "video",120      media: video,121      caption: caption +122        `\n\n<blockquote><b>Downloaded by:</b> <a href="tg://user?id=${user.id}">${name}</a></blockquote>`,123      parse_mode: "HTML"124    }125  })126 127  if (!res_yt.ok) {128    Bot.runCommand("!")129  }130}131 132/* command handler */133if (request.reply_to_message && request.reply_to_message.text) {134  getYTVideo(request.reply_to_message.text)135} else if (params) {136  getYTVideo(params)137} else {138  msg.reply("❗ Please provide a Youtube video link.")139}