prevent panic failure
This commit is contained in:
parent
5dfd8dee1b
commit
bac2969295
1 changed files with 3 additions and 1 deletions
|
@ -188,7 +188,9 @@ func ChannelInfo(channelID string) (*YoutubeStatsResponse, error) {
|
||||||
pageBody := string(body)
|
pageBody := string(body)
|
||||||
dataStartIndex := strings.Index(pageBody, "window[\"ytInitialData\"] = ") + 26
|
dataStartIndex := strings.Index(pageBody, "window[\"ytInitialData\"] = ") + 26
|
||||||
dataEndIndex := strings.Index(pageBody, "]}}};") + 4
|
dataEndIndex := strings.Index(pageBody, "]}}};") + 4
|
||||||
|
if dataEndIndex < dataStartIndex {
|
||||||
|
return nil, errors.Err("start index is lower than end index. cannot extract channel info!")
|
||||||
|
}
|
||||||
data := pageBody[dataStartIndex:dataEndIndex]
|
data := pageBody[dataStartIndex:dataEndIndex]
|
||||||
var decodedResponse YoutubeStatsResponse
|
var decodedResponse YoutubeStatsResponse
|
||||||
err = json.Unmarshal([]byte(data), &decodedResponse)
|
err = json.Unmarshal([]byte(data), &decodedResponse)
|
||||||
|
|
Loading…
Reference in a new issue