Exemple #1
0
        public static YoutubeVideoCommentInfo[] ParseCommentsResponse(JArray contents)
        {
            //gets all comments
            //var continuationContents = response["response"]["continuationContents"]["itemSectionContinuation"]["contents"];

            //var itemSectionContinuation = continuationContents["itemSectionContinuation"];
            var allRootComments = new List <YoutubeVideoCommentInfo>();

            foreach (var content in contents)
            {
                var commentInfo = new YoutubeVideoCommentInfo();
                commentInfo.Extra = content.ToString(Formatting.None);
                var c = content["commentThreadRenderer"]["comment"]["commentRenderer"];
                commentInfo.Id   = c["commentId"] + string.Empty;
                commentInfo.Text = c["contentText"]["simpleText"] + string.Empty;
                if (string.IsNullOrEmpty(commentInfo.Text))
                {
                    commentInfo.Text = c["contentText"]?["runs"]?[0]?["text"] +string.Empty;
                }

                if (string.IsNullOrEmpty(commentInfo.Text))
                {
                    ;
                }

                commentInfo.AuthorName       = c["authorText"]?["simpleText"] +string.Empty;
                commentInfo.AuthorThumbnails =
                    c["authorThumbnail"]?["thumbnails"].Select(cc => cc["url"] + string.Empty).ToArray();
                commentInfo.AuthorChannelId = c["authorEndpoint"]?["commandMetadata"]?["webCommandMetadata"]?["url"]
                                              ?.ToString()
                                              ?.RemoveThisFirst("/channel/") + string.Empty;

                commentInfo.LikeCount            = c["likeCount"] + string.Empty;
                commentInfo.ReplyCount           = c["publishedTimeText"]["replyCount"] + string.Empty;
                commentInfo.AuthorIsChannelOwner = c["publishedTimeText"]["authorIsChannelOwner"] + string.Empty;
                commentInfo.PublishedTime        = c["publishedTimeText"]["runs"].Select(r => r["text"] + string.Empty)
                                                   .FirstOrDefault();
                var replies       = c["replies"];
                var continuations = replies?["commentRepliesRenderer"]["continuations"].FirstOrDefault();
                if (continuations != null)
                {
                    commentInfo.TokenContinuation =
                        continuations["nextContinuationData"]["continuation"] + string.Empty;
                    commentInfo.TokenClickTrackingParams =
                        continuations["nextContinuationData"]["clickTrackingParams"] + string.Empty;
                }

                allRootComments.Add(commentInfo);
            }

            return(allRootComments.ToArray());
        }
Exemple #2
0
        public static string Generate(YoutubeVideoCommentInfo comment)
        {
            if (string.IsNullOrEmpty(comment.VideoId))
            {
                ;
            }
            return($@"

if(not exists(select top(1) 1 from [dbo].[Comments] where Id=N'{comment.Id.Sqlize()}'))
INSERT INTO [dbo].[Comments]
           ([Id]
           ,[Text]
           ,[AuthorName]
           ,[AuthorThumbnails]
           ,[AuthorChannelId]
           ,[PublishedTime]
           ,[LikeCount]
           ,[AuthorIsChannelOwner]
           ,[VideoId]
           ,[Extra]
           ,[ReplyCount])
     VALUES
           (N'{comment.Id.Sqlize()}'
           ,N'{comment.Text.Sqlize()}'
           ,N'{comment.AuthorName.Sqlize()}'
           ,N'{comment.AuthorThumbnails.JoinWith().Sqlize()}'
           ,N'{comment.AuthorChannelId.Sqlize()}'
           ,N'{comment.PublishedTime.Sqlize()}'
           ,N'{comment.LikeCount.Sqlize()}'
           ,N'{comment.AuthorIsChannelOwner.Sqlize()}'
           ,N'{comment.VideoId.Sqlize()}'
           ,N'{comment.Extra.Sqlize()}'
           ,N'{comment.ReplyCount.Sqlize()}');
else 
UPDATE [dbo].[Comments]
   SET  
       [Text] = N'{comment.Text.Sqlize()}'
      ,[AuthorName] = N'{comment.AuthorName.Sqlize()}'
      ,[AuthorThumbnails] = N'{comment.AuthorThumbnails.JoinWith().Sqlize()}'
      ,[AuthorChannelId] = N'{comment.AuthorChannelId.Sqlize()}'
      ,[PublishedTime] = N'{comment.PublishedTime.Sqlize()}'
      ,[LikeCount] = N'{comment.LikeCount.Sqlize()}'
      ,[AuthorIsChannelOwner] = N'{comment.AuthorIsChannelOwner.Sqlize()}'
      ,[ReplyCount] = N'{comment.ReplyCount.Sqlize()}'
      ,[VideoId] = N'{comment.VideoId.Sqlize()}'
      ,[Extra] = N'{comment.Extra.Sqlize()}'
 WHERE Id=N'{comment.Id.Sqlize()}';


");
        }