public void CommentsReplies(Domain.Socioboard.Models.Mongo.MongoYoutubeComments itemMainComments)
        {
            string            apiKey = AppSettings.googleApiKey_TestApp;
            oAuthTokenYoutube ObjoAuthTokenYtubes = new oAuthTokenYoutube(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
            oAuthToken        objToken            = new oAuthToken(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);
            Video             objVideo            = new Video(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);

            try
            {
                string  commentsReply  = objVideo.Get_CommentsRepliesBy_CmParentId(itemMainComments.commentId, apiKey);
                JObject jCommentsReply = JObject.Parse(commentsReply);
                MongoYoutubeComments _ObjMongoYtCommentsReply;
                foreach (var itemReply in jCommentsReply["items"])
                {
                    _ObjMongoYtCommentsReply    = new MongoYoutubeComments();
                    _ObjMongoYtCommentsReply.Id = ObjectId.GenerateNewId();
                    try
                    {
                        _ObjMongoYtCommentsReply.ChannelId = itemMainComments.ChannelId;
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.videoId = itemMainComments.videoId;
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.commentId = itemReply["id"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.authorDisplayName = itemReply["snippet"]["authorDisplayName"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.authorProfileImageUrl = itemReply["snippet"]["authorProfileImageUrl"].ToString().Replace(".jpg", "");
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.authorChannelUrl = itemReply["snippet"]["authorChannelUrl"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.authorChannelId = itemReply["snippet"]["authorChannelId"]["value"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.commentDisplay = itemReply["snippet"]["textDisplay"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.commentOriginal = itemReply["snippet"]["textOriginal"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.viewerRating = itemReply["snippet"]["viewerRating"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.likesCount = itemReply["snippet"]["likeCount"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.publishTime = itemReply["snippet"]["publishedAt"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.publishTimeUnix = UnixTimeFromDatetime(Convert.ToDateTime(_ObjMongoYtCommentsReply.publishTime));
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.updatedTime = itemReply["snippet"]["updatedAt"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.totalReplyCount = "ReplyType";
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtCommentsReply.parentIdforReply = itemReply["snippet"]["parentId"].ToString();
                    }
                    catch { }
                    _ObjMongoYtCommentsReply.active          = true;
                    _ObjMongoYtCommentsReply.review          = false;
                    _ObjMongoYtCommentsReply.sbGrpTaskAssign = false;
                    try
                    {
                        _lstGlobalCom.Add(_ObjMongoYtCommentsReply);//Global Type

                        MongoRepository _mongoRepo   = new MongoRepository("YoutubeVideosCommentsReply");
                        var             ret          = _mongoRepo.Find <MongoYoutubeComments>(t => t.commentId.Equals(_ObjMongoYtCommentsReply.commentId));
                        var             task_Reports = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        int count_Reports = task_Reports.Result.Count;
                        if (count_Reports < 1)
                        {
                            try
                            {
                                _mongoRepo.Add(_ObjMongoYtCommentsReply);
                            }
                            catch { }
                        }
                        else
                        {
                            try
                            {
                                FilterDefinition <BsonDocument> filter = new BsonDocument("commentId", _ObjMongoYtCommentsReply.commentId);
                                var update = Builders <BsonDocument> .Update.Set("commentDisplay", _ObjMongoYtCommentsReply.commentDisplay).Set("commentOriginal", _ObjMongoYtCommentsReply.commentOriginal).Set("publishTimeUnix", _ObjMongoYtCommentsReply.publishTimeUnix);

                                _mongoRepo.Update <MongoYoutubeComments>(update, filter);
                            }
                            catch { }
                        }
                    }
                    catch (Exception ex) { }
                }
            }
            catch
            {
            }
        }
Beispiel #2
0
        private static void GetYtComments(string VideoId, string apiKey, string ChannelId)
        {
            var _Videos = new Video(AppSettings.googleClientId, AppSettings.googleClientSecret, AppSettings.googleRedirectionUrl);

            try
            {
                MongoYoutubeComments _ObjMongoYtComments;
                var _CommentsData  = _Videos.Get_CommentsBy_VideoId(VideoId, "", "", apiKey);
                var J_CommentsData = JObject.Parse(_CommentsData);

                foreach (var itemComment in J_CommentsData.SelectTokens("items[*]"))
                {
                    _ObjMongoYtComments    = new MongoYoutubeComments();
                    _ObjMongoYtComments.Id = ObjectId.GenerateNewId();

                    _ObjMongoYtComments.ChannelId             = ChannelId;
                    _ObjMongoYtComments.videoId               = itemComment.SelectToken("snippet.videoId")?.ToString();
                    _ObjMongoYtComments.commentId             = itemComment.SelectToken("id")?.ToString();
                    _ObjMongoYtComments.authorDisplayName     = itemComment.SelectToken("snippet.topLevelComment.snippet.authorDisplayName")?.ToString();
                    _ObjMongoYtComments.authorProfileImageUrl = itemComment.SelectToken("snippet.topLevelComment.snippet.authorProfileImageUrl")?.ToString()?.Replace(".jpg", "");
                    _ObjMongoYtComments.authorChannelUrl      = itemComment.SelectToken("snippet.topLevelComment.snippet.authorChannelUrl")?.ToString();
                    _ObjMongoYtComments.authorChannelId       = itemComment.SelectToken("snippet.topLevelComment.snippet.authorChannelId.value")?.ToString();
                    _ObjMongoYtComments.commentDisplay        = itemComment.SelectToken("snippet.topLevelComment.snippet.textDisplay")?.ToString();
                    _ObjMongoYtComments.commentOriginal       = itemComment.SelectToken("snippet.topLevelComment.snippet.textOriginal")?.ToString();
                    _ObjMongoYtComments.viewerRating          = itemComment.SelectToken("snippet.topLevelComment.snippet.viewerRating")?.ToString();
                    _ObjMongoYtComments.likesCount            = itemComment.SelectToken("snippet.topLevelComment.snippet.likeCount")?.ToString();
                    _ObjMongoYtComments.publishTime           = itemComment.SelectToken("snippet.topLevelComment.snippet.publishedAt")?.ToString();
                    _ObjMongoYtComments.publishTimeUnix       = UnixTimeFromDatetime(Convert.ToDateTime(_ObjMongoYtComments.publishTime));
                    _ObjMongoYtComments.updatedTime           = itemComment.SelectToken("snippet.topLevelComment.snippet.updatedAt")?.ToString();
                    _ObjMongoYtComments.totalReplyCount       = itemComment.SelectToken("snippet.totalReplyCount")?.ToString();
                    _ObjMongoYtComments.active          = true;
                    _ObjMongoYtComments.review          = false;
                    _ObjMongoYtComments.sbGrpTaskAssign = false;

                    try
                    {
                        _lstGlobalComVideos.Add(_ObjMongoYtComments);//Global var for update the comments
                        var youtubecommentsrepo = new MongoRepository("YoutubeVideosComments");
                        var ret  = youtubecommentsrepo.Find <MongoYoutubeComments>(t => t.commentId.Equals(_ObjMongoYtComments.commentId));
                        var task = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        var count = task.Result.Count;
                        if (count < 1)
                        {
                            try
                            {
                                youtubecommentsrepo.Add(_ObjMongoYtComments);
                            }
                            catch { }
                        }
                        else
                        {
                            try
                            {
                                var filter = new BsonDocument("commentId", _ObjMongoYtComments.commentId);
                                var update = Builders <BsonDocument> .Update.Set("authorDisplayName", _ObjMongoYtComments.authorDisplayName).Set("authorProfileImageUrl", _ObjMongoYtComments.authorProfileImageUrl).Set("commentDisplay", _ObjMongoYtComments.commentDisplay).Set("commentOriginal", _ObjMongoYtComments.commentOriginal).Set("viewerRating", _ObjMongoYtComments.viewerRating).Set("likesCount", _ObjMongoYtComments.likesCount).Set("totalReplyCount", _ObjMongoYtComments.totalReplyCount).Set("updatedTime", _ObjMongoYtComments.updatedTime).Set("publishTimeUnix", _ObjMongoYtComments.publishTimeUnix).Set("active", _ObjMongoYtComments.active);

                                youtubecommentsrepo.Update <MongoYoutubeComments>(update, filter);
                            }
                            catch { }
                        }
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #3
0
        public static void GetYtComments(string VideoId, string apiKey, string ChannelId)
        {
            Video _Videos = new Video(AppSettings.GoogleConsumerKey, AppSettings.GoogleConsumerSecret, AppSettings.GoogleRedirectUri);

            try
            {
                //Domain.Socioboard.Domain.GooglePlusActivities _GooglePlusActivities = null;


                MongoYoutubeComments _ObjMongoYtComments;
                string  _CommentsData  = _Videos.Get_CommentsBy_VideoId(VideoId, "", "", apiKey);
                JObject J_CommentsData = JObject.Parse(_CommentsData);
                foreach (var item in J_CommentsData["items"])
                {
                    _ObjMongoYtComments    = new MongoYoutubeComments();
                    _ObjMongoYtComments.Id = ObjectId.GenerateNewId();

                    try
                    {
                        _ObjMongoYtComments.ChannelId = ChannelId;
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.videoId = item["snippet"]["videoId"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.commentId = item["id"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.authorDisplayName = item["snippet"]["topLevelComment"]["snippet"]["authorDisplayName"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.authorProfileImageUrl = item["snippet"]["topLevelComment"]["snippet"]["authorProfileImageUrl"].ToString().Replace(".jpg", "");
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.authorChannelUrl = item["snippet"]["topLevelComment"]["snippet"]["authorChannelUrl"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.authorChannelId = item["snippet"]["topLevelComment"]["snippet"]["authorChannelId"]["value"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.commentDisplay = item["snippet"]["topLevelComment"]["snippet"]["textDisplay"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.commentOriginal = item["snippet"]["topLevelComment"]["snippet"]["textOriginal"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.viewerRating = item["snippet"]["topLevelComment"]["snippet"]["viewerRating"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.likesCount = item["snippet"]["topLevelComment"]["snippet"]["likeCount"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.publishTime = item["snippet"]["topLevelComment"]["snippet"]["publishedAt"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.updatedTime = item["snippet"]["topLevelComment"]["snippet"]["updatedAt"].ToString();
                    }
                    catch { }
                    try
                    {
                        _ObjMongoYtComments.totalReplyCount = item["snippet"]["totalReplyCount"].ToString();
                    }
                    catch { }

                    try
                    {
                        MongoRepository youtubecommentsrepo = new MongoRepository("YoutubeVideosComments");
                        var             ret  = youtubecommentsrepo.Find <MongoYoutubeComments>(t => t.commentId.Equals(_ObjMongoYtComments.commentId));
                        var             task = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        int count = task.Result.Count;
                        if (count < 1)
                        {
                            try
                            {
                                youtubecommentsrepo.Add(_ObjMongoYtComments);
                            }
                            catch { }
                        }
                        else
                        {
                            try
                            {
                                FilterDefinition <BsonDocument> filter = new BsonDocument("commentId", _ObjMongoYtComments.commentId);
                                var update = Builders <BsonDocument> .Update.Set("authorDisplayName", _ObjMongoYtComments.authorDisplayName).Set("authorProfileImageUrl", _ObjMongoYtComments.authorProfileImageUrl).Set("commentDisplay", _ObjMongoYtComments.commentDisplay).Set("commentOriginal", _ObjMongoYtComments.commentOriginal).Set("viewerRating", _ObjMongoYtComments.viewerRating).Set("likesCount", _ObjMongoYtComments.likesCount).Set("totalReplyCount", _ObjMongoYtComments.totalReplyCount).Set("updatedTime", _ObjMongoYtComments.updatedTime);

                                youtubecommentsrepo.Update <MongoYoutubeComments>(update, filter);
                            }
                            catch { }
                        }
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
            }
        }