This commit is contained in:
2022-04-23 19:06:58 +03:00
parent 58809317eb
commit 074fe2eb0e
5 changed files with 28 additions and 12 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,6 @@
using System; using PluginManager.Others.Exceptions;
using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -22,8 +24,8 @@ namespace MusicCommands
private async Task<string> GetYoutubeVideoID() private async Task<string> GetYoutubeVideoID()
{ {
//https://www.youtube.com/watch?v=i-p--m7qaCM&ab_channel=Leviathan //https://www.youtube.com/watch?v=i-p--m7qaCM&ab_channel={channel}/
return URL.Split("=")[1].Split('&')[0]; return URL.Split('=')[1].Split('&')[0];
} }
public async Task<Stream> GetStream() public async Task<Stream> GetStream()
@@ -32,13 +34,18 @@ namespace MusicCommands
if (type == LinkType.SPOTIFY) s = await GetSpotifyMusicStreamAsync(); if (type == LinkType.SPOTIFY) s = await GetSpotifyMusicStreamAsync();
else if (type == LinkType.YOUTUBE) s = await GetYoutubeMusicStreamAsync(); else if (type == LinkType.YOUTUBE) s = await GetYoutubeMusicStreamAsync();
else s = await GetRAWMusicStreamAsync(); else s = await GetRAWMusicStreamAsync();
if (s == null)
{
Console.WriteLine("Failed to get the stream for url: " + this.URL);
throw new APIException("URL [" + this.URL + "] is invalid", "async Task <Stream> GetStream()", "Work in progress", PluginManager.Others.Error.STREAM_NOT_FOUND);
}
return s; return s;
} }
private async Task<Stream> GetSpotifyMusicStreamAsync() private async Task<Stream> GetSpotifyMusicStreamAsync()
{ {
Stream response = null; throw new APIException("Not implemented", "async Task<Stream> GetSpotifyMusicStream()",
return response; "Work in progress", PluginManager.Others.Error.STREAM_NOT_FOUND);
} }
private async Task<Stream> GetYoutubeMusicStreamAsync() private async Task<Stream> GetYoutubeMusicStreamAsync()

View File

@@ -8,7 +8,7 @@
{ WINDOWS, LINUX, MAC_OS, UNKNOWN } { WINDOWS, LINUX, MAC_OS, UNKNOWN }
public enum Error public enum Error
{ UNKNOWN_ERROR, GUILD_NOT_FOUND, } { UNKNOWN_ERROR, GUILD_NOT_FOUND, STREAM_NOT_FOUND }
public enum OutputLogLevel { NONE, INFO, WARNING, ERROR, CRITICAL } public enum OutputLogLevel { NONE, INFO, WARNING, ERROR, CRITICAL }
} }

View File

@@ -2,11 +2,19 @@ using System;
namespace PluginManager.Others.Exceptions namespace PluginManager.Others.Exceptions
{ {
[System.Serializable] [Serializable]
public class APIException : Exception public class APIException : Exception
{ {
public string? Function { get; } public string? Function { get; } = "not specified";
public Error? ErrorCode { get; } public Error? ErrorCode { get; } = Error.UNKNOWN_ERROR;
public string? PossibleCause { get; } = "not specified";
public APIException(string message, string? function, string possible_cause, Error error) : base(message)
{
ErrorCode = error;
Function = function;
PossibleCause = possible_cause;
}
public APIException(string message, string? function, Error? errorCode) : base(message) public APIException(string message, string? function, Error? errorCode) : base(message)
{ {
@@ -16,14 +24,12 @@ namespace PluginManager.Others.Exceptions
public APIException(string message, string? function) : base(message) public APIException(string message, string? function) : base(message)
{ {
ErrorCode = Error.UNKNOWN_ERROR;
Function = function; Function = function;
} }
public APIException(string message) : base(message) public APIException(string message) : base(message)
{ {
ErrorCode = Error.UNKNOWN_ERROR;
Function = "Unspecified_Function";
} }
public void Print() public void Print()
@@ -31,6 +37,9 @@ namespace PluginManager.Others.Exceptions
Console.WriteLine("Message Content: " + Message); Console.WriteLine("Message Content: " + Message);
Console.WriteLine("Function: " + Function); Console.WriteLine("Function: " + Function);
Console.WriteLine("Error Code: " + ErrorCode.ToString()); Console.WriteLine("Error Code: " + ErrorCode.ToString());
Console.WriteLine("Possible cause: " + PossibleCause);
if (this.StackTrace != null)
Functions.WriteErrFile(this.StackTrace);
} }
} }