2017-07-01 06:15:58 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using NadekoBot.Extensions;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2017-07-01 06:15:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2017-07-01 19:22:11 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-01 06:15:58 +00:00
|
|
|
|
|
2017-07-17 02:37:51 +00:00
|
|
|
|
namespace NadekoBot.Modules.Music.Common
|
2017-07-01 06:15:58 +00:00
|
|
|
|
{
|
|
|
|
|
public class SongInfo
|
|
|
|
|
{
|
|
|
|
|
public string Provider { get; set; }
|
|
|
|
|
public MusicType ProviderType { get; set; }
|
|
|
|
|
public string Query { get; set; }
|
|
|
|
|
public string Title { get; set; }
|
2017-07-05 14:59:59 +00:00
|
|
|
|
public Func<Task<string>> Uri { get; set; }
|
2017-07-11 01:16:56 +00:00
|
|
|
|
public string Thumbnail { get; set; }
|
2017-07-01 06:15:58 +00:00
|
|
|
|
public string QueuerName { get; set; }
|
2017-07-04 13:38:19 +00:00
|
|
|
|
public TimeSpan TotalTime { get; set; } = TimeSpan.Zero;
|
2017-07-01 06:15:58 +00:00
|
|
|
|
|
|
|
|
|
public string PrettyProvider => (Provider ?? "???");
|
|
|
|
|
//public string PrettyFullTime => PrettyCurrentTime + " / " + PrettyTotalTime;
|
|
|
|
|
public string PrettyName => $"**[{Title.TrimTo(65)}]({SongUrl})**";
|
|
|
|
|
public string PrettyInfo => $"{PrettyTotalTime} | {PrettyProvider} | {QueuerName}";
|
|
|
|
|
public string PrettyFullName => $"{PrettyName}\n\t\t`{PrettyTotalTime} | {PrettyProvider} | {Format.Sanitize(QueuerName.TrimTo(15))}`";
|
|
|
|
|
public string PrettyTotalTime
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (TotalTime == TimeSpan.Zero)
|
|
|
|
|
return "(?)";
|
|
|
|
|
if (TotalTime == TimeSpan.MaxValue)
|
|
|
|
|
return "∞";
|
|
|
|
|
var time = TotalTime.ToString(@"mm\:ss");
|
|
|
|
|
var hrs = (int)TotalTime.TotalHours;
|
|
|
|
|
|
|
|
|
|
if (hrs > 0)
|
|
|
|
|
return hrs + ":" + time;
|
|
|
|
|
return time;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SongUrl
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (ProviderType)
|
|
|
|
|
{
|
2017-07-02 17:00:25 +00:00
|
|
|
|
case MusicType.YouTube:
|
2017-07-01 06:15:58 +00:00
|
|
|
|
return Query;
|
|
|
|
|
case MusicType.Soundcloud:
|
|
|
|
|
return Query;
|
|
|
|
|
case MusicType.Local:
|
|
|
|
|
return $"https://google.com/search?q={ WebUtility.UrlEncode(Title).Replace(' ', '+') }";
|
|
|
|
|
case MusicType.Radio:
|
|
|
|
|
return $"https://google.com/search?q={Title}";
|
|
|
|
|
default:
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-04 13:38:19 +00:00
|
|
|
|
private string _videoId = null;
|
|
|
|
|
public string VideoId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ProviderType == MusicType.YouTube)
|
|
|
|
|
return _videoId = _videoId ?? videoIdRegex.Match(Query)?.ToString();
|
|
|
|
|
|
|
|
|
|
return _videoId ?? "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set => _videoId = value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-01 06:15:58 +00:00
|
|
|
|
private readonly Regex videoIdRegex = new Regex("<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+", RegexOptions.Compiled);
|
|
|
|
|
}
|
|
|
|
|
}
|