Ejemplo n.º 1
0
        private void CrawlPosters(string data)
        {
            if (string.IsNullOrEmpty(data)) return;

            JavaScriptSerializer json = new JavaScriptSerializer();

            try
            {
                data = HttpContext.Current.Server.UrlDecode(data);
            }
            catch (Exception)
            {
                // in some cases data is already decoded - hence we dont need to redecoded it. it throws an exception
            }

            XMLMovieProperties prop = json.Deserialize<XMLMovieProperties>(data);

            //string movieUrl,string movieUniqueName
            TableManager tblMgr = new TableManager();
            List<string> urls = new SantaImageCrawler().GetMoviePosterUrls(prop.SantaPosterLink);
            ImdbCrawler ic = new ImdbCrawler();

            MovieEntity me = tblMgr.GetMovieByUniqueName(prop.MovieName);
            List<string> processedUrl = json.Deserialize<List<string>>(me.Posters);

            me.Pictures = (string.IsNullOrEmpty(me.Pictures) || me.Pictures == "null") ? "[]" : me.Pictures;

            List<CloudMovie.APIRole.UDT.PosterInfo> posters = json.Deserialize<List<CloudMovie.APIRole.UDT.PosterInfo>>(me.Pictures);

            int imageCounter = 1;
            string newImageName = string.Empty;

            if (processedUrl != null)
            {
                imageCounter = processedUrl.Count + 1;

                foreach (string process in processedUrl)
                {
                    CloudMovie.APIRole.UDT.PosterInfo info = new CloudMovie.APIRole.UDT.PosterInfo();
                    info.url = process;
                    posters.Add(info);
                }
            }
            else
            {
                processedUrl = new List<string>();
                posters = new List<CloudMovie.APIRole.UDT.PosterInfo>();

            }

            foreach (string url in urls)
            {
                CloudMovie.APIRole.UDT.PosterInfo info = new CloudMovie.APIRole.UDT.PosterInfo();

                try
                {
                    string posterPath = ic.GetNewImageName(prop.MovieName, ic.GetFileExtension(url), imageCounter, false, ref newImageName);
                    ic.DownloadImage(url, posterPath);

                    processedUrl.Add(newImageName);

                    info.url = newImageName;
                    info.source = prop.SantaPosterLink;
                    posters.Add(info);

                    imageCounter++;
                }
                catch (Exception)
                {
                    // Skip that image
                }
            }

            me.Posters = json.Serialize(processedUrl);
            me.Pictures = json.Serialize(posters);
            tblMgr.UpdateMovieById(me);
        }
Ejemplo n.º 2
0
        public ActionResult GetPosters(XMLMovieProperties prop)
        {
            try
            {
                if (prop == null)
                    return null;

                JavaScriptSerializer json = new JavaScriptSerializer();
                TableManager tblMgr = new TableManager();
                List<string> urls = new SantaImageCrawler().GetMoviePosterUrls(prop.SantaPosterLink);
                ImdbCrawler ic = new ImdbCrawler();

                MovieEntity me = tblMgr.GetMovieByUniqueName(prop.MovieName.ToLower().Replace(" ", "-").Replace(".", ""));
                List<string> processedUrl = json.Deserialize<List<string>>(me.Posters);
                me.Pictures = (string.IsNullOrEmpty(me.Pictures) || me.Pictures == "null") ? "[]" : me.Pictures;

                List<PosterInfo> posters = json.Deserialize<List<PosterInfo>>(me.Pictures);

                int imageCounter = 1;
                string newImageName = string.Empty;

                if (processedUrl != null)
                {
                    imageCounter = processedUrl.Count + 1;

                    if (posters == null)
                        posters = new List<PosterInfo>();

                    foreach (string process in processedUrl)
                    {
                        PosterInfo info = new PosterInfo();
                        info.url = process;
                        posters.Add(info);
                    }
                }
                else
                {
                    processedUrl = new List<string>();
                    posters = new List<PosterInfo>();

                }

                foreach (string url in urls)
                {
                    PosterInfo info = new PosterInfo();

                    try
                    {
                        string posterPath = ic.GetNewImageName(prop.MovieName, ic.GetFileExtension(url), imageCounter, false, ref newImageName);
                        ic.DownloadImage(url, posterPath);

                        processedUrl.Add(newImageName);

                        info.url = newImageName;
                        info.source = prop.SantaPosterLink;
                        posters.Add(info);

                        imageCounter++;
                    }
                    catch (Exception)
                    {
                        // Skip that image
                    }
                }

                me.Posters = JsonConvert.SerializeObject(processedUrl);
                me.Pictures = JsonConvert.SerializeObject(posters);
                tblMgr.UpdateMovieById(me);
            }
            catch (Exception)
            {

            }

            return null;
            //return Json(new { Status = "Ok", Message = "Selected news deleted successfully." }, JsonRequestBehavior.AllowGet);
        }