private static async Task <TimeSpan?> GetByNameAsync(Uri url, string youTubeKey = null, ITwitchCredentials twitchCredentials = null) { if (url == null) { throw new ArgumentNullException(); } if (url.AbsolutePath.EndsWith(".mp4", StringComparison.InvariantCultureIgnoreCase)) { // Assume MP4 return(await MP4.GetDurationAsync(url)); } else if (url.AbsolutePath.EndsWith(".m3u8", StringComparison.InvariantCultureIgnoreCase)) { // Assume HLS return(await HLS.GetPlaylistDurationAsync(url)); } else if (url.Authority.EndsWith("vimeo.com")) { return(await Vimeo.GetDurationAsync(url)); } else if (url.Authority.EndsWith("youtube.com") || url.Authority.EndsWith("youtu.be")) { return(youTubeKey == null ? null : await new YouTube(youTubeKey).GetDurationAsync(url)); } else if (url.Authority.EndsWith("dailymotion.com") || url.Authority.EndsWith("dai.ly")) { return(await Dailymotion.GetDurationAsync(url)); } else if (url.Authority.EndsWith("twitch.tv")) { return(await new Twitch(twitchCredentials).GetDurationAsync(url)); } else if (url.Authority.EndsWith("soundcloud.com")) { return(await SoundCloud.GetDurationAsync(url)); } else { return(null); } }