예제 #1
0
        public override Response ParseDynamicData(dynamic json)
        {
            var response = new Response();

            response.TotalResults = json.total;
            response.PageToken    = Convert.ToString(json.page);

            var list  = new List <ResponseDetail>();
            var items = json.list;

            if (items != null)
            {
                foreach (var each in items)
                {
                    var detail = new ResponseDetail();
                    detail.Duration     = each.duration_formatted;
                    detail.Id           = each.id;
                    detail.Uri          = each.url;
                    detail.EmbededUri   = string.Format(IFrameUri, detail.Id);
                    detail.CreateUser   = each["owner.screenname"];
                    detail.ThumbnailUri = each.thumbnail_url;
                    detail.Title        = each.title;
                    detail.ViewCount    = $"{each.views_total}";
                    list.Add(detail);
                }
            }
            response.Items = list;
            return(response);
        }
예제 #2
0
        public override Response ParseDynamicData(dynamic json)
        {
            var response = new Response();

            var meta = json.meta;

            response.TotalResults = meta.totalCount;
            response.PageToken    = Convert.ToString(meta.id);

            var list  = new List <ResponseDetail>();
            var items = json.data;

            if (items != null)
            {
                foreach (var each in items)
                {
                    var detail = new ResponseDetail();
                    int sec    = int.Parse(Convert.ToString(each.lengthSeconds));
                    detail.Duration   = ToDuration(sec);
                    detail.Id         = each.contentId;
                    detail.Uri        = string.Format(IFrameUri, each.contentId);
                    detail.EmbededUri = string.Format(IFrameUri, each.contentId);

                    // detail.CreateUser = each["owner.screenname"];
                    detail.ThumbnailUri = each.thumbnailUrl;
                    detail.Title        = each.title;
                    detail.ViewCount    = $"{each.viewCounter}";
                    list.Add(detail);
                }
            }
            response.Items = list;
            return(response);
        }
예제 #3
0
        public override Response ParseDynamicData(dynamic json)
        {
            var response = new Response();

            var data   = json.data;
            var result = data.result;
            var videos = result.video;

            if (double.TryParse(Convert.ToString(data.numResults), out double value))
            {
                response.TotalResults = value;
            }
            response.PageToken = Convert.ToString(data.page);
            var list = new List <ResponseDetail>();

            try
            {
                foreach (var each in videos)
                {
                    var detail = new ResponseDetail();
                    detail.Id         = Convert.ToString(each.id);
                    detail.Uri        = each.arcurl;
                    detail.EmbededUri = string.Format(EmbedUrl, each.aid);

                    DateTime?pub = FromUnixTime(each.pubdate);
                    detail.PublishedAt = pub?.ToShortDateString();

                    detail.Title = Regex.Replace(each.title, "<[^>]*?>", "");
                    // detail.Title = Regex.Replace(each.title, "<[^>]*?>", "");
                    // detail.ThumbnailUri = $"https:{each.pic}";
                    detail.ThumbnailUri = $"{each.pic}";

                    detail.CreateUser = each.author;
                    detail.Duration   = each.duration;
                    detail.ViewCount  = Convert.ToString(each.play);

                    list.Add(detail);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
            response.Items = list;

            return(response);
        }
예제 #4
0
        public override Response ParseDynamicData(dynamic json)
        {
            var response = new Response();

            var pageInfo = json.pageInfo;

            if (pageInfo != null)
            {
                response.TotalResults = pageInfo.totalResults;
            }

            try
            {
                response.PageToken = json.nextPageToken;
            }
            catch
            {
            }

            var list = new List <ResponseDetail>();

            try
            {
                var items = json.items;
                if (items != null)
                {
                    foreach (var each in items)
                    {
                        var detail = new ResponseDetail();
                        var id     = each.id;
                        detail.Id         = id.videoId;
                        detail.Uri        = string.Format(downloadUrl, detail.Id);
                        detail.EmbededUri = string.Format(IFrameUri, detail.Id);
                        var snippet = each.snippet;
                        if (DateTime.TryParse(snippet.publishedAt, out DateTime dt))
                        {
                            var dts = dt.ToShortDateString();
                            detail.PublishedAt = dts;
                        }
                        detail.Title = snippet.title;

                        var thumbnails = snippet.thumbnails;
                        var medium     = thumbnails.medium;
                        detail.ThumbnailUri = medium.url;


                        var detailUri         = string.Format(SearchDetaillUri, detail.Id, ApiKey);
                        var dynamicDetail     = Utils.JsonRead(detailUri);
                        var detailItem        = dynamicDetail.items[0];
                        var detailItemSnippet = detailItem.snippet;
                        detail.CreateUser = detailItemSnippet.channelTitle;

                        var      contentDetails = detailItem.contentDetails;
                        var      duration       = contentDetails.duration;
                        string   text           = (duration as string).Replace("PT", "").Replace("H", ":").Replace("M", ":").Replace("S", "");
                        string[] array          = text.Split(new char[] { ':' });
                        if (array.Length == 1)
                        {
                            array = new string[] { "00", array[0] };
                        }
                        detail.Duration = string.Join(":", array.Select(x => x.PadLeft(2, '0')));

                        var statistics = detailItem.statistics;
                        detail.ViewCount = $"{statistics.viewCount}";

                        list.Add(detail);
                    }
                }
                response.Items = list;
            }
            catch
            {
            }
            return(response);
        }