Exemplo n.º 1
0
        public async Task <bool> ReupdateSeoField()
        {
            var films = _dbContext.Films.Where(x => x.Id > 4047);

            foreach (var film in films)
            {
                var keyworks = string.Empty;

                var starFilm = _dbContext.FilmStars.Where(x => x.FilmId == film.Id).Select(x => x.StarId);

                foreach (var star in _dbContext.Stars.Where(x => starFilm.Contains(x.Id)).Select(x => x.Title))
                {
                    keyworks += star + ", ";
                }

                var tagFilm = _dbContext.FilmTags.Where(x => x.FilmId == film.Id).Select(x => x.TagId);
                foreach (var tag in _dbContext.Tags.Where(x => tagFilm.Contains(x.Id)).Select(x => x.Title))
                {
                    keyworks += tag + ", ";
                }

                var catFilm = _dbContext.FilmGenres.Where(x => x.FilmId == film.Id).Select(x => x.GenreId);
                foreach (var cat in _dbContext.Genres.Where(x => catFilm.Contains(x.Id)).Select(x => x.Title))
                {
                    keyworks += cat + ", ";
                }

                var seo = new JavCrawl.Models.Seo.SeoFilm();
                seo.keyword = keyworks.Trim().TrimEnd(',');
                seo.title   = film.Title;
                seo.desc    = film.Storyline.Length > 246 ? film.Storyline.Substring(0, 240) + "..." : film.Storyline;

                film.Seo = JsonConvert.SerializeObject(seo);
                await _dbContext.SaveChangesAsync();
            }

            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> SaveJavHiHiMovie(JavHiHiMovie movie)
        {
            var film = _dbContext.Films.FirstOrDefault(x => x.Slug == movie.url);

            if (film != null)
            {
                return(await UpdateEpisode(film.Id, movie.linkepisode));
            }

            using (var dbTransaction = await _dbContext.Database.BeginTransactionAsync())
            {
                try
                {
                    var keyworks = string.Empty;

                    foreach (var star in movie.pornstars)
                    {
                        keyworks += star + ", ";
                    }

                    foreach (var tag in movie.tags)
                    {
                        keyworks += tag + ", ";
                    }

                    foreach (var cat in movie.categories)
                    {
                        keyworks += cat + ", ";
                    }

                    string thumb_cover = null;
                    string thumb_name  = null;
                    int?   ftpId       = null;
                    if (!string.IsNullOrWhiteSpace(movie.image))
                    {
                        var ftpUpload = await _ftpHelper.RemoteFiles(movie.image, movie.url);

                        if (ftpUpload.IsSuccessful)
                        {
                            thumb_name = ftpUpload.FileName;
                            ftpId      = ftpUpload.ServerId;
                        }
                    }

                    if (movie.image == movie.image_small)
                    {
                        thumb_cover = thumb_name;
                    }
                    else if (!string.IsNullOrWhiteSpace(movie.image_small))
                    {
                        var ftpUpload = await _ftpHelper.RemoteFiles(movie.image_small, movie.url + "-cover");

                        if (ftpUpload.IsSuccessful)
                        {
                            thumb_cover = ftpUpload.FileName;
                            ftpId       = ftpUpload.ServerId;
                        }
                    }

                    if (string.IsNullOrWhiteSpace(thumb_cover))
                    {
                        thumb_cover = thumb_name;
                    }
                    if (string.IsNullOrWhiteSpace(thumb_name))
                    {
                        thumb_name = thumb_cover;
                    }

                    var seo = new JavCrawl.Models.Seo.SeoFilm();
                    seo.keyword = keyworks.Trim().TrimEnd(',');
                    seo.title   = movie.name;
                    seo.desc    = (movie.descriptions.Length > 246 ? movie.descriptions.Substring(0, 240) + "..." : movie.descriptions);

                    var newFilm = new Films
                    {
                        CategoryId    = movie.fromsite == "hihi" ? 1 : 2,
                        ThumbName     = thumb_name,
                        CoverName     = thumb_cover,
                        Title         = movie.name,
                        TitleEn       = movie.name,
                        TitleAscii    = movie.name,
                        Slug          = movie.url,
                        Date          = movie.published,
                        Order         = movie.published.UnixTicks(),
                        Online        = 1,
                        Hot           = 0,
                        Free          = 0,
                        Slide         = 0,
                        QualityId     = 1,
                        Episodes      = "HD",
                        ExistEpisodes = "HD",
                        Runtime       = movie.duration,
                        Description   = movie.name,
                        Storyline     = movie.descriptions,
                        Viewed        = int.Parse(movie.view.Replace(",", "").Replace(".", "")),
                        Seo           = JsonConvert.SerializeObject(seo),
                        CreatedAt     = DateTime.Now,
                        Reported      = 0,
                        FtpId         = ftpId,
                        Extend        = movie.fromsite
                    };


                    await _dbContext.Films.AddAsync(newFilm);

                    await _dbContext.SaveChangesAsync();

                    if (newFilm.Id > 0)
                    {
                        var idCountry = await GetCountry("Japanese");

                        await _dbContext.FilmCountries.AddAsync(new FilmCountries
                        {
                            CountryId = idCountry,
                            FilmId    = newFilm.Id
                        });

                        await _dbContext.SaveChangesAsync();

                        var idDirector = GetDirector("JAV");
                        await _dbContext.FilmDirectors.AddAsync(new FilmDirectors
                        {
                            DirectorId = idDirector,
                            FilmId     = newFilm.Id
                        });

                        await _dbContext.SaveChangesAsync();

                        var filmGenres = new List <FilmGenres>();
                        foreach (var genre in movie.categories)
                        {
                            var idGenre = await GetGenre(genre);

                            filmGenres.Add(new FilmGenres
                            {
                                FilmId  = newFilm.Id,
                                GenreId = idGenre
                            });
                        }
                        await _dbContext.FilmGenres.AddRangeAsync(filmGenres);

                        await _dbContext.SaveChangesAsync();

                        var filmTags = new List <FilmTags>();
                        foreach (var tag in movie.tags)
                        {
                            var idTag = await GetTag(tag);

                            filmTags.Add(new FilmTags
                            {
                                FilmId = newFilm.Id,
                                TagId  = idTag
                            });
                        }
                        await _dbContext.FilmTags.AddRangeAsync(filmTags);

                        await _dbContext.SaveChangesAsync();

                        var filmStars = new List <FilmStars>();
                        foreach (var star in movie.pornstars)
                        {
                            var idStar = await GetStar(star, movie.fromsite);

                            filmStars.Add(new FilmStars
                            {
                                FilmId = newFilm.Id,
                                StarId = idStar
                            });
                        }
                        await _dbContext.FilmStars.AddRangeAsync(filmStars);

                        await _dbContext.SaveChangesAsync();

                        var episodes = new List <Episodes>();

                        foreach (var eps in movie.linkepisode)
                        {
                            episodes.Add(new Episodes
                            {
                                Title     = eps.Contains("bitporno") ? "Server BP" : (eps.Contains("openload") ? "Server OL" : (eps.Contains("rapidvideo") ? "Server RP" : "Server HD")),
                                FilmId    = newFilm.Id,
                                FileName  = eps,
                                Type      = "Full",
                                Viewed    = int.Parse(movie.view.Replace(",", "").Replace(".", "")),
                                CreatedAt = DateTime.Now
                            });
                        }

                        await _dbContext.Episodes.AddRangeAsync(episodes);

                        await _dbContext.SaveChangesAsync();
                    }

                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("SaveJavHiHiMovie: " + ex.Message);

                    dbTransaction.Rollback();
                    return(false);
                }
            }
        }