Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

github.com/parallax4/youtube

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/parallax4/youtube


Version published
Created
Source

Download Youtube Video in Golang

GitHub license GoDoc Build Status Coverage

This package is a Youtube video download package, for more detail refer https://github.com/rg3/youtube-dl for more download options.

Overview

Install:

go get github.com/kkdai/youtube

OR

git clone https://github.com/kkdai/youtube.git
go run youtubedr/main.go

Install in Termux

pkg install youtubedr

Usage

Use the binary directly

It's really simple to use, just get the video id from youtube url - ex: https://www.youtube.com/watch?v=rFejpH_tAHM, the video id is rFejpH_tAHM

$ youtubedr QAGDGja7kbs

$ youtubedr https://www.youtube.com/watch?v=rFejpH_tAHM

Import this package in your golang program

package main

import (
	"flag"
	"fmt"
	"log"
	"os/user"
	"path/filepath"

	. "github.com/kkdai/youtube"
)

func main() {
	flag.Parse()
	log.Println(flag.Args())
	usr, _ := user.Current()
	currentDir := fmt.Sprintf("%v/Movies/youtubedr", usr.HomeDir)
	log.Println("download to dir=", currentDir)
	y := NewYoutube(true)
	arg := flag.Arg(0)
	if err := y.DecodeURL(arg); err != nil {
		fmt.Println("err:", err)
	}
	if err := y.StartDownload(currentDir, "dl.mp4", "medium",0); err != nil {
		fmt.Println("err:", err)
	}
}

Options:

optiontypedescriptiondefault value
-dstringthe output directory$HOME/Movies/youtubedr
-ostringthe output file name ( ext will auto detect on default value )[video's title].ext
-dstringthe Socks 5 proxy (e.g. 10.10.10.10:7878)
-qstringthe output file quality (medium, hd720)
-istringthe output file itag (13, 17 etc..)0
-infoboolshow information of available streams (quality, itag, MIMEtype)

Example:

  • Get information of dotGo-2015-rob-pike video for downloading

    go get github.com/kkdai/youtube/youtubedr

    Download video from dotGo 2015 - Rob Pike - Simplicity is Complicated

    youtubedr -info https://www.youtube.com/watch?v=rFejpH_tAHM
    
    Title: dotGo 2015 - Rob Pike - Simplicity is Complicated
    Author: dotconferences
    -----available streams-----
    itag:  18 , quality: medium , type: video/mp4; codecs="avc1.42001E, mp4a.40.2"
    itag:  22 , quality:  hd720 , type: video/mp4; codecs="avc1.64001F, mp4a.40.2"
    itag: 137 , quality: hd1080 , type: video/mp4; codecs="avc1.640028"
    itag: 248 , quality: hd1080 , type: video/webm; codecs="vp9"
    ........
    
  • Download dotGo-2015-rob-pike-video

    go get github.com/kkdai/youtube/youtubedr

    Download video from dotGo 2015 - Rob Pike - Simplicity is Complicated

    youtubedr https://www.youtube.com/watch?v=rFejpH_tAHM
    
  • Download video to specific folder and name

    go get github.com/kkdai/youtube/youtubedr

    Download video from dotGo 2015 - Rob Pike - Simplicity is Complicated to current directory and name the file to simplicity-is-complicated.mp4

    youtubedr -d ./ -o simplicity-is-complicated.mp4 https://www.youtube.com/watch?v=rFejpH_tAHM
    
  • Download video with specific quality

    go get github.com/kkdai/youtube/youtubedr

    Download video from dotGo 2015 - Rob Pike - Simplicity is Complicated with specific quality

    youtubedr -q medium https://www.youtube.com/watch?v=rFejpH_tAHM
    
    Special case by quality hd1080:

    Installation of ffmpeg is necessary for hd1080

    ffmpeg   //check ffmpeg is installed, if not please download ffmpeg and set to your PATH.
    youtubedr -q hd1080 https://www.youtube.com/watch?v=rFejpH_tAHM
    
  • Download video with specific itag

    go get github.com/kkdai/youtube/youtubedr

    Download video from dotGo 2015 - Rob Pike - Simplicity is Complicated

    youtubedr -i 18 https://www.youtube.com/watch?v=rFejpH_tAHM
    

How it works

  • Parse the video ID you input in URL
    • ex: https://www.youtube.com/watch?v=rFejpH_tAHM, the video id is rFejpH_tAHM
  • Get video information via video id.
    • Use URL: http://youtube.com/get_video_info?video_id=
  • Parse and decode video information.
    • Download URL in "url="
    • title in "title="
  • Download video from URL
    • Need the string combination of "url"

Inspired

Project52

It is one of my project 52.

License

This package is licensed under MIT license. See LICENSE for details.

FAQs

Package last updated on 29 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc