Example #1
0
        private void bgWorkerQuickSearch_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            lblStatus.Text = "Progress " + e.ProgressPercentage + "%";

            KeywordQuickSearch o = e.UserState as KeywordQuickSearch;

            FillKeywordsGrid(o.Details);
        }
        private void FillKeywordDetails(ref KeywordQuickSearch C, SearchVideos.RootObject R)
        {
            C.Details.AvgViewCount     = (int)C.Details.Videos.Average(x => x.ViewCount);
            C.Details.HighestViewCount = C.Details.Videos.Max(x => x.ViewCount);
            C.Details.LowestViewCount  = C.Details.Videos.Min(x => x.ViewCount);

            int old = C.Details.Videos.Where(x => DateTime.Now.Year - x.UploadedDate.Year == 1).Count();

            C.Details.OldVideos = old;
            C.Details.NewVideos = C.Details.Videos.Count - old;

            DefaultAlgorithm algo = new DefaultAlgorithm();

            C.Details.Overall = algo.Calculate(C, Difficulty);
            C.Details.Results = R.pageInfo.totalResults;
        }
Example #3
0
 private void bgWorkerVideosSearch_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     try
     {
         KeywordQuickSearch o = e.Result as KeywordQuickSearch;
         FillVideosGrid(o.Details.Videos);
         tabs2.TabPages[1].Text = "Video's: " + o.Details.Keyword;
     }
     catch { }
     finally
     {
         /*
          * When a "calc all" process is going on
          * you may want to see first page of a certain kw
          * but you may not disrupt the ongoing process.
          */
         //ToggleBusy(false);
     }
 }
        private KeywordQuickSearch InternalQuickSearch(string keyword)
        {
            var _http = new Http();

            http.Add(_http);

            var r = YouTubeAPI.SearchVideos(_http, keyword, 1);

            if (r == null)
            {
                return(null);
            }

            var o = new KeywordQuickSearch();

            if (r.items.Count > 0)
            {
                o.Details.Keyword = keyword;
                foreach (var item in r.items)
                {
                    var q = YouTubeAPI.VideoDetails(_http, item.id.videoId);
                    var c = YouTubeAPI.VideoComments(_http, item.id.videoId);
                    var h = YouTubeAPI.ChannelDetails(_http, item.snippet.channelId);
                    var i = FillVideoDetails(q, c, h);
                    if (i != null)
                    {
                        o.Details.Videos.Add(i);
                    }
                }
                FillKeywordDetails(ref o, r);
            }
            else
            {
                o.Details.Keyword = keyword;
            }

            return(o);
        }
        public string Calculate(KeywordQuickSearch C, IDifficulty D)
        {
            int    bad     = 0;
            int    good    = 0;
            string overall = "EASY/MEDIUM/HARD";

            foreach (var v in C.Details.Videos)
            {
                if (v.ViewCount > D.AvgViewCount)
                {
                    bad += 10;
                }
                else
                {
                    good += 10;
                }

                if (DateTime.Now.Year - v.UploadedDate.Year > 1)
                {
                    bad += 5;
                }
                else
                {
                    good += 5;
                }

                if (v.Likes > D.AvgLikes)
                {
                    bad += 3;
                }
                else
                {
                    good += 3;
                }

                if (v.Dislikes > D.AvgDislikes)
                {
                    good += 3;
                }
                else
                {
                    bad += 3;
                }

                if (v.VideoDuration.TotalMinutes > 5)
                {
                    bad += 3;
                }
                else
                {
                    good += 3;
                }
            }

            double T = (double)((double)good / (double)bad);

            if (T <= 0.5)
            {
                overall = "HARD";
            }
            else if (T > 0.5 && T <= 1.5)
            {
                overall = "MEDIUM";
            }
            else
            {
                overall = "EASY";
            }

            return(overall);
        }