bypass socialblade block

stop using socialblade for now
This commit is contained in:
Niko Storni 2020-08-21 00:15:14 +02:00
parent 24cf937e14
commit ecda80b02d
2 changed files with 12 additions and 8 deletions

View file

@ -73,11 +73,7 @@ func (s *Sync) walletSetup() error {
} }
log.Debugf("Starting balance is %.4f", balance) log.Debugf("Starting balance is %.4f", balance)
videosOnYoutube, err := ytapi.CountVideosInChannel(s.DbChannelData.ChannelId) videosOnYoutube := int(s.DbChannelData.TotalVideos)
if err != nil {
logUtils.SendErrorToSlack(errors.FullTrace(errors.Prefix("failed to get video count through socialblade. Falling back to API count", err)))
videosOnYoutube = int(s.DbChannelData.TotalVideos)
}
log.Debugf("Source channel has %d videos", videosOnYoutube) log.Debugf("Source channel has %d videos", videosOnYoutube)
if videosOnYoutube == 0 { if videosOnYoutube == 0 {

View file

@ -123,15 +123,23 @@ func GetVideosToSync(config *sdk.APIConfig, channelID string, syncedVideos map[s
return videos, nil return videos, nil
} }
// CountVideosInChannel is unused for now... keeping it here just in case
func CountVideosInChannel(channelID string) (int, error) { func CountVideosInChannel(channelID string) (int, error) {
res, err := http.Get("https://socialblade.com/youtube/channel/" + channelID) url := "https://socialblade.com/youtube/channel/" + channelID
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36")
req.Header.Add("Accept", "*/*")
req.Header.Add("Host", "socialblade.com")
res, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
return 0, err return 0, errors.Err(err)
} }
defer res.Body.Close() defer res.Body.Close()
var line string var line string
scanner := bufio.NewScanner(res.Body) scanner := bufio.NewScanner(res.Body)
for scanner.Scan() { for scanner.Scan() {
if strings.Contains(scanner.Text(), "youtube-stats-header-uploads") { if strings.Contains(scanner.Text(), "youtube-stats-header-uploads") {