Example #1
0
        public async Task TestYt([NotNull] string url)
        {
            var result = await _yt.DownloadAudio(url);

            await ReplyAsync(result.Status.ToString());

            if (result.Status == YoutubeDownloadStatus.Success && result.File != null)
            {
                await ReplyAsync(result.File.File.FullName);
                await ReplyAsync(result.File.ThumbnailUrl);
                await ReplyAsync(result.File.Title);
                await ReplyAsync(result.File.Url);
            }

            result.File?.Dispose();
        }
Example #2
0
        public async Task PlayUrl([NotNull] string url)
        {
            // Tolerate misusing the play command to invoke `play-random`
            if (url.ToLowerInvariant() == "random")
            {
                await PlayRandom();

                return;
            }

            // Try to find this item in the library
            var match = await(await _library.Get(Context.Guild.Id, url: url.ToLowerInvariant())).SingleOrDefault();

            if (match != null)
            {
                await Enqueue(match);

                return;
            }

            // Try to download this URL using one of the downloaders we know of
            if (await _youtube.IsValidUrl(url))
            {
                var ytd = await _youtube.DownloadAudio(url);

                if (ytd.Status != YoutubeDownloadStatus.Success || ytd.File == null)
                {
                    await ReplyAsync("I couldn't download that track");

                    return;
                }

                using (ytd.File)
                    using (var stream = ytd.File.File.OpenRead())
                    {
                        // Add to library
                        var track = await _library.Add(Context.Guild.Id, Context.User.Id, stream, ytd.File.Title, ytd.File.Duration, ytd.File.Url, ytd.File.ThumbnailUrl);

                        // Play it
                        await Enqueue(track);
                    }
            }
            else
            {
                await ReplyAsync("Sorry, that isn't a URL I know how to play");
            }
        }