本文整理汇总了Golang中github.com/matthieugrieger/mumbledj/interfaces.Track.GetURL方法的典型用法代码示例。如果您正苦于以下问题:Golang Track.GetURL方法的具体用法?Golang Track.GetURL怎么用?Golang Track.GetURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/matthieugrieger/mumbledj/interfaces.Track
的用法示例。
在下文中一共展示了Track.GetURL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Download
// Download downloads the audio associated with the incoming `track` object
// and stores it `track.Filename`.
func (yt *YouTubeDL) Download(t interfaces.Track) error {
player := "--prefer-ffmpeg"
if viper.GetString("defaults.player_command") == "avconv" {
player = "--prefer-avconv"
}
filepath := os.ExpandEnv(viper.GetString("cache.directory") + "/" + t.GetFilename())
// Determine which format to use.
format := "bestaudio"
for _, service := range DJ.AvailableServices {
if service.GetReadableName() == t.GetService() {
format = service.GetFormat()
}
}
// Check to see if track is already downloaded.
if _, err := os.Stat(filepath); os.IsNotExist(err) {
var cmd *exec.Cmd
if t.GetService() == "Mixcloud" {
cmd = exec.Command("youtube-dl", "--verbose", "--no-mtime", "--output", filepath, "--format", format, "--external-downloader", "aria2c", player, t.GetURL())
} else {
cmd = exec.Command("youtube-dl", "--verbose", "--no-mtime", "--output", filepath, "--format", format, player, t.GetURL())
}
output, err := cmd.CombinedOutput()
if err != nil {
args := ""
for s := range cmd.Args {
args += cmd.Args[s] + " "
}
logrus.Warnf("%s\n%s\nyoutube-dl: %s", args, string(output), err.Error())
return errors.New("Track download failed")
}
if viper.GetBool("cache.enabled") {
DJ.Cache.CheckDirectorySize()
}
}
return nil
}