A very simple command line tool for downloading YouTube videos.

Overview

GoTube

Build Status

Overview

This repository contains a single-file implementation of YouTube video downloader written in Go. It does not require any third-party packages, only built-in packages from the standard library. The code is compact and easily-readable.

Installation

You can fetch one of the executable binaries (preferably latest one) from Releases. The binaries only support Windows (32 and 64 bit) and Linux (32 and 64 bit) this time.

You can also install GoTube directly from command line. Simply just type a command below in your terminal:

go get github.com/marethyu/gotube

Building From Source

Run the following commands:

git clone https://github.com/marethyu/gotube.git
cd gotube
go get golang.org/x/sync/errgroup
go build gotube.go

How It Works?

When GoTube receives a YouTube video URL as an input, it will extract a video id portion of the URL. Then it sends a HTTP GET request to a server through URL https://www.youtube.com/get_video_info with the video id as a query string. The GET request will return an encoded data containing YouTube video data which will be decoded by GoTube. It will then extract the video's title, file format and its download URL from the data. After getting all necessary data, GoTube makes a video file with specified title and file format in User's OS and sends another HTTP GET request to the download URL. The data received through the GET request will be copied to the created video file.

Steps:

  1. GoTube begins by extracting a video id from a YouTube URL (ex. if the URL is https://www.youtube.com/watch?v=9aUlHLaVmkc, GoTube will extract 9aUlHLaVmkc part).
  2. GoTube sends an HTTP GET request to a server through https://www.youtube.com/get_video_info with the video id as a query string (ex. using id from the previous example, https://www.youtube.com/get_video_info?video_id=9aUlHLaVmkc).
  3. GoTube retrieves the video's title, file format and its download URL from an encoded data received through the GET request.
  4. GoTube creates a video file in User's OS and make another GET request through the download URL.
  5. GoTube copies contents of data received through the GET request to the created video file.

Example Usage

Basic (install to the current directory):

gotube https://www.youtube.com/watch?v=2fsMUqYix0c

Download multiple videos:

gotube https://www.youtube.com/watch?v=2fsMUqYix0c https://www.youtube.com/watch?v=wJMkvlTAzHc

Install to the specified download directory (<download directory>):

gotube -outdir=<download directory> https://www.youtube.com/watch?v=MXStYQSLd_M

With verbose option:

gotube -v https://www.youtube.com/watch?v=wJMkvlTAzHc

Option to download audio (requires ffmpeg, get one here if you don't have one installed):

gotube -a https://www.youtube.com/watch?v=Hh_HyNfyOKs

TODO

  • Download whole playlist

Contributing

I appreciate any kind of contributions. It can include code changes, new features and recommendations.

License

It's licensed under BSD-3-Clause.

Issues
  • GoTube: streamingData is missing from this video

    GoTube: streamingData is missing from this video

    Hi there,

    What is the possible cause of the following error?

    $ ./gotube https://www.youtube.com/watch?v=nVjsGKrE6E8
    GoTube: streamingData is missing from this video 'nVjsGKrE6E8'
    

    However, the example provided in README worked :)

    $ ./gotube https://www.youtube.com/watch?v=2fsMUqYix0c
    <nil>
    $ #Downloaded successfully
    
    opened by raresraf 2
  • quality

    quality

    Everything is super, thank you very much

    Just not enough quality :( audio at 33 kb sec video 640x480

    You can increase the quality to audio at 128 kb sec 1080p video or whatever else

    I use google translator

    opened by sifaaa 1
  • Add Travis CI for linting

    Add Travis CI for linting

    Adds a simple Travis CI script for running gofmt. Now, the build badge on the readme will actually work once you activate Travis :)

    See example build here: https://travis-ci.com/github/kx-chen/gotube/jobs/315607780

    This also helps enforce gofmt on all commits, you can see the checkmark on the list of commits https://github.com/kx-chen/gotube/commits/add-travis-ci

    opened by kx-chen 1
  • Add support for download multiple videos asynchronously

    Add support for download multiple videos asynchronously

    Hi @Marethyu12!

    I also changed the command line style and error handlings.

    $ gotube [-outdir=<OUT_DIRECTORY>] [-v] [-a] <YT_VID_URL> [<YT_VID_URL>...]
    

    Let me know if you would prefer a different way to resolve this!

    opened by matsuyoshi30 1
  • linter fixes

    linter fixes

    Problem: various areas of the code had potential errors not being handled. Solution: add error handling. Notes: last commit is possible contentious change, but it keeps errcheck happy.

    opened by Integralist 0
  • Precompiled binaries

    Precompiled binaries

    The title says it all.

    For anyone who doesn't know what a precompiled binary is, it's a binary/executable file. When you run go run, golang automatically creates then executes your binary.

    Why does this help? If people don't have go installed, they won't use the project. But with precompiled binaries, they can just download the binary file and execute it.

    The thing is... Binaries are different for different computer architectures. Some common architectures are x86_64, arm and amd.

    I won't be able to contribute from my computer for a little bit, so feel free to compile the binaries yourself.

    Have a scintillating Sunday, Bobbbay

    opened by bobbbay 0
  • "It does not require any third-party packages,"

    hi,

    the readme still says: "It does not require any third-party packages," but now it also says to install "golang.org/x/sync/errgroup". Do you plan to restore the "no-external dependency"?

    opened by szabgab 1
  • panic: interface conversion: interface {} is nil, not map[string]interface {}

    panic: interface conversion: interface {} is nil, not map[string]interface {}

    I get the following exception:

    go run gotube.go -v -a 'https://www.youtube.com/watch?v=QmhcdlvUIUY&list=PL3rN31hgtvRZZ6pe_brZQMOIFIBwdv5IF'
    
    GoTube: Making a HTTP GET request thru https://www.youtube.com/get_video_info?video_id=QmhcdlvUIUY...
    panic: interface conversion: interface {} is nil, not map[string]interface {}
    
    goroutine 5 [running]:
    main.DownloadYTVideo(0x7ffe90b80117, 0x53, 0x714d8c, 0x1, 0xc000040101, 0x0, 0x0)
    	/home/gabor/work/gotube/gotube.go:293 +0x2315
    main.Download.func1(0xc000000008, 0x72a878)
    	/home/gabor/work/gotube/gotube.go:409 +0xcb
    golang.org/x/sync/errgroup.(*Group).Go.func1(0xc000082c60, 0xc000012500)
    	/home/gabor/go/src/golang.org/x/sync/errgroup/errgroup.go:57 +0x57
    created by golang.org/x/sync/errgroup.(*Group).Go
    	/home/gabor/go/src/golang.org/x/sync/errgroup/errgroup.go:54 +0x66
    exit status 2
    
    $ go version
    go version go1.12.9 linux/amd64
    

    On this commit: 3637197ce368d10a2b82778e1775aaf5ec498006

    opened by szabgab 0
Owner
Jimmy Yang
Always writes bad code and makes bugs.
Jimmy Yang
A youtube library for retrieving metadata, and obtaining direct links to video-only/audio-only/mixed versions of videos on YouTube in Go.

A youtube library for retrieving metadata, and obtaining direct links to video-only/audio-only/mixed versions of videos on YouTube in Go. Install go g

José Pastor 4 May 14, 2022
Command-line program to download videos from YouTube.com and other video sites

youtube-dl - download videos from youtube.com or other video platforms INSTALLATION DESCRIPTION OPTIONS CONFIGURATION OUTPUT TEMPLATE FORMAT SELECTION

youtube-dl 111.1k Jun 26, 2022
📱🥴 TikTok terminal client for browsing & downloading videos

tiktik ?? ?? - TikTok Terminal Client Name inspiration - this yt vid Huge Thanks to Egor who wrote the parsing part Installation ?? go get -u github.c

Ilya Revenko 71 Jun 20, 2022
A very very simple CLI tool to know the next and previous SpaceX flights.

Rocket A very very simple CLI tool to know the next and previous SpaceX flights. Commands rocket Get the next flight. rocket latest Get the last fligh

Quentin 3 Apr 19, 2021
📥 Command-line tool to download videos from hanime.tv

hanime Command-line tool to download videos from hanime.tv Requirements Installation Install via go get Install from source Install from release Usage

私はレオンです 26 Jun 18, 2022
youtube-command-line-tool

youtube-command-line-tool 簡單的 youtube data api串接 Youtube Data Api 官方文件 How to use 申請GOOGLE API KEY 複製.env cp .env.example .env API KEY 放入.env GOOGL

Niguai 0 Dec 7, 2021
You-Get is a tiny command-line utility to download media contents (videos, audios, images) from the Web,

You-Get NOTICE: Read this if you are looking for the conventional "Issues" tab. You-Get is a tiny command-line utility to download media contents (vid

Mort Yao 44.3k Jun 26, 2022
Go-Suit is a very very wacky version of a bash terminal but in go, however with a little twitst

Go-Suit Go-Suit is a very very wacky version of a bash terminal but in go, however with a little twitst languages -> Go-Lang packages Third Party -> g

RE43P3R 0 May 19, 2022
An easy-to-use cli tool for downloading manga

mangodl Download and search manga right from the terminal! Report Bug || Request Feature Table of Contents About the Project Built With Getting Starte

null 132 Jun 25, 2022
A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

null 0 Nov 22, 2021
CLI to support with downloading and compiling terraform providers for Mac with M1 chip

m1-terraform-provider-helper A CLI to help with managing the installation and compilation of terraform providers when running a new M1 Mac. Motivation

kreuzwerker GmbH 170 Jun 23, 2022
"steal" NFTs by downloading them via OpenSea api ;)

go-NFThief "steal" NFTs by downloading them via OpenSea api. now you don't have to manually screenshot them ;) Options to: download a collection via c

null 1 Apr 11, 2022
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Clement Sam 2k Jun 25, 2022
A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purpose—to prompt for a value to be included in another command line. readval prints

Venky 0 Dec 22, 2021
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Gruntwork 599 Jun 26, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

Maxar Infrastructure 1 Feb 5, 2022
A command line tool for simplified docker volume command built with go

dockervol A command line tool for simplified docker volume command built with go. Features: Remove anonymous volume (beta) Remove volume by matching n

Moh Achun Armando 0 Dec 18, 2021
An easy to use go program to download videos from Reddit

Gedditsave Download videos from reddit from the command line. Use guide geddit -

Solaris 30 Jun 5, 2022
An easy to use go program to download videos from Reddit.

Gettit Download videos from reddit from the command line. Use guide gettit -u post_url Example : gettit -u https://www.reddit.com/r/programminghorror/

Solaris 30 Jun 5, 2022