// NewYTDLFile creates a video file downloader. // func NewYTDLFile(log cdtype.Logger, url string) (Filer, error) { info, e := ytdl.GetVideoInfo(url) if e != nil { return nil, fmt.Errorf("Unable to fetch video info: %s", e.Error()) } // formats := info.Formats // // parse filter arguments, and filter through formats // for _, filter := range options.filters { // filter, e := parseFilter(filter) // if !log.Err(e) { // formats = filter(formats) // } // } // if len(formats) == 0 { // return nil, fmt.Errorf("No formats available that match criteria: %s", e.Error()) // } log.Info("Author", info.Author) log.Info("Description", info.Description) log.Info("ID", info.ID) log.Info("vid", info) var list []*Format for _, v := range info.Formats { nf := &Format{ Itag: v.Itag, Extension: v.Extension, Resolution: v.Resolution, VideoEncoding: v.VideoEncoding, AudioEncoding: v.AudioEncoding, AudioBitrate: v.AudioBitrate, } s := v.ValueForKey("clen") if s != nil { nf.Size, e = strconv.Atoi(s.(string)) nf.Size /= 1000000 log.Err(e, "convert size. format=", v.Itag) // } else { // log.Info("no clen", v.Itag) } list = append(list, nf) } // pretty.Println(info) return &YTDLFile{ VideoInfo: *info, formats: list, log: log, }, nil }
// Init will try to load the own config data from the file, and create it if missing. // func Init(log cdtype.Logger, file string, e error) error { if e != nil { return e } // Create file if needed. if !files.IsExist(file) { source := globals.DirShareData(GuiFilename) e := files.CopyFile(source, file, os.FileMode(0644)) if e != nil { return e } log.Info("created config file", file) } // Create our user settings Settings = ConfigSettings{ File: file, log: log, } return Settings.Load() }