Example #1
0
        private void QueueLoadOfCachedFiles()
        {
            // Do an init check for local files.  A bit hacky but much faster.  Needs work!
            var path = Path.Combine(Path.GetTempPath(), "mosaic", "cells");

            if (Directory.Exists(path))
            {
                var files = Directory.GetFiles(path, "*.png");

                foreach (var file in files)
                {
                    var fileBaseName = Path.GetFileNameWithoutExtension(file);
                    var newImage     = new ImgurImage(fileBaseName, fileBaseName, "image/png", null, new string[0]);
                    _queuedDownloads.Enqueue(newImage);
                    System.Console.WriteLine($"FOUND cached image: {file}");
                }
            }
        }
Example #2
0
        public void Parse(JObject json)
        {
            //System.Console.WriteLine($"Parsing response:\n{json.ToString()}");

            var excluded = new string[] { "image/gif", "video/mp4" };

            if (json != null)
            {
                foreach (var child in json["data"].Children())
                {
                    bool albumIsNsfw = child["nsfw"].Value <bool>();
                    bool albumIsAd   = child["is_ad"].Value <bool>();
                    if (!albumIsNsfw && !albumIsAd)
                    {
                        string albumId    = child["id"].Value <string>();
                        string albumTitle = child["title"].Value <string>();

                        JToken imageDefs = child["images"];
                        if (imageDefs != null)
                        {
                            foreach (var imageDef in imageDefs.Children())
                            {
                                var type = imageDef["type"].Value <string>();
                                if (!excluded.Contains(type, StringComparer.OrdinalIgnoreCase) &&
                                    imageDef["width"].Value <int>() < 2000 &&
                                    imageDef["height"].Value <int>() < 2000)
                                {
                                    var image = new ImgurImage(
                                        imageDef["id"].Value <string>() ?? albumId,
                                        imageDef["title"].Value <string>() ?? albumTitle,
                                        type,
                                        new Uri(imageDef["link"].Value <string>()),
                                        child["tags"].Children()["name"].Values <string>());

                                    Images.Add(image);
                                }
                            }
                        }
                    }
                }
            }
        }