Skip to content

Instantly share code, notes, and snippets.

@mgdelacroix
Last active January 31, 2017 11:24
Show Gist options
  • Save mgdelacroix/58a4b648665de99c2bf1a86dc833f645 to your computer and use it in GitHub Desktop.
Save mgdelacroix/58a4b648665de99c2bf1a86dc833f645 to your computer and use it in GitHub Desktop.
Small program to read a file and use youtube-dl to download the urls contained in it
package main
import (
"fmt"
"io/ioutil"
"os/exec"
"strings"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func get_file_lines(filename string) []string {
dat, err := ioutil.ReadFile(filename)
check(err)
return strings.Split(string(dat), "\n")
}
func download_video(video string) {
cmd := exec.Command("youtube-dl", video)
fmt.Println("++ About to download the following video:", video)
out, err := cmd.Output()
check(err)
fmt.Println(string(out))
fmt.Println("-- Download finished")
}
func download_videos(videos []string) {
for _, video := range videos {
download_video(video)
}
}
func main() {
videos := get_file_lines("videos.txt")
download_videos(videos)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment