Browse Source

Updated youtube search to use the new UI. This requires an API key.

tags/3.0.5
Teknikode 4 years ago
parent
commit
cdf7ae6575
1 changed files with 4 additions and 4 deletions
  1. 4
    4
      Modules/YouTube/YouTube.cs

+ 4
- 4
Modules/YouTube/YouTube.cs View File

@@ -30,8 +30,8 @@ namespace Combot.Modules.Plugins

private void YoutubeSearch(CommandMessage command)
{
string urlTemplate = "http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&max-results=1&q={0}";
Uri searchUrl = new Uri(string.Format(urlTemplate, command.Arguments["Query"]));
string urlTemplate = "https://www.googleapis.com/youtube/v3/search?part=snippet&q={0}&key={1}";
Uri searchUrl = new Uri(string.Format(urlTemplate, command.Arguments["Query"], GetOptionValue("API Key")));
WebClient web = new WebClient();
web.Encoding = Encoding.UTF8;
try
@@ -39,9 +39,9 @@ namespace Combot.Modules.Plugins
string page = web.DownloadString(searchUrl);

JObject parsed = (JObject) JsonConvert.DeserializeObject(page);
if (parsed["data"]["totalItems"].Value<int>() > 0)
if (parsed["items"].Any())
{
string videoID = parsed["data"]["items"].First().Value<string>("id");
string videoID = parsed["items"].First()["id"].Value<string>("videoId");
string vidDescription = GetYoutubeDescription(videoID);
string youtubeMessage = string.Format("{0} - {1}", vidDescription, string.Format("http://youtu.be/{0}", videoID));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, youtubeMessage);

Loading…
Cancel
Save