-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ytdl.js #60
ytdl.js #60
Conversation
WalkthroughThe changes update the "song" command in the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant S as Song Command (ytdl.js)
participant T as Tubidy API
U->>S: Sends "song <query>" command
S->>T: Requests search results with query
alt Results available
T-->>S: Returns first result (link, title)
S->>T: Requests audio using the result link
T-->>S: Returns audio file
S->>U: Sends download message & audio file
else No results found
T-->>S: Returns empty response
S->>U: Sends no results message
end
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
assets/plugins/ytdl.jsOops! Something went wrong! :( ESLint: 9.5.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@eslint/js/src/configs/eslint-all' imported from /eslint.config.mjs ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
assets/plugins/ytdl.js (1)
86-111
:⚠️ Potential issueSecurity check! 🔒 (Because even mercenaries need protection!)
Hey there, fellow code ninja! Your security is looking about as tight as my spandex suit - which is to say, not tight enough!
Here are some security concerns that need addressing:
- You're not validating the content type before sending it to users
- No size limits on downloads (my healing factor can handle infinite size, your server can't!)
- No validation of the downloaded URLs
Here's a quick fix for content validation:
+ const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB limit + const ALLOWED_MIME_TYPES = ['audio/mpeg', 'audio/mp3']; + + // Add before downloading + const response = await fetch(buff); + const contentType = response.headers.get('content-type'); + const contentLength = response.headers.get('content-length'); + + if (!ALLOWED_MIME_TYPES.includes(contentType)) { + return await message.reply("Nice try! But that's not an audio file! 🕵️♂️"); + } + + if (contentLength > MAX_FILE_SIZE) { + return await message.reply("Whoa there! That file is bigger than my ego! Try something smaller! 📦"); + }
🧹 Nitpick comments (2)
assets/plugins/ytdl.js (2)
11-11
: Chimichanga alert! 🌯 We've got an unused import here!Hey there! Your friendly neighborhood Deadpool noticed you're importing
yta
andytv
from ytdl but never using them. That's like bringing katanas to a pillow fight - totally unnecessary!-const { yta, ytv } = require("../../lib/ytdl");
86-111
: Time for some architectural wisdom! 🏗️Those hardcoded URLs are like my face - they need some serious restructuring! Let's make this more maintainable!
Consider moving the API URLs to a configuration file:
// config/api.js module.exports = { TUBIDY_API: { BASE_URL: 'https://diegoson-naxordeve.hf.space/tubidy', SEARCH_ENDPOINT: '/search', DOWNLOAD_ENDPOINT: '/dl' } };Also, how about we add some rate limiting? We don't want to get banned faster than I get kicked out of the X-Men!
Want me to whip up a complete implementation with rate limiting and proper error handling? Just say the word! 🎯
assets/plugins/ytdl.js
Outdated
let toBuffu = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${toBuffer.link}`; | ||
let get = await fetch(toBuffu); | ||
let toAudio = await get.json(); | ||
if (!toAudio.media || !toAudio.media.length) return; | ||
let buff = toAudio.media.find(m => m.type === 'download')?.link; | ||
if (!buff) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maximum effort needed here! 💪 Your error handling is missing in action!
Just like my healing factor, your code needs some regeneration capabilities! You're making another fetch call without any protection!
Let's wrap this bad boy in a try-catch:
- let toBuffu = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${toBuffer.link}`;
- let get = await fetch(toBuffu);
- let toAudio = await get.json();
- if (!toAudio.media || !toAudio.media.length) return;
- let buff = toAudio.media.find(m => m.type === 'download')?.link;
- if (!buff) return;
+ try {
+ const toBuffu = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${encodeURIComponent(toBuffer.link)}`;
+ const get = await fetch(toBuffu);
+ if (!get.ok) throw new Error(`HTTP error! status: ${get.status}`);
+ const toAudio = await get.json();
+ if (!toAudio.media || !toAudio.media.length) {
+ return await message.reply("No audio found! Did someone steal it? 🤔");
+ }
+ const buff = toAudio.media.find(m => m.type === 'download')?.link;
+ if (!buff) {
+ return await message.reply("Found the audio but can't get the download link! Talk about a tease! 😅");
+ }
+ } catch (error) {
+ return await message.reply(`Holy macaroni! Something went wrong: ${error.message}`);
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
let toBuffu = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${toBuffer.link}`; | |
let get = await fetch(toBuffu); | |
let toAudio = await get.json(); | |
if (!toAudio.media || !toAudio.media.length) return; | |
let buff = toAudio.media.find(m => m.type === 'download')?.link; | |
if (!buff) return; | |
try { | |
const toBuffu = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${encodeURIComponent(toBuffer.link)}`; | |
const get = await fetch(toBuffu); | |
if (!get.ok) throw new Error(`HTTP error! status: ${get.status}`); | |
const toAudio = await get.json(); | |
if (!toAudio.media || !toAudio.media.length) { | |
return await message.reply("No audio found! Did someone steal it? 🤔"); | |
} | |
const buff = toAudio.media.find(m => m.type === 'download')?.link; | |
if (!buff) { | |
return await message.reply("Found the audio but can't get the download link! Talk about a tease! 😅"); | |
} | |
} catch (error) { | |
return await message.reply(`Holy macaroni! Something went wrong: ${error.message}`); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
assets/plugins/ytdl.js (1)
94-97
:⚠️ Potential issueTime to level up our URL game! 🎮
We're raw-dogging those URLs without any encoding! That's more dangerous than my usual stunts!
Let's make it safer:
- const findUrl = `https://diegoson-naxordeve.hf.space/tubidy/search?q=${match}`; + const findUrl = `https://diegoson-naxordeve.hf.space/tubidy/search?q=${encodeURIComponent(match)}`; const search = await fetch(findUrl); + if (!search.ok) throw new Error(`Search failed with status: ${search.status}`); const dlink = await search.json(); - if (!dlink || !dlink.length) return await message.reply("Not_found"); + if (!dlink || !dlink.length) return await message.reply("No results found! Even I couldn't find this one! 🤷♂️");🧰 Tools
🪛 Biome (1.9.4)
[error] 97-97: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
[error] 97-97: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
🧹 Nitpick comments (2)
assets/plugins/ytdl.js (2)
11-11
: Chimichangas! We've got an unused import here! 🌯Hey sugar bear, looks like we're importing
yta
andytv
from ytdl but never using them! It's like bringing katanas to a pillow fight - totally unnecessary!Let's slice this line right out:
-const { yta, ytv } = require("../../lib/ytdl");
94-102
: Let's talk about that hardcoded API endpoint! 🎯Using a hardcoded API endpoint is like putting all your chimichangas in one basket! What happens when the service goes down or changes?
Consider:
- Moving the API URL to a config file
- Adding request timeouts
- Implementing rate limiting
- Having fallback services
Want me to help set up a proper configuration structure? Just say the word!
🧰 Tools
🪛 Biome (1.9.4)
[error] 97-97: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
[error] 97-97: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
[error] 98-98: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
[error] 101-101: Shouldn't redeclare 'dlink'. Consider to delete it or rename it.
'dlink' is defined here:
(lint/suspicious/noRedeclare)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
assets/plugins/ytdl.js
(2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
assets/plugins/ytdl.js
[error] 97-97: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
[error] 97-97: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
[error] 98-98: This variable is used before its declaration.
The variable is declared here:
(lint/correctness/noInvalidUseBeforeDeclaration)
[error] 101-101: Shouldn't redeclare 'dlink'. Consider to delete it or rename it.
'dlink' is defined here:
(lint/suspicious/noRedeclare)
} catch (error) { | ||
console.error(error); | ||
return await message.reply("oops"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Your error handling is as basic as a vanilla ice cream! 🍦
Come on, we can do better than just "oops"! Let's give users something they can actually work with!
- console.error(error);
- return await message.reply("oops");
+ console.error('Tubidy download error:', error);
+ return await message.reply(`Holy macaroni! Something went wrong: ${error.message || 'Unknown error'}`);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
} catch (error) { | |
console.error(error); | |
return await message.reply("oops"); | |
} | |
} catch (error) { | |
console.error('Tubidy download error:', error); | |
return await message.reply(`Holy macaroni! Something went wrong: ${error.message || 'Unknown error'}`); | |
} |
const dlink = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${toBuffer.link}`; | ||
const teres = await fetch(dlink); | ||
const toAudio = await tores.json(); | ||
if (!toAudio.media || !toAudio.media.length) return; | ||
const buff = toAudio.media.find(m => m.type === 'download')?.link; | ||
if (!buff) return await message.reply("not found"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maximum effort needed here! Variable naming chaos! 🎭
- You're redeclaring
dlink
faster than I can break the fourth wall! - What's a
tores
? Did you meanteres
? Or was it supposed to betoRes
? Even my healing factor can't fix these typos!
Let's clean this up:
- const dlink = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${toBuffer.link}`;
- const teres = await fetch(dlink);
- const toAudio = await tores.json();
+ const downloadUrl = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${encodeURIComponent(toBuffer.link)}`;
+ const response = await fetch(downloadUrl);
+ if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
+ const toAudio = await response.json();
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const dlink = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${toBuffer.link}`; | |
const teres = await fetch(dlink); | |
const toAudio = await tores.json(); | |
if (!toAudio.media || !toAudio.media.length) return; | |
const buff = toAudio.media.find(m => m.type === 'download')?.link; | |
if (!buff) return await message.reply("not found"); | |
const downloadUrl = `https://diegoson-naxordeve.hf.space/tubidy/dl?url=${encodeURIComponent(toBuffer.link)}`; | |
const response = await fetch(downloadUrl); | |
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); | |
const toAudio = await response.json(); | |
if (!toAudio.media || !toAudio.media.length) return; | |
const buff = toAudio.media.find(m => m.type === 'download')?.link; | |
if (!buff) return await message.reply("not found"); |
🧰 Tools
🪛 Biome (1.9.4)
[error] 101-101: Shouldn't redeclare 'dlink'. Consider to delete it or rename it.
'dlink' is defined here:
(lint/suspicious/noRedeclare)
Updated ytdl (song) download to uses tubidy.cool fast platform to download audios along with it's video 2
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Documentation