Download video and music using Python

Using our API to download YouTube video, SoundCloud music, Facebook media, etc with Python. For FREE!

Code Example

Python


Our API is really easy to use to download media files! Check this example out. How to download a YouTube video with Python:

# This code snippet use an open-source library. http://unirest.io/python

response = unirest.get("https://getvideo.p.mashape.com/?url=PAGE-WITH-MEDIA",
  headers={
    "X-Mashape-Key": "YOUR-API-KEY",
    "Accept": "text/plain"
  }
)'

This will return a JSON array with download links, thumbnails, etc!

For example, let’s say you want to download the Stranger Things, Season 2 Trailer, from YouTube. First, find the URL to the awesome trailer, in this case it’s “https://www.youtube.com/watch?v=vgS2L7WPIO4”.

Then, use that URL (with URL encoding), and your Mashape API key, as above. If you don’t have an API key yet, click here to get started.

So, your code should look something like this:

# This code snippet use an open-source library. http://unirest.io/python

response = unirest.get("https://getvideo.p.mashape.com/?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DnfWlot6h_JM",
  headers={
    "X-Mashape-Key": "YOUR-API-KEY",
    "Accept": "text/plain"
  }
)'

You will get a JSON array back as a result:

 {
   "status":true,
   "message":"Successfully received info.",
   "site":"Youtube",
   "title":"Stranger Things | Season 2 Comic Con \"Thriller\" Trailer [HD] | Netflix", 
   "like_count":274960,
   "dislike_count":2775,
   "view_count":9045654,
   "duration":183,
   "upload_date":"20170722",
   "description":"The first trailer for Stranger Things 2 is here. It\u2019s 1984 and the citizens of Hawkins, Indiana are still reeling from the horrors of the demogorgon and the secrets of Hawkins Lab. Will Byers has been rescued from the Upside Down [...]",
   "tags":[
      "Netflix",
      "Trailer",
      "Stranger Things",
      "Winona Ryder",
      "David Harbour",
      "Shawn Levy",
      "Millie Brown",
      "Demogorgon",
      "Finn Wolfhard"],
   "uploader":"Netflix",
   "uploader_url":"http:\/\/www.youtube.com\/user\/NewOnNetflix",
   "thumbnail":"https:\/\/i.ytimg.com\/vi\/vgS2L7WPIO4\/maxresdefault.jpg",
   "streams":[
   {
      "url":"https:\/\/r6---sn-4g57knkz.googlevideo.com\/videoplayback?id=9d[...]",
      "format":"audio only (DASH audio)",
      "format_note":"Audio only, no video",
      "extension":"m4a",
      "video_codec":"none",
      "audio_codec":"mp4a.40.5",
      "filesize":1438229,
      "height":null,
      "width":null
   },
   {
      "url":"https:\/\/r6---sn-4g57knkz.googlevideo.com\/videoplayback?key=[...]",
      "format":"1920x1080 (1080p)",
      "format_note":"1080p",
      "extension":"webm",
      "video_codec":"vp9",
      "audio_codec":"none",
      "filesize":68016821,
      "height":1080,
      "width":1920
   },
  {
      ...
   }

In the array, you have “status” and “message” to give you the results, a thumbnail, and the most important parts, the “streams” array!

The “streams” array will contain all variants of the video, with or without audio, and in different quality!

Just pick the URL you want to download, and you are set to watch a great trailer for a great show!

Developers are downloading 50,000+ videos daily with our API. For FREE!