public void Save(TVShow metadata, string folder) { Save( new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement("tvshow", new XElement("title", metadata.Title), new XElement("plot", metadata.Plot), new XElement("premiered", metadata.Premiered?.ToString("yyyy-MM-dd")) )), folder, "tvshow"); if (!string.IsNullOrWhiteSpace(metadata.PosterPathOrUrl)) { var posterMetadataPath = Path.Combine(folder, $"folder{Path.GetExtension(metadata.PosterPathOrUrl)}"); if (Uri.TryCreate(metadata.PosterPathOrUrl, UriKind.Absolute, out var uri) && !uri.IsFile) { var response = HttpClient.GetAsync(uri).Result; using var fileStream = new FileStream(posterMetadataPath, FileMode.CreateNew); response.Content.CopyToAsync(fileStream); } else { File.Copy(metadata.PosterPathOrUrl, posterMetadataPath); } } }
public void Save(TVShow metadata, string folder) { Save( new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement("tvshow", new XElement("title", metadata.Title), new XElement("plot", metadata.Plot), new XElement("premiered", metadata.Premiered?.ToString("yyyy-MM-dd")) )), folder, "tvshow"); metadata.PosterPathOrUrl.Do(posterPathOrUrl => Save(posterPathOrUrl, folder, "folder")); }