patch
This commit is contained in:
@@ -1,26 +1,66 @@
|
||||
using Discord.Net;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MusicCommands
|
||||
{
|
||||
public class LinkMusic
|
||||
{
|
||||
private string URL;
|
||||
public string URL { get; private set; }
|
||||
public LinkType type { get; private set; }
|
||||
|
||||
|
||||
public LinkMusic(string URL)
|
||||
{
|
||||
this.URL = URL;
|
||||
if (URL.StartsWith("https://www.youtube.com/watch?v="))
|
||||
type = LinkType.YOUTUBE;
|
||||
else if (URL.StartsWith("https://open.spotify.com/track/"))
|
||||
type = LinkType.SPOTIFY;
|
||||
else type = LinkType.RAW;
|
||||
}
|
||||
public async Task<Stream> GetMusicStreamAsync()
|
||||
|
||||
private async Task<string> GetYoutubeVideoID()
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
return await client.OpenReadTaskAsync(this.URL);
|
||||
//https://www.youtube.com/watch?v=i-p--m7qaCM&ab_channel=Leviathan
|
||||
return URL.Split("=")[1].Split('&')[0];
|
||||
}
|
||||
|
||||
public async Task<Stream> GetStream()
|
||||
{
|
||||
Stream s;
|
||||
if (type == LinkType.SPOTIFY) s = await GetSpotifyMusicStreamAsync();
|
||||
else if (type == LinkType.YOUTUBE) s = await GetYoutubeMusicStreamAsync();
|
||||
else s = await GetRAWMusicStreamAsync();
|
||||
return s;
|
||||
}
|
||||
|
||||
private async Task<Stream> GetSpotifyMusicStreamAsync()
|
||||
{
|
||||
Stream response = null;
|
||||
return response;
|
||||
}
|
||||
|
||||
private async Task<Stream> GetYoutubeMusicStreamAsync()
|
||||
{
|
||||
//https://www.youtube.com/get_video_info?video_id={id}&el=detailpage
|
||||
string ID = await GetYoutubeVideoID();
|
||||
|
||||
|
||||
using (var webc = new WebClient())
|
||||
{
|
||||
Stream s = await webc.OpenReadTaskAsync($"https://www.youtube.com/get_video_info?video_id={ID}&el=detailpage");
|
||||
string str = await new StreamReader(s).ReadToEndAsync();
|
||||
Console.WriteLine(str);
|
||||
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task<Stream> GetRAWMusicStreamAsync()
|
||||
{
|
||||
return await new WebClient().OpenReadTaskAsync(URL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
MusicCommands/LinkType.cs
Normal file
13
MusicCommands/LinkType.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MusicCommands
|
||||
{
|
||||
public enum LinkType
|
||||
{
|
||||
YOUTUBE, RAW, SPOTIFY
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>warnings</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>../BUILDS/</OutputPath>
|
||||
<ErrorReport>none</ErrorReport>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -7,13 +7,6 @@ using Discord;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MusicCommands
|
||||
{
|
||||
class lplay : DBCommand
|
||||
@@ -33,7 +26,6 @@ namespace MusicCommands
|
||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||
{
|
||||
|
||||
|
||||
Data.voiceChannel = (context.User as IGuildUser)?.VoiceChannel;
|
||||
if (Data.voiceChannel == null) { await context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; }
|
||||
|
||||
@@ -44,7 +36,7 @@ namespace MusicCommands
|
||||
if (Data.CurrentlyRunning != null)
|
||||
Data.CurrentlyRunning.Stop();
|
||||
LinkMusic music = new LinkMusic(Functions.GetArguments(message)[0]);
|
||||
Data.CurrentlyRunning = new MusicPlayer(await music.GetMusicStreamAsync(), discord);
|
||||
Data.CurrentlyRunning = new MusicPlayer(await music.GetStream(), discord);
|
||||
await Data.CurrentlyRunning.StartSendAudio();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user