Ejemplo n.º 1
0
// Get actually sends the data
func (m *Middleware) Get(ib *irc.Connection, from string, to string, message string) {
	if !m.Started {
		return
	}
	client := &http.Client{
		Transport: &transport.APIKey{Key: configuration.Config.GoogleAPIKey},
	}
	for _, bit := range strings.Fields(message) {
		rs := ytre.FindAllStringSubmatch(bit, -1)
		if len(rs) > 0 {
			service, err := yt.New(client)
			if err != nil {
				fmt.Println("should send")
				log.Printf("Error creating new YouTube client: %v\n", err)
				return
			}
			response, err := service.Videos.List("snippet, statistics, contentDetails").Id(rs[0][1]).Do()
			if err != nil {
				log.Println(err)
				return
			}
			for _, val := range response.Items {
				ib.Privmsgf(to, FormatOutput(val))
			}
		}
	}
}
Ejemplo n.º 2
0
func main() {
	// Start up the YouTube service
	service, err := youtube.New(&http.Client{
		Transport: &transport.APIKey{Key: googleAPIKey},
	})
	if err != nil {
		log.Fatal(err.Error())
	}

	playlistItems := make([]*OrderedPlaylistItem, 0)
	sieve := make(chan *youtube.PlaylistItem)

	// fetch the video ids
	go playlistItemsSieve(service, playlist, sieve)

	// dispatch the downloads
	var counter int = 1
	for video := range sieve {
		orderedVideo := OrderedPlaylistItem{video, counter, 1}
		playlistItems = append(playlistItems, &orderedVideo)
		counter++
	}

	wg := new(sync.WaitGroup)
	for _, video := range playlistItems {
		wg.Add(1)
		go func(v *OrderedPlaylistItem) {
			var e error = v.Download()
			if shouldConvert() && e == nil {
				e = v.ConvertToMp3(Artist, Album)
				os.Remove(v.M4aFname())
			}
			if e != nil {
				fmt.Println(e.Error())
			}
			wg.Done()
		}(video)
	}
	wg.Wait()

}
Ejemplo n.º 3
0
// youtubeMain is an example that demonstrates calling the YouTube API.
// It is similar to the sample found on the Google Developers website:
// https://developers.google.com/youtube/v3/docs/videos/insert
// but has been modified slightly to fit into the examples framework.
//
// Example usage:
//   go build -o go-api-demo
//   go-api-demo -clientid="my-clientid" -secret="my-secret" youtube filename
func youtubeMain(client *http.Client, argv []string) {
	if len(argv) < 1 {
		fmt.Fprintln(os.Stderr, "Usage: youtube filename")
		return
	}
	filename := argv[0]

	service, err := youtube.New(client)
	if err != nil {
		log.Fatalf("Unable to create YouTube service: %v", err)
	}

	upload := &youtube.Video{
		Snippet: &youtube.VideoSnippet{
			Title:       "Test Title",
			Description: "Test Description", // can not use non-alpha-numeric characters
			CategoryId:  "22",
		},
		Status: &youtube.VideoStatus{PrivacyStatus: "unlisted"},
	}

	// The API returns a 400 Bad Request response if tags is an empty string.
	upload.Snippet.Tags = []string{"test", "upload", "api"}

	call := service.Videos.Insert("snippet,status", upload)

	file, err := os.Open(filename)
	defer file.Close()
	if err != nil {
		log.Fatalf("Error opening %v: %v", filename, err)
	}

	response, err := call.Media(file).Do()
	if err != nil {
		log.Fatalf("Error making YouTube API call: %v", err)
	}
	fmt.Printf("Upload successful! Video ID: %v\n", response.Id)
}
Ejemplo n.º 4
0
func main() {
	flag.Parse()

	client := &http.Client{
		Transport: &googtransport.APIKey{Key: apiKey},
	}

	service, err := youtube.New(client)
	if err != nil {
		log.Fatalf("Error creating new YouTube client: %v", err)
	}

	call := service.Search.List("id,snippet").Q(query).MaxResults(*maxResults).Order("date")
	response, err := call.Do()
	if err != nil {
		log.Fatalf("Error making search API call: %v", err)
	}

	videos := make(map[string]Video)

	for _, item := range response.Items {
		switch item.Id.Kind {
		case "youtube#video":
			videos[item.Id.VideoId] = Video{
				item.Id.VideoId, item.Snippet.Title, item.Snippet.Thumbnails.High.Url}
		}
	}
	printIDs("Videos", videos)
	db, err := sql.Open("postgres", getDbURL())
	if err != nil {
		panic(err)
	}
	println("Connection success!")
	defer db.Close()
	updateDb(db, videos)
}