API-XX commited on
Commit
81aa044
Β·
verified Β·
1 Parent(s): 76d50d5

Upload case.js

Browse files
Files changed (1) hide show
  1. case.js +38 -48
case.js CHANGED
@@ -2977,62 +2977,52 @@ ${listAdmin}
2977
  });
2978
  break;
2979
  }
2980
- case 'animedl': {
2981
- if (!q.includes('|')) return conn.sendMessage(m.chat, {
2982
- text: `\`Invalid format\`\nExample: *${prefix + command} solo leveling|1*`
2983
- });
2984
-
2985
- await loading();
2986
 
2987
- try {
2988
- let [anime, episode] = q.split('|').map(x => x.trim());
2989
- let apiUrl = `https://api-xx-xi.hf.space/api/animedl?name=${encodeURIComponent(anime)}&episode=${encodeURIComponent(episode)}`;
2990
- let response = await fetch(apiUrl);
2991
- let json = await response.json();
2992
 
2993
- if (!json.success || !json.downloadLinks.length) {
2994
- return conn.sendMessage(m.chat, {
2995
- text: `❌ *No download links found for ${anime} Episode ${episode}*`
2996
- });
2997
- }
2998
 
2999
- function parseSize(size) {
3000
- let match = size.match(/([\d.]+)\s*(MB|GB)/i);
3001
- if (!match) return Infinity;
3002
- let value = parseFloat(match[1]);
3003
- return match[2].toLowerCase() === 'gb' ? value * 1024 : value;
3004
- }
3005
 
3006
- let bestMatch = json.downloadLinks.reduce((prev, curr) => {
3007
- return Math.abs(parseSize(curr.size) - 100) < Math.abs(parseSize(prev.size) - 100) ? curr : prev;
3008
- });
 
 
3009
 
3010
- let {
3011
- link,
3012
- size
3013
- } = bestMatch;
3014
 
3015
- conn.sendMessage(m.chat, {
3016
- text: `πŸŽ₯ *Downloading ${anime} Episode ${episode}*\nπŸ“¦ *Size:* ${size}`
3017
- });
 
3018
 
3019
- await conn.sendMessage(m.chat, {
3020
- document: {
3021
- url: link
3022
- },
3023
- mimetype: 'video/mp4',
3024
- fileName: `${anime} - Episode ${episode}.mp4`,
3025
- caption: fontx(`🎬 *${anime} - Episode ${episode}*\nπŸ“₯ *Size:* ${size}`)
3026
- });
3027
 
3028
- } catch (error) {
3029
- console.error("Error in animedl case:", error);
3030
- conn.sendMessage(m.chat, {
3031
- text: "❌ An error occurred while fetching the anime. Please try again later."
3032
- });
3033
- }
3034
- break;
3035
- }
3036
  case 'play':
3037
  case 'songs': {
3038
  if (!text) {
 
2977
  });
2978
  break;
2979
  }
2980
+ case 'animedl': {
2981
+ if (!q.includes('|')) {
2982
+ return conn.sendMessage(m.chat, {
2983
+ text: `\`Invalid format\`\nExample: *${prefix + command} solo leveling|1*`
2984
+ });
2985
+ }
2986
 
2987
+ await loading();
 
 
 
 
2988
 
2989
+ try {
2990
+ let [anime, episode] = q.split('|').map(x => x.trim());
2991
+ let apiUrl = `https://api-xx-xi.hf.space/api/animedl?name=${encodeURIComponent(anime)}&episode=${encodeURIComponent(episode)}`;
 
 
2992
 
2993
+ let response = await fetch(apiUrl);
2994
+ let json = await response.json();
 
 
 
 
2995
 
2996
+ if (!json.success || !json.download_link) {
2997
+ return conn.sendMessage(m.chat, {
2998
+ text: `❌ *No download link found for ${anime} Episode ${episode}.*`
2999
+ });
3000
+ }
3001
 
3002
+ let downloadLink = json.download_link;
3003
+ let title = json.title || `${anime} - Episode ${episode}`;
 
 
3004
 
3005
+ // Notify the user
3006
+ await conn.sendMessage(m.chat, {
3007
+ text: fontx(`πŸŽ₯ *Fetching ${title}*\n⏳ Please wait...`)
3008
+ });
3009
 
3010
+ // Send the episode as a file
3011
+ await conn.sendMessage(m.chat, {
3012
+ document: { url: downloadLink },
3013
+ mimetype: 'video/mp4',
3014
+ fileName: `${title}.mp4`,
3015
+ caption: fontx(`🎬 *${title}*\nπŸ“₯ *Download Complete!*`)
3016
+ });
 
3017
 
3018
+ } catch (error) {
3019
+ console.error("Error in animedl case:", error);
3020
+ conn.sendMessage(m.chat, {
3021
+ text: "❌ An error occurred while fetching the anime. Please try again later."
3022
+ });
3023
+ }
3024
+ break;
3025
+ }
3026
  case 'play':
3027
  case 'songs': {
3028
  if (!text) {