示例#1
0
        public static YoutubeCommentThread TextFormat(this YoutubeCommentThread commentThread, TextFormat format)
        {
            var settings = commentThread.Settings.Clone();

            settings.TextFormat = format;
            return(CommentThread(settings, commentThread.PartTypes.ToArray()));
        }
示例#2
0
        public static YoutubeCommentThread SearchTerms(this YoutubeCommentThread commentThread, string s)
        {
            var settings = commentThread.Settings.Clone();

            settings.SearchTerms = s;
            return(CommentThread(settings, commentThread.PartTypes.ToArray()));
        }
示例#3
0
        public static List <Item> GetItems(string url)
        {
            try
            {
                string      videoId   = url.Split('=')[1];
                string      pageToken = "&pageToken=";
                string      token     = "";
                List <Item> items     = new List <Item>();

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(YouTubeAPIUrl);

                // Add an Accept header for JSON format.
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));


                do
                {
                    // List data response.
                    HttpResponseMessage response = client.GetAsync(UrlParameters + videoId + pageToken + token).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        // Parse the response body.
                        object dataObjects = response.Content.ReadAsAsync <object>().Result;

                        YoutubeCommentThread commentThread = JsonConvert.DeserializeObject <YoutubeCommentThread>(dataObjects.ToString());
                        Parallel.ForEach(commentThread.items, i => items.Add(i));

                        token = commentThread.nextPageToken;
                    }
                    else
                    {
                        Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                    }
                } while (!string.IsNullOrWhiteSpace(token));
                ;
                client.Dispose();
                return(items);
            }
            catch (Exception ex)
            {
                throw new SystemException("Error at " + System.Reflection.MethodBase.GetCurrentMethod().Name + " : " + ex.Message + " : " + ex.InnerException);
            }
        }
示例#4
0
 public static YoutubeCommentThread RequestAllParts(this YoutubeCommentThread commentThread)
 {
     return(commentThread.RequestReplies().RequestSnippet());
 }
示例#5
0
 public static YoutubeCommentThread RequestSnippet(this YoutubeCommentThread commentThread)
 {
     return(commentThread.RequestPart(PartType.Snippet));
 }
示例#6
0
 public static YoutubeCommentThread RequestReplies(this YoutubeCommentThread commentThread)
 {
     return(commentThread.RequestPart(PartType.Replies));
 }
示例#7
0
 public static YoutubeCommentThread RequestPart(this YoutubeCommentThread commentThread, PartType partType)
 {
     return(CommentThread(commentThread.Settings.Clone(), commentThread.PartTypes.Append(partType).ToArray()));
 }
示例#8
0
 public static YoutubeChannel Channel(this YoutubeCommentThread commentThread)
 {
     return(commentThread.TopLevelComment.Channel());
 }
示例#9
0
 public static YoutubeVideo Video(this YoutubeCommentThread commentThread)
 {
     return(commentThread.TopLevelComment.Video());
 }
示例#10
0
 public static YoutubeCommentThread FormatPlainText(this YoutubeCommentThread commentThread)
 {
     return(commentThread.TextFormat(Enums.TextFormat.PlainText));
 }
示例#11
0
 public static YoutubeCommentThread FormatHtml(this YoutubeCommentThread commentThread)
 {
     return(commentThread.TextFormat(Enums.TextFormat.Html));
 }