Anda di halaman 1dari 4

Command Line Tool and C# Class for Uploading Videos

on Vimeo
Andreask84

23 Aug 2019 CPOL

A command line tool and a simple C# class with a complete set of functions to easily upload videos on Vimeo

Download source - 2.4 MB


Download command line tool - 593.8 KB
Project GitHub page

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

Set the thumbnail for a given video. The


void SetPicture(string videoId, int timeOffset) picture will be taken by the given frame of
the video

Set the thumbnail for a given video using


void SetPicture(string videoId, string fileName)
an image file

void SetVideoMetadata(string videoId, string name, Set name and description for a given
string description) video

string UploadVideo(string videoFileName, string


Upload a video. You can pass a callback
videoName, string videoDescription,
that will be called for each megabyte sent
System.Action<long,long> uploadCB)

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)

About the Author


Andreask84 No Biography provided
Software Developer
Unknown

Comments and Discussions


9 messages have been posted for this article Visit https://www.codeproject.com/Articles/1103215/Command-Line-Tool-
and-Csharp-Class-for-Uploading-V to post and view comments on this article, or click here to get a print view with messages.

Permalink Article Copyright 2016 by Andreask84


Advertise Everything else Copyright © CodeProject, 1999-
Privacy 2019
Cookies
Terms of Use Web02 2.8.190921.1

Anda mungkin juga menyukai