예제 #1
0
        protected override List <PhotoDownload> DoImageDownload(PhotoInput photoInput)
        {
            //Console.WriteLine(Resource.readingUrl);
            var web  = new HtmlWeb();
            var page = web.Load(photoInput.Url).DocumentNode;

            photoInput.Path     = page.QuerySelector("h1.category-heading").InnerText.Trim().RemoveInvalidPathChars();
            photoInput.FullPath = PhotoPath + photoInput.Path;
            Photo.WriteRootInfoFile(photoInput);

            var gallery = page.QuerySelectorAll("figure.media a");

            var listPhotoDownload = new List <PhotoDownload>();

            foreach (var imageFrame in gallery)
            {
                var photoDownload = new PhotoDownload
                {
                    Url    = imageFrame.GetAttributeValue("data-article", ""),
                    Status = false,
                    Title  = HttpUtility.HtmlDecode(imageFrame.GetAttributeValue("data-title", ""))
                };
                photoDownload.Name = Photo.GetName(photoDownload.Url);
                photoDownload.Path = Path.GetFullPath(photoInput.FullPath) + "\\" + photoDownload.Name;
                listPhotoDownload.Add(photoDownload);
            }

            return(listPhotoDownload);
        }
예제 #2
0
        protected override List <PhotoDownload> DoImageDownload(PhotoInput photoInput)
        {
            Console.WriteLine(Resource.readingUrl);
            var web  = new HtmlWeb();
            var page = web.Load(photoInput.Url).DocumentNode;

            photoInput.Path     = page.QuerySelector("h1.container_12.title").InnerText.Trim().RemoveInvalidPathChars();
            photoInput.FullPath = PhotoPath + photoInput.Path;
            photoInput.Desc     = page.QuerySelector("div.container_12.lead").InnerText.Trim();
            Photo.WriteRootInfoFile(photoInput);
            var listPhotoDownload = new List <PhotoDownload>();
            //var gallery = page.QuerySelectorAll("div.tumblr.hide-mobile");

            var gallery = page.QuerySelectorAll("section.container_12.content div.single_photo");

            foreach (var imageFrame in gallery)
            {
                var photoDownload = new PhotoDownload
                {
                    Url    = imageFrame.QuerySelector("img.article_img").GetAttributeValue("src", ""), //imageFrame.GetAttributeValue("data-content", ""),
                    Status = false,
                    Title  = HttpUtility.HtmlDecode(imageFrame.QuerySelector("div.text").InnerText)    //HttpUtility.HtmlDecode(imageFrame.GetAttributeValue("data-caption", ""))
                };
                photoDownload.Name = Photo.GetName(photoDownload.Url);
                photoDownload.Path = Path.GetFullPath(photoInput.FullPath) + "\\" + photoDownload.Name;
                listPhotoDownload.Add(photoDownload);
            }


            return(listPhotoDownload);
        }
예제 #3
0
        // ReSharper disable once UnusedMethodReturnValue.Global
        internal static bool WriteRootInfoFile(PhotoInput photoInput)
        {
            var directoryInfo = new DirectoryInfo(photoInput.FullPath);

            try
            {
                if (!directoryInfo.Exists)
                {
                    directoryInfo.Create();
                }
            }
            catch (IOException exception)
            {
                throw new PhotoInputException("An error ocured while creating directory", exception);
            }
            var writer          = File.CreateText(photoInput.FullPath + "\\root.info");
            var isWriteComplete = false;

            try
            {
                writer.WriteLine("Path: ");
                writer.WriteLine(photoInput.Path);
                writer.WriteLine();
                writer.WriteLine("Url: ");
                writer.WriteLine(photoInput.Url);
                writer.WriteLine();
                if (!String.IsNullOrEmpty(photoInput.Desc))
                {
                    writer.WriteLine("Desc: ");
                    writer.WriteLine(photoInput.Desc);
                    var picasaFile = photoInput.FullPath + "\\.picasa.ini";
                    File.WriteAllText(picasaFile, Resource.PicasaDescription + photoInput.Desc);
                    File.SetAttributes(picasaFile, FileAttributes.System);
                    File.SetAttributes(picasaFile, FileAttributes.Hidden);
                }

                isWriteComplete = true;
            }
            catch (Exception)
            {
                // ignored
            }
            finally
            {
                writer.Close();
            }

            return(isWriteComplete);
        }
예제 #4
0
        internal static PhotoInput TakeUserInput(string photoPath, bool showPathOption = true)
        {
            var photoInput = new PhotoInput();

            if (showPathOption)
            {
                Console.WriteLine(Resource.inputFolderPath);
                var dirPath = Console.ReadLine();

                if (string.IsNullOrEmpty(dirPath))
                {
                    throw new PhotoInputException("Invalid input values");
                }

                dirPath = dirPath.RemoveInvalidPathChars();

                dirPath = photoPath + dirPath;

                var directoryInfo = new DirectoryInfo(dirPath);

                try
                {
                    if (!directoryInfo.Exists)
                    {
                        directoryInfo.Create();
                    }
                }
                catch (IOException exception)
                {
                    throw new PhotoInputException("An error ocured while creating directory", exception);
                }


                photoInput.Path = dirPath;
            }

            Console.WriteLine(Resource.inputUrl);
            var url = Console.ReadLine();

            if (string.IsNullOrEmpty(url))
            {
                throw new PhotoInputException("Invalid url provided");
            }

            photoInput.Url = url;

            Console.Clear();
            return(photoInput);
        }
예제 #5
0
        protected override List <PhotoDownload> DoImageDownload(PhotoInput photoInput)
        {
            //Console.WriteLine(Resource.readingUrl);
            var web  = new HtmlWeb();
            var page = web.Load(photoInput.Url).DocumentNode;

            photoInput.Path = page.QuerySelector("title").InnerText.Trim().RemoveInvalidPathChars().RemoveInvalidSputnikPhotoChars();

            if (photoInput.Path.Contains("This Week in Pictures"))
            {
                photoInput.Path = photoInput.Path + "\\" + DateTime.ParseExact(photoInput.Url.Substring(30, 8), "yyyyMMdd", CultureInfo.InvariantCulture).ToString("MMMM dd yyyy");
            }

            photoInput.FullPath = PhotoPath + photoInput.Path;


            photoInput.Desc = HttpUtility.HtmlDecode(page.QuerySelector("div.b-article__text").InnerText.Trim());
            Photo.WriteRootInfoFile(photoInput);


            var gallery = page.QuerySelector("#gallery").QuerySelectorAll("li");

            var listPhotoDownload = new List <PhotoDownload>();

            foreach (var imageFrame in gallery)
            {
                var photoDownload = new PhotoDownload
                {
                    Url    = imageFrame.GetAttributeValue("data-src", ""),
                    Status = false,
                    Title  = HttpUtility.HtmlDecode(imageFrame.GetAttributeValue("data-sub-html", ""))
                };
                photoDownload.Name = Photo.GetName(photoDownload.Url);
                photoDownload.Path = Path.GetFullPath(photoInput.FullPath) + "\\" + photoDownload.Name;
                listPhotoDownload.Add(photoDownload);
            }

            return(listPhotoDownload);
        }
예제 #6
0
 protected abstract List <PhotoDownload> DoImageDownload(PhotoInput photoInput);