Пример #1
0
        /// <summary>
        /// Imports the watch list - ONE BIGASS FUNCTION
        /// </summary>
        public static void importWatchList()
        {
            if (HTMLHandler.loggedIn)
            {
                notImportingWatchList = false;
                string watchlistURL = (
                    "http://www.furaffinity.net/watchlist/by/"
                    + HTMLHandler.faUsername
                    );
                string lookingFor = "/user/";
                string XPath      =
                    "/html[1]/body[1]/div[1]/table[1]/tr[2]/td[1]/table[1]//a[@href]"; // lazy
                string currentPageURL = "";

                bool pageHasWatches = true;
                int  pageNum        = 1;

                watchedArtists = new ArrayList();
                HtmlWeb hw = new HtmlWeb();

                {
                    // check if page has submissions
                    while (pageHasWatches)
                    {
                        // if page number is 1, use default url
                        if (pageNum == 1)
                        {
                            currentPageURL = (watchlistURL);
                        }
                        // if page number is greater than 1, add page number to end of url
                        else if (pageNum > 1)
                        {
                            currentPageURL = (
                                watchlistURL +
                                "/"
                                + pageNum +
                                "/"
                                );
                        }

                        var          client  = new cookieHandler.MyWebClient();
                        HtmlDocument HTMLDoc =
                            client.GetPageWithCookies(currentPageURL, downloaderForm.userCookies);

                        // ADD A NULL CHECK HERE:
                        if (HTMLDoc == null)
                        {
                            // Handle null document here

                            // End the function if necessary
                            return;
                        }

                        // check to see if current page is empty
                        Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                         Logger.logStatus("Checking Checking for watches on page " + pageNum + ".")
                                                                         ));

                        switch (HTMLDoc.DocumentNode.SelectSingleNode(XPath) != null)
                        {
                        case false:
                            Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                             Logger.logStatus("No watches on page " + pageNum + ".")
                                                                             ));

                            pageHasWatches        = false;
                            notImportingWatchList = true;
                            break;

                        case true:
                            Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                             Logger.logStatus("watch found, proceeding with parse")
                                                                             ));

                            pageHasWatches = true;
                            break;

                        default:
                            Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                             Logger.logError(Strings.Error)
                                                                             ));

                            break;
                        }

                        // Parse for watches
                        if (pageHasWatches)
                        {
                            foreach (HtmlNode node in HTMLDoc.DocumentNode.SelectNodes(XPath))
                            {
                                string hrefValue = node.GetAttributeValue("href", string.Empty);

                                Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                                 Logger.logDebug("Searching through " + hrefValue)
                                                                                 ));

                                // If contains a desired link, add it to the list of links
                                if (node.OuterHtml.Contains(lookingFor))
                                {
                                    Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                                     Logger.logDebug("Trimming :" + hrefValue)
                                                                                     ));

                                    string trimEnd     = hrefValue.Remove(hrefValue.Length - 1);
                                    string croppedName = trimEnd.Remove(0, 6);

                                    Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                                     Logger.logStatus("Found user " + croppedName)
                                                                                     ));

                                    watchedArtists.Add(croppedName);
                                }
                            }
                        }
                        // add 1 to page #
                        pageNum++;
                        // don't trip FA's bullshit
                        Thread.Sleep(HTMLHandler.htmlDelayLength);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Download the files in the list
        /// </summary>
        /// <param name="artist"></param>
        /// <param name="subType"></param>
        public static void downloadFilesFromURLs(ArtistObject artist, SubmissionType subType)
        {
            if (checkifDownloadCancelled())
            {
                return;
            }
            ArrayList linksToDownload;
            string    galleryType = "";

            switch (subType)
            {
            case SubmissionType.Gallery:
                linksToDownload = artist.galleryFileLinks;
                galleryType     = "Gallery";
                break;

            case SubmissionType.Scraps:
                linksToDownload = artist.scrapsFileLinks;
                galleryType     = "Scraps";
                break;

            case SubmissionType.Favorites:
                linksToDownload = artist.favoritesFileLinks;
                galleryType     = "Favorites";
                break;

            case SubmissionType.Journals:
                linksToDownload = artist.journalsFileLinks;
                galleryType     = "Journals";
                break;

            default:
                linksToDownload = new ArrayList();
                galleryType     = "ERROR";
                break;
            }

            // Setup the local download folder (create if necessary)
            string downloadFolder = downloadLocalFolderSetup
                                    (
                artist.artistName,
                galleryType,
                linksToDownload.Count
                                    );

            if (linksToDownload.Count == 0)
            {
                Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                 Logger.logStatus(
                                                                     "Skipping "
                                                                     + artist.artistName + "'s "
                                                                     + galleryType)
                                                                 ));
            }
            else
            {
                Program.mainForm.lbOutput.BeginInvoke(new Action(() =>
                                                                 Logger.logDownload(
                                                                     "Downloading "
                                                                     + linksToDownload.Count + " " + galleryType +
                                                                     " submissions for "
                                                                     + artist.artistName +
                                                                     " to " + downloadFolder)
                                                                 ));
            }

            foreach (string submissionURL in linksToDownload)
            {
                //numCurrentDownload++; // moved

                if (checkifDownloadCancelled())
                {
                    return;
                }
                string fileName = "";

                // download the journal HTML doc
                if (galleryType == "Journals")
                {
                    HtmlWeb      hw     = new HtmlWeb();
                    var          client = new cookieHandler.MyWebClient();
                    HtmlDocument HTMLDoc
                        = client.GetPageWithCookies((submissionURL),
                                                    downloaderForm.userCookies);

                    string uncroppedJournalName
                        = HTMLDoc.DocumentNode.SelectSingleNode("//title[text()]").InnerText;

                    string journalName = uncroppedJournalName.Remove
                                             (uncroppedJournalName.Length - 40);

                    // remove invalid characters from journal title
                    foreach (string invalidCharacter in HTMLHandler.invalidCharacters)
                    {
                        if (!checkifDownloadCancelled())
                        {
                            {
                                journalName = journalName.Replace(invalidCharacter, "_");
                            }
                            journalName = journalName.Replace("&#39;", "'");
                            fileName    = ("/" + journalName + ".html");
                        }
                    }
                }
                else
                {
                    fileName = ("/" + Path.GetFileName(new Uri(submissionURL).LocalPath));
                    //string fileName = ("/" + Path.GetFileName(new Uri(submissionURL).LocalPath));
                }

                numCurrentDownload++;                                  // moved
                // Check to see if we should download the file, then download it if so
                downloadFile(submissionURL, downloadFolder, fileName); //, galleryType);
            }
        }