You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

grab.go 845B

123456789101112131415161718192021222324252627282930313233343536
  1. package apijson
  2. import (
  3. "net/http"
  4. )
  5. const videoURL = "https://www.youtube.com/watch?pbj=1&v="
  6. const channelURL = "https://www.youtube.com/browse_ajax?ctoken="
  7. func GrabVideo(videoID string) *http.Request {
  8. req, err := http.NewRequest("GET", videoURL + videoID, nil)
  9. if err != nil { panic(err) }
  10. setHeaders(&req.Header)
  11. return req
  12. }
  13. func GrabChannelPage(channelID string, page uint) *http.Request {
  14. // Generate page URL
  15. token := GenChannelPageToken(channelID, uint64(page))
  16. url := channelURL + token
  17. // Prepare request
  18. req, err := http.NewRequest("GET", url, nil)
  19. if err != nil { panic(err) }
  20. setHeaders(&req.Header)
  21. return req
  22. }
  23. func setHeaders(h *http.Header) {
  24. h.Add("Host", "www.youtube.com")
  25. h.Add("User-Agent", "yt-mango/0.1")
  26. h.Add("X-YouTube-Client-Name", "1")
  27. h.Add("X-YouTube-Client-Version", "2.20170707")
  28. }