This commit is contained in:
2022-04-21 12:55:25 +03:00
parent c14044a77c
commit 22ef6f3427
14 changed files with 202 additions and 96 deletions

View File

@@ -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);
}
}
}