public async Task <List <VodDetails> > GetVods(VodQuery vodQuery) { if (vodQuery == null) { throw new ArgumentNullException(nameof(vodQuery)); } if (string.IsNullOrWhiteSpace(vodQuery.StreamId)) { throw new ArgumentNullException(nameof(vodQuery.StreamId)); } var getVideosQuery = new GetVideosQuery() { UserId = vodQuery.StreamId, First = vodQuery.Take }; var videos = await twitchTvHelixClient.GetVideos(getVideosQuery); var vods = videos.Select(video => { var largeThumbnail = video.ThumbnailTemplateUrl.Replace("%{width}", "640").Replace("%{height}", "360"); // stupid f*****g new duration format from twitch instead of just returning seconds or some other sensible value var match = Regex.Match(video.Duration, @"((?<hours>\d+)?h)?((?<mins>\d+)?)m?(?<secs>\d+)s"); var hours = match.Groups["hours"].Value; var mins = match.Groups["mins"].Value; var secs = match.Groups["secs"].Value; var timespan = new TimeSpan(hours.ToInt(), mins.ToInt(), secs.ToInt()); return(new VodDetails { Url = video.Url, Length = timespan, RecordedAt = video.CreatedAt, Views = video.ViewCount, //Game = video.Game, Description = video.Description, Title = video.Title, PreviewImage = largeThumbnail, ApiClient = this, }); }).ToList(); return(vods); }
public async Task <List <VodDetails> > GetVods(VodQuery vodQuery) { var channelVideosQuery = new ExternalAPIs.Hitbox.Query.ChannelVideosQuery(vodQuery.StreamId); try { var videos = await hitboxClient.GetChannelVideos(channelVideosQuery); return(videos.Select(x => { TimeSpan length; if (!TimeSpan.TryParse(x.MediaDurationFormat, out length)) { length = TimeSpan.Zero; } return new VodDetails() { Length = length, Game = x.CategoryName, Url = VideoPrefix + x.MediaId, Title = x.MediaTitle, Description = x.MediaStatus, RecordedAt = x.MediaDateAdded ?? DateTimeOffset.MinValue, Views = x.MediaViews, PreviewImage = StaticContentPrefixUrl + x.MediaThumbnail, ApiClient = this, }; }).ToList()); } // special case exception handling for no videos available // unfortunately hitbox doesn't differentiate between a valid channel with no videos and an invalid channel // an email has been sent so hopefully they'll sort this out in the future and I can remove this comment! catch (HttpRequestWithStatusException ex) when(ex.StatusCode == HttpStatusCode.NotFound && ex.Message.Contains("no_media_found")) { return(new List <VodDetails>()); } }
public async Task <List <VodDetails> > GetVods(VodQuery vodQuery) { if (vodQuery == null) { throw new ArgumentNullException(nameof(vodQuery)); } if (string.IsNullOrWhiteSpace(vodQuery.StreamId)) { throw new ArgumentNullException(nameof(vodQuery.StreamId)); } var channelVideosQuery = new ChannelVideosQuery() { ChannelName = vodQuery.StreamId, Take = vodQuery.Take, Skip = vodQuery.Skip, HLSVodsOnly = true, BroadcastsOnly = vodQuery.VodTypes.Contains(BroadcastVodType) }; var channelVideos = await twitchTvClient.GetChannelVideos(channelVideosQuery); var vods = channelVideos.Select(channelVideo => new VodDetails { // hack to correct the url path for twitch videos see github issue: https://github.com/laurencee/Livestream.Monitor/issues/24 // was previously twitch.tv/videos/XXXXXXX // now is twitch.tv/user/v/XXXXXXX Url = channelVideo.Url.Replace(@"twitch.tv/videos/", @"twitch.tv/user/v/"), Length = TimeSpan.FromSeconds(channelVideo.Length), RecordedAt = channelVideo.RecordedAt ?? DateTimeOffset.MinValue, Views = channelVideo.Views, Game = channelVideo.Game, Description = channelVideo.Description, Title = channelVideo.Title, PreviewImage = channelVideo.Preview, ApiClient = this, }).ToList(); return(vods); }
public async Task <List <VodDetails> > GetVods(VodQuery vodQuery) { if (string.IsNullOrEmpty(vodQuery.StreamId)) { throw new ArgumentNullException("vodQuery.StreamId"); } int streamid; if (!int.TryParse(vodQuery.StreamId, out streamid)) { if (!channelNameIdMap.TryGetValue(vodQuery.StreamId, out streamid)) { var channel = await beamProClient.GetStreamDetails(vodQuery.StreamId, CancellationToken.None); channelNameIdMap[channel.token] = channel.id; streamid = channel.id; } } var pagedQuery = new BeamProPagedQuery() { Skip = vodQuery.Skip, Take = vodQuery.Take }; var vods = await beamProClient.GetChannelVideos(streamid, pagedQuery); var vodDetails = vods.ConvertAll(input => new VodDetails() { Views = input.viewsTotal.GetValueOrDefault(), Length = TimeSpan.FromSeconds(input.duration), Title = input.name, RecordedAt = input.createdAt.GetValueOrDefault(), Url = input.vods?[0]?.baseUrl, ApiClient = this, }); return(vodDetails); }
public async Task <List <VodDetails> > GetVods(VodQuery vodQuery) { if (string.IsNullOrEmpty(vodQuery.StreamId)) { throw new ArgumentNullException("vodQuery.StreamId"); } int streamid; if (!int.TryParse(vodQuery.StreamId, out streamid)) { if (!channelNameIdMap.TryGetValue(vodQuery.StreamId, out streamid)) { var channel = await mixerClient.GetStreamDetails(vodQuery.StreamId, CancellationToken.None); channelNameIdMap[channel.token] = channel.id; streamid = channel.id; } } var pagedQuery = new MixerPagedQuery() { Skip = vodQuery.Skip, Take = vodQuery.Take }; var vods = await mixerClient.GetChannelVideos(streamid, pagedQuery); var vodDetails = vods.Select(x => new VodDetails() { Views = x.viewsTotal.GetValueOrDefault(), Length = TimeSpan.FromSeconds(x.duration), Title = x.name, RecordedAt = x.createdAt.GetValueOrDefault(), Url = $"{BaseUrl}{vodQuery.StreamId}?vod={x.id}", ApiClient = this, }).ToList(); return(vodDetails); }
public Task <List <VodDetails> > GetVods(VodQuery vodQuery) { throw new NotImplementedException(); }
public Task <List <VodDetails> > GetVods(VodQuery vodQuery) { return(Task.FromResult(new List <VodDetails>())); }