SoundCloud track streaming support, trivia win = 10, bye is not a mention
This commit is contained in:
parent
a7fc6e5bda
commit
3b66f8106a
105
NadekoBot/Classes/Music/SoundCloud.cs
Normal file
105
NadekoBot/Classes/Music/SoundCloud.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace NadekoBot.Classes.Music {
|
||||||
|
public class SoundCloud {
|
||||||
|
private static readonly SoundCloud _instance = new SoundCloud();
|
||||||
|
public static SoundCloud Default => _instance;
|
||||||
|
|
||||||
|
static SoundCloud() { }
|
||||||
|
public SoundCloud() { }
|
||||||
|
|
||||||
|
public async Task<SoundCloudVideo> GetVideoAsync(string url) {
|
||||||
|
if (string.IsNullOrWhiteSpace(url))
|
||||||
|
throw new ArgumentNullException(nameof(url));
|
||||||
|
if (string.IsNullOrWhiteSpace(NadekoBot.creds.SoundCloudClientID))
|
||||||
|
throw new ArgumentNullException(nameof(NadekoBot.creds.SoundCloudClientID));
|
||||||
|
|
||||||
|
var response = await Modules.Searches.GetResponseAsync($"http://api.soundcloud.com/resolve?url={url}&client_id={NadekoBot.creds.SoundCloudClientID}");
|
||||||
|
|
||||||
|
var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject<SoundCloudVideo>(response);
|
||||||
|
if (responseObj?.Kind != "track")
|
||||||
|
throw new InvalidOperationException("Url is either not a track, or it doesn't exist.");
|
||||||
|
|
||||||
|
return responseObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsSoundCloudLink(string url) =>
|
||||||
|
System.Text.RegularExpressions.Regex.IsMatch(url, "(.*)(soundcloud.com|snd.sc)(.*)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SoundCloudVideo {
|
||||||
|
public string Kind ="";
|
||||||
|
public long Id = 0;
|
||||||
|
public SoundCloudUser User = new SoundCloudUser();
|
||||||
|
public string Title = "";
|
||||||
|
public string FullName => User.Name + " - " + Title;
|
||||||
|
public bool Streamable = false;
|
||||||
|
public string StreamLink => $"https://api.soundcloud.com/tracks/{Id}/stream?client_id={NadekoBot.creds.SoundCloudClientID}";
|
||||||
|
}
|
||||||
|
public class SoundCloudUser {
|
||||||
|
[Newtonsoft.Json.JsonProperty("username")]
|
||||||
|
public string Name;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
{"kind":"track",
|
||||||
|
"id":238888167,
|
||||||
|
"created_at":"2015/12/24 01:04:52 +0000",
|
||||||
|
"user_id":43141975,
|
||||||
|
"duration":120852,
|
||||||
|
"commentable":true,
|
||||||
|
"state":"finished",
|
||||||
|
"original_content_size":4834829,
|
||||||
|
"last_modified":"2015/12/24 01:17:59 +0000",
|
||||||
|
"sharing":"public",
|
||||||
|
"tag_list":"Funky",
|
||||||
|
"permalink":"18-fd",
|
||||||
|
"streamable":true,
|
||||||
|
"embeddable_by":"all",
|
||||||
|
"downloadable":false,
|
||||||
|
"purchase_url":null,
|
||||||
|
"label_id":null,
|
||||||
|
"purchase_title":null,
|
||||||
|
"genre":"Disco",
|
||||||
|
"title":"18 Ж",
|
||||||
|
"description":"",
|
||||||
|
"label_name":null,
|
||||||
|
"release":null,
|
||||||
|
"track_type":null,
|
||||||
|
"key_signature":null,
|
||||||
|
"isrc":null,
|
||||||
|
"video_url":null,
|
||||||
|
"bpm":null,
|
||||||
|
"release_year":null,
|
||||||
|
"release_month":null,
|
||||||
|
"release_day":null,
|
||||||
|
"original_format":"mp3",
|
||||||
|
"license":"all-rights-reserved",
|
||||||
|
"uri":"https://api.soundcloud.com/tracks/238888167",
|
||||||
|
"user":{
|
||||||
|
"id":43141975,
|
||||||
|
"kind":"user",
|
||||||
|
"permalink":"mrb00gi",
|
||||||
|
"username":"Mrb00gi",
|
||||||
|
"last_modified":"2015/12/01 16:06:57 +0000",
|
||||||
|
"uri":"https://api.soundcloud.com/users/43141975",
|
||||||
|
"permalink_url":"http://soundcloud.com/mrb00gi",
|
||||||
|
"avatar_url":"https://a1.sndcdn.com/images/default_avatar_large.png"
|
||||||
|
},
|
||||||
|
"permalink_url":"http://soundcloud.com/mrb00gi/18-fd",
|
||||||
|
"artwork_url":null,
|
||||||
|
"waveform_url":"https://w1.sndcdn.com/gsdLfvEW1cUK_m.png",
|
||||||
|
"stream_url":"https://api.soundcloud.com/tracks/238888167/stream",
|
||||||
|
"playback_count":7,
|
||||||
|
"download_count":0,
|
||||||
|
"favoritings_count":1,
|
||||||
|
"comment_count":0,
|
||||||
|
"attachments_uri":"https://api.soundcloud.com/tracks/238888167/attachments"}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
@ -53,21 +53,31 @@ namespace NadekoBot.Classes.Music {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async void ResolveStreamLink() {
|
private async void ResolveStreamLink() {
|
||||||
Video video = null;
|
string uri = null;
|
||||||
try {
|
try {
|
||||||
if (OnResolving != null)
|
if (SoundCloud.Default.IsSoundCloudLink(Query)) {
|
||||||
OnResolving();
|
|
||||||
var links = await Searches.FindYoutubeUrlByKeywords(Query);
|
|
||||||
var videos = await YouTube.Default.GetAllVideosAsync(links);
|
|
||||||
video = videos
|
|
||||||
.Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
|
|
||||||
.OrderByDescending(v => v.AudioBitrate)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (video == null) // do something with this error
|
var svideo = await SoundCloud.Default.GetVideoAsync(Query);
|
||||||
throw new Exception("Could not load any video elements based on the query.");
|
Title = svideo.FullName + " - SoundCloud";
|
||||||
|
uri = svideo.StreamLink;
|
||||||
|
Console.WriteLine(uri);
|
||||||
|
} else {
|
||||||
|
|
||||||
Title = video.Title; //.Substring(0,video.Title.Length-10); // removing trailing "- You Tube"
|
if (OnResolving != null)
|
||||||
|
OnResolving();
|
||||||
|
var links = await Searches.FindYoutubeUrlByKeywords(Query);
|
||||||
|
var videos = await YouTube.Default.GetAllVideosAsync(links);
|
||||||
|
var video = videos
|
||||||
|
.Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
|
||||||
|
.OrderByDescending(v => v.AudioBitrate)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (video == null) // do something with this error
|
||||||
|
throw new Exception("Could not load any video elements based on the query.");
|
||||||
|
|
||||||
|
Title = video.Title; //.Substring(0,video.Title.Length-10); // removing trailing "- You Tube"
|
||||||
|
uri = video.Uri;
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
privateState = StreamState.Completed;
|
privateState = StreamState.Completed;
|
||||||
if (OnResolvingFailed != null)
|
if (OnResolvingFailed != null)
|
||||||
@ -76,7 +86,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
musicStreamer = new MusicStreamer(this, video.Uri);
|
musicStreamer = new MusicStreamer(this, uri);
|
||||||
if (OnQueued != null)
|
if (OnQueued != null)
|
||||||
OnQueued();
|
OnQueued();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ namespace NadekoBot.Classes.Trivia {
|
|||||||
public bool GameActive { get; private set; } = false;
|
public bool GameActive { get; private set; } = false;
|
||||||
public bool ShouldStopGame { get; private set; }
|
public bool ShouldStopGame { get; private set; }
|
||||||
|
|
||||||
public int WinRequirement { get; } = 3;
|
public int WinRequirement { get; } = 10;
|
||||||
|
|
||||||
public TriviaGame(CommandEventArgs e) {
|
public TriviaGame(CommandEventArgs e) {
|
||||||
_server = e.Server;
|
_server = e.Server;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
public string TrelloAppKey;
|
public string TrelloAppKey;
|
||||||
public bool? ForwardMessages;
|
public bool? ForwardMessages;
|
||||||
public string OsuApiKey;
|
public string OsuApiKey;
|
||||||
|
public string SoundCloudClientID;
|
||||||
}
|
}
|
||||||
public class AnimeResult
|
public class AnimeResult
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ namespace NadekoBot.Commands {
|
|||||||
var controls = AnnouncementsDictionary[e.Server.Id];
|
var controls = AnnouncementsDictionary[e.Server.Id];
|
||||||
var channel = NadekoBot.client.GetChannel(controls.ByeChannel);
|
var channel = NadekoBot.client.GetChannel(controls.ByeChannel);
|
||||||
if (channel == null) return;
|
if (channel == null) return;
|
||||||
var msg = controls.ByeText.Replace("%user%", e.User.Mention).Trim();
|
var msg = controls.ByeText.Replace("%user%", "**"+e.User.Name+"**").Trim();
|
||||||
if (string.IsNullOrEmpty(msg))
|
if (string.IsNullOrEmpty(msg))
|
||||||
return;
|
return;
|
||||||
Greeted++;
|
Greeted++;
|
||||||
|
@ -56,6 +56,10 @@ namespace NadekoBot {
|
|||||||
Console.WriteLine("No osu API key found. Osu functionality is disabled.");
|
Console.WriteLine("No osu API key found. Osu functionality is disabled.");
|
||||||
else
|
else
|
||||||
Console.WriteLine("Osu enabled.");
|
Console.WriteLine("Osu enabled.");
|
||||||
|
if(string.IsNullOrWhiteSpace(creds.SoundCloudClientID))
|
||||||
|
Console.WriteLine("No soundcloud Client ID found. Soundcloud streaming is disabled.");
|
||||||
|
else
|
||||||
|
Console.WriteLine("SoundCloud streaming enabled.");
|
||||||
|
|
||||||
//init parse
|
//init parse
|
||||||
ParseClient.Initialize(creds.ParseID, creds.ParseKey);
|
ParseClient.Initialize(creds.ParseID, creds.ParseKey);
|
||||||
|
@ -136,6 +136,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Classes\Music\MusicControls.cs" />
|
<Compile Include="Classes\Music\MusicControls.cs" />
|
||||||
<Compile Include="Classes\Music\StreamRequest.cs" />
|
<Compile Include="Classes\Music\StreamRequest.cs" />
|
||||||
|
<Compile Include="Classes\Music\SoundCloud.cs" />
|
||||||
<Compile Include="Commands\TriviaCommand.cs" />
|
<Compile Include="Commands\TriviaCommand.cs" />
|
||||||
<Compile Include="Classes\SParser.cs" />
|
<Compile Include="Classes\SParser.cs" />
|
||||||
<Compile Include="Classes\Trivia\TriviaGame.cs" />
|
<Compile Include="Classes\Trivia\TriviaGame.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user