From 645bb1bd853fd0f47fef29fe645af8f2c1d08ff1 Mon Sep 17 00:00:00 2001 From: Seregy Date: Wed, 10 Aug 2016 22:36:53 +0300 Subject: [PATCH 1/2] Fixed youtube time arguments --- NadekoBot/Modules/Music/Classes/Song.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Music/Classes/Song.cs b/NadekoBot/Modules/Music/Classes/Song.cs index d235776a..d3f5b571 100644 --- a/NadekoBot/Modules/Music/Classes/Song.cs +++ b/NadekoBot/Modules/Music/Classes/Song.cs @@ -297,10 +297,22 @@ namespace NadekoBot.Modules.Music.Classes if (video == null) // do something with this error throw new Exception("Could not load any video elements based on the query."); - var m = Regex.Match(query, @"\?t=(?\d*)"); + + var m = Regex.Match(query, @"\?t=((?\d*)h)?((?\d*)m)?((?\d*)s)?"); int gotoTime = 0; if (m.Captures.Count > 0) - int.TryParse(m.Groups["t"].ToString(), out gotoTime); + { + int hours; + int minutes; + int seconds; + + int.TryParse(m.Groups["h"].ToString(), out hours); + int.TryParse(m.Groups["m"].ToString(), out minutes); + int.TryParse(m.Groups["s"].ToString(), out seconds); + + gotoTime = hours * 60 * 60 + minutes * 60 + seconds; + } + var song = new Song(new SongInfo { Title = video.Title.Substring(0, video.Title.Length - 10), // removing trailing "- You Tube" From 034fe99f3f5a45147df5185d87c87347c9ff4b09 Mon Sep 17 00:00:00 2001 From: Seregy Date: Thu, 11 Aug 2016 00:38:51 +0300 Subject: [PATCH 2/2] Fixed regex for links with just numeric time --- NadekoBot/Modules/Music/Classes/Song.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Music/Classes/Song.cs b/NadekoBot/Modules/Music/Classes/Song.cs index d3f5b571..0b0a479a 100644 --- a/NadekoBot/Modules/Music/Classes/Song.cs +++ b/NadekoBot/Modules/Music/Classes/Song.cs @@ -298,7 +298,7 @@ namespace NadekoBot.Modules.Music.Classes if (video == null) // do something with this error throw new Exception("Could not load any video elements based on the query."); - var m = Regex.Match(query, @"\?t=((?\d*)h)?((?\d*)m)?((?\d*)s)?"); + var m = Regex.Match(query, @"\?t=((?\d*)h)?((?\d*)m)?((?\d*)s?)?"); int gotoTime = 0; if (m.Captures.Count > 0) {