public static string GenerateMovieMeterXml(DownloadItem downloadItem, string idType, string value) { var apiProxy = (IMMApi)XmlRpcProxyGen.Create(typeof(IMMApi)); const string imdb = "imdb"; const string search = "search"; var filmDetail = new FilmDetail(); if (idType == imdb) { value = apiProxy.RetrieveByImdb(getSessionKey(), value); } else if (idType == search) { var filmlist = apiProxy.Search(getSessionKey(), value); if (filmlist.Length > 0) { value = filmlist[0].filmId; } else { return string.Empty; } } filmDetail = apiProxy.RetrieveDetails(getSessionKey(), value.ToInt()); var movieMeter = new MovieMeter(); using (var stringWriter = new StringWriterWithEncoding(movieMeter.HtmlEncoding)) { using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter)) { xmlWriter.WriteStartElement("moviemeter"); XWrite.WriteEnclosedElement(xmlWriter, "id", filmDetail.filmId); XWrite.WriteEnclosedElement(xmlWriter, "imdbid", filmDetail.imdb); XWrite.WriteEnclosedElement(xmlWriter, "title", filmDetail.title); XWrite.WriteEnclosedElement(xmlWriter, "year", filmDetail.year); foreach (var actor in filmDetail.actors) { XWrite.WriteEnclosedElement(xmlWriter, "actor", actor.name); } foreach (var genre in filmDetail.genres) { XWrite.WriteEnclosedElement(xmlWriter, "genre", genre); } XWrite.WriteEnclosedElement(xmlWriter, "plot", filmDetail.plot); foreach (var actor in filmDetail.directors) { XWrite.WriteEnclosedElement(xmlWriter, "director", actor.name); } XWrite.WriteEnclosedElement(xmlWriter, "releasedate", filmDetail.dates_cinema[0].date); foreach (var country in filmDetail.countries) { XWrite.WriteEnclosedElement(xmlWriter, "country", country.name, "code", country.iso_3166_1); } XWrite.WriteEnclosedElement(xmlWriter, "countries", filmDetail.countries_text); XWrite.WriteEnclosedElement(xmlWriter, "rating", filmDetail.average); xmlWriter.WriteEndElement(); } return stringWriter.ToString(); } }
public static string GenerateMovieMeterXml(DownloadItem downloadItem, string idType, string value) { var apiProxy = (IMMApi)XmlRpcProxyGen.Create(typeof(IMMApi)); const string imdb = "imdb"; const string search = "search"; var filmDetail = new FilmDetail(); if (idType == imdb) { value = apiProxy.RetrieveByImdb(getSessionKey(), value); } else if (idType == search) { var filmlist = apiProxy.Search(getSessionKey(), value); if (filmlist.Length > 0) { value = filmlist[0].filmId; } else { return(string.Empty); } } filmDetail = apiProxy.RetrieveDetails(getSessionKey(), value.ToInt()); var movieMeter = new MovieMeter(); using (var stringWriter = new StringWriterWithEncoding(movieMeter.HtmlEncoding)) { using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter)) { xmlWriter.WriteStartElement("moviemeter"); XWrite.WriteEnclosedElement(xmlWriter, "id", filmDetail.filmId); XWrite.WriteEnclosedElement(xmlWriter, "imdbid", filmDetail.imdb); XWrite.WriteEnclosedElement(xmlWriter, "title", filmDetail.title); XWrite.WriteEnclosedElement(xmlWriter, "year", filmDetail.year); foreach (var actor in filmDetail.actors) { XWrite.WriteEnclosedElement(xmlWriter, "actor", actor.name); } foreach (var genre in filmDetail.genres) { XWrite.WriteEnclosedElement(xmlWriter, "genre", genre); } XWrite.WriteEnclosedElement(xmlWriter, "plot", filmDetail.plot); foreach (var actor in filmDetail.directors) { XWrite.WriteEnclosedElement(xmlWriter, "director", actor.name); } XWrite.WriteEnclosedElement(xmlWriter, "releasedate", filmDetail.dates_cinema[0].date); foreach (var country in filmDetail.countries) { XWrite.WriteEnclosedElement(xmlWriter, "country", country.name, "code", country.iso_3166_1); } XWrite.WriteEnclosedElement(xmlWriter, "countries", filmDetail.countries_text); XWrite.WriteEnclosedElement(xmlWriter, "rating", filmDetail.average); xmlWriter.WriteEndElement(); } return(stringWriter.ToString()); } }