Beispiel #1
0
        private static int CountBlock(TLWebPage webPage, TLPageBlockBase pageBlock, int count)
        {
            if (pageBlock is TLPageBlockPhoto photoBlock)
            {
                var photo = GetPhotoWithId(webPage, photoBlock.PhotoId) as TLPhoto;
                if (photo == null)
                {
                    return(count);
                }

                return(count + 1);
            }
            else if (pageBlock is TLPageBlockVideo videoBlock)
            {
                var document = GetDocumentWithId(webPage, videoBlock.VideoId) as TLDocument;
                if (document == null)
                {
                    return(count);
                }

                return(count + 1);
            }

            return(count);
        }
Beispiel #2
0
        public static int CountWebPageMedia(TLWebPage webPage)
        {
            var result = 0;
            var blocks = webPage.CachedPage?.Blocks ?? new TLVector <TLPageBlockBase>();

            foreach (var block in blocks)
            {
                if (block is TLPageBlockSlideshow slideshow)
                {
                    foreach (var item in slideshow.Items)
                    {
                        result = CountBlock(webPage, item, result);
                    }
                }
                else if (block is TLPageBlockCollage collage)
                {
                    foreach (var item in collage.Items)
                    {
                        result = CountBlock(webPage, item, result);
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
        public static TLDocumentBase GetDocumentWithId(TLWebPage webPage, long id)
        {
            if (webPage == null || webPage.CachedPage == null)
            {
                return(null);
            }

            if (webPage.Document != null && webPage.Document.Id == id)
            {
                return(webPage.Document);
            }

            foreach (var document in webPage.CachedPage.Documents)
            {
                if (document.Id == id)
                {
                    return(document);
                }
            }

            return(null);
        }
Beispiel #4
0
        public static TLPhotoBase GetPhotoWithId(TLWebPage webPage, long id)
        {
            if (webPage == null || webPage.CachedPage == null)
            {
                return(null);
            }

            if (webPage.Photo != null && webPage.Photo.Id == id)
            {
                return(webPage.Photo);
            }

            foreach (var photo in webPage.CachedPage.Photos)
            {
                if (photo.Id == id)
                {
                    return(photo);
                }
            }

            return(null);
        }