Ejemplo n.º 1
0
        public async Task AddRadio(params string[] words)
        {
            Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Radio);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Radio);

            if (p.youtubeService == null)
            {
                await ReplyAsync(Base.Sentences.NoApiKey(Context.Guild.Id));
            }
            else
            if (words.Length == 0)
            {
                await ReplyAsync(Sentences.RadioNeedArg(Context.Guild.Id));
            }
            else if (p.radios.Any(x => x.m_guildId == Context.Guild.Id) && !p.radios.Find(x => x.m_guildId == Context.Guild.Id).CanAddMusic())
            {
                await ReplyAsync(Sentences.RadioTooMany(Context.Guild.Id));
            }
            else
            {
                if (!p.radios.Any(x => x.m_guildId == Context.Guild.Id))
                {
                    if (!await StartRadio(Context.Channel))
                    {
                        return;
                    }
                }
                var result = await Features.Entertainment.YouTube.SearchYouTube(words, Program.p.youtubeService);

                if (result.error == Features.Entertainment.Error.YouTube.None)
                {
                    RadioChannel radio = p.radios.Find(x => x.m_guildId == Context.Guild.Id);
                    if (radio.ContainMusic(result.answer.url))
                    {
                        await ReplyAsync(Sentences.RadioAlreadyInList(Context.Guild.Id));

                        return;
                    }
                    await ReplyAsync(Sentences.SongAdded(Context.Guild.Id, result.answer.name));

                    string fileName = "Saves/Radio/" + radio.m_guildId + "/" + Utilities.CleanWord(result.answer.name) + ".mp3";
                    radio.AddMusic(fileName, result.answer.name, result.answer.url, result.answer.imageUrl, Context.User.ToString());
                    ProcessStartInfo youtubeDownload = new ProcessStartInfo()
                    {
                        FileName       = "youtube-dl",
                        Arguments      = $"-x --audio-format mp3 -o " + fileName + " " + result.answer.url,
                        CreateNoWindow = true
                    };
                    youtubeDownload.WindowStyle = ProcessWindowStyle.Hidden;
                    Process.Start(youtubeDownload).WaitForExit();
                    radio.StopDownloading(result.answer.url);
                    await radio.Play();
                }
                else
                {
                    await ReplyAsync("YouTube error: " + result.error);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task addRadio(params string[] words)
        {
            p.doAction(Context.User, Context.Guild.Id, Program.Module.Radio);
            if (words.Length == 0)
            {
                await ReplyAsync(Sentences.radioNeedArg(Context.Guild.Id));
            }
            else if (p.radios.Any(x => x.m_guildId == Context.Guild.Id) && !p.radios.Find(x => x.m_guildId == Context.Guild.Id).CanAddMusic())
            {
                await ReplyAsync(Sentences.radioTooMany(Context.Guild.Id));
            }
            else
            {
                if (!p.radios.Any(x => x.m_guildId == Context.Guild.Id))
                {
                    if (!await StartRadio(Context.Channel))
                    {
                        return;
                    }
                }
                Tuple <string, string> youtubeResult = await YoutubeModule.GetYoutubeVideo(words, Context.Channel);

                if (youtubeResult != null)
                {
                    RadioChannel radio = p.radios.Find(x => x.m_guildId == Context.Guild.Id);
                    if (radio.ContainMusic(youtubeResult.Item1))
                    {
                        await ReplyAsync(Sentences.radioAlreadyInList(Context.Guild.Id));

                        return;
                    }
                    radio.AddMusic("Saves/Radio/" + radio.m_guildId + "/" + Program.cleanWord(youtubeResult.Item2) + ".mp3", youtubeResult.Item2, youtubeResult.Item1, await Context.Guild.GetUserAsync(Sentences.myId), Context.Guild.Id.ToString());
                    YouTubeVideo video = GetYoutubeVideo(youtubeResult.Item1);
                    if (video == null)
                    {
                        radio.RemoveSong(youtubeResult.Item1);
                        await ReplyAsync(Sentences.cantDownload(Context.Guild.Id));
                    }
                    else
                    {
                        await ReplyAsync(youtubeResult.Item2 + " was added to the list.");

                        DownloadAudio(video, radio, youtubeResult.Item1, Program.cleanWord(youtubeResult.Item2));
                    }
                }
            }
        }