public async Task <ActionResult <IEnumerable <ApiModel.Video> > > GetVideos() { var query = new GetVideosQuery(); var videos = await _dataHandler.ExecuteQuery(query); return(Ok(videos)); }
public async Task <List <VideoDto> > Handle(GetVideosQuery request, CancellationToken cancellationToken) { DataBlock dataBlock = await _context.DataBlocks .SingleOrDefaultAsync(db => db.CreatedBy.Equals(request.UserId) && db.Id == request.DataBlockId, cancellationToken); if (dataBlock == null) { throw new NotFoundException(nameof(DataBlock), request.DataBlockId); } var videos = await _context.DataBlockVideos .Include(dbv => dbv.Video) .Where(dbv => dbv.DataBlockId == dataBlock.Id) .Select(dbv => new VideoDto() { Id = dbv.VideoId, Title = dbv.Video.Title, Description = dbv.Video.Description, PreviewImageData = Convert.ToBase64String(dbv.Video.PreviewImageData), PreviewImageType = dbv.Video.PreviewImageType, Privacy = new PrivacyEntityDto() { Id = dbv.Video.Privacy.Id, BeginDate = dbv.Video.Privacy.BeginDate, EndDate = dbv.Video.Privacy.EndDate, IsAlways = dbv.Video.Privacy.IsAlways.Value, PrivacyLevel = dbv.Video.Privacy.PrivacyLevel } }) .ToListAsync(cancellationToken); return(videos); }
public async Task GetChannelVideos(string userId) { var channelVideosQuery = new GetVideosQuery() { UserId = userId, }; var channelVideos = await sut.GetVideos(channelVideosQuery); Assert.NotNull(channelVideos); Assert.NotEmpty(channelVideos); }
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 <Video> > GetVideos(GetVideosQuery getVideosQuery, CancellationToken cancellationToken = default) { if (getVideosQuery == null) { throw new ArgumentNullException(nameof(getVideosQuery)); } var request = RequestConstants.Videos + "?first=" + getVideosQuery.First; if (!string.IsNullOrWhiteSpace(getVideosQuery.CursorPagination.After)) { request += "&after=" + getVideosQuery.CursorPagination.After; } if (getVideosQuery.VideoIds?.Any() == true) { foreach (var videoId in getVideosQuery.VideoIds) { request += "&id=" + videoId; } } if (!string.IsNullOrWhiteSpace(getVideosQuery.GameId)) { request += "&game_id=" + getVideosQuery.GameId; } if (!string.IsNullOrWhiteSpace(getVideosQuery.UserId)) { request += "&user_id=" + getVideosQuery.UserId; } var channelVideosRoot = await ExecuteRequest <VideosRoot>(request, cancellationToken); return(channelVideosRoot.Videos); }