Пример #1
0
        /// <summary>
        /// Проводит операции с полученным списком презентаций по публикации на сайте soft
        /// </summary>
        /// <param name="lst">Список презентаций, которые были получены с rutor</param>
        /// <returns>Если операция выполнена успешно - true, инчае false</returns>
        async Task <bool> FlowRutor(IList <RutorListItem> lst)
        {
            foreach (RutorListItem item in lst)
            {
                //Парсим
                RutorParseItemInput paramRutorItem =
                    _context.RutorParseItemInputs
                    .Single(el => el.Active);
                paramRutorItem.ListItemId = item.Id;
                RutorItem rutorItem = await _rutorService.ParseItem(paramRutorItem);

                if (rutorItem == null)
                {
                    _logger.LogError("Не удалось распарсить пост. ListItemId = " + item.Id);
                    return(false);
                }

                //Выкладываем
                PublishResult result = await Send(nameof(RutorItem), rutorItem.Id);

                if (result == PublishResult.Error)
                {
                    _logger.LogError("Ошибка при отправке поста");
                    return(false);
                }
                if (result == PublishResult.FileExist)
                {
                    _logger.LogError("Пост уже существует, переходим к следующему");
                    continue;
                }
            }
            return(true);
        }
        /// <summary>
        /// Парсит указанную раздачу и записывает ее в базу
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task <RutorItem> ParseItem(RutorParseItemInput param)
        {
            RutorItem item = await ParsePageItem(param);

            if (item != null)
            {
                _context.RutorItems.Add(item);
                _context.SaveChanges();
                return(item);
            }
            _logger.LogError("Не удалось распрарсить раздачу");
            return(null);
        }
        /// <summary>
        /// Парсит указанную раздачу
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        async Task <RutorItem> ParsePageItem(RutorParseItemInput param)
        {
            RutorListItem listItem =
                _context
                .RutorListItems
                .SingleOrDefault(el => el.Id == param.ListItemId);

            if (listItem != null)
            {
                string page = await GetPage(param.UriItem + listItem.HrefNumber,
                                            param.ProxySocks5Addr,
                                            param.ProxySocks5Port,
                                            param.ProxyActive);

                if (page != null)
                {
                    var htmlDocument = new HtmlDocument();
                    htmlDocument.LoadHtml(page);

                    List <RutorItemSpoiler> listSpoiler = GetSpoilers(htmlDocument,
                                                                      param.XPathExprSpoiler);
                    List <RutorItemImg> listImgs = GetImgs(htmlDocument,
                                                           param.XPathExprImgs,
                                                           listSpoiler);
                    string description = GetDescription(htmlDocument,
                                                        param.XPathExprDescription,
                                                        param.XPathExprSpoiler);

                    if (description == null || listImgs == null)
                    {
                        _logger.LogError($"Не удалось получить описание презентации или ее изображения. RutorListItem.Id - {listItem.Id} / Href - {listItem.HrefNumber}");
                        return(null);
                    }

                    var result = new RutorItem
                    {
                        Created         = DateTime.Now,
                        Name            = listItem.Name,
                        Description     = description,
                        Spoilers        = listSpoiler,
                        Imgs            = listImgs,
                        RutorListItemId = param.ListItemId,
                    };
                    return(result);
                }
                _logger.LogError($"Не удалось получить веб страницу с презентацией. RutorListItem.Id - {listItem.Id} / Href - {listItem.HrefNumber}");
                return(null);
            }
            _logger.LogError("Не удалось найти в базе раздачу из списка с указнным Id");
            return(null);
        }
Пример #4
0
        public async Task <TimeSpan> Execute()
        {
            DataRepository  repository = new DataRepository();
            RutorCollection collection = await repository.Get <RutorCollection>();

            RutorCrawler crawler = new RutorCrawler();
            RutorItem    missing = collection.MissingDetails().FirstOrDefault();

            if (missing != null)
            {
                collection.Apply(missing.Id, await crawler.Details(missing.Id));
                await repository.Update(collection);

                return(TimeSpan.FromSeconds(10));
            }

            return(TimeSpan.FromMinutes(10));
        }
Пример #5
0
        public async Task <ActionResult <RutorItem> > ParseItem([FromBody] RutorParseItemInput parseParam)
        {
            RutorItem item = await _rutorService.ParseItem(parseParam);

            if (item != null)
            {
                foreach (var img in item.Imgs)
                {
                    img.RutorItem = null;
                }
                foreach (var spl in item.Spoilers)
                {
                    spl.RutorItem = null;
                }
                item.RutorListItem = null;
                return(Ok(item));
            }
            return(BadRequest("Не удалось распарсить"));
        }
Пример #6
0
        public static void ClassInitialize(TestContext context)
        {
            TestPage testPage0 = new TestPage
            {
                url         = @"http://rutor.is/torrent/541697/beloff-2019.2-minstall-vs-wpi-2019-pc-iso",
                description = @"<br><img src=""http://img15.lostpic.net/2019/01/02/12e0aa4792bfadadf135371c64e22316.jpg""><br>",
                spoilers    = 6,
                pic         = 1,
            };

            TestPage testPage1 = new TestPage
            {
                url         = @"http://rutor.is/torrent/315024/gimp-2.10.8-final-2019-rs",
                description = @"<img src=""http://i5.imageban.ru/out/2015/12/19/805d48652ce568b6b6f9262d5d54028c.jpg"" style=""float:right;"">",
                spoilers    = 3,
                pic         = 7,
            };

            testedNowPage = testPage0;

            preposts pr = new preposts
            {
                href = testedNowPage.url,
            };
            bool flagCall = false;

            item              = new RutorItem();
            item.OnPostMaked += delegate(object s, EventArgs e)
            {
                flagCall = true;
            };
            item.GetPost(pr);

            for (int callCount = 0; callCount < 48 && !flagCall; callCount++)
            {
                Thread.Sleep(250);
            }
        }
        /// <summary>
        /// Преобразует RutorPost в SoftPost
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        async Task <SoftPost> RutorToSoft(DriverToSoftInput param)
        {
            RutorItem rutorItem = _context
                                  .RutorItems
                                  .Include(el => el.RutorListItem)
                                  .Include(el => el.Imgs)
                                  .Include(el => el.Spoilers)
                                  .SingleOrDefault(el => el.Id == param.ParseItemId);

            if (rutorItem != null)
            {
                var post = new SoftPost();
                post.RutorItemId = param.ParseItemId;
                post.Name        = rutorItem.Name;
                post.Created     = DateTime.Now;

                string torrentFile = await DownloadFile(param.TorrentUri + rutorItem.RutorListItem.HrefNumber,
                                                        Path.GetRandomFileName().Replace('.', '_') + ".torrent",
                                                        param.ProxySocks5Addr,
                                                        param.ProxySocks5Port,
                                                        param.ProxyActive);

                if (torrentFile == null)
                {
                    _logger.LogError($"Не удалось загрузить торрент файл. RutorItem.Id: {param.ParseItemId}; Href: {rutorItem.RutorListItem.HrefNumber}");
                    return(null);
                }
                post.TorrentFile = torrentFile;

                string posterFile = await GetPosterImgRutor(rutorItem.Imgs, param);

                if (posterFile == null)
                {
                    _logger.LogError($"Не удалось загрузить постер. RutorItem.Id: {param.ParseItemId}; Href: {rutorItem.RutorListItem.HrefNumber}");
                    return(null);
                }
                FileInfo img = new FileInfo(posterFile);
                if (img.Length > param.MaxPosterSize * 1024)
                {
                    posterFile = _imgsConverter.ConvertToJpg(posterFile, 100);
                }
                post.PosterImg = posterFile;

                var queryUriImgs =
                    (from el in rutorItem.Imgs
                     where el.ParentUrl != null
                     select el.ParentUrl).ToList();
                var queryParams =
                    (from el in _context.ImghostParsingInputs
                     where el.Active == true
                     select el).ToList();
                List <string> screenshots =
                    (await _imghostService.GetOriginalsUri(new ImghostGetOriginalsInput
                {
                    ImgsUri = queryUriImgs,
                    ParsingParams = queryParams,
                })).ToList();
                var queryScr =
                    (from el in screenshots
                     select new SoftPostImg
                {
                    Created = DateTime.Now,
                    ImgUri = el,
                }).ToList();
                post.Imgs = queryScr;

                post.Description = FormatDescriptionRutor(rutorItem.Description, post.PosterImg);
                post.Spoilers    = FormatSpoilersRutor(rutorItem.Spoilers);

                return(post);
            }
            _logger.LogError($"В базе не найдена раздача с указанным Id. RutorItem.Id: {param.ParseItemId}");
            return(null);
        }