Пример #1
0
        public async Task <VimeoVidoeResponseDto> CreateVideoUploadTicketAsync(int lectureId, VidoeUploadTicketRequestDto request)
        {
            // 1. get user & lecture info
            var user = await GetCurrentUser();

            var lecture = await _lectureRepository.GetLectureAsync(lectureId);

            if (lecture == null)
            {
                throw new NotFoundException("lecture not found");
            }
            // 2. verify the course state and course author
            lecture.Section.Course.CourseUpdateValidate(user);
            // 3. gernerate the vimeo upload ticket
            var vimeoVideoTitle     = lecture.Section.Course.Id + "-" + lecture.Section.Id.ToString() + "-" + lecture.Id.ToString();
            var vidoeUploadResponse = await VimeoHelper.VideoUploadTicketCreatePostAsync(_vimeoConfig.Token, _vimeoConfig.UploadVideoTicketRequestUrl, request.FileSize, vimeoVideoTitle);

            var vimeoVideoId = new Uri(vidoeUploadResponse.Uri).Segments.Last();

            if (vimeoVideoId == null)
            {
                throw new VideoUpdateException("Cannot upload video because no vimeo video ID found, please contact our tech support.");
            }
            // 4. add the video into the course vimeo album
            var vimeoAlbumId = lecture.Section.Course.VimeoAlbumId;

            if (vimeoAlbumId == null)
            {
                throw new VideoUpdateException("Fail to add video into album because album ID not found, please contact our tech support.");
            }
            var addAlbumVideoUrl = string.Format(_vimeoConfig.AddAlbumVideoUrl, vimeoAlbumId, vimeoVideoId);
            await VimeoHelper.AddVideoToAlbum(_vimeoConfig.Token, addAlbumVideoUrl);

            // 5. add video metedata into database
            var video = lecture.AddVideoContent(user, request.Title, request.Desctiption, vimeoVideoId, request.DurationInSecond);
            await _lectureRepository.SaveAsync();

            vidoeUploadResponse.VideoId = video.Id;
            // 6 return the upload ticket
            return(vidoeUploadResponse);
        }
Пример #2
0
        public async Task <VimeoVidoeResponseDto> CreatePreviewVideoUploadTicketAsync(int courseId, VidoeUploadTicketRequestDto request)
        {
            var user = await GetCurrentUser();

            var course = await _courseRepository.GetCourseAsync(courseId, false);

            if (course == null)
            {
                throw new NotFoundException("course not found");
            }
            course.CourseUpdateValidate(user);
            var vimeoVideoTitle     = course.Id + "-preview";
            var vidoeUploadResponse = await VimeoHelper.VideoUploadTicketCreatePostAsync(_vimeoConfig.Token, _vimeoConfig.UploadVideoTicketRequestUrl, request.FileSize, vimeoVideoTitle);

            var vimeoVideoId = new Uri(vidoeUploadResponse.Uri).Segments.Last();

            if (vimeoVideoId == null)
            {
                throw new VideoUpdateException("Cannot upload video because no vimeo video ID found, please contact our tech support.");
            }
            var vimeoAlbumId = course.VimeoAlbumId;

            if (vimeoAlbumId == null)
            {
                throw new VideoUpdateException("Fail to add video into album because album ID not found, please contact our tech support.");
            }
            var addAlbumVideoUrl = string.Format(_vimeoConfig.AddAlbumVideoUrl, vimeoAlbumId, vimeoVideoId);
            await VimeoHelper.AddVideoToAlbum(_vimeoConfig.Token, addAlbumVideoUrl);

            // 5. add video metedata into database
            var video = course.AddPreviewVideo(vimeoVideoId);
            await _courseRepository.SaveAsync();

            // 6 return the upload ticket
            vidoeUploadResponse.VideoId = video.Id;
            return(vidoeUploadResponse);
        }