Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions cmd/youtubedr/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type PlaylistInfo struct {
}

var (
isDownloader bool
// listCmd represents the list command
listCmd = &cobra.Command{
Use: "list",
Expand All @@ -27,23 +28,32 @@ var (
Run: func(_ *cobra.Command, args []string) {
playlist, err := getDownloader().GetPlaylist(args[0])
exitOnError(err)
if !isDownloader {
playlistInfo := PlaylistInfo{
Title: playlist.Title,
Author: playlist.Author,
}
for _, v := range playlist.Videos {
playlistInfo.Videos = append(playlistInfo.Videos, VideoInfo{
ID: v.ID,
Title: v.Title,
Author: v.Author,
Duration: v.Duration.String(),
})
}

playlistInfo := PlaylistInfo{
Title: playlist.Title,
Author: playlist.Author,
exitOnError(writeOutput(os.Stdout, &playlistInfo, func(w io.Writer) {
writePlaylistOutput(w, &playlistInfo)
}))
} else {
for i := 0; i < len(playlist.Videos); i++ {
err := download(playlist.Videos[i].ID)
if err != nil {
fmt.Println(err.Error())
}
err = nil
}
}
for _, v := range playlist.Videos {
playlistInfo.Videos = append(playlistInfo.Videos, VideoInfo{
ID: v.ID,
Title: v.Title,
Author: v.Author,
Duration: v.Duration.String(),
})
}

exitOnError(writeOutput(os.Stdout, &playlistInfo, func(w io.Writer) {
writePlaylistOutput(w, &playlistInfo)
}))
},
}
)
Expand Down Expand Up @@ -71,5 +81,8 @@ func writePlaylistOutput(w io.Writer, info *PlaylistInfo) {

func init() {
rootCmd.AddCommand(listCmd)

listCmd.Flags().BoolVarP(&isDownloader, "downloader", "d", false, "Download playlist")
listCmd.Flags().StringVarP(&outputDir, "output", "o", ".", "The output directory.")
addFormatFlag(listCmd.Flags())
}