How to Download a Video | C#

Aspose.HTML for .NET API provides a powerful toolset to analyze and collect information from HTML documents and gives a possibility to download video by its URL. You can easily create your own application using API functionalities or just download and watch your favorite video offline without any internet connection.

Text “Banner Video Grabber”

Data Scraping Namespaces

Data Scraping is a way to get data from websites. Aspose.HTML API provides DataScraping.MultimediaScraping Namespace that implements various multimedia scraping classes:

Class Description
Multimedia This class provides functionality to collect and download VideoInfo (information about video & audio) from the associated page.
MultimediaFactory This class represents an abstract factory which is used for Multimedia objects creation.
MultimediaInfo Represents multimedia information such as Description, Duration, MultimediaHost, Thumbnails, Titles.
MultimediaScraper Provides functionality to register and select Multimedia object, which will be able to collect information from the specified page URL.
MultimediaHost Represents host of the multimedia object.
VideoFormatInfo Represents information about a video format: names of the audio and video codec; bitrate value in KBit/s, extension, file size, video track height and width in pixels, etc.
VideoFormatInfoCollection Represents a VideoFormatInfo collection, i.e. information about all available video formats.
VideoInfo Represents video information such as Description, Duration, Formats, MultimediaHost, Thumbnails, Titles.

Using the mentioned classes, you can get information or download video data through the web.

The Aspose.Html provides Namespaces responsible for YouTube, YouKu and Zoom multimedia data scraping. You find the description and C# examples of getting video info and downloading videos from YouTube, YouKu and Zoom in the following articles:

  • Download YouTube Videos - You learn how to get specific video information and download YouTube videos.
  • Download Zoom Videos - This article provides a general description of how to get specific video information and download Zoom videos.
  • Download YouKu Videos - You will find C # examples for getting specific video information and downloading YouKu videos.

Video Info

Getting information about a video file using Aspose.HTML API, the following steps should be done:

  1. Set a URL of the video you want to extract data from.
  2. Initialize an instance of the MultimediaScraper class.
  3. Create a multimedia object that collects information from the specified URL.
  4. Create a VideoInfo object.
  5. Get information about the video and display it in the console.

The following code snippet can be used to get information about a video file such as Title, Description, Duration, Thumbnails, and Formats Count.

In the example above, we use the GetMultimedia(url) method of MultimediaScraper class for initializing multimedia object that can receive information from the specified page URL. The CollectVideoInfo() method of the Multimedia class collects and provides video information from the associated URL. These can be the VideoInfo class properties such as Description, Duration, Formats, MultimediaHost, Thumbnails, and Title for a video file.

Video Formats Info

You may download a video in different formats: in the best available quality or, for example, in low size when you are on a slow or intermittent connection. Using the VideoFormatInfo class, you can select a video format based on some criterion or criteria.

Consider the following code snippet to get information about all the available formats for the selected video:

Download a Video

The Aspose.HTML API includes a set of features for downloading video files. With this functionality, you can programmatically download videos through your own front end in your own application. You may download a video in different formats: in the best available quality or, for example, in low size when you are on a slow or intermittent connection. Using the VideoFormatInfo class, you can select a video format based on some criterion or criteria and specify the desired file extension.

To download a video file with Aspose.HTML, you should follow a few steps:

  1. Set a URL and file name to download a video.
  2. Initialize an instance of the MultimediaScraper class.
  3. Create a multimedia object.
  4. Create a VideoInfo object.
  5. Select a format based on some criterion or criteria. For example, select the first element from the collection of video formats with minimal bitrate and present audio and video codecs.
  6. Specify a video format and full file path for the output file.
  7. Download video using the Download() method.

Here is a C# example of how to download videos using the API and get information about them.

The Download() method of the Multimedia class takes as parameters the information about the video file to download (it is a local VideoFormatInfo variable format) and a local path to the output file filePath; then, it downloads the video file to your local file system.

Text “Banner Data Scrapers”