Click here to Skip to main content
14,299,664 members

Command Line Tool and C# Class for Uploading Videos on Vimeo

Rate this:
5.00 (4 votes)
Please Sign up or sign in to vote.
5.00 (4 votes)
23 Aug 2019CPOL
A command line tool and a simple C# class with a complete set of functions to easily upload videos on Vimeo

Introduction

Vimeo is a great platform to archive and share videos with other people; it provides a simple and complete set of APIs to control almost all his functions (https://developer.vimeo.com/api). You may need to programmatically upload your video files here, for instance, because you have an application that automatically produces videos that need to be shared with some user. How to deal with this situation?

On the Internet, you can find some wrappers for the API in Java, C# and Python (https://developer.vimeo.com/api/libraries). I looked for one to be used in my C# application but I did not find any that satisfied my expectations: open source and very simple. Vimeo also provides a feature that allows you to pull videos automatically from your Dropbox account. It has the advantage that theoretically for uploading a video, you just need to copy a file in a folder and that the upload is performed on a dedicated process. The cons are that it does not provide a lot of flexibility, for instance, you cannot set the video title, description and preview or do some actions after the upload. In addition, you do not have the exact control on when the video is uploaded and you will depend on the Dropbox system. A nice solution for me was a "Vimeo command line tool" that can be easily started from an external application. Therefore, I decided to create it along with a simple C# class for managing the Vimeo API that can be easily integrated into any application. Here, I will describe these tools and you can download the full source code of both.

Background

The Vimeo HTTP API needs an authorization token to be included on the authorization header of the HTTP requests. Therefore, this token is required also for using my command line tool and my class. To obtain the token, you need to:

  1. Register your app on https://developer.vimeo.com/apps, by clicking Create new app and filling the form shown.
  2. Enter your app page, click Request Upload Access and fill the form.
  3. Once you get the upload access, go on your app page, open the section Authentication and press Generate token to create it.

Using the Command Line Tool

vimeouploader.exe is a command line tool that you can use to upload videos on Vimeo and to control many other features provided by this service. It is compiled using C # and it requires the .NET Framework 4.

The syntax is the following:

Vimeouploader <command> -t=<token> -f=<videofile> -pf=<picturefile> -pt=<picturetime>
 -v=<video id> -n=<video name> -d=<video description> 
 -cf=<folder to check for video upload> -df=<folder for uploaded videos> -ci=<check interval>

The command argument is required, the others are optional and depend on the command value.

You must provide a valid authorization token using the –t argument, if the token is invalid, you will receive the following error: "The remote server returned an error: (401) Unauthorized".

For instance, you can get the list of your videos using:

Vimeouploader LV -t=<token>

You can avoid providing the token each time you call vimeouploader.exe saving its value on the registry with the following command:

Vimeouploader ST -t=<token> 

So, to get the list of videos next time, you can just call:

Vimeouploader LV

The available commands are:

  • LV: List your videos. The information reported is: video URI, video name and creation time. You can get more information for a specific video using the VINFO command (see below).
  • The next commands may require a video id argument: it is the video URI without the “/videos/” part.
  • QUOTA: Display your used and available space.
  • UPLOAD: Upload a video. You have to provide a valid video file name on the –f argument, optionally you can specify the video name on the –n argument and the video description on the –d argument. Example:
    Vimeouploader UPLOAD -f="c:\video.avi" -n="video1" -d="my First Video"

    Once the upload is completed, the software will display the following line: "Video Uploaded: <videoid>".

    You can embed this video on your site using this URI: https://player.vimeo.com/video/<videoid>

  • DEL: Delete a video, you must provide the video id on the –v argument. Example:
    Vimeouploader DEL -v:<videoid>
  • EDT: Set the name and the description for a given video. You must provide the video id on the –v argument, the video name on the -n argument and the video description on the -d argument. Example:
    Vimeouploader EDT -v:<videoid> -n="Video1" -d="My first video"
  • SETPIC: Set the preview picture for a given video. You must provide the video id on the –v argument, an image path on the -pf argument. Example:
    Vimeouploader SETPIC -v:<videoid> -pf="v:\videoimm.jpg"
  • UINFO: Display information about your Vimeo account
  • VINFO: Display information about the specified video. You must provide the video id on the –v argument. Example:
    Vimeouploader VINFO -v:<videoid>
  • VSTATUS: Display just the status of the specified video. You must provide the video id on the –v argument.
  • ST: Save authorization token on the registry, in order to avoid specifying it each time. You have to specify the token on the -t argument.
  • PULLFD: Check a given folder, if there is a video, it will be uploaded and moved to another folder. You have to specify the folder to check on the -cf argument and the folder where move the uploaded videos on the -df argument.
    Vimeouploader PULLFD -cf:"c:\video_to_upload" -df:"c:\video_uploaded"

    Each video uploaded will have as title the name of the file. You can also include on the folder a picture with the same name of the video. If the tool finds it, it will upload it as well and set it as thumbnail for the video. The check for new videos is performed every 5 seconds by default, but you can specify a custom check interval (in milliseconds) using the -ci argument.

  • HELP: Display the software version and a quick description of the available commands

Using the VimeoApi C# Class

VimeoApi class is a very simple class that you can use to interact with Vimeo in your C# application. You just need to include the file VimeoApi.cs in your solution, and add a reference to Newtonsoft.Json (which is used to decode the Json information returned from the Vimeo API).

The class constructor accepts as parameter the authorization token, which can be obtained as described above.

The methods exposed by the VimeoApi class are:

Name Description
void DeleteVideo(string videoId)

Delete the specified video

VimeoApi.UserInfo GetQuota() Get available space on Vimeo
UserInfo GetUserInfo() Get information about the Vimeo account
VideoEntryData GetVideoDetails(string videoId) Get information about a video
VideoEntry GetVideos() Get user videos
string GetVideoStatus(string videoId) Get video status description
void SaveAuth() Save authorization token to the registry
void ReadAuth() Read authorization token from the registry
void SetPicture(string videoId, int timeOffset) Set the thumbnail for a given video. The picture will be taken by the given frame of the video
void SetPicture(string videoId, string fileName) Set the thumbnail for a given video using an image file
void SetVideoMetadata(string videoId, string name, string description) Set name and description for a given video
string UploadVideo(string videoFileName, string videoName, string videoDescription, System.Action<long,long> uploadCB) Upload a video. You can pass a callback that will be called for each megabyte sent

Points of Interest

In this article, we presented an interesting command line tool that enables you to easily upload videos on Vimeo and to control other functions. You can use this tool on its own, or call it by another application. There may be some features that could be added but I think that this initial version is already a powerful tool for automating the upload of video to Vimeo.

You can use also the VimeoApi C# class for this purpose. Its main advantage with respect to other C# wrappers is that it is a single class included in a single .cs file, hence it is easy to integrate into your application, easy to debug in case of problems and easy to change adapting it to your needs.

History

  • 30 May 2016: Initial version
  • 23 August 2019: Recompiled project using Net Framework 4.7.2, to avoid the error "System.Net.WebException", and forcing the use of Vimeo API 3.2, to avoid issue during upload.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Andreask84
Software Developer
Unknown
No Biography provided

Comments and Discussions

 
QuestionError during upload Pin
Akram El Assas26-Aug-19 8:47
memberAkram El Assas26-Aug-19 8:47 
AnswerRe: Error during upload Pin
Andreask8429-Aug-19 21:10
memberAndreask8429-Aug-19 21:10 
GeneralRe: Error during upload Pin
Akram El Assas29-Aug-19 22:51
memberAkram El Assas29-Aug-19 22:51 
Questiongood Pin
jual valve flange fitting25-Aug-19 22:27
professionaljual valve flange fitting25-Aug-19 22:27 
AnswerRe: good Pin
Andreask8429-Aug-19 21:10
memberAndreask8429-Aug-19 21:10 
QuestionIs this still working with the newest API? Pin
Jeremy_G14-May-19 9:29
memberJeremy_G14-May-19 9:29 
AnswerRe: Is this still working with the newest API? Pin
Andreask8423-Aug-19 21:25
memberAndreask8423-Aug-19 21:25 
QuestionA question Pin
Member 1367392811-Feb-18 23:08
memberMember 1367392811-Feb-18 23:08 
PraiseThank you Pin
harisivan011-Dec-16 21:58
memberharisivan011-Dec-16 21:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Article
Posted 29 May 2016

Stats

12.4K views
459 downloads
8 bookmarked