ytsearch icon indicating copy to clipboard operation
ytsearch copied to clipboard

Comments

Open 89z opened this issue 4 years ago • 3 comments

Is it possible to get comments for a video?

89z avatar Aug 22 '21 21:08 89z

youtube_explode_dart has such a feature, so I think it's possible.

raitonoberu avatar Aug 23 '21 07:08 raitonoberu

I am still working on a solution, but I have a start. You can make a request like this to get the comments:

POST /youtubei/v1/next?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8 HTTP/1.1
Host: www.youtube.com

{
  "context": {
    "client": {"clientName": "WEB","clientVersion": "2.20210820.01.00"}
  },
  "continuation": "Eg0SC3E1VW5UNElrNktVGAYyDyINIgtxNVVuVDRJazZLVQ=="
}

and you can get continuation like this:

package main

import (
   "encoding/base64"
   "fmt"
   p "google.golang.org/protobuf/testing/protopack"
)

func main() {
   m := p.Message{
      p.Tag{2, p.BytesType}, p.LengthPrefix{
         p.Tag{2, p.BytesType}, p.String("q5UnT4Ik6KU"),
      },
      p.Tag{3, p.VarintType}, p.Varint(6),
      p.Tag{6, p.BytesType}, p.LengthPrefix{
         p.Tag{4, p.BytesType}, p.LengthPrefix{
            p.Tag{4, p.BytesType}, p.String("q5UnT4Ik6KU"),
         },
      },
   }
   s := base64.StdEncoding.EncodeToString(m.Marshal())
   fmt.Println(s)
}

alternatively, before the above request, you can make another request like this:

POST /youtubei/v1/next?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8 HTTP/1.1
Host: www.youtube.com

{
  "context": {
    "client": {"clientName": "WEB","clientVersion": "2.20210820.01.00"}
  },
  "videoID": "q5UnT4Ik6KU"
}

and the continuation value will be in the response.

89z avatar Aug 23 '21 20:08 89z

I found a better package for encoding:

package proto

import (
   "encoding/base64"
   "github.com/philpearl/plenc"
)

type continuation struct {
   A struct {
      VideoID string `plenc:"2"`
   } `plenc:"2"`
   B uint32 `plenc:"3"`
   C struct {
      A struct {
         VideoID string `plenc:"4"`
      } `plenc:"4"`
   } `plenc:"6"`
}

func newContinuation(videoID string) continuation {
   var con continuation
   con.A.VideoID = videoID
   con.B = 6
   con.C.A.VideoID = videoID
   return con
}

func (c continuation) encode() (string, error) {
   b, err := plenc.Marshal(nil, c)
   if err != nil {
      return "", err
   }
   return base64.StdEncoding.EncodeToString(b), nil
}

89z avatar Sep 02 '21 15:09 89z