Skip to content

Commit

Permalink
Add video metadata when uploading with pull link
Browse files Browse the repository at this point in the history
  • Loading branch information
Basvg authored and mfilippov committed Sep 7, 2022
1 parent 7299af7 commit 48335f8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/VimeoDotNet/IVimeoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Task<IUploadRequest> UploadEntireFileAsync(IBinaryContent fileContent,
/// Create new upload ticket asynchronously
/// </summary>
/// <returns>Upload ticket</returns>
Task<Video> UploadPullLinkAsync(string link);
Task<Video> UploadPullLinkAsync(string link, VideoUpdateMetadata metaData = null);

/// <summary>
/// Upload and set thumbnail active
Expand Down
55 changes: 55 additions & 0 deletions src/VimeoDotNet/Models/VideoUpdateMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using VimeoDotNet.Enums;

namespace VimeoDotNet.Models
Expand Down Expand Up @@ -64,5 +65,59 @@ public class VideoUpdateMetadata
/// </summary>
[PublicAPI]
public bool? AllowDownloadVideo { get; set; }

/// <inheritdoc />
[PublicAPI]
public IDictionary<string, string> GetParameterValues()
{
var parameters = new Dictionary<string, string>();

if (Name != null)
{
parameters["name"] = Name.Trim();
}

if (Description != null)
{
parameters["description"] = Description.Trim();
}

if (Privacy != null)
{
parameters["privacy.view"] = Privacy.ToString().ToLower();
}

if (Privacy == VideoPrivacyEnum.Password)
{
parameters["password"] = Password;
}

if (EmbedPrivacy != null)
{
parameters["privacy.embed"] = EmbedPrivacy.ToString().ToLower();
}

if (Comments != null)
{
parameters["privacy.comments"] = Comments.ToString().ToLower();
}

if (ReviewLinkEnabled.HasValue)
{
parameters["review_link"] = ReviewLinkEnabled.Value ? "true" : "false";
}

if (AllowDownloadVideo.HasValue)
{
parameters["privacy.download"] = AllowDownloadVideo.Value ? "true" : "false";
}

if (AllowAddToAlbumChannelGroup.HasValue)
{
parameters["privacy.add"] = AllowAddToAlbumChannelGroup.Value ? "true" : "false";
}

return parameters;
}
}
}
14 changes: 12 additions & 2 deletions src/VimeoDotNet/VimeoClient_Upload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,19 @@ public async Task<IUploadRequest> UploadEntireFileAsync(IBinaryContent fileConte
}

/// <inheritdoc />
public async Task<Video> UploadPullLinkAsync(string link)
public async Task<Video> UploadPullLinkAsync(string link, VideoUpdateMetadata metaData = null)
{
try
{
var param = new ParameterDictionary {{"type", "pull"}, {"link", link}};
var param = new ParameterDictionary {{"upload.approach", "pull"}, {"upload.link", link}};

if (metaData != null)
{
foreach (var parameter in metaData.GetParameterValues())
{
param.Add(parameter.Key, parameter.Value);
}
}

var request = _apiRequestFactory.AuthorizedRequest(
AccessToken,
Expand All @@ -162,6 +170,8 @@ public async Task<Video> UploadPullLinkAsync(string link)
param
);

request.ApiVersion = ApiVersions.v3_4;

return await ExecuteApiRequest<Video>(request).ConfigureAwait(false);
}
catch (Exception ex)
Expand Down
46 changes: 1 addition & 45 deletions src/VimeoDotNet/VimeoClient_Videos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,51 +355,7 @@ private IApiRequest GenerateVideoPatchRequest(long clipId, VideoUpdateMetadata m
request.Path = Endpoints.Video;

request.UrlSegments.Add("clipId", clipId.ToString());
var parameters = new Dictionary<string, string>();
if (metaData.Name != null)
{
parameters["name"] = metaData.Name.Trim();
}

if (metaData.Description != null)
{
parameters["description"] = metaData.Description.Trim();
}

if (metaData.Privacy != null)
{
parameters["privacy.view"] = metaData.Privacy.ToString().ToLower();
}

if (metaData.Privacy == VideoPrivacyEnum.Password)
{
parameters["password"] = metaData.Password;
}

if (metaData.EmbedPrivacy != null)
{
parameters["privacy.embed"] = metaData.EmbedPrivacy.ToString().ToLower();
}

if (metaData.Comments != null)
{
parameters["privacy.comments"] = metaData.Comments.ToString().ToLower();
}

if (metaData.ReviewLinkEnabled.HasValue)
{
parameters["review_link"] = metaData.ReviewLinkEnabled.Value ? "true" : "false";
}

if (metaData.AllowDownloadVideo.HasValue)
{
parameters["privacy.download"] = metaData.AllowDownloadVideo.Value ? "true" : "false";
}

if (metaData.AllowAddToAlbumChannelGroup.HasValue)
{
parameters["privacy.add"] = metaData.AllowAddToAlbumChannelGroup.Value ? "true" : "false";
}
var parameters = metaData.GetParameterValues();

request.Body = new FormUrlEncodedContent(parameters);

Expand Down

0 comments on commit 48335f8

Please sign in to comment.