Пример #1
0
        public override BuildResults Crawl()
        {
            string randomFilePath = this.PrepareFolderAndRandomFile();

            Exception exception = null;

            //CustomHttpCrawler client = new CustomHttpCrawler(new Uri(base.URI), randomFilePath, this.Encoding, this.LocalVersion, this.UserAgent);

            using (CustomWebClient client = new CustomWebClient(new Uri(base.URI), randomFilePath, this.Encoding, this.LocalVersion, this.UserAgent, proxyType))
            {
                if (this.ManualProxy != null)
                {
                    client.ManualProxy = this.ManualProxy;
                }

                //[Bug 730427:DownloadFileActivity need return directly when set manully proxy and download failed]
                for (int count = 0; count < CustomWebClient.ProxyList.Count; count++)
                {
                    BuildResults result = client.DownloadFile();
                    this.RemoteVersion = client.RemoteVersion;
                    exception          = client.Exception;
                    switch (result)
                    {
                    case BuildResults.Crawler_Succeed:
                        FileHelper.MoveFile(randomFilePath, this.LocalPath);
                        return(BuildResults.Crawler_Succeed);

                    case BuildResults.Crawler_NoNewFileFound:
                        return(result);

                    case BuildResults.Crawler_404NotFound:
                        throw exception;

                    case BuildResults.Crawler_RemoteServerNoResponse:
                    case BuildResults.Crawler_UnexpectedError:
                        //System.Threading.Thread.Sleep(5 * 1000);
                        break;

                    case BuildResults.Crawler_ProtocolError:
                        throw exception;
                    }
                }
            }

            if (exception == null)
            {
                return(BuildResults.Crawler_UnexpectedError);
            }
            else
            {
                throw exception;
            }
        }
Пример #2
0
        Torrent Download(Episode episode, EpisodeTorrentSearcherResult result)
        {
            var webClient = new CustomWebClient();
            if(!Directory.Exists("Torrents")) Directory.CreateDirectory("Torrents");

            var fileName = @"torrents\" + result.Title + ".torrent";

            try {
                webClient.DownloadFile(result.DownloadURL, fileName);
            } catch(Exception e) {
                Logger.Build().Episode(episode.ID).Message("Error downloading torrent: " + result.DownloadURL + " - " + e).Error();
                return null;
            }

            Torrent torrent;
            try {
                torrent = TorrentParser.ParseFile(fileName);
            } catch(Exception e) {
                Logger.Build().Episode(Episode.ID).Message("Error parsing torrent file: " + fileName + "-->" + e).Error();
                return null;
            }

            return torrent;
        }