// get : api/Trailer?n={movie's unique name} protected override string ProcessRequest() { JavaScriptSerializer json = new JavaScriptSerializer(); try { var tableMgr = new TableManager(); // get query string parameters var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query); if (string.IsNullOrEmpty(qpParams["n"])) { throw new ArgumentException(Constants.API_EXC_MOVIE_NAME_NOT_EXIST); } string movieUniqueName = qpParams["n"].ToString(); //get movie object by movie's unique name var movie = tableMgr.GetMovieByUniqueName(movieUniqueName); if (movie != null) { // if movie is not null then return trailer string (in json) return movie.Trailers; } } catch (Exception ex) { // if any error occured then return User friendly message with system error message return json.Serialize(new { Status = "Error", UserMessage = Constants.UM_WHILE_SEARCHING_MOVIES_TRAILER, ActualError = ex.Message }); } // if movie is null then return single object. return string.Empty; }
/// <summary> /// Entry point for the crawler. Pass the URL from source file (XML) /// </summary> /// <param name="url"></param> /// <returns></returns> public MovieEntity Crawl(string url) { MovieEntity movie = new MovieEntity(); TableManager tableMgr = new TableManager(); thumbnailPath = string.Empty; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { #region Get Movie Page Content Stream receiveStream = response.GetResponseStream(); StreamReader readStream = null; if (response.CharacterSet == null) readStream = new StreamReader(receiveStream); else readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); moviePageContent = readStream.ReadToEnd(); response.Close(); readStream.Close(); #endregion movie = PopulateMovieDetails(moviePageContent); bool crawlPosters = true; TableManager tblMgr = new TableManager(); MovieEntity me = tblMgr.GetMovieByUniqueName(movie.UniqueName); if (me != null && !string.IsNullOrEmpty(me.RowKey)) { movie.RowKey = me.RowKey; movie.MovieId = me.MovieId; movie.Popularity = Util.DEFAULT_POPULARITY; movie.Posters = me.Posters; movie.Songs = me.Songs; movie.Trailers = me.Trailers; movie.State = me.State; crawlPosters = false; } PopulateMovieDetails(ref movie, url, crawlPosters); return movie; ////tableMgr.UpdateMovieById(movie); } } catch (Exception ex) { Debug.WriteLine("An error occurred while populating the movie details. Url = " + url + ". Error=" + ex.Message); } return movie; }
private string GetTwitterHandle(string type, string name) { TableManager tbl = new TableManager(); switch (type) { case "movie": MovieEntity movie = tbl.GetMovieByUniqueName(name); return movie.TwitterHandle; case "artist": ArtistEntity artist = tbl.GetArtist(name); return artist.TwitterHandle; case "critics": return string.Empty; } return string.Empty; }
internal static string GetMovieInfo(string name) { name = name.ToLower(); string json = string.Empty; if (!CacheManager.TryGet<string>(CacheConstants.MovieInfoJson + name, out json)) { try { var tableMgr = new TableManager(); // get single movie object form database by its unique name var movie = tableMgr.GetMovieByUniqueName(name); if (movie != null) { MovieInfo movieInfo = new MovieInfo(); movieInfo.movieId = movie.MovieId; movieInfo.Movie = movie; // get reviews for movie by movie id var reviewList = tableMgr.GetReviewsByMovieId(movie.MovieId); // if reviews not null then add review to review list. var userReviews = (reviewList != null) ? reviewList.Select(review => { ReviewerEntity reviewer = tableMgr.GetReviewerById(review.Value.ReviewerId); ReviewEntity objReview = review.Value as ReviewEntity; objReview.ReviewerName = reviewer.ReviewerName; objReview.CriticsRating = objReview.SystemRating == 0 ? "" : (objReview.SystemRating == -1 ? 0 : 100).ToString(); //objReview.OutLink = reviewer.ReviewerImage; return objReview; }) : Enumerable.Empty<ReviewEntity>(); //add reviewlist to movieinfo reviews movieInfo.MovieReviews = userReviews.ToList(); // serialize movie object and return. json = jsonSerializer.Value.Serialize(movieInfo); } else { // if movie not found then return empty string json = string.Empty; } CacheManager.Add<string>(CacheConstants.MovieInfoJson + name, json); } catch (Exception ex) { // if any error occured then return User friendly message with system error message // use jsonError here because more custumizable json = jsonSerializer.Value.Serialize( new { Status = "Error", UserMessage = "Unable to find " + name + " movie.", ActualError = ex.Message }); } } return json; }
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); }
// get : api/MovieInfo?q={movieId} protected override string ProcessRequest() { JavaScriptSerializer json = new JavaScriptSerializer(); try { var tableMgr = new TableManager(); MovieInfo movieInfo = new MovieInfo(); // get query string parameters var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query); if (string.IsNullOrEmpty(qpParams["q"])) { throw new ArgumentException(Constants.API_EXC_MOVIE_NAME_NOT_EXIST); } string name = qpParams["q"].ToString(); // get single movie object form database by its uinque name var movie = tableMgr.GetMovieByUniqueName(name); if (movie != null) { List<ReviewEntity> userReviews = new List<ReviewEntity>(); movieInfo.movieId = movie.MovieId; // get reviews for movie by movie id var reviewList = tableMgr.GetReviewsByMovieId(movie.MovieId); if (reviewList != null) { // if reviews not null then add review to review list. foreach (var review in reviewList) { ReviewerEntity reviewer = tableMgr.GetReviewerById(review.Value.ReviewerId); ReviewEntity objReview = review.Value as ReviewEntity; objReview.Affiliation = reviewer.Affilation; objReview.ReviewerName = reviewer.ReviewerName; objReview.OutLink = reviewer.ReviewerImage; userReviews.Add(objReview); } } //add reviewlist to movieinfo reviews movieInfo.MovieReviews = userReviews; // serialize movie object and return. return json.Serialize(movieInfo); } else { // if movie not found then return empty string return string.Empty; } } catch (Exception ex) { // if any error occured then return User friendly message with system error message return json.Serialize(new { Status = "Error", UserMessage = Constants.UM_WHILE_GETTING_MOVIE, ActualError = ex.Message }); } }
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); }