コード例 #1
0
        public static void AddToImagesFile(string showDirectoryPath, Image image, string imageFilePath)
        {
            ValidationUtility.ThrowIfNullOrEmpty(showDirectoryPath, "showDirectoryPath");
            ValidationUtility.ThrowIfNullOrEmpty(image, "image");
            ValidationUtility.ThrowIfNullOrEmpty(imageFilePath, "imageFilePath");

            DirectoryInfo showDirectory = new DirectoryInfo(showDirectoryPath);

            if (showDirectory.Exists)
            {
                XmlDocument doc            = new XmlDocument();
                XmlNode     imagesNode     = null;
                string      imagesFilePath = string.Concat(showDirectory.FullName, "\\Images.xml");
                FileInfo    imagesFile     = new FileInfo(imagesFilePath);

                if (!imagesFile.Exists)
                {
                    XmlNode rootNode = doc.AddNode("Root");
                    imagesNode = rootNode.AddNode("Images");
                }
                else
                {
                    doc.Load(imagesFilePath);
                    imagesNode = doc.SelectSingleNode("//Root/Images");
                    if (imagesNode == null)
                    {
                        imagesNode = doc.SelectSingleNode("//Root").AddNode("Images");
                    }
                }

                XmlNode imageNode = imagesNode.AddNode("Image");
                imageNode.AddNode("ID", image.ID.ToString());
                imageNode.AddNode("Path", imageFilePath);

                doc.Save(imagesFile.FullName);
            }
            else
            {
                throw new DirectoryNotFoundException(string.Format("Directory {0} was not found.", showDirectoryPath));
            }
        }
コード例 #2
0
        public void CreateFiles(EntityBase entity, bool overwrite, UserConfiguration configuration)
        {
            Episode       episode           = (Episode)entity;
            DirectoryInfo seasonDirectory   = new DirectoryInfo(episode.Parent.Path);
            DirectoryInfo metadataDirectory = new DirectoryInfo(System.IO.Path.Combine(seasonDirectory.FullName, "metadata"));

            if (seasonDirectory.Exists)
            {
                XmlDocument doc              = new XmlDocument();
                string      episodeName      = this.GetIdentifierAndName(episode, true, true);
                string      episodeImageName = string.Concat(episodeName, ".jpg");
                string      episodeXmlName   = string.Concat(episodeName, ".xml");
                string      episodeFilePath  = System.IO.Path.Combine(metadataDirectory.FullName, episodeXmlName);

                if (overwrite && File.Exists(episodeFilePath))
                {
                    File.Delete(episodeFilePath);
                }
                FileInfo episodeFile = new FileInfo(episodeFilePath);
                XmlNode  rootNode    = null;

                if (!episodeFile.Exists)
                {
                    Directory.CreateDirectory(episodeFile.DirectoryName);
                    rootNode = doc.AddNode("Item");
                }
                else
                {
                    doc.Load(episodeFilePath);
                    rootNode = doc.SelectSingleNode("//Item");
                }

                // Download the episode thumbnail image for the episode if it doesn't already exists.
                string imageFilePath = System.IO.Path.Combine(metadataDirectory.FullName, episodeImageName);
                if (!File.Exists(imageFilePath))
                {
                    Image thumbnail = this.GetThumbnailImage(episode);
                    if (thumbnail != null && !string.IsNullOrEmpty(thumbnail.URL))
                    {
                        TraceManager.TraceFormat("Downloading image {0} to {1}", thumbnail.URL, imageFilePath);
                        EpisodeService.DownloadImage(thumbnail.URL, imageFilePath);
                    }
                    else
                    {
                        TraceManager.Trace(string.Format("Unable to find thumbnail image for {0}", episode.Name), TraceTypes.Error);
                    }
                }

                // Rename the file if necessary
                string          currentEpisodeName = System.IO.Path.GetFileNameWithoutExtension(episode.Path);
                string          extension          = System.IO.Path.GetExtension(episode.Path);
                string          newPath            = string.Concat(System.IO.Path.Combine(seasonDirectory.FullName, episodeName), extension);
                MatchCollection matches            = Regex.Matches(currentEpisodeName, ShowService.SeasonEpisodeRegex, RegexOptions.IgnoreCase);

                if (currentEpisodeName != episodeName && matches.Count == 1)
                {
                    TraceManager.Trace(string.Format("Renaming {0} to {1}", episode.Path, newPath), TraceTypes.OperationStarted);
                    File.Move(episode.Path, newPath);
                }
                else if (matches.Count > 1)
                {
                    TraceManager.Trace(string.Format("Skipping renaming \"{0}\" to \"{1}\" because there were ({2}) season/episode numbers in the filename.", currentEpisodeName, episodeName, matches.Count.ToString()), TraceVerbosity.Minimal);
                }

                rootNode.AddNode("ID", episode.EpisodeNumber.ToString());
                rootNode.AddNode("EpisodeID", episode.ID.ToString());
                rootNode.AddNode("EpisodeName", episode.Name);
                rootNode.AddNode("EpisodeNumber", episode.EpisodeNumber.ToString());
                rootNode.AddNode("FirstAired", episode.Created.ToString("yyyy-MM-dd"));
                rootNode.AddNode("Overview", episode.Description);
                rootNode.AddNode("DVD_chapter", EpisodeService.WriteIntValue(episode.DVD_Chapter));
                rootNode.AddNode("DVD_discid", EpisodeService.WriteIntValue(episode.DVD_DiscID));
                rootNode.AddNode("DVD_episodenumber", EpisodeService.WriteDoubleValue(episode.DVD_EpisodeNumber));
                rootNode.AddNode("DVD_season", EpisodeService.WriteIntValue(episode.DVD_SeasonNumber));
                rootNode.AddNode("Director", episode.Director);
                rootNode.AddNode("GuestStars", string.Concat("|", string.Join("|", episode.GuestStars), "|"));
                rootNode.AddNode("IMDB_ID", episode.IMDB_ID);
                rootNode.AddNode("Language", episode.Language);
                rootNode.AddNode("ProductionCode", EpisodeService.WriteIntValue(episode.ProductionCode));
                rootNode.AddNode("Rating", EpisodeService.WriteDoubleValue(episode.Rating));
                rootNode.AddNode("Writer", episode.Writer);
                rootNode.AddNode("SeasonNumber", EpisodeService.WriteIntValue(episode.SeasonNumber));
                rootNode.AddNode("absolute_number");
                rootNode.AddNode("seasonid", EpisodeService.WriteIntValue(episode.SeasonID));
                rootNode.AddNode("seriesid", EpisodeService.WriteIntValue(episode.SeriesID));
                rootNode.AddNode("filename", string.Concat("/", episodeImageName));

                doc.Save(episodeFilePath);
            }
            else
            {
                throw new DirectoryNotFoundException(string.Format("Directory {0} was not found.", seasonDirectory.FullName));
            }
        }
コード例 #3
0
        private static XmlDocument GenerateXMLDocument(List <XfaModel> modelList)
        {
            var xmlDocument = new XmlDocument();

            foreach (var model in modelList.OrderBy(c => c.FieldName))
            {
                var currentNodeStructure = "";
                var keyWithoutSubform    = new Regex(XfaRegex.TEXT_WITHOUT_SUBFORM).Replace(model.FieldName, "");
                var nodeLevels           = keyWithoutSubform.Split('.');

                for (var i = 0; i < nodeLevels.Length; i++)
                {
                    var innerText = "";
                    var nodeText  = GetNodeText(nodeLevels[i]);
                    var nodeIndex = GetNodeIndex(nodeLevels[i]);

                    if (i == nodeLevels.Length - 1)
                    {
                        innerText = model.Value;
                    }

                    var isEmptyStructure = string.IsNullOrWhiteSpace(currentNodeStructure);

                    var nodeParents = isEmptyStructure ?
                                      xmlDocument.SelectNodes($"./{ nodeText }").ToEnumerable().ToList() :
                                      xmlDocument.SelectNodes(currentNodeStructure).ToEnumerable().ToList();

                    currentNodeStructure = isEmptyStructure ?
                                           $"./{ nodeText }" :
                                           $"{ currentNodeStructure }/{ nodeText }";

                    var nodeChilds = xmlDocument.SelectNodes(currentNodeStructure).ToEnumerable();

                    if (nodeParents.Count > 0)
                    {
                        XmlNode currentNode   = null;
                        var     haveSameLevel = nodeChilds.Any(prop => prop.Name.Equals(nodeText) &&
                                                               prop.Attributes["index"].Value.Equals(nodeIndex) &&
                                                               keyWithoutSubform.Contains(prop.GetFullPath(true)));

                        if (haveSameLevel && (
                                (nodeParents.Count > 1 && nodeParents.Last().SelectNodes($"./{  nodeText }").Count > 0) ||
                                (nodeParents.Count == 1)
                                ))
                        {
                            continue;
                        }

                        if (nodeChilds.Count() > 0)
                        {
                            currentNode = nodeChilds.FirstOrDefault(n => keyWithoutSubform.Contains(n.GetFullPath(true)) && n.Name.Contains(nodeText));
                        }

                        if (currentNode == null)
                        {
                            currentNode = nodeParents.FirstOrDefault(n => keyWithoutSubform.Contains(n.GetFullPath(true)));
                        }

                        currentNode?.AddNode(xmlDocument, nodeText, nodeIndex, innerText);
                    }
                    else
                    {
                        xmlDocument.AddNode(nodeText, nodeIndex, innerText);
                    }
                }
            }

            return(xmlDocument);
        }
コード例 #4
0
        public void CreateFiles(EntityBase entity, bool overwrite, UserConfiguration configuration)
        {
            Show          show      = (Show)entity;
            DirectoryInfo directory = new DirectoryInfo(show.Path);

            if (directory.Exists)
            {
                string filePath = string.Concat(directory.FullName, "\\series.xml");
                if (File.Exists(filePath))
                {
                    if (overwrite)
                    {
                        File.Delete(filePath);
                    }
                    else
                    {
                        return;
                    }
                }

                XmlDocument doc      = new XmlDocument();
                XmlNode     rootNode = doc.AddNode("Series");
                rootNode.AddNode("id", show.ID.ToString());
                rootNode.AddNode("Actors", string.Concat("|", string.Join("|", show.Actors), "|"));
                rootNode.AddNode("ContentRating", show.ContentRating);
                rootNode.AddNode("FirstAired", show.Created.ToString("yyyy-MM-dd"));
                rootNode.AddNode("Genre", string.Concat("|", string.Join("|", show.Genres), "|"));
                rootNode.AddNode("IMDbId", show.IMDB_ID);
                rootNode.AddNode("IMDB_ID", show.IMDB_ID);
                rootNode.AddNode("Overview", show.Description);
                rootNode.AddNode("Network", show.Network);
                rootNode.AddNode("Rating", show.Rating);
                rootNode.AddNode("Runtime", show.Runtime.ToString());
                rootNode.AddNode("SeriesName", show.Name);
                rootNode.AddNode("Status", show.Status);

                // Save the file
                doc.Save(filePath);

                // Download banner images
                string bannerFilePath = System.IO.Path.Combine(show.Path, "banner.jpg");
                if (!File.Exists(bannerFilePath))
                {
                    Library.Entities.Image image = this.GetBannerImage(show);
                    if (image != null && !string.IsNullOrWhiteSpace(image.URL))
                    {
                        EpisodeService.DownloadImage(image.URL, bannerFilePath);
                    }
                    else
                    {
                        TraceManager.TraceFormat("Unable to find a suitable banner image for {0}.", show.Name);
                    }
                }

                // Download poster image
                string posterFile = System.IO.Path.Combine(show.Path, "folder.jpg");
                if (!File.Exists(posterFile))
                {
                    Image poster = show.Images.Where((i) => i.MappedType == ImageType.Poster).OrderByDescending((i) => i.Height).ToList().FirstOrDefault();
                    if (poster != null)
                    {
                        TraceManager.Trace("Downloading poster image ...", TraceTypes.OperationStarted);
                        EpisodeService.DownloadImage(poster.URL, posterFile);
                    }
                    else
                    {
                        TraceManager.Trace(string.Format("Unable to find a poster file for {0}.", show.Name), TraceTypes.Error);
                    }
                }

                foreach (Season season in show.Seasons)
                {
                    if (!string.IsNullOrEmpty(season.Path))
                    {
                        new SeasonService().CreateFiles(season, overwrite, configuration);
                    }
                }
            }
            else
            {
                throw new DirectoryNotFoundException(string.Format("Directory {0} was not found.", directory.FullName));
            }
        }
コード例 #5
0
        public void CreateFiles(EntityBase entity, bool overwrite, UserConfiguration configuration)
        {
            Movie         movie     = (Movie)entity;
            DirectoryInfo directory = new DirectoryInfo(movie.Path);

            if (directory.Exists)
            {
                // Rename
                string movieNameFormat   = (!string.IsNullOrWhiteSpace(configuration.MovieNameFormat)) ? configuration.MovieNameFormat : "{NAME} ({YEAR})";
                string renamedFolderName = movieNameFormat.Replace("{YEAR}", movie.Created.Year.ToString()).Replace("{NAME}", movie.Name);
                renamedFolderName = renamedFolderName.ReplaceInvalidPathCharacters(string.Empty);
                if (System.IO.Path.GetFileName(movie.Path) != renamedFolderName)
                {
                    string renamedFullPath = System.IO.Path.Combine(directory.Parent.FullName, renamedFolderName);
                    TraceManager.Trace(string.Format("Renaming {0} to {1}.", movie.Path, renamedFullPath), TraceVerbosity.Minimal, TraceTypes.OperationCompleted);
                    try {
                        directory.MoveTo(renamedFullPath);
                    } catch (Exception ex) {
                        TraceManager.Trace(string.Format("Unable to move file {0} to {1}. Exception: {2}", directory.FullName, renamedFullPath, ex.Message), TraceTypes.Error);
                    }
                    movie.Path = renamedFullPath;
                }

                // Create the mymovies.xml file
                string filePath = string.Concat(directory.FullName, "\\mymovies.xml");
                if (File.Exists(filePath))
                {
                    if (overwrite)
                    {
                        File.Delete(filePath);
                    }
                    else
                    {
                        return;
                    }
                }

                XmlDocument doc      = new XmlDocument();
                XmlNode     rootNode = doc.AddNode("Title");
                rootNode.AddNode("LocalTitle", movie.Name);
                rootNode.AddNode("OriginalTitle", movie.Name);
                rootNode.AddNode("SortTitle", movie.Name);
                rootNode.AddNode("ForcedTitle");
                rootNode.AddNode("IMDBrating", movie.IMDBRating.ToString("F1"));
                rootNode.AddNode("ProductionYear", movie.Created.Year.ToString());
                rootNode.AddNode("MPAARating", movie.MPAARating.ToUpperInvariant());
                rootNode.AddNode("Added");
                rootNode.AddNode("IMDbId", movie.IMDBIdValue.ToString());
                rootNode.AddNode("RunningTime", movie.Runtime.ToString());
                rootNode.AddNode("TMDbId", movie.ID.ToString());
                rootNode.AddNode("CDUniverseId");

                XmlNode studios = rootNode.AddNode("Studios");
                movie.Studios.ForEach((studio) => studios.AddNode("Studio", studio));
                XmlNode persons = rootNode.AddNode("Persons");
                foreach (Person person in movie.Cast)
                {
                    XmlNode personNode = persons.AddNode("Person");
                    personNode.AddNode("Name", person.Name);
                    personNode.AddNode("Type", person.Job);
                    personNode.AddNode("Role", person.Character);
                }
                XmlNode genres = rootNode.AddNode("Genres");
                movie.Genres.ForEach((genre) => genres.AddNode("Genre", genre));

                rootNode.AddNode("Description", movie.Description);
                rootNode.AddNode("Budget", movie.Budget.ToString());
                rootNode.AddNode("Revenue", movie.Revenue.ToString());

                // Save the file
                doc.Save(filePath);

                // Fetch the poster
                string posterFile = System.IO.Path.Combine(movie.Path, "folder.jpg");
                if (!File.Exists(posterFile))
                {
                    Image poster = movie.Images.Where((i) => i.MappedType == ImageType.Poster).OrderByDescending((i) => i.Height).ToList().FirstOrDefault();
                    this.SetPosterImage(movie, poster);
                }
            }
            else
            {
                throw new DirectoryNotFoundException(string.Format("Directory {0} was not found.", directory.FullName));
            }
        }