Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
adjust youtube info parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nikooo777 committed Nov 6, 2023
1 parent e5886f0 commit b382f33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion sdk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ func (a *APIConfig) SetChannelStatus(channelID string, status string, failureRea
return a.SetChannelStatus(channelID, status, failureReason, transferState)
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, nil, errors.Err(err)
}
if res.StatusCode >= http.StatusInternalServerError {
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
log.Debugln(string(body))
Expand Down
6 changes: 4 additions & 2 deletions ytapi/ytapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ func ChannelInfo(channelID string, attemptNo int, ipPool *ip_manager.IPPool) (*Y
if dataStartIndex == 25 {
dataStartIndex = strings.Index(pageBody, "var ytInitialData = ") + 20
}
dataEndIndex := strings.Index(pageBody, "]}}};</script>") + 4
if dataEndIndex < dataStartIndex {
// get end index by matching pattern AFTER the start index
dataEndIndex := strings.Index(pageBody[dataStartIndex:], ";</script>") + dataStartIndex
//dataEndIndex := strings.Index(pageBody, "}]}}};</script>") + 5
if dataEndIndex == dataStartIndex {
return nil, errors.Err("start index is lower than end index. cannot extract channel info!")
}
data := pageBody[dataStartIndex:dataEndIndex]
Expand Down

0 comments on commit b382f33

Please sign in to comment.