This commit is contained in:
Alex Grintsvayg 2020-07-27 14:52:21 -04:00
parent edbb22fcf0
commit bffc0823be
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
3 changed files with 8 additions and 17 deletions

View file

@ -1,9 +0,0 @@
package manager
import (
"github.com/lbryio/ytsync/v5/ytapi"
)
func (s *Sync) CountVideos() (uint64, error) {
return ytapi.VideosInChannel(s.APIConfig.YoutubeAPIKey, s.YoutubeChannelID)
}

View file

@ -72,7 +72,7 @@ func (s *Sync) walletSetup() error {
} }
log.Debugf("Starting balance is %.4f", balance) log.Debugf("Starting balance is %.4f", balance)
n, err := s.CountVideos() n, err := ytapi.CountVideosInChannel(s.APIConfig.YoutubeAPIKey, s.YoutubeChannelID)
if err != nil { if err != nil {
return err return err
} }

View file

@ -46,7 +46,7 @@ type VideoParams struct {
var mostRecentlyFailedChannel string // TODO: fix this hack! var mostRecentlyFailedChannel string // TODO: fix this hack!
func GetVideosToSync(apiKey, channelID string, syncedVideos map[string]sdk.SyncedVideo, quickSync bool, maxVideos int, videoParams VideoParams) ([]Video, error) { func GetVideosToSync(apiKey, channelID string, syncedVideos map[string]sdk.SyncedVideo, quickSync bool, maxVideos int, videoParams VideoParams) ([]Video, error) {
playlistID, err := PlaylistID(apiKey, channelID) playlistID, err := getPlaylistID(apiKey, channelID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -57,7 +57,7 @@ func GetVideosToSync(apiKey, channelID string, syncedVideos map[string]sdk.Synce
var videos []Video var videos []Video
for { for {
playlistItems, nextPageToken, err = PlaylistItems(apiKey, playlistID, nextPageToken) playlistItems, nextPageToken, err = getPlaylistItems(apiKey, playlistID, nextPageToken)
if len(playlistItems) < 1 { if len(playlistItems) < 1 {
// If there are 50+ videos in a playlist but less than 50 are actually returned by the API, youtube will still redirect // If there are 50+ videos in a playlist but less than 50 are actually returned by the API, youtube will still redirect
@ -81,7 +81,7 @@ func GetVideosToSync(apiKey, channelID string, syncedVideos map[string]sdk.Synce
videoIDs[i] = item.Snippet.ResourceId.VideoId videoIDs[i] = item.Snippet.ResourceId.VideoId
} }
vids, err := Videos(apiKey, videoIDs) vids, err := getVideos(apiKey, videoIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -112,7 +112,7 @@ func GetVideosToSync(apiKey, channelID string, syncedVideos map[string]sdk.Synce
return videos, nil return videos, nil
} }
func VideosInChannel(apiKey, channelID string) (uint64, error) { func CountVideosInChannel(apiKey, channelID string) (uint64, error) {
client := &http.Client{ client := &http.Client{
Transport: &transport.APIKey{Key: apiKey}, Transport: &transport.APIKey{Key: apiKey},
} }
@ -152,7 +152,7 @@ func ChannelInfo(apiKey, channelID string) (*ytlib.ChannelSnippet, *ytlib.Channe
return response.Items[0].Snippet, response.Items[0].BrandingSettings, nil return response.Items[0].Snippet, response.Items[0].BrandingSettings, nil
} }
func PlaylistID(apiKey, channelID string) (string, error) { func getPlaylistID(apiKey, channelID string) (string, error) {
service, err := ytlib.New(&http.Client{Transport: &transport.APIKey{Key: apiKey}}) service, err := ytlib.New(&http.Client{Transport: &transport.APIKey{Key: apiKey}})
if err != nil { if err != nil {
return "", errors.Prefix("error creating YouTube service", err) return "", errors.Prefix("error creating YouTube service", err)
@ -179,7 +179,7 @@ func PlaylistID(apiKey, channelID string) (string, error) {
return playlistID, nil return playlistID, nil
} }
func PlaylistItems(apiKey, playlistID, nextPageToken string) ([]*ytlib.PlaylistItem, string, error) { func getPlaylistItems(apiKey, playlistID, nextPageToken string) ([]*ytlib.PlaylistItem, string, error) {
service, err := ytlib.New(&http.Client{Transport: &transport.APIKey{Key: apiKey}}) service, err := ytlib.New(&http.Client{Transport: &transport.APIKey{Key: apiKey}})
if err != nil { if err != nil {
return nil, "", errors.Prefix("error creating YouTube service", err) return nil, "", errors.Prefix("error creating YouTube service", err)
@ -198,7 +198,7 @@ func PlaylistItems(apiKey, playlistID, nextPageToken string) ([]*ytlib.PlaylistI
return response.Items, response.NextPageToken, nil return response.Items, response.NextPageToken, nil
} }
func Videos(apiKey string, videoIDs []string) ([]*ytlib.Video, error) { func getVideos(apiKey string, videoIDs []string) ([]*ytlib.Video, error) {
service, err := ytlib.New(&http.Client{Transport: &transport.APIKey{Key: apiKey}}) service, err := ytlib.New(&http.Client{Transport: &transport.APIKey{Key: apiKey}})
if err != nil { if err != nil {
return nil, errors.Prefix("error creating YouTube service", err) return nil, errors.Prefix("error creating YouTube service", err)