A very simple command line tool for downloading YouTube videos.

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.

Owner
Jimmy Yang
Always writes bad code and makes bugs.
Jimmy Yang
Comments
  • 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
    
  • 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

  • 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

  • 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!

  • 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.

  • 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

  • "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"?

  • 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

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

Dec 10, 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

Jan 9, 2023
📱🥴 TikTok terminal client for browsing & downloading videos
📱🥴 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

Dec 3, 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

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

Dec 18, 2022
youtube-command-line-tool
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

Nov 20, 2022
You-Get is a tiny command-line utility to download media contents (videos, audios, images) from the Web,
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

Jan 2, 2023
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

Nov 22, 2021
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

May 19, 2022
An easy-to-use cli tool for downloading manga
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

Nov 26, 2022
An open-source GitLab command line tool bringing GitLab's cool features to your command line
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

Dec 30, 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

Dec 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

Jan 2, 2023
"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

Apr 11, 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.

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

Dec 31, 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

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

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

Dec 18, 2021
Package command provide simple API to create modern command-line interface

Package command Package command provide simple API to create modern command-line interface, mainly for lightweight usage, inspired by cobra Usage pack

Jan 16, 2022
Watcher - A simple command line app to watch files in a directory for changes and run a command when files change!

Watcher - Develop your programs easily Watcher watches all the files present in the directory it is run from of the directory that is specified while

Mar 27, 2022