Exemplo n.º 1
0
        private void ProcessDeleteFile(string pathAndFile, DeleteNfoParams deleteNfoParams)
        {
            try
            {
                XDocument xd = XDocument.Load(pathAndFile);

                if (KodiNfoXml.CheckForMissingInformation(xd, deleteNfoParams))
                {
                    File.Delete(pathAndFile);
                    Log.WriteInformation(string.Format("DELETION of NFO file {0} SUCCEEDED", pathAndFile));
                    App.CountNfoFilesDeleted++;
                }
            }
            catch (Exception x)
            {
                Log.WriteError(string.Format("DELETION of NFO file {0} FAILED", pathAndFile));
                Log.WriteException(x);
                App.CountNfoFilesFailedDeleted++;
            }
        }
Exemplo n.º 2
0
        private void ProcessFile(string pathAndFile)
        {
            string path       = Path.GetDirectoryName(pathAndFile);
            string filename   = Path.GetFileName(pathAndFile);
            string filenameNE = Path.GetFileNameWithoutExtension(pathAndFile);

            string nfoFilename = Path.Combine(path, filenameNE) + ".nfo";
            bool   bExists     = File.Exists(nfoFilename);

            if (bExists && !App.ReplaceExisting)
            {
                Log.WriteInformation(string.Format("FILE {0} already exists. Options is to NOT REPLACE", nfoFilename));
                return;
            }

            int indexLastDot = filename.LastIndexOf('.');

            if (indexLastDot >= 0)
            {
                filename = filename.Replace('.', ':');
                char[] cArray = filename.ToArray();
                cArray[indexLastDot] = '.';
                filename             = new string(cArray);
            }

            var dicFileInfo = string.Format("-{0}-", filename).ItsApplyTagTemplate(string.Format("-{0}-", App.FileFilter), "[[", "]]");

            if (indexLastDot >= 0)
            {
                filename = filename.Replace(':', '.');
            }

            if (dicFileInfo.Count == 0)
            {
                Log.WriteWarning(string.Format("Could not apply tag template to file {0}", filename));
                return;
            }

            string genre = KodiNfoRootTree.Genre ?? string.Empty;
            string title = KodiNfoRootTree.Title ?? string.Empty;
            string year  = KodiNfoRootTree.Year ?? string.Empty;

            foreach (var dict in dicFileInfo)
            {
                if (dict.ContainsKey("genre"))
                {
                    var g = dict["genre"];
                    if (g.Count == 1)
                    {
                        genre = g[0].Replace(':', '.');
                    }
                }
                if (dict.ContainsKey("title"))
                {
                    var t = dict["title"];
                    if (t.Count == 1)
                    {
                        title = t[0].Replace(':', '.');;
                    }
                }
                if (dict.ContainsKey("year"))
                {
                    var y = dict["year"];
                    if (y.Count == 1)
                    {
                        year = y[0].Replace(':', '.');;
                    }
                }
            }

            title = this.CleanTitle(title);

            int iYear = -1;

            if (!int.TryParse(year, out iYear))
            {
                Log.WriteWarning(string.Format("Could not identify year {0} for file {1}", year, pathAndFile));
                return;
            }

            string thumb;
            string plot;
            string rating;

            Actor[]  actor;
            string[] director;
            string[] genres;
            string[] writer;
            string[] producer;

            this.GetAdditional(pathAndFile, title, year, out thumb, out plot, out genres, out actor, out director, out writer, out producer, out rating);

            if (!string.IsNullOrEmpty(genre) && !string.IsNullOrWhiteSpace(genre) &&
                genres.Length == 0)
            {
                genres = new string[] { genre };
            }
            KodiNfoXml knx = new KodiNfoXml(title, title, genres, year, thumb, plot, actor, director, writer, rating, producer);

            try
            {
                knx.ToXDocument().Save(nfoFilename);
                App.CountNfoFilesWritten++;
                Log.WriteInformation(string.Format("CREATION NFO file {0} SUCCEEDED", nfoFilename));
            }
            catch (Exception)
            {
                App.CountNfoFilesFailedWritten++;
                Log.WriteWarning(string.Format("CREATION NFO file {0} FAILED", nfoFilename));
            }
        }