From 935877c1f7e8f5638ffaebb674cdd17a258c0458 Mon Sep 17 00:00:00 2001 From: Nyah Check Date: Wed, 6 Sep 2017 20:40:51 -0600 Subject: [PATCH] Refactored code base. --- api/apiconv.go | 7 ---- api/apiconv_test.go | 7 ---- api/apidata.go | 39 +++++++++++++++++++++ api/apisearch.go | 79 ------------------------------------------- api/apisearch_test.go | 8 ----- auth/auth_test.go | 1 + cmd/ytd/ytd.go | 2 -- 7 files changed, 40 insertions(+), 103 deletions(-) delete mode 100644 api/apiconv.go delete mode 100644 api/apiconv_test.go delete mode 100644 api/apisearch.go delete mode 100644 api/apisearch_test.go diff --git a/api/apiconv.go b/api/apiconv.go deleted file mode 100644 index 2376028..0000000 --- a/api/apiconv.go +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2017 YTD Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// apiconv: Converts downloaded flv file to mp3. - -package api diff --git a/api/apiconv_test.go b/api/apiconv_test.go deleted file mode 100644 index 5db1c3e..0000000 --- a/api/apiconv_test.go +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2017 YTD Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// apiconv_test: Tests apiconv.go - -package api diff --git a/api/apidata.go b/api/apidata.go index d034a76..c843d87 100644 --- a/api/apidata.go +++ b/api/apidata.go @@ -167,3 +167,42 @@ func APIDownloadVideo(videoStream map[string][]string) ([]byte, err) { return nil } + + +//Search youtube API for video data. +func SearchApi(service youtube.Service) { + + + // Group video, channel, and playlist results in separate lists. + videos := make(map[string]string) + channels := make(map[string]string) + playlists := make(map[string]string) + + // Iterate through each item and add it to the correct list. + for _, item := range response.Items { + switch item.Id.Kind { + case "youtube#video": + videos[item.Id.VideoId] = item.Snippet.Title + case "youtube#channel": + channels[item.Id.ChannelId] = item.Snippet.Title + case "youtube#playlist": + playlists[item.Id.PlaylistId] = item.Snippet.Title + } + } + + printIDs("Videos", videos) + printIDs("Channels", channels) + printIDs("Playlists", playlists) +} + +// Print the ID and title of each result in a list as well as a name that +// identifies the list. For example, print the word section name "Videos" +// above a list of video search results, followed by the video ID and title +// of each matching video. +func APIPrintIDs(sectionName string, matches map[string]string) { + fmt.Printf("%v:\n", sectionName) + for id, title := range matches { + fmt.Printf("[%v] %v\n", id, title) + } + fmt.Printf("\n\n") +} diff --git a/api/apisearch.go b/api/apisearch.go deleted file mode 100644 index aee8074..0000000 --- a/api/apisearch.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2017 YTD Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// apisearch: Performs search queries on Youtube and returns results. - -package api - -import ( - "flag" - "fmt" - "log" - "net/http" - - "code.google.com/p/google-api-go-client/googleapi/transport" - "code.google.com/p/google-api-go-client/youtube/v3" -) - -var ( - query = flag.String("query", "Google", "Search term") - maxResults = flag.Int64("max-results", 25, "Max YouTube results") -) - -const developerKey = "YOUR DEVELOPER KEY" - -func main() { - flag.Parse() - - client := &http.Client{ - Transport: &transport.APIKey{Key: developerKey}, - } - - service, err := youtube.New(client) - if err != nil { - log.Fatalf("Error creating new YouTube client: %v", err) - } - - // Make the API call to YouTube. - call := service.Search.List("id,snippet"). - Q(*query). - MaxResults(*maxResults) - response, err := call.Do() - if err != nil { - log.Fatalf("Error making search API call: %v", err) - } - - // Group video, channel, and playlist results in separate lists. - videos := make(map[string]string) - channels := make(map[string]string) - playlists := make(map[string]string) - - // Iterate through each item and add it to the correct list. - for _, item := range response.Items { - switch item.Id.Kind { - case "youtube#video": - videos[item.Id.VideoId] = item.Snippet.Title - case "youtube#channel": - channels[item.Id.ChannelId] = item.Snippet.Title - case "youtube#playlist": - playlists[item.Id.PlaylistId] = item.Snippet.Title - } - } - - printIDs("Videos", videos) - printIDs("Channels", channels) - printIDs("Playlists", playlists) -} - -// Print the ID and title of each result in a list as well as a name that -// identifies the list. For example, print the word section name "Videos" -// above a list of video search results, followed by the video ID and title -// of each matching video. -func printIDs(sectionName string, matches map[string]string) { - fmt.Printf("%v:\n", sectionName) - for id, title := range matches { - fmt.Printf("[%v] %v\n", id, title) - } - fmt.Printf("\n\n") -} diff --git a/api/apisearch_test.go b/api/apisearch_test.go deleted file mode 100644 index 0af420a..0000000 --- a/api/apisearch_test.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2017 YTD Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// apisearch_test: Tests api_search - -package api - diff --git a/auth/auth_test.go b/auth/auth_test.go index e69de29..8832b06 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -0,0 +1 @@ +package auth diff --git a/cmd/ytd/ytd.go b/cmd/ytd/ytd.go index e354aaf..0170fd5 100644 --- a/cmd/ytd/ytd.go +++ b/cmd/ytd/ytd.go @@ -15,8 +15,6 @@ import ( "net/http" "net/url" "os" - "os/user" - "os/strings" "strconv" "strings" "syscall"