hlfw.ca

ytcli

Download patch

ref: acca03e5ebdd8a723d49a29f45009c2af11e8b35
parent: 6480f771f6de3ea9fffad8cf42a7c346849d730a
author: Halfwit <michaelmisch1985@gmail.com>
date: Mon Jun 3 18:51:39 PDT 2019

Do the correct fields function

--- a/call.go
+++ b/call.go
@@ -9,11 +9,11 @@
 	"google.golang.org/api/youtube/v3"
 )
 
-var yt = "https://www.youtube.com/watch?feeds=items/VideoId,items/snippet/title,items/snippet/thumbnails/high/url&v="
+var yt = "https://www.youtube.com/watch?v="
 
 func playlistSearch(query string, service *youtube.Service) map[string]string {
 	results := make(map[string]string)
-	call := service.Search.List("id,snippet").Q(query).MaxResults(*nresults)
+	call := service.Search.List("id,snippet").Q(query).MaxResults(*nresults).Fields("items(id(kind, playlistId), snippet(thumbnails/default/url, title))")
 	response, err := call.Do()
 	if err != nil {
 		log.Fatal(err)
@@ -34,12 +34,12 @@
 func channelSearch(query string, service *youtube.Service) map[string]string {
 	// Fetch channel ID
 	results := make(map[string]string)
-	call := service.Search.List("id,snippet").Q(query).MaxResults(1)
+	call := service.Search.List("id,snippet").Q(query).MaxResults(1).Fields("items/id/channelId")
 	id, err := call.Do()
 	if err != nil {
 		log.Fatal(err)
 	}
-	call2 := service.Search.List("id,snippet").MaxResults(*nresults).ChannelId(id.Items[0].Id.ChannelId)
+	call2 := service.Search.List("id,snippet").MaxResults(*nresults).ChannelId(id.Items[0].Id.ChannelId).Fields("items(id/kind, id/videoId, snippet/thumbnails/default/url, snippet/title)")
 	response, err := call2.Do()
 	if err != nil {
 		log.Fatal(err)
@@ -59,7 +59,7 @@
 
 func normalSearch(query string, service *youtube.Service) map[string]string {
 	results := make(map[string]string)
-	call := service.Search.List("id,snippet").Q(query).MaxResults(*nresults)
+	call := service.Search.List("id,snippet").Q(query).MaxResults(*nresults).Fields("items(id/kind, id/videoId, snippet(title, thumbnails/default/url))")
 	response, err := call.Do()
 	if err != nil {
 		log.Fatal(err)
@@ -81,7 +81,7 @@
 	results := make(map[string]string)
 	feed := "https://youtube.com/feeds/video.xml?channel_id="
 	if *channel {
-		call := service.Search.List("id,snippet").Q(query).MaxResults(*nresults)
+		call := service.Search.List("id,snippet").Q(query).MaxResults(*nresults).Fields("items(id/kind, id/channelId, snippet/title)")
 		response, err := call.Do()
 		if err != nil {
 			log.Fatal(err)
@@ -96,7 +96,7 @@
 		// This was slapped out pretty quickly
 		r := regexp.MustCompile(`^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$`)
 		vid := r.FindStringSubmatch(query)
-		call := service.Videos.List("id,snippet").Id(vid[5])
+		call := service.Videos.List("id,snippet").Id(vid[5]).Fields("item/snippet(channelId, channelTitle)")
 		response, err := call.Do()
 		if err != nil {
 			log.Fatal(err)
@@ -112,7 +112,7 @@
 	results := make(map[string]string)
 	r := regexp.MustCompile(`^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$`)
 	vid := r.FindStringSubmatch(query)
-	call := service.Search.List("id,snippet").RelatedToVideoId(vid[5]).MaxResults(*nresults).Type("video")
+	call := service.Search.List("id,snippet").RelatedToVideoId(vid[5]).MaxResults(*nresults).Type("video").Fields("items(id/videoId, snippet(thumbnails/default/url, title))")
 	response, err := call.Do()
 	if err != nil {
 		log.Fatal(err)