Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YouTube UI add reply to comment #250

Closed
Benjamin-Loison opened this issue Mar 7, 2024 · 4 comments
Closed

YouTube UI add reply to comment #250

Benjamin-Loison opened this issue Mar 7, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request low priority Nice to have feature. medium A task that should take less than a day to complete.

Comments

@Benjamin-Loison
Copy link
Owner

Benjamin-Loison commented Mar 7, 2024

Requested on Discord.

After minimize_curl.py (note that the commentText is part of the response, STATUS_SUCCEEDED is more general):

curl https://www.youtube.com/youtubei/v1/comment/create_comment_reply -X POST -H 'Content-Type: application/json' -H 'Origin: https://www.youtube.com' -H 'Authorization: SAPISIDHASH CENSORED' -H 'Cookie: __Secure-1PSIDTS=sidts-CENSORED; __Secure-1PSID=CENSORED; __Secure-1PAPISID=CENSORED' --data-raw '{"context": {"client": {"clientName": "WEB", "clientVersion": "2.20240306.07.00-canary_experiment_2.20240304.00.00"}}, "createReplyParams": "EgszNzNUa3N5bm93SSIaVWd5SUhMLWJIajNmZ25YZHVPZDRBYUFCQWcqAggAUAfoAQA%3D", "commentText": "my answer"}'

https://www.youtube.com/watch?v=373TksynowI&lc=UgyIHL-bHj3fgnXduOd4AaABAg

https://yt.lemnoslife.com/noKey/commentThreads?part=replies&id=UgyIHL-bHj3fgnXduOd4AaABAg

import requests
import json

url = 'https://yt.lemnoslife.com/noKey/commentThreads'

params = {
    'part': 'replies',
    'id': 'UgyIHL-bHj3fgnXduOd4AaABAg'
}

data = requests.get(url, params = params).json()
print(json.dumps(data, indent = 4))
echo 'EgszNzNUa3N5bm93SSIaVWd5SUhMLWJIajNmZ25YZHVPZDRBYUFCQWcqAggAUAfoAQA=' | base64 -d
373TksynowI"�UgyIHL-bHj3fgnXduOd4AaABAgP�
echo 'EgszNzNUa3N5bm93SSIaVWd5SUhMLWJIajNmZ25YZHVPZDRBYUFCQWcqAggAUAfoAQA=' | base64 -d | protoc --decode_raw
2: "373TksynowI"
4: "UgyIHL-bHj3fgnXduOd4AaABAg"
5 {
  1: 0
}
10: 7
29: 0

test.proto:

syntax = "proto3";

message message0
{
  string videoId = 2;
  string commentId = 4;
  message1 message10 = 5;
  uint32 uint320 = 10;
  uint32 uint321 = 29;
}

message message1
{
  uint32 uint322 = 1;
}

test.data:

videoId: "373TksynowI"
commentId: "UgyIHL-bHj3fgnXduOd4AaABAg"
message10: {
    uint322: 0
}
uint320: 7
uint321: 0
protoc --encode=message0 test.proto < test.data
373TksynowI"�UgyIHL-bHj3fgnXduOd4AaABAg*P
protoc --encode=message0 test.proto < test.data | base64
EgszNzNUa3N5bm93SSIaVWd5SUhMLWJIajNmZ25YZHVPZDRBYUFCQWcqAFAH

Not identical for the moment...

For an unknown reason when provide above proto and following JSON to https://www.protobufpal.com we get the same YouTube UI protobuf (i.e. EgszNzNUa3N5bm93SSIaVWd5SUhMLWJIajNmZ25YZHVPZDRBYUFCQWcqAggAUAfoAQA=):

{
  "videoId": "373TksynowI",
  "commentId": "UgyIHL-bHj3fgnXduOd4AaABAg",
  "message10": {
    "uint322": 0
  },
  "uint320": 7,
  "uint321": 0
}

https://yt.lemnoslife.com/noKey/comments?part=snippet&id=UgyIHL-bHj3fgnXduOd4AaABAg.A0h8yXKhWTrA0h9U2nnZ09

https://yt.lemnoslife.com/noKey/commentThreads?part=snippet&id=UgyIHL-bHj3fgnXduOd4AaABAg&fields=items/snippet/totalReplyCount

https://yt.lemnoslife.com/noKey/comments?part=snippet&parentId=UgyIHL-bHj3fgnXduOd4AaABAg&maxResults=100

import requests
import json

url = 'https://yt.lemnoslife.com/noKey/comments'

params = {
    'part': 'snippet',
    'parentId': 'UgyIHL-bHj3fgnXduOd4AaABAg',
    'maxResults': 100
}
pageToken = ''

while True:
    params['pageToken'] = pageToken
    response = requests.get(url, params = params).json()
    items = response['items']
    if not 'nextPageToken' in response:
        break
    pageToken = response['nextPageToken']

print(items[-1]['snippet']['textOriginal'])

Related to #91 and #190.

@Benjamin-Loison Benjamin-Loison added enhancement New feature or request low priority Nice to have feature. quick A task that should take less than two hours to complete. labels Mar 7, 2024
@Benjamin-Loison Benjamin-Loison self-assigned this Mar 7, 2024
@Benjamin-Loison Benjamin-Loison added medium A task that should take less than a day to complete. and removed quick A task that should take less than two hours to complete. labels Mar 7, 2024
@Benjamin-Loison
Copy link
Owner Author

syntax = "proto3";

message message0
{
  string videoId = 2;
  string commentId = 4;
}
{
  "videoId": "373TksynowI",
  "commentId": "UgyIHL-bHj3fgnXduOd4AaABAg"
}

is enough and minimized (if remove videoId, then get Request contains an invalid argument.).

@Benjamin-Loison Benjamin-Loison added the waiting details Further information is requested label Mar 7, 2024
@Benjamin-Loison
Copy link
Owner Author

Waiting original requester answer on Discord.

@Benjamin-Loison Benjamin-Loison removed the waiting details Further information is requested label Mar 8, 2024
@Benjamin-Loison
Copy link
Owner Author

Benjamin-Loison commented Mar 9, 2024

import requests
import json
import time

url = 'https://yt.lemnoslife.com/noKey/comments'

params = {
    'part': 'snippet',
    'parentId': 'UgyIHL-bHj3fgnXduOd4AaABAg',
    'maxResults': 100
}
pageToken = ''
initialLastComment = None

while True:
    while True:
        params['pageToken'] = pageToken
        response = requests.get(url, params = params).json()
        items = response['items']
        if not 'nextPageToken' in response:
            break
        pageToken = response['nextPageToken']
    
    lastComment = items[-1]['snippet']['textOriginal']
    print(lastComment)
    if initialLastComment is None:
        initialLastComment = lastComment
    elif initialLastComment != lastComment:
        break
    time.sleep(1)

@Benjamin-Loison
Copy link
Owner Author

Benjamin-Loison commented Mar 9, 2024

node test.js

test.js:

const protobuf = require("protobufjs");
const fs = require("fs");
const crypto = require("node:crypto")
const axios = require("axios")

const root = protobuf.loadSync("messages.proto");

const message0 = root.lookupType("message0")

const outerMessage = message0.create({
  videoId: "373TksynowI",
  commentId: "UgyIHL-bHj3fgnXduOd4AaABAg",
})

const createReplyParams = message0.encode(outerMessage).finish().toString("base64")

const authorization = "SAPISIDHASH CENSORED"

const commentText = "nodejs 4"

const headers = {
  'authorization': authorization,
  'content-type': 'application/json',
  'cookie': '__Secure-1PAPISID=CENSORED; __Secure-1PSID=CENSORED; __Secure-1PSIDTS=sidts-CENSORED',
  'origin': 'https://www.youtube.com',
  'X-Goog-AuthUser': '1',
}

const body = {
  'commentText': commentText,
  'createReplyParams': createReplyParams,
  'context': {
    'client': {
      'clientName': "WEB",
      'clientVersion': "2.20240308.00.00"
    }
  }
}

axios.post("https://www.youtube.com/youtubei/v1/comment/create_comment_reply", body, {headers})
  .then(response => {
    console.log('response', JSON.stringify(response.data, null, 4))
  })
  .catch(error => {
    console.log('error', error)
  })

messages.proto:

syntax = "proto3";

message message0
{
  string videoId = 2;
  string commentId = 4;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority Nice to have feature. medium A task that should take less than a day to complete.
Projects
None yet
Development

No branches or pull requests

1 participant