Example #1
0
        public string GetAllYoutubeChannelByUserIdAndProfileId(string UserId, string ProfileId)
        {
            Domain.Socioboard.Domain.YoutubeChannel lstYoutubeChannel = new Domain.Socioboard.Domain.YoutubeChannel();
            try
            {
                if (objYoutubeChannelRepository.checkYoutubeChannelExists(ProfileId, Guid.Parse(UserId)))
                {
                    lstYoutubeChannel = objYoutubeChannelRepository.getYoutubeChannelDetailsById(ProfileId, Guid.Parse(UserId));
                }
                else
                {
                    lstYoutubeChannel = objYoutubeChannelRepository.getYoutubeChannelDetailsById(ProfileId);
                }

                return(new JavaScriptSerializer().Serialize(lstYoutubeChannel));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return("Something Went Wrong");
            }
        }
Example #2
0
        public string GetYoutubeChannelVideos(string userid, string profileid)
        {
            string ret            = string.Empty;
            string strfinaltoken  = string.Empty;
            string channelDetails = string.Empty;

            Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(profileid, Guid.Parse(userid));
            Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel = objYoutubeChannelRepository.getYoutubeChannelDetailsById(profileid, Guid.Parse(userid));

            oAuthTokenYoutube objoAuthTokenYoutube = new oAuthTokenYoutube();
            string            finaltoken           = objoAuthTokenYoutube.GetAccessToken(objYoutubeAccount.Refreshtoken);
            JObject           objArray             = JObject.Parse(finaltoken);

            //foreach (var item in objArray)
            //{
            try
            {
                strfinaltoken = objArray["access_token"].ToString();
                // break;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            //}
            PlaylistItems objPlaylistItems = new PlaylistItems();

            try
            {
                channelDetails = objPlaylistItems.Get_PlaylistItems_List(strfinaltoken, GlobusGooglePlusLib.Authentication.oAuthTokenYoutube.Parts.snippet.ToString(), objYoutubeChannel.Uploadsid);
            }
            catch (Exception ex)
            {
            }



            return(channelDetails);
        }
Example #3
0
        public void GetYoutubeChannelVideos(string userid, string profileid)
        {
            string ret            = string.Empty;
            string strfinaltoken  = string.Empty;
            string channelDetails = string.Empty;

            Domain.Socioboard.Domain.YoutubeAccount        objYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(profileid, Guid.Parse(userid));
            List <Domain.Socioboard.Domain.YoutubeChannel> lstYoutubeChannel = objYoutubeChannelRepository.getYoutubeChannelDetailsById(profileid, Guid.Parse(userid));

            foreach (Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel in lstYoutubeChannel)
            {
                oAuthTokenYoutube objoAuthTokenYoutube = new oAuthTokenYoutube();
                string            finaltoken           = objoAuthTokenYoutube.GetAccessToken(objYoutubeAccount.Refreshtoken);
                JObject           objArray             = JObject.Parse(finaltoken);
                //foreach (var item in objArray)
                //{
                try
                {
                    strfinaltoken = objArray["access_token"].ToString();
                    // break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                //}
                PlaylistItems objPlaylistItems = new PlaylistItems();
                Video         objVideo         = new Video();
                try
                {
                    Domain.Socioboard.MongoDomain.YouTubeFeed _YouTubeFeed;
                    channelDetails = objPlaylistItems.Get_PlaylistItems_List(strfinaltoken, GlobusGooglePlusLib.Authentication.oAuthTokenYoutube.Parts.snippet.ToString(), objYoutubeChannel.Uploadsid);
                    JObject obj   = JObject.Parse(channelDetails);
                    JArray  array = (JArray)obj["items"];
                    foreach (var item in array)
                    {
                        try
                        {
                            _YouTubeFeed             = new Domain.Socioboard.MongoDomain.YouTubeFeed();
                            _YouTubeFeed.Id          = ObjectId.GenerateNewId();
                            _YouTubeFeed.ChannelName = item["snippet"]["channelTitle"].ToString();
                            _YouTubeFeed.PublishTime = DateTime.Parse(item["snippet"]["publishedAt"].ToString()).ToString("yyyy/MM/dd HH:mm:ss");
                            _YouTubeFeed.Thumbnail   = item["snippet"]["thumbnails"]["maxres"]["url"].ToString();
                            _YouTubeFeed.Title       = item["snippet"]["title"].ToString();
                            _YouTubeFeed.ChannelId   = item["snippet"]["channelId"].ToString();
                            _YouTubeFeed.Description = item["snippet"]["description"].ToString();
                            _YouTubeFeed.VideoId     = item["snippet"]["resourceId"]["videoId"].ToString();
                            _YouTubeFeed.YoutubeId   = profileid;

                            string  videodetail = objVideo.Get_VideoDetails_byId(_YouTubeFeed.VideoId, strfinaltoken, "contentDetails,statistics");
                            JObject objv        = JObject.Parse(videodetail);
                            var     videodata   = objv["items"][0];

                            _YouTubeFeed.commentCount  = videodata["statistics"]["commentCount"].ToString();
                            _YouTubeFeed.dislikeCount  = videodata["statistics"]["dislikeCount"].ToString();
                            _YouTubeFeed.duration      = videodata["contentDetails"]["duration"].ToString();
                            _YouTubeFeed.favoriteCount = videodata["statistics"]["favoriteCount"].ToString();
                            _YouTubeFeed.likeCount     = videodata["statistics"]["likeCount"].ToString();
                            _YouTubeFeed.viewCount     = videodata["statistics"]["viewCount"].ToString();

                            var rt   = youtubefeedrepo.Find <Domain.Socioboard.MongoDomain.YouTubeFeed>(t => t.VideoId.Equals(_YouTubeFeed.VideoId));
                            var task = Task.Run(async() =>
                            {
                                return(await rt);
                            });
                            int count = task.Result.Count;
                            if (count < 1)
                            {
                                youtubefeedrepo.Add(_YouTubeFeed);
                            }
                            else
                            {
                                FilterDefinition <BsonDocument> filter = new BsonDocument("VideoId", _YouTubeFeed.VideoId);
                                var update = Builders <BsonDocument> .Update.Set("commentCount", _YouTubeFeed.commentCount).Set("dislikeCount", _YouTubeFeed.dislikeCount).Set("duration", _YouTubeFeed.duration).Set("favoriteCount", _YouTubeFeed.favoriteCount)
                                             .Set("likeCount", _YouTubeFeed.likeCount).Set("viewCount", _YouTubeFeed.viewCount);

                                youtubefeedrepo.Update <Domain.Socioboard.MongoDomain.YouTubeFeed>(update, filter);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }