Socket
Socket
Sign inDemoInstall

gitlab.com/ttpcodes/youtube-dl-go

Package Overview
Dependencies
4
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gitlab.com/ttpcodes/youtube-dl-go

Package youtube-dl-go wraps youtube-dl's Python API. youtube-dl-go is a simple wrapper to the popular youtube-dl application for Python. This allows you to access the youtube-dl binary programmatically in any application that you write.


Version published

Readme

Source

youtube-dl-go

A Go library that wraps youtube-dl's Python API.

coverage report GoDoc pipeline status

youtube-dl-go is a simple wrapper to the popular youtube-dl application for Python. This allows you to access the youtube-dl binary programmatically in any application that you write.

The motivation for creating this library was simple: many of the other pure Go solutions for downloading YouTube videos were lacking in features or were woefully out of date, making them difficult to use and implement in actual projects. By wrapping youtube-dl with this library, we get easy access to an already well developed download solution while also having an easy to use API for our Go applications.

This package is still in a very alpha stage. It is not being actively developed, as its main purpose is to provide a good youtube-dl interface for my other project, Prismriver. That being said however, I am more than happy to respond to feature requests to increase the functionality of this library.

Usage

All downloads are initiated by creating a Downloader instance. There is an Output function which will allow you to specify where the file is downloaded, and supports various output templates from youtube-dl. Downloads can be run by calling Run, which blocks the program until the download completes, or with RunProgress, which provides channels to track the download's progress and wait for a completed download.

package main

import (
	"fmt"
	"gitlab.com/ttpcodes/youtube-dl-go"
)

func main() {
	// Guess what my favorite song is as of this writing?
	downloader := youtubedl.NewDownloader("https://www.youtube.com/watch?v=Qu_OzBsgRcI")
	downloader.Output("~/Downloads/RealOrFake")
	path, err := downloader.Run()
	if err != nil {
		fmt.Print(err)
		return
	}
	fmt.Printf("File was downloaded to %s", path)
	
	// My other favorite song, which I'll use to show channel usage:
	downloader2 := youtubedl.NewDownloader("https://www.youtube.com/watch?v=6nDrD2WNSJU")
	downloader2.Output("~/Downloads/" + youtubedl.ID)
	progressChan, resultChan, err := downloader2.RunProgress()
	if err != nil {
	    fmt.Print(err)
	}
	for progress := range progressChan {
		fmt.Printf("Current progress: %f", progress)
	}
	result := <- resultChan
	if result.Err != nil {
		fmt.Print(err)
		return
	}
	fmt.Printf("File 2 was downloaded to %s", result.Path)
}

When run, the program will output something similar to this:

File was downloaded to /home/ttpcodes/Downloads/RealOrFake.mkv
Current progress: 0.000000
Current progress: 0.050000
Current progress: 0.050000
Current progress: 0.100000
Current progress: 0.250000
Current progress: 0.500000
Current progress: 1.000000
Current progress: 1.950000
Current progress: 3.950000
Current progress: 7.900000
Current progress: 15.750000
Current progress: 31.500000
... # Omitted progress lines
Current progress: 60.800000
Current progress: 71.650000
Current progress: 93.300000
Current progress: 100.000000
File 2 was downloaded to /home/ttpcodes/Downloads/6nDrD2WNSJU.mkv

API

API documentation can be found on GoDoc.

Installation

Any Go method of package management should support the installation of this package. My preferred package management method is dep:

dep ensure gitlab.com/ttpcodes/youtube-dl-go

LICENSE

This project is licensed under the MIT License.

FAQs

Last updated on 28 Oct 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc