Skip to content

Live Radio stations and Youtube url to mp3 #352

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gaurvviii
Copy link

Title: Add Live Radio Support & YouTube to MP3 Conversion

Description:
This pull request introduces two major features to the bot:

Live Radio Support – Users can now stream live radio stations directly through the bot. Added support for various radio stream URLs.
YouTube to MP3 Conversion – Users can provide a YouTube URL, and the bot will convert and play the audio. This improves accessibility for users who prefer listening without streaming the video.
Changes & Additions:

Implemented a radio command to handle live streaming links.
Added a YouTube to MP3 converter using yt-dlp for efficient audio extraction.
Updated the help command to reflect new features.
Optimized playback handling for seamless integration of new features.
Testing & Notes:

Tested multiple radio stations for compatibility.
Ensured YouTube conversion handles common formats and errors gracefully.
Verified smooth playback transitions between different audio sources.
Looking forward to feedback! 🚀

@iGameCreep
Copy link
Contributor

Looks great overall !
Just a few things:

  • There are some unused imports and possibly other lint issues. A quick lint pass would help clean things up.
  • When a radio stream fails, the only indication is a console log (Radio stream ended or errored, attempting to reconnect...). It might be good to inform the user directly in the UI so they’re not left wondering why there’s no audio.
  • Youtube isn't a reliable source to use now as they are actively creating measures against bot (I mean it worked for me but we usually get a lot of issues from that; the external download service may get banned/won't work at some point)
    I’ll leave a few comments with more specific thoughts where something feels a bit off.

const { EmbedBuilder } = require('discord.js');
const { Translate } = require('../process_tools');

module.exports = async ({ client, inter }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused client parameter

const { Translate } = require('../process_tools');
const { stopRadio } = require('../utils/radioPlayer');

module.exports = async ({ client, inter }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused client parameter

let result = false;

// Check if there's an active connection for this guild
if (activeConnections && activeConnections.has(inter.guild.id)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use optional chaining (activeConnections?.has(inter.guild.id)) instead (lint)

const { ApplicationCommandOptionType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const { Translate } = require('../../process_tools');
const radioStations = require('../../radioStations');
const { playRadioStation, stopRadio } = require('../../utils/radioPlayer');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused stopRadio import


const defaultEmbed = new EmbedBuilder().setColor('#2f3136');

// Set quality based on user selection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why base quality off of volume ? Aren't these 2 different things ?

const activeConnections = new Map();

// Cache for converted URLs to avoid redundant conversions
const convertedUrlCache = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

player.on(AudioPlayerStatus.Idle, () => {
console.log('Radio stream ended or errored, attempting to reconnect...');
// Try to restart the stream after a brief delay
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During this loop, user is never informed of what is going on. The only sign is the log in the console, which the user doesn't see.

// First request to get the conversion started
const response = await axios.get(`https://cnvmp3.com/v23/api/single/mp3/${videoId}`);

if (!response.data || !response.data.id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional chain would be better

// Second request to get the download URL
const statusResponse = await axios.get(`https://cnvmp3.com/v23/api/mp3/${conversionId}`);

if (!statusResponse.data || !statusResponse.data.url) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here; optional chain

const { useMainPlayer, QueryType } = require('discord-player');

// Store active YouTube connections to manage them
const activeYoutubeConnections = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use discord-player to stream the music, then you can just stay with queues and the hooks (useQueue)


// Create an audio resource from the stream
const resource = createAudioResource(streamResponse, {
inputType: StreamType.Arbitrary,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the value defined in the radioStations.js file ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants