class_docstr: Youtube List Comments  by video id Table implementation
class_docstr_tok: ["Youtube","List","Comments","by","video","id","Table","implementation"]
docstr: Pulls all the records from the given youtube api end point and returns it select()
  
  Returns
  -------
  pd.DataFrame of all the records of the "commentThreads()" API end point
docstr_tok: ["Pulls","all","the","records","from","the","given","youtube","api","end","point","and","returns","it","select","(",")","Returns","--","--","--","-","pd.DataFrame","of","all","the","records","of","the","``","commentThreads","(",")","''","API","end","point"]
code: def get_comments(self, video_id: str, channel_id: str):
      """Pulls all the records from the given youtube api end point and returns it select()
  
      Returns
      -------
      pd.DataFrame of all the records of the "commentThreads()" API end point
      """
  
      if video_id and channel_id:
          channel_id = None
  
      resource = (
          self.handler.connect()
          .commentThreads()
          .list(
              part="snippet, replies",
              videoId=video_id,
              allThreadsRelatedToChannelId=channel_id,
              textFormat="plainText",
          )
      )
  
      data = []
      while resource:
          comments = resource.execute()
  
          for comment in comments["items"]:
              replies = []
              if "replies" in comment:
                  for reply in comment["replies"]["comments"]:
                      replies.append(
                          {
                              "reply_author": reply["snippet"][
                                  "authorDisplayName"
                              ],
                              "user_id": reply["snippet"][
                                  "authorChannelId"
                              ]["value"],
                              "reply": reply["snippet"]["textOriginal"],
                          }
                      )
              else:
                  replies.append(
                      {
                          "reply_author": None,
                          "user_id": None,
                          "reply": None,
                      }
                  )
  
              data.append(
                  {
                      "channel_id": comment["snippet"]["channelId"],
                      "video_id": comment["snippet"]["videoId"],
                      "user_id": comment["snippet"]["topLevelComment"][
                          "snippet"
                      ]["authorChannelId"]["value"],
                      "comment_id": comment["snippet"][
                          "topLevelComment"
                      ]["id"],
                      "display_name": comment["snippet"][
                          "topLevelComment"
                      ]["snippet"]["authorDisplayName"],
                      "comment": comment["snippet"]["topLevelComment"][
                          "snippet"
                      ]["textDisplay"],
                      "published_at": comment["snippet"][
                          "topLevelComment"
                      ]["snippet"]["publishedAt"],
                      "updated_at": comment["snippet"][
                          "topLevelComment"
                      ]["snippet"]["updatedAt"],
                      "replies": replies,
                  }
              )
  
          if "nextPageToken" in comments:
              resource = (
                  self.handler.connect()
                  .commentThreads()
                  .list(
                      part="snippet, replies",
                      videoId=video_id,
                      allThreadsRelatedToChannelId=channel_id,
                      textFormat="plainText",
                      pageToken=comments["nextPageToken"],
                  )
              )
          else:
              break
  
      youtube_comments_df = pd.json_normalize(
          data,
          "replies",
          [
              "comment_id",
              "channel_id",
              "video_id",
              "user_id",
              "display_name",
              "comment",
              "published_at",
              "updated_at",
          ],
          record_prefix="replies.",
      )
      youtube_comments_df = youtube_comments_df.rename(
          columns={
              "replies.user_id": "reply_user_id",
              "replies.reply_author": "reply_author",
              "replies.reply": "reply",
          }
      )
  
      # check if DataFrame is empty
      if youtube_comments_df.empty:
          return youtube_comments_df
      else:
          return youtube_comments_df[
              [
                  "comment_id",
                  "channel_id",
                  "video_id",
                  "user_id",
                  "display_name",
                  "comment",
                  "published_at",
                  "updated_at",
                  "reply_user_id",
                  "reply_author",
                  "reply",
              ]
          ]
  
imports: from typing import List
  from mindsdb.integrations.libs.api_handler import APITable
  from mindsdb.integrations.utilities.sql_utils import extract_comparison_conditions
  from mindsdb.utilities import log
  from mindsdb_sql.parser import ast
  from mindsdb.integrations.handlers.utilities.query_utilities import SELECTQueryParser, SELECTQueryExecutor, INSERTQueryParser
  import pandas
  import re
  from youtube_transcript_api import YouTubeTranscriptApi
  from youtube_transcript_api.formatters import JSONFormatter
label_desc: Use image node_id 5 for calling the YoutubeCommentsTable obj's underlying member method code with example usage: obj.get_comments(video_id, channel_id) and returns: youtube_comments_df, youtube_comments_df