开发者

Limit the length of a video uploaded to YouTube via C#

开发者 https://www.devze.com 2023-03-26 19:20 出处:网络
I\'m working on a project that will use the .NET wrapper for the YouTube API. We will provide a form to users where开发者_运维知识库 they can upload a video and it will get posted to a specific page o

I'm working on a project that will use the .NET wrapper for the YouTube API. We will provide a form to users where开发者_运维知识库 they can upload a video and it will get posted to a specific page on YouTube. We'd like to limit the length of videos that are uploaded to 60 seconds. Is it possible to set such a length limit at the C#-level in the upload code? I was unable to find anything specific about this in the API docs.

I suspect that this cannot be done as you need to upload the actual video first to determine its length.


You will have to resort to saving the file locally on the server before transmitting it to YouTube. You would then have to use a Media Library to load the video and confirm its length before doing any further processing.

See this for an example.

I haven't used the YouTube API, but an alternative may be to upload the video, check its legnth from YouTube and remove it if it is in violation of your limits.


You are correct. You would have to upload and then check the file attributes to determine length. Theoretically, you can query this while streaming, as you can look at the metadata in the header. I have never queried video, so I am not sure how this is formatted. If you head this direction, you can abort the stream if the header has a length attribute greater than 60 seconds.

A possible issue here is certain types of media files don't contain the length attribute. I am not sure about the types one can upload to YouTube, however.

0

精彩评论

暂无评论...
验证码 换一张
取 消