Example #1
0
        public async Task <IActionResult> DeleteVideo(long?clipId)
        {
            try
            {
                if (clipId > 0)
                {
                    VimeoClient vimeoClient = new VimeoClient(accessToken);

                    await vimeoClient.DeleteVideoAsync(clipId.Value); //apaga do vimeo

                    var video = _applicationDbContext.localUploadRequests.Where(x => x.ClipId == clipId).FirstOrDefault();
                    _applicationDbContext.localUploadRequests.Remove(video); //apaga do sql
                    await _applicationDbContext.SaveChangesAsync();

                    ViewBag.status = "deleted";
                }
            }
            catch (Exception e)
            {
                ViewBag.status = "ERRO: " + e.Message;
            }
            return(View()); /* , jsonrequestbehavior.allowget(.net) */
        }
        public void Integration_VimeoClient_UploadEntireFile_UploadsFile()
        {
            // arrange
            long           length;
            IUploadRequest completedRequest;

            using (var file = new BinaryContent(GetFullPath(TESTFILEPATH)))
            {
                length = file.Data.Length;
                VimeoClient client = CreateAuthenticatedClient();

                // act
                completedRequest = client.UploadEntireFile(file);
            }

            // assert
            Assert.IsNotNull(completedRequest);
            Assert.IsTrue(completedRequest.AllBytesWritten);
            Assert.IsTrue(completedRequest.IsVerifiedComplete);
            Assert.AreEqual(length, completedRequest.BytesWritten);
            Assert.IsNotNull(completedRequest.ClipUri);
            Assert.IsTrue(completedRequest.ClipId > 0);
        }
Example #3
0
        public (Metadata Metadata, Response Response) GetMetaData(TrainingMaterial trainingMaterial)
        {
            long clipId = 0;
            var  client = new VimeoClient(config.VideoSettings.Token);

            if (!long.TryParse(trainingMaterial.ExternalId, out clipId))
            {
                return(null, Response.CreateResponse(new IllegalOperationException("The training material id could not be converted into the desired format (string to long)")));
            }

            try {
                var video = client.GetVideoAsync(clipId).Result;
                if (video == null || video.id != clipId)
                {
                    return(null, Response.CreateResponse(new EntityNotFoundException("The desired video could not be retrieved from the host service (Vimeo)")));
                }

                return(new Metadata {
                    Status = video.status, Thumbnail = (video.pictures?.sizes?.Count > 0 ? video.pictures.sizes[0].link : string.Empty), Url = video.StandardVideoLink
                }, Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(null, Response.CreateResponse(ex));
            }
        }
        public void Integration_VimeoClient_AlbumVideoManagement()
        {
            VimeoClient client = CreateAuthenticatedClient();

            // assume this album and video are configured in the current account...
            long albumId = vimeoSettings.AlbumId;
            long videoId = vimeoSettings.VideoId;

            // add it...
            bool  isAdded    = client.AddToAlbum(albumId, videoId);
            Video addedVideo = client.GetAlbumVideo(albumId, videoId);
            bool  isPresent  = addedVideo != null;

            Assert.IsTrue(isAdded, "AddToAlbum failed.");
            Assert.IsTrue(isAdded == isPresent, "Returned value does not match actual presence of video.");

            // then remove it...
            bool  isRemoved    = client.RemoveFromAlbum(albumId, videoId);
            Video removedVideo = client.GetAlbumVideo(albumId, videoId);
            bool  isAbsent     = removedVideo == null;

            Assert.IsTrue(isRemoved, "RemoveFromAlbum failed.");
            Assert.IsTrue(isRemoved == isAbsent, "Returned value does not match actual abscence of video.");
        }
        public void Integration_VimeoClient_DeleteVideo_DeletesVideo()
        {
            // arrange
            long           length;
            IUploadRequest completedRequest;

            using (var file = new BinaryContent(GetFullPath(TESTFILEPATH)))
            {
                length = file.Data.Length;
                VimeoClient client = CreateAuthenticatedClient();
                // act
                completedRequest = client.UploadEntireFile(file);
                completedRequest.AllBytesWritten.ShouldBeTrue();
                completedRequest.ShouldNotBeNull();
                completedRequest.IsVerifiedComplete.ShouldBeTrue();
                completedRequest.BytesWritten.ShouldEqual(length);
                completedRequest.ClipUri.ShouldNotBeNull();
                completedRequest.ClipId.HasValue.ShouldBeTrue();
                Debug.Assert(completedRequest.ClipId != null, "completedRequest.ClipId != null");
                client.DeleteVideo(completedRequest.ClipId.Value);
                client.GetVideo(completedRequest.ClipId.Value).ShouldBeNull();
            }
            // assert
        }
Example #6
0
        public void Integration_VimeoClient_UpdateAccountInformation_UpdatesCurrentAccountInfo()
        {
            // first, ensure we can retrieve the current user...
            VimeoClient client   = CreateAuthenticatedClient();
            User        original = client.GetAccountInformation();

            Assert.IsNotNull(original);

            // next, update the user record with some new values...
            string testName     = "King Henry VIII";
            string testBio      = "";
            string testLocation = "England";

            User updated = client.UpdateAccountInformation(new EditUserParameters
            {
                Name     = testName,
                Bio      = testBio,
                Location = testLocation
            });

            // inspect the result and ensure the values match what we expect...
            // the vimeo api will set string fields to null if the value passed in is an empty string
            // so check against null if that is what we are passing in, otherwise, expect the passed value...
            if (string.IsNullOrEmpty(testName))
            {
                Assert.IsNull(updated.name);
            }
            else
            {
                Assert.AreEqual(testName, updated.name);
            }

            if (string.IsNullOrEmpty(testBio))
            {
                Assert.IsNull(updated.bio);
            }
            else
            {
                Assert.AreEqual(testBio, updated.bio);
            }

            if (string.IsNullOrEmpty(testLocation))
            {
                Assert.IsNull(updated.location);
            }
            else
            {
                Assert.AreEqual(testLocation, updated.location);
            }

            // restore the original values...
            User final = client.UpdateAccountInformation(new Parameters.EditUserParameters
            {
                Name     = original.name ?? string.Empty,
                Bio      = original.bio ?? string.Empty,
                Location = original.location ?? string.Empty
            });

            // inspect the result and ensure the values match our originals...
            if (string.IsNullOrEmpty(original.name))
            {
                Assert.IsNull(final.name);
            }
            else
            {
                Assert.AreEqual(original.name, final.name);
            }

            if (string.IsNullOrEmpty(original.bio))
            {
                Assert.IsNull(final.bio);
            }
            else
            {
                Assert.AreEqual(original.bio, final.bio);
            }

            if (string.IsNullOrEmpty(original.location))
            {
                Assert.IsNull(final.location);
            }
            else
            {
                Assert.AreEqual(original.location, final.location);
            }
        }
Example #7
0
        private int SyncVimeo(RockContext rockContext)
        {
            ContentChannelItem contentItem = GetContentItem(rockContext);

            if (contentItem != null)
            {
                if (contentItem.Attributes == null)
                {
                    contentItem.LoadAttributes();
                }

                long videoId = _vimeoId;

                if (_vimeoId == 0)
                {
                    videoId = this.tbVimeoId.Text.AsInteger();
                }

                if (contentItem.AttributeValues.ContainsKey(_vimeoIdKey))
                {
                    contentItem.AttributeValues[_vimeoIdKey].Value = videoId.ToString().AsInteger().ToString();
                }
                else
                {
                    contentItem.SetAttributeValue(_durationAttributeKey, videoId.ToString().AsInteger());
                }

                var client = new VimeoClient(_accessToken);
                var vimeo  = new Video();
                var width  = GetAttributeValue("ImageWidth").AsInteger();
                var video  = vimeo.GetVideoInfo(client, videoId, width);

                var cbName = cblSyncOptions.Items.FindByValue("Name");
                if (cbName != null && cbName.Selected == true)
                {
                    contentItem.Title = video.name;
                }

                var cbDescription = cblSyncOptions.Items.FindByValue("Description");
                if (cbDescription != null && cbDescription.Selected == true)
                {
                    contentItem.Content = video.description;
                }

                var cbImage = cblSyncOptions.Items.FindByValue("Image");
                if (cbImage != null && cbImage.Selected == true)
                {
                    if (contentItem.AttributeValues.ContainsKey(_imageAttributeKey))
                    {
                        contentItem.AttributeValues[_imageAttributeKey].Value = video.imageUrl;
                    }
                    else
                    {
                        contentItem.SetAttributeValue(_imageAttributeKey, video.imageUrl);
                    }
                }

                var cbDuration = cblSyncOptions.Items.FindByValue("Duration");
                if (cbDuration != null && cbDuration.Selected == true)
                {
                    if (contentItem.AttributeValues.ContainsKey(_durationAttributeKey))
                    {
                        contentItem.AttributeValues[_durationAttributeKey].Value = video.duration.ToString();
                    }
                    else
                    {
                        contentItem.SetAttributeValue(_durationAttributeKey, video.duration.ToString());
                    }
                }

                var cbHDVideo = cblSyncOptions.Items.FindByValue("HD Video");
                if (cbHDVideo != null && cbHDVideo.Selected == true && !string.IsNullOrWhiteSpace(video.hdLink))
                {
                    if (contentItem.AttributeValues.ContainsKey(_hdVideoAttributeKey))
                    {
                        contentItem.AttributeValues[_hdVideoAttributeKey].Value = video.hdLink;
                    }
                    else
                    {
                        contentItem.SetAttributeValue(_hdVideoAttributeKey, video.hdLink);
                    }
                }

                var cbSDVideo = cblSyncOptions.Items.FindByValue("SD Video");
                if (cbSDVideo != null && cbSDVideo.Selected == true && !string.IsNullOrWhiteSpace(video.sdLink))
                {
                    if (contentItem.AttributeValues.ContainsKey(_sdVideoAttributeKey))
                    {
                        contentItem.AttributeValues[_sdVideoAttributeKey].Value = video.sdLink;
                    }
                    else
                    {
                        contentItem.SetAttributeValue(_sdVideoAttributeKey, video.sdLink);
                    }
                }

                var cbHLSVideo = cblSyncOptions.Items.FindByValue("HLS Video");
                if (cbHLSVideo != null && cbHLSVideo.Selected == true && !string.IsNullOrWhiteSpace(video.hlsLink))
                {
                    if (contentItem.AttributeValues.ContainsKey(_hlsVideoAttributeKey))
                    {
                        contentItem.AttributeValues[_hlsVideoAttributeKey].Value = video.hlsLink;
                    }
                    else
                    {
                        contentItem.SetAttributeValue(_hlsVideoAttributeKey, video.hlsLink);
                    }
                }

                // Save Everything
                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentItem.SaveAttributeValues(rockContext);
                });
            }

            return(contentItem.Id);
        }
Example #8
0
 public VimeoHelper(VimeoConfiguration config)
 {
     _vimeoConfig = config;
     _vimeoClient = new VimeoClient(_vimeoConfig.Token);
 }
Example #9
0
 public VimeoService(VimeoCredential vimeoCredential)
 {
     _vimeoCredential     = vimeoCredential;
     _vimeoClient         = new VimeoClient(_vimeoCredential.ClientId, _vimeoCredential.ClientSecret);
     _authorizationClient = new AuthorizationClient(_vimeoCredential.ClientId, _vimeoCredential.ClientSecret);
 }
Example #10
0
 public ApiEndpoints(VimeoClient client)
 {
     _Client = client;
 }
        public async Task Integration_VimeoClient_UpdateTextTrackAsync()
        {
            // arrange
            VimeoClient client   = CreateAuthenticatedClient();
            var         original = await client.GetTextTrackAsync(vimeoSettings.VideoId, vimeoSettings.TextTrackId);

            original.ShouldNotBeNull();

            // act
            // update the text track record with some new values...
            var testName     = "NewTrackName";
            var testType     = "subtitles";
            var testLanguage = "fr";
            var testActive   = false;

            var updated = await client.UpdateTextTrackAsync(
                vimeoSettings.VideoId,
                vimeoSettings.TextTrackId,
                new TextTrack
            {
                name     = testName,
                type     = testType,
                language = testLanguage,
                active   = testActive
            });

            // inspect the result and ensure the values match what we expect...
            // assert
            testName.ShouldEqual(updated.name);
            testType.ShouldEqual(updated.type);
            testLanguage.ShouldEqual(updated.language);
            testActive.ShouldEqual(updated.active);

            // restore the original values...
            var final = await client.UpdateTextTrackAsync(
                vimeoSettings.VideoId,
                vimeoSettings.TextTrackId,
                new TextTrack
            {
                name     = original.name,
                type     = original.type,
                language = original.language,
                active   = original.active
            });

            // inspect the result and ensure the values match our originals...
            if (string.IsNullOrEmpty(original.name))
            {
                final.name.ShouldBeNull();
            }
            else
            {
                original.name.ShouldEqual(final.name);
            }

            if (string.IsNullOrEmpty(original.type))
            {
                final.type.ShouldBeNull();
            }
            else
            {
                original.type.ShouldEqual(final.type);
            }

            if (string.IsNullOrEmpty(original.language))
            {
                final.language.ShouldBeNull();
            }
            else
            {
                original.language.ShouldEqual(final.language);
            }

            original.active.ShouldEqual(final.active);
        }
Example #12
0
 public ApiEndpoints(VimeoClient client)
 {
     _Client = client;
 }
        private void SyncVimeo()
        {
            var lookupContext       = new RockContext();
            var contentChannelItems = new List <ContentChannelItem>();
            var completed           = 0;

            var  client = new VimeoClient(_accessToken);
            var  vimeo  = new Video();
            var  width  = GetAttributeValue("ImageWidth").AsInteger();
            long userId = GetAttributeValue("VimeoUserId").AsInteger();
            var  videos = vimeo.GetVideos(client, userId, width);

            var vimeoIdKey = GetAttributeValue("VimeoIdKey");

            foreach (var video in videos)
            {
                var contentChannelItem = new ContentChannelItemService(lookupContext)
                                         .Queryable("ContentChannel,ContentChannelType")
                                         .WhereAttributeValue(lookupContext, vimeoIdKey, video.vimeoId.ToString())
                                         .FirstOrDefault(i => i.ContentChannelId == _contentChannelId);

                if (contentChannelItem != null && contentChannelItem.Id != 0)
                {
                    if (contentChannelItem.Attributes == null)
                    {
                        contentChannelItem.LoadAttributes();
                    }

                    var cbName = cblSyncOptions.Items.FindByValue("Name");
                    if (cbName != null && cbName.Selected == true)
                    {
                        contentChannelItem.Title = video.name;
                    }

                    var cbDescription = cblSyncOptions.Items.FindByValue("Description");
                    if (cbDescription != null && cbDescription.Selected == true)
                    {
                        contentChannelItem.Content = video.description;
                    }

                    var cbImage = cblSyncOptions.Items.FindByValue("Image");
                    if (cbImage != null && cbImage.Selected == true)
                    {
                        contentChannelItem.AttributeValues[_imageAttributeKey].Value = video.imageUrl;
                    }

                    var cbDuration = cblSyncOptions.Items.FindByValue("Duration");
                    if (cbDuration != null && cbDuration.Selected == true)
                    {
                        contentChannelItem.AttributeValues[_durationAttributeKey].Value = video.duration.ToString();
                    }

                    var cbHDVideo = cblSyncOptions.Items.FindByValue("HD Video");
                    if (cbHDVideo != null && cbHDVideo.Selected == true && !string.IsNullOrWhiteSpace(video.hdLink))
                    {
                        contentChannelItem.AttributeValues[_hdVideoAttributeKey].Value = video.hdLink;
                    }

                    var cbSDVideo = cblSyncOptions.Items.FindByValue("SD Video");
                    if (cbSDVideo != null && cbSDVideo.Selected == true && !string.IsNullOrWhiteSpace(video.sdLink))
                    {
                        contentChannelItem.AttributeValues[_sdVideoAttributeKey].Value = video.sdLink;
                    }

                    var cbHLSVideo = cblSyncOptions.Items.FindByValue("HLS Video");
                    if (cbHLSVideo != null && cbHLSVideo.Selected == true && !string.IsNullOrWhiteSpace(video.hlsLink))
                    {
                        contentChannelItem.AttributeValues[_hlsVideoAttributeKey].Value = video.hlsLink;
                    }

                    contentChannelItems.Add(contentChannelItem);
                    completed++;

                    if (completed % _batchSize < 1)
                    {
                        SaveContentChannelItems(contentChannelItems);
                        contentChannelItems.Clear();
                    }
                }
            }

            // Save leftovers
            if (contentChannelItems.Any())
            {
                SaveContentChannelItems(contentChannelItems);
                contentChannelItems.Clear();
            }
        }
Example #14
0
        /// <summary>
        /// Returns a List of VideoInfo objects with all video info from a user.
        /// </summary>
        /// <param name="client">The VimeoClient to use.</param>
        /// <param name="width">The closest width of the image url to return. Default is 1920px.</param>
        public List <VideoInfo> GetVideos(VimeoClient client, long userId, int width = 1920)
        {
            var retVal = new List <VideoInfo>();
            var videos = new List <VimeoDotNet.Models.Video>();

            int page = 1;

            while (page > 0)
            {
                VimeoDotNet.Models.Paginated <VimeoDotNet.Models.Video> pagedVideos = null;
                var task = Task.Run(async() =>
                {
                    pagedVideos = await client.GetUserVideosAsync(userId, page, null);
                });
                task.Wait();

                videos.AddRange(pagedVideos.data);

                int num = 0;

                if (pagedVideos.paging.next != null)
                {
                    int.TryParse(pagedVideos.paging.next.Split('=').Last(), out num);
                }

                page = num;
            }

            foreach (var video in videos)
            {
                var videoInfo = new VideoInfo();

                videoInfo.vimeoId = ( long )video.id;
                videoInfo.name    = video.name;
                if (string.IsNullOrWhiteSpace(video.description))
                {
                    videoInfo.description = string.Empty;
                }
                else
                {
                    videoInfo.description = string.Format("<p>{0}</p>", video.description.Replace("\n", "<br>"));
                }
                videoInfo.duration = video.duration;
                videoInfo.hdLink   = video.HighDefinitionVideoSecureLink;
                videoInfo.sdLink   = video.StandardVideoSecureLink;
                videoInfo.hlsLink  = video.StreamingVideoSecureLink;

                if (video.pictures != null)
                {
                    //
                    // for 0.8.x vimeo dot net structure
                    //

                    var pictures = video.pictures.ToList();
                    var picSizes = pictures.FirstOrDefault(p => p.active == true).sizes.ToList();

                    //
                    // for > 0.8.x vimeo dot net structure
                    //
                    //var picSizes = video.pictures.sizes.ToList();

                    if (picSizes.Count > 0)
                    {
                        videoInfo.imageUrl = picSizes.Aggregate((x, y) => Math.Abs(x.width - width) < Math.Abs(y.width - width) ? x : y).link;
                    }
                }

                retVal.Add(videoInfo);
            }

            return(retVal);
        }
Example #15
0
        public async Task <IActionResult> Upload()       //HttpPostedFile(.net) == IFormFile
        {
            var       files        = Request.Form.Files; //Request.File(.net) == Request.Form.Files
            IFormFile file         = files[0];           //HttpPostedFileBase(.net) == IFormFile
            string    uploadstatus = "";

            try
            {
                if (file != null)
                {
                    VimeoClient vimeoClient = new VimeoClient(accessToken);
                    var         authcheck   = await vimeoClient.GetAccountInformationAsync();

                    if (authcheck.Name != null)
                    {
                        IUploadRequest uploadRequest = new UploadRequest();
                        BinaryContent  binaryContent = new BinaryContent(file.OpenReadStream(), file.ContentType); //InputStream(.net) == OpenReadStream()

                        long chunksizeLong = 0;                                                                    //tamanho do pedaço
                        long contentleght  = file.Length;                                                          //tamanho do arquivo em bytes
                        long temp1         = contentleght / 1024;                                                  //tamanho do arquivo em Kilobytes
                        if (temp1 > 1)
                        {
                            chunksizeLong = temp1 / 1024;            //tamanho do arquivo em Megabytes
                            chunksizeLong = chunksizeLong / 10;
                            chunksizeLong = chunksizeLong * 1048576; //1048576 bytes(1024 * 1024) = 1 MB
                        }
                        else
                        {
                            chunksizeLong = 1048576; //chunk size equal to 1 MB
                        }

                        int chunksize = unchecked ((int)chunksizeLong); //converte de long para int (https://stackoverflow.com/questions/858904/can-i-convert-long-to-int)
                        uploadRequest = await vimeoClient.UploadEntireFileAsync(binaryContent, chunksize, null);

                        uploadstatus = String.Concat("file uploaded ", "https://vimeo.com/", uploadRequest.ClipId.Value.ToString(), "/none");
                        //_applicationDbContext.ApplicationUser = uploadRequest.ClipId.Value;
                        var user = await _userManager.GetUserAsync(User); //obtém Denizard

                        //user.ClipIdUser = uploadRequest.ClipId.Value; // coloco o ClipId no user Denizard


                        user.UploadRequests.Add(new LocalUploadRequest(
                                                    uploadRequest.ChunkSize,
                                                    uploadRequest.BytesWritten,
                                                    uploadRequest.IsVerifiedComplete,
                                                    uploadRequest.ClipUri,
                                                    uploadRequest.FileLength,
                                                    uploadRequest.ClipId,
                                                    user
                                                    ));

                        _applicationDbContext.SaveChanges(); // salvo as mudanças do user Denizard
                    }
                }
            }
            catch (Exception e)
            {
                uploadstatus = "not uploaded: " + e.Message;
                if (e.InnerException != null)
                {
                    uploadstatus += e.InnerException.Message;
                }
            }
            ViewBag.UploadStatus = uploadstatus;
            return(View());
        }