コード例 #1
0
        private static void LoadCatalog(string parameters)
        {
            List <EpItem> list     = new List <EpItem>();
            string        itemPath = parameters.ToLower();
            string        dir      = EpItem.GetCatalogPosterDir(itemPath);

            EpItem.CatalogPosterDir = dir;
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            if (File.Exists(itemPath))
            {
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List <EpItem>));
                try
                {
                    using (var sr = new StreamReader(itemPath))
                    {
                        list = serializer.Deserialize(sr) as List <EpItem>;
                    }
                }
                catch { }
            }
            Source         = list;
            CurrentCatalog = itemPath;
        }
コード例 #2
0
        private static void CreatePassportTo(string ToPath)
        {
            if (!Directory.Exists(ToPath))
            {
                return;
            }


            List <string> files = Directory.GetFiles(ToPath, EpItem.p_PassportName, SearchOption.TopDirectoryOnly).ToList();

            if (!files.Any())
            {
                List <string> movies = Directory.GetFiles(ToPath, "*.m4v", SearchOption.TopDirectoryOnly).ToList();
                if (movies.Any())
                {
                    EpItem item = new EpItem(0);
                    item.Name = Path.GetFileName(ToPath);
                    List <string> lines = EpItem.SetToPassport(item);
                    File.WriteAllLines(Path.Combine(ToPath, EpItem.p_PassportName), lines);
                }
            }

            List <string> dirs = Directory.GetDirectories(ToPath).ToList();

            foreach (var item in dirs)
            {
                CreatePassportTo(item);
            }
        }
コード例 #3
0
        private static void DoTempwork2(string passportPath)
        {
            List <string> dirList = Directory.GetDirectories(passportPath).ToList();

            foreach (var dir in dirList)
            {
                DoTempwork2(dir);
            }

            List <string> passportList = Directory.GetFiles(passportPath, EpItem.p_PassportName).ToList();

            foreach (var pass in passportList)
            {
                List <string> passport = new List <string>(File.ReadAllLines(pass));
                if (passport != null)
                {
                    EpItem item    = EpItem.GetFromPassport(passport, passportPath);
                    string dirname = Path.GetDirectoryName(passportPath);
                    string name    = Path.GetFileName(passportPath);
                    if (item.Catalog != "JAV")
                    {
                        if (!name.StartsWith("["))
                        {
                            string newdirname = Path.Combine(dirname, $"[{item.Country}] {name}");
                            Directory.Move(passportPath, newdirname);
                        }
                    }
                }
                return;
            }
        }
コード例 #4
0
        internal static void UpdateItem(EpItem item)
        {
            if (!Directory.Exists(Path.GetDirectoryName(item.ItemPath)))
            {
                return;
            }
            List <string> passportData = EpItem.SetToPassport(item);

            File.WriteAllLines(item.ItemPath, passportData);
        }
コード例 #5
0
        internal void UpdateFrom(EpItem item)
        {
            this.ItemPath  = item.ItemPath;
            this.Name      = item.Name;
            this.Serie     = item.Serie;
            this.Catalog   = item.Catalog;
            this.LastEdit  = item.LastEdit;
            this.Country   = item.Country;
            this.Year      = item.Year;
            this.Month     = item.Month;
            this.Day       = item.Day;
            this.AltTitle  = item.AltTitle;
            this.Rated     = item.Rated;
            this.XRated    = item.XRated;
            this.Kind      = item.Kind;
            this.Type      = item.Type;
            this.Stage     = item.Stage;
            this.Variant   = item.Variant;
            this.Brand     = item.Brand;
            this.Star      = item.Star;
            this.MyDescr   = item.MyDescr;
            this.Director  = item.Director;
            this.Studio    = item.Studio;
            this.IMDB      = item.IMDB;
            this.LastCheck = item.LastCheck;

            this.PersonName = item.PersonName;
            this.PersonAge  = item.PersonAge;
            this.PersonSex  = item.PersonSex;
            this.PersonType = item.PersonType;
            this.PersonKind = item.PersonKind;
            this.Size       = item.Size;
            this.Length     = item.Length;

            this.SourceFolderExist = item.SourceFolderExist;

            this.Comments.Clear();
            this.Comments.AddRange(item.Comments);
        }
コード例 #6
0
 internal static void SaveCatalog()
 {
     if (string.IsNullOrEmpty(CurrentCatalog))
     {
         return;
     }
     if (File.Exists(CurrentCatalog))
     {
         File.Copy(CurrentCatalog, Path.ChangeExtension(CurrentCatalog, "bak"), true);
     }
     System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List <EpItem>));
     using (var writer = new StreamWriter(CurrentCatalog))
     {
         serializer.Serialize(writer, Source);
     }
     foreach (EpItem item in Source)
     {
         if (Directory.Exists(item.ItemDirectory))
         {
             List <string> lines = EpItem.SetToPassport(item);
             File.WriteAllLines(Path.Combine(item.ItemDirectory, EpItem.p_PassportName), lines);
         }
     }
 }
コード例 #7
0
        internal static EpItem GetFromPassport(List <string> passport, string path)
        {
            EpItem result = new EpItem(1);

            result.ItemPath = path;
            bool isComments = false;

            foreach (var line in passport)
            {
                string term = line.Trim();



                if (term.StartsWith(p_COMMENTS_BEGIN))
                {
                    term = term.Replace(p_COMMENTS_BEGIN, string.Empty);
                    term = term.Replace(p_COMMENTS_END, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Comments.Add(term);
                    }
                    isComments = true;
                }
                else if (isComments)
                {
                    if (term.Contains(p_COMMENTS_END))
                    {
                        term       = term.Replace(p_COMMENTS_END, string.Empty);
                        isComments = false;
                    }
                    result.Comments.Add(term);
                }
                else if (term.StartsWith(p_GID))
                {
                    term = term.Replace(p_GID, string.Empty);
                    Guid temp;
                    if (Guid.TryParse(term.Trim(), out temp))
                    {
                        result.GID = temp;
                    }
                }
                else if (term.StartsWith(p_Name))
                {
                    term = term.Replace(p_Name, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Name = term;
                    }
                }
                else if (term.StartsWith(p_Catalog))
                {
                    term = term.Replace(p_Catalog, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Catalog = term;
                    }
                }
                else if (term.StartsWith(p_Serie))
                {
                    term = term.Replace(p_Serie, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Serie = term;
                    }
                }
                else if (term.StartsWith(p_LastEdit))
                {
                    term = term.Replace(p_LastEdit, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.LastEdit = Convert.ToInt32(term);
                    }
                }
                else if (term.StartsWith(p_AltTitle))
                {
                    term = term.Replace(p_AltTitle, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.AltTitle = term;
                    }
                }
                else if (term.StartsWith(p_Country))
                {
                    term = term.Replace(p_Country, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Country = term;
                    }
                }
                else if (term.StartsWith(p_Year))
                {
                    term = term.Replace(p_Year, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        if (term.Length > 4)
                        {
                            term = term.Substring(0, 4);
                        }
                        result.Year = Convert.ToInt32(term);
                    }
                }
                else if (term.StartsWith(p_Month))
                {
                    term = term.Replace(p_Month, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        if (term.Length > 2)
                        {
                            term = term.Substring(0, 2);
                        }
                        result.Month = Convert.ToInt32(term);
                    }
                }
                else if (term.StartsWith(p_Day))
                {
                    term = term.Replace(p_Day, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        if (term.Length > 2)
                        {
                            term = term.Substring(0, 2);
                        }
                        result.Day = Convert.ToInt32(term);
                    }
                }
                else if (term.StartsWith(p_Rated))
                {
                    term = term.Replace(p_Rated, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Rated = term;
                    }
                }
                else if (term.StartsWith(p_XRated))
                {
                    term = term.Replace(p_XRated, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.XRated = term;
                    }
                }
                else if (term.StartsWith(p_Kind))
                {
                    term = term.Replace(p_Kind, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Kind = term;
                    }
                }
                else if (term.StartsWith(p_Stage))
                {
                    term = term.Replace(p_Stage, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Stage = term;
                    }
                }
                else if (term.StartsWith(p_Variant))
                {
                    term = term.Replace(p_Variant, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Variant = term;
                    }
                }
                else if (term.StartsWith(p_Type))
                {
                    term = term.Replace(p_Type, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Type = term;
                    }
                }
                else if (term.StartsWith(p_Brand))
                {
                    term = term.Replace(p_Brand, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Brand = term;
                    }
                }
                else if (term.StartsWith(p_Star))
                {
                    term = term.Replace(p_Star, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Star = term;
                    }
                }
                else if (term.StartsWith(p_MyDescr))
                {
                    term = term.Replace(p_MyDescr, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.MyDescr = term;
                    }
                }
                else if (term.StartsWith(p_Director))
                {
                    term = term.Replace(p_Director, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Director = term;
                    }
                }
                else if (term.StartsWith(p_Studio))
                {
                    term = term.Replace(p_Studio, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Studio = term;
                    }
                }
                else if (term.StartsWith(p_IMDB))
                {
                    term = term.Replace(p_IMDB, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.IMDB = term;
                    }
                }

                else if (term.StartsWith(p_PersonName))
                {
                    term = term.Replace(p_PersonName, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.PersonName = term;
                    }
                }
                else if (term.StartsWith(p_PersonAge))
                {
                    term = term.Replace(p_PersonAge, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.PersonAge = term;
                    }
                }
                else if (term.StartsWith(p_PersonSex))
                {
                    term = term.Replace(p_PersonSex, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.PersonSex = term;
                    }
                }
                else if (term.StartsWith(p_PersonType))
                {
                    term = term.Replace(p_PersonType, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.PersonType = term;
                    }
                }
                else if (term.StartsWith(p_PersonKind))
                {
                    term = term.Replace(p_PersonKind, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.PersonKind = term;
                    }
                }
                else if (term.StartsWith(p_Size))
                {
                    term = term.Replace(p_Size, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        int size;
                        if (int.TryParse(term, out size))
                        {
                            result.Size = size;
                        }
                    }
                }
                else if (term.StartsWith(p_Length))
                {
                    term = term.Replace(p_Length, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.Length = term;
                    }
                }

                else if (term.StartsWith(p_LastCheck))
                {
                    term = term.Replace(p_LastCheck, string.Empty);
                    if (!string.IsNullOrWhiteSpace(term))
                    {
                        result.LastCheck = term;
                    }
                }
            }
            return(result);
        }
コード例 #8
0
        // PASSPORT LOAD-SAVE
        internal static List <string> SetToPassport(EpItem item)
        {
            List <string> result = new List <string>();

            result.Add(p_GID + item.GID.ToString());
            result.Add(p_Name + item.Name);
            result.Add(p_Catalog + item.Catalog);
            result.Add($"{p_LastEdit}{item.LastEdit}");

            if (!string.IsNullOrEmpty(item.Serie))
            {
                result.Add(p_Serie + item.Serie);
            }
            if (!string.IsNullOrEmpty(item.AltTitle))
            {
                result.Add(p_AltTitle + item.AltTitle);
            }
            if (!string.IsNullOrEmpty(item.Country))
            {
                result.Add(p_Country + item.Country);
            }
            if (item.Year > 0)
            {
                result.Add(p_Year + (item.Year > 0 ? item.Year.ToString() : string.Empty));
            }
            if (item.Month > 0)
            {
                result.Add(p_Month + (item.Month > 0 ? item.Month.ToString() : string.Empty));
            }
            if (item.Day > 0)
            {
                result.Add(p_Day + (item.Day > 0 ? item.Day.ToString() : string.Empty));
            }
            if (!string.IsNullOrEmpty(item.Rated))
            {
                result.Add(p_Rated + item.Rated);
            }
            if (!string.IsNullOrEmpty(item.XRated))
            {
                result.Add(p_XRated + item.XRated);
            }
            if (!string.IsNullOrEmpty(item.Kind))
            {
                result.Add(p_Kind + item.Kind);
            }
            if (!string.IsNullOrEmpty(item.Type))
            {
                result.Add(p_Type + item.Type);
            }
            if (!string.IsNullOrEmpty(item.Brand))
            {
                result.Add(p_Brand + item.Brand);
            }
            if (!string.IsNullOrEmpty(item.Star))
            {
                result.Add(p_Star + item.Star);
            }
            if (!string.IsNullOrEmpty(item.Stage))
            {
                result.Add(p_Stage + item.Stage);
            }
            if (!string.IsNullOrEmpty(item.Variant))
            {
                result.Add(p_Variant + item.Variant);
            }
            if (!string.IsNullOrEmpty(item.MyDescr))
            {
                result.Add(p_MyDescr + item.MyDescr);
            }
            if (!string.IsNullOrEmpty(item.Director))
            {
                result.Add(p_Director + item.Director);
            }
            if (!string.IsNullOrEmpty(item.Studio))
            {
                result.Add(p_Studio + item.Studio);
            }
            if (!string.IsNullOrEmpty(item.IMDB))
            {
                result.Add(p_IMDB + item.IMDB);
            }

            if (!string.IsNullOrEmpty(item.PersonName))
            {
                result.Add(p_PersonName + item.PersonName);
            }
            if (!string.IsNullOrEmpty(item.PersonAge))
            {
                result.Add(p_PersonAge + item.PersonAge);
            }
            if (!string.IsNullOrEmpty(item.PersonSex))
            {
                result.Add(p_PersonSex + item.PersonSex);
            }
            if (!string.IsNullOrEmpty(item.PersonType))
            {
                result.Add(p_PersonType + item.PersonType);
            }
            if (!string.IsNullOrEmpty(item.PersonKind))
            {
                result.Add(p_PersonKind + item.PersonKind);
            }
            if (!string.IsNullOrEmpty(item.LastCheck))
            {
                result.Add(p_LastCheck + item.LastCheck);
            }

            if (item.Size > 0)
            {
                result.Add(p_Size + item.Size.ToString());
            }
            if (!string.IsNullOrEmpty(item.Length))
            {
                result.Add(p_Length + item.Length);
            }

            if (item.Comments.Count == 1)
            {
                if (!string.IsNullOrEmpty(item.Comments.First()))
                {
                    result.Add(p_COMMENTS_BEGIN + item.Comments.First() + p_COMMENTS_END);
                }
            }
            else if (item.Comments.Count > 0)
            {
                List <string> ttt = new List <string>();
                ttt.AddRange(item.Comments);

                ttt[0] = p_COMMENTS_BEGIN + item.Comments.First();

                ttt[ttt.Count - 1] = item.Comments.Last() + p_COMMENTS_END;
                result.AddRange(ttt);
            }

            return(result);
        }
コード例 #9
0
        private static void CreateUpdateFromPassport(string passportPath)
        {
            List <string> passport = new List <string>(File.ReadAllLines(passportPath));

            if (passport != null)
            {
                EpItem item = EpItem.GetFromPassport(passport, passportPath);
                if (item.GID == null || Guid.Empty.Equals(item.GID))
                {
                    item.GID = Guid.NewGuid();
                }

                string dirname = Path.GetDirectoryName(passportPath);
                if (string.IsNullOrEmpty(item.Name))
                {
                    if (passportPath.Contains(@"/HEN/"))
                    {
                        item.Catalog = "HEN";
                    }
                    else if (passportPath.Contains(@"/MOV/"))
                    {
                        item.Catalog = "MOV";
                    }
                    else if (passportPath.Contains(@"/AMA/"))
                    {
                        item.Catalog = "AMA";
                    }
                    else if (passportPath.Contains(@"/JAV/"))
                    {
                        item.Catalog = "JAV";
                    }
                    else if (passportPath.Contains(@"/WEB/"))
                    {
                        item.Catalog = "WEB";
                    }
                    else if (passportPath.Contains(@"/PTD/"))
                    {
                        item.Catalog = "PTD";
                    }
                    else if (passportPath.Contains(@"/PRS/"))
                    {
                        item.Catalog = "PRS";
                    }
                    else if (passportPath.Contains(@"/COM/"))
                    {
                        item.Catalog = "COM";
                    }


                    item.Name = UppercaseWords(Path.GetFileName(dirname));
                    if (string.IsNullOrEmpty(item.Director) && item.Catalog == "HEN" && item.Kind == "Hentai Artist")
                    {
                        string director = Directory.GetParent(dirname).Name;
                        item.Director = UppercaseWords(director);
                    }
                    else if (string.IsNullOrEmpty(item.Studio) && item.Catalog == "HEN" && item.Kind == "GameCG")
                    {
                        string studio = Directory.GetParent(dirname).Name;
                        item.Studio = studio.ToUpper();
                    }



                    //string sounddir = Path.Combine(dirname, "SOUND");
                    //if (Directory.Exists(sounddir))
                    //{
                    //    var filesmp3 = Directory.GetFiles(sounddir, "*.mp3").ToList();
                    //    var i = 0;
                    //    foreach (string fn in filesmp3)
                    //    {
                    //        i++;
                    //        string filename = Path.GetFileName(fn);
                    //        if (filename.Length < 45)//string.len"0001.a9da9cd436174c35aa1a0fa0d33636b0.mp3")
                    //        {
                    //            string gid = Guid.NewGuid().ToString();
                    //            string newpath = Path.GetFileNameWithoutExtension(filename);
                    //            newpath = $"{newpath}.{gid}.mp3";
                    //            newpath = Path.Combine(sounddir, newpath);
                    //            File.Move(fn, newpath);
                    //        }
                    //    }
                    //}
                    string eventsdir = Path.Combine(dirname, "EVENTS");
                    if (!Directory.Exists(eventsdir))
                    {
                        Directory.CreateDirectory(eventsdir);
                        var filesjpg = Directory.GetFiles(dirname, "*.jpg").ToList();
                        var i        = 0;
                        foreach (string fn in filesjpg)
                        {
                            i++;
                            string filename = Path.GetFileName(fn);
                            if (filename.Length > 100)
                            {
                                filename = filename.Substring(0, 100) + i.ToString() + ".jpg";
                            }
                            string newpath = Path.Combine(eventsdir, filename);
                            File.Move(fn, newpath);
                        }
                        var filespng = Directory.GetFiles(dirname, "*.png").ToList();
                        i = 0;
                        foreach (string fn in filespng)
                        {
                            i++;
                            string filename = Path.GetFileName(fn);
                            if (filename.Length > 100)
                            {
                                filename = filename.Substring(0, 100) + i.ToString() + ".png";
                            }
                            string newpath = Path.Combine(eventsdir, filename);
                            File.Move(fn, newpath);
                        }
                        List <String> cpslist = new List <string>();
                        cpslist.Add(Path.Combine(eventsdir, "1.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "01.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "001.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "0001.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "00001.jpg"));
                        foreach (var newcaption in cpslist)
                        {
                            if (File.Exists(newcaption))
                            {
                                File.Copy(newcaption, Path.Combine(dirname, "POSTER.jpg"), false);
                                break;
                            }
                        }
                    }
                }
                else
                {
                }



                item.SourceFolderExist = true;
                // size
                var  filesmp3 = Directory.GetFiles(dirname, "*.m4v").ToList();
                long s        = 0;
                int  d        = 1000000;
                foreach (string fn in filesmp3)
                {
                    try
                    {
                        FileInfo fi = new FileInfo(fn);
                        s += fi.Length;
                    }
                    catch (Exception)
                    {
                        // path too long exception
                        //throw;
                    }
                }
                if (s > 0)
                {
                    item.Size = Convert.ToInt32((s / d));
                }

                //poster
                bool copyPoster        = false;
                bool reversecopyPoster = false;
                var  existingItem      = Source.Where(x => x.GID == item.GID).FirstOrDefault();

                string dirPoster     = EpItem.GetCatalogPosterDir(CurrentCatalog);
                string newPostername = Path.Combine(dirPoster, $"{item.GID}.jpg");

                if (existingItem == null)
                {
                    if (string.IsNullOrEmpty(item.Name))
                    {
                        string   name     = Path.GetFileName(Path.GetDirectoryName(passportPath)).ToLower();
                        TextInfo cultInfo = new CultureInfo("en-US", false).TextInfo;
                        item.Name = cultInfo.ToTitleCase(name);
                    }
                    Source.Add(item);
                    UpdateItem(item);
                    copyPoster = true;
                }
                else
                {
                    if (existingItem.LastEdit < item.LastEdit)
                    {
                        existingItem.UpdateFrom(item);
                        copyPoster = true;
                    }
                    else
                    {
                        existingItem.Size              = item.Size;
                        existingItem.ItemPath          = item.ItemPath;
                        existingItem.SourceFolderExist = item.SourceFolderExist;
                        copyPoster        = !File.Exists(newPostername);
                        reversecopyPoster = !copyPoster;
                    }
                }
                if (copyPoster)
                {
                    bool posterExist = File.Exists(item.PosterPath);
                    if (posterExist)
                    {
                        try
                        {
                            File.Copy(item.PosterPath, newPostername, true);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else if (reversecopyPoster)
                {
                    bool posterExist = File.Exists(newPostername);
                    if (posterExist)
                    {
                        try
                        {
                            if (!File.Exists(item.PosterPath))
                            {
                                File.Copy(newPostername, item.PosterPath, false);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
コード例 #10
0
        private static void DoTempWork1_OneCountry(string mark, string fromPath, string toPath)
        {
            string Country = mark;
            string Catalog = "MOV";
            string Studio  = string.Empty;
            string Actors  = string.Empty;
            string Serie   = string.Empty;
            int    Year    = 0;


            var files = Directory.GetFiles(fromPath, "*.m4v", SearchOption.TopDirectoryOnly).ToList();

            foreach (var fn in files)
            {
                string source = fn;
                string fnwe   = Path.GetFileName(fn);
                if (fnwe.StartsWith($"[{Country}]"))
                {
                    string newfnwe = $"{Country} {fnwe.Replace($"[{Country}]", string.Empty)}";
                    File.Move(Path.Combine(fromPath, fnwe), Path.Combine(fromPath, newfnwe));
                    fnwe   = newfnwe;
                    source = newfnwe;
                }

                if (fnwe.ToUpper().StartsWith($"{mark} "))
                {
                    string nfm = fnwe.Remove(0, 4);
                    nfm = nfm.Replace(".m4v", string.Empty);
                    nfm = nfm.Trim();
                    bool ok = false;

                    if (fnwe.ToUpper().StartsWith("$"))
                    {
                        Country = string.Empty;
                        Catalog = mark.Replace("$", string.Empty);
                        var items = nfm.Split(' ');
                        if (items[0].Contains("[") && items[0].Contains("]"))
                        {
                            Studio = items[0].Replace("[", string.Empty).Replace("]", string.Empty).Trim();
                        }

                        ok = true;
                    }
                    else
                    {
                        string yearstr = nfm.Substring(0, 4);
                        if (int.TryParse(yearstr, out Year))
                        {
                            if (Year > 1949 && Year < 2025)
                            {
                                nfm = nfm.Remove(0, 4);
                                ok  = true;
                            }
                        }
                    }

                    if (nfm.Contains("{") && nfm.Contains("}"))
                    {
                        int fi = nfm.IndexOf('{') + 1;
                        int si = nfm.IndexOf('}') - 1;
                        Actors = nfm.Substring(fi, si - fi + 1);
                        nfm    = nfm.Replace("{" + Actors + "}", string.Empty).Trim();
                    }

                    if (Catalog == "MOV" && nfm.Contains("[") && nfm.Contains("]"))
                    {
                        int fi = nfm.IndexOf('[') + 1;
                        int si = nfm.IndexOf(']') - 1;
                        Studio = nfm.Substring(fi, si - fi + 1);
                    }

                    if (Catalog == "JAV" && nfm.Contains("[") && nfm.Contains("]"))
                    {
                        Studio = string.Empty;
                        int fi = nfm.IndexOf('[') + 1;
                        int si = nfm.IndexOf(']') - 1;
                        Serie = nfm.Substring(fi, si - fi + 1);
                        nfm   = nfm.Replace("[" + Serie + "]", string.Empty).Trim();
                    }

                    if (ok)
                    {
                        string Name    = nfm.Trim();
                        string newPath = string.Empty;
                        if (Catalog == "MOV")
                        {
                            newPath = Path.Combine(toPath, Catalog, Year.ToString());
                            if (Name.Contains("-"))
                            {
                                while (Char.IsDigit(Name.Last()))
                                {
                                    Name = Name.Remove(Name.Length - 1);
                                }
                                if (Name.Last() == '-')
                                {
                                    Name = Name.Remove(Name.Length - 1);
                                }
                                Name = Name.Trim();
                            }
                        }
                        else if (Catalog == "JAV")
                        {
                            newPath = Path.Combine(toPath, Catalog, Serie);
                        }
                        else
                        {
                            newPath = Path.Combine(toPath, Catalog, Studio);
                        }


                        if (!Directory.Exists(newPath))
                        {
                            Directory.CreateDirectory(newPath);
                        }
                        if (Directory.Exists(newPath))
                        {
                            newPath = Path.Combine(newPath, Name);
                            if (!Directory.Exists(newPath))
                            {
                                Directory.CreateDirectory(newPath);
                                EpItem item = new EpItem(0);
                                item.Name    = Name;
                                item.Catalog = Catalog;
                                item.Country = Country;
                                item.Year    = Year;
                                item.Studio  = Studio;
                                item.Star    = Actors;
                                item.Serie   = Serie;
                                List <string> lines = EpItem.SetToPassport(item);
                                File.WriteAllLines(Path.Combine(newPath, EpItem.p_PassportName), lines);
                            }

                            File.Move(source, Path.Combine(newPath, Name) + ".m4v");
                        }
                    }
                }
            }
        }
コード例 #11
0
        private static void DoFOLDER(string fromPath, string toDir, List <string> parentokens)
        {
            /*
             * $01-Catalog
             * $02-Star
             * $03-Kind
             * $04-Serie
             * $05-Country
             * $06-Year
             * $07-Studio
             * $08-XRated
             * $09-Type
             * $10-Director
             * $11-NOSORT
             *
             * $JAV [JUFE] JUFE-085.m4v
             *
             * $01 JAV $02  $04  $
             * $01 JAV $04  $
             * $01 JAV $!!!JAV Movies!!!
             *
             * * $01 WEB $03 WEBCLIP $08 P $07 $
             *
             * $01 HEN $03 ARTIST COMIX $10 Georges Levis $Coco
             * $01 HEN $03 ARTIST BOARD $10 Zumi $Zumi Art
             * $01 HEN $03 ARTIST PINUP $10 Luis Royo $Luis Royo Art
             * $01 HEN $03 GameCG $07 BLACKRAINBOW $11 SORTED $!!!IMAGE SETS!!!
             *
             * $01 R3D $03 ARTIST 3D $10 Smerinka $!!!IMAGE SETS!!!
             *
             * $01 MGZ $03 ERO MAGAZIN $04 Cancans de Paris $!!!IMAGE SETS!!!
             * $01 MGZ $03 PRN MAGAZIN $04 Silwa - Backdoor Lovers $!!!IMAGE SETS!!!
             *
             * $01 COM $03 COMIX PRINTED $04 Top Model $!!!IMAGE SETS!!!
             *
             *
             * $01 MOD $03 ACTRESS $02 Eva Hedger $!!!IMAGE SETS!!!
             * $01 MOD $03 FASHION $02 Eva Hedger $!!!IMAGE SETS!!!
             * $01 MOD $03 SOFT $02 Eva Hedger $!!!IMAGE SETS!!!
             * $01 MOD $03 HARD $02 Eva Hedger $!!!IMAGE SETS!!!
             *
             */


            List <string> dirs;

            if (parentokens != null)
            {
                dirs = Directory.GetDirectories(fromPath, "*", SearchOption.TopDirectoryOnly).ToList();
            }
            else
            {
                dirs = Directory.GetDirectories(fromPath, "$*", SearchOption.TopDirectoryOnly).ToList();
            }

            foreach (var dir in dirs)
            {
                string        toPath = toDir;
                EpItem        item   = new EpItem(0);
                string        dn     = Path.GetFileName(dir);
                bool          marked = dn.Contains("$");
                List <string> tokens = dn.Split('$').ToList();
                if (!marked)
                {
                    item.Name = dn;
                    tokens    = new List <string>();
                }
                if (parentokens != null)
                {
                    tokens.AddRange(parentokens);
                }

                if (tokens.Last() == "!!!IMAGE SETS!!!")
                {
                    var files = Directory.GetFiles(dir, "*.pdf", SearchOption.TopDirectoryOnly).ToList();
                    files.AddRange(Directory.GetFiles(dir, "*.djvu", SearchOption.TopDirectoryOnly).ToList());
                    foreach (var f in files)
                    {
                        string pdfdir = Path.Combine(dir, Path.GetFileNameWithoutExtension(f));
                        Directory.CreateDirectory(pdfdir);
                        File.Move(f, Path.Combine(pdfdir, Path.GetFileName(f)));
                    }

                    tokens.Remove(tokens.Last());
                    DoFOLDER(dir, toDir, tokens);
                    Directory.Delete(dir);
                    continue;
                }
                else if (tokens.Last() == "!!!JAV Movies!!!")
                {
                    var javfiles = Directory.GetFiles(dir, "*", SearchOption.TopDirectoryOnly).ToList();
                    foreach (var jf in javfiles)
                    {
                        string   fn       = Path.GetFileNameWithoutExtension(jf);
                        string[] vals     = fn.Split('-');
                        string   jserie   = vals[0];
                        string   fullname = $"$01 JAV $04 {jserie.ToUpper()} ${fn.ToUpper()}";
                        fullname = Path.Combine(dir, fullname);
                        Directory.CreateDirectory(fullname);
                        File.Move(jf, Path.Combine(fullname, Path.GetFileName(jf)));
                    }
                    DoFOLDER(dir, toDir, null);
                    continue;
                }
                bool alreadysorted = false;
                foreach (string tok in tokens)
                {
                    if (string.IsNullOrEmpty(tok.Trim()))
                    {
                        continue;
                    }
                    string mark = tok.Substring(0, 2);
                    string val  = tok.Remove(0, 2).Trim();
                    if (mark == "01")
                    {
                        item.Catalog = val;
                    }
                    else if (mark == "02")
                    {
                        item.Star = val;
                    }
                    else if (mark == "03")
                    {
                        item.Kind = val;
                    }
                    else if (mark == "04")
                    {
                        item.Serie = val;
                    }
                    else if (mark == "05")
                    {
                        item.Country = val;
                    }
                    else if (mark == "06")
                    {
                        item.Year = Convert.ToInt32(val);
                    }
                    else if (mark == "07")
                    {
                        item.Studio = val;
                    }
                    else if (mark == "08")
                    {
                        item.XRated = val;
                    }
                    else if (mark == "09")
                    {
                        item.Type = val;
                    }
                    else if (mark == "10")
                    {
                        item.Director = val;
                    }
                    else if (mark == "11")
                    {
                        alreadysorted = (val == "SORTED");
                    }
                    else
                    {
                        item.Name = tok.Trim();
                    }
                }
                if (!string.IsNullOrEmpty(item.Name))
                {
                    if (!string.IsNullOrEmpty(item.Catalog))
                    {
                        toPath = $@"{toPath}\{item.Catalog}";
                    }
                    if (item.Catalog == "WEB")
                    {
                        if (!string.IsNullOrEmpty(item.Studio))
                        {
                            toPath = $@"{toPath}\{item.Studio}";
                        }
                    }
                    else if (item.Catalog == "MOV")
                    {
                        toPath = $@"{toPath}\{item.Year}";
                    }
                    else if (item.Catalog == "HEN" ||
                             item.Catalog == "R3D" ||
                             item.Catalog == "COM" ||
                             item.Catalog == "MOD" ||
                             item.Catalog == "MGZ")
                    {
                        if (!string.IsNullOrEmpty(item.Kind))
                        {
                            toPath = $@"{toPath}\{item.Kind}";
                        }
                        if (!string.IsNullOrEmpty(item.Director))
                        {
                            toPath = $@"{toPath}\{item.Director}";
                        }
                        if (!string.IsNullOrEmpty(item.Serie))
                        {
                            toPath = $@"{toPath}\{item.Serie}";
                        }
                        if (item.Year > 0)
                        {
                            toPath = $@"{toPath}\{item.Year}";
                        }
                        if (!string.IsNullOrEmpty(item.Star))
                        {
                            toPath = $@"{toPath}\{item.Star}";
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(item.Serie))
                        {
                            toPath = $@"{toPath}\{item.Serie}";
                        }
                    }


                    if (!Directory.Exists(toPath))
                    {
                        Directory.CreateDirectory(toPath);
                    }

                    string newname = Path.Combine(toPath, item.Name);
                    if (item.Catalog == "MOV")
                    {
                        newname = Path.Combine(toPath, $"[{item.Country}] {item.Name}");
                    }

                    if (
                        !alreadysorted &&
                        (
                            item.Catalog == "HEN" ||
                            item.Catalog == "R3D" ||
                            item.Catalog == "COM" ||
                            item.Catalog == "MOD" ||
                            item.Catalog == "MGZ"
                        ) &&
                        parentokens != null)
                    {
                        string eventsdir = Path.Combine(dir, "EVENTS");
                        Directory.CreateDirectory(eventsdir);
                        var files = Directory.GetFiles(dir, "*", SearchOption.TopDirectoryOnly).ToList();
                        files.ForEach(x => File.Move(x, Path.Combine(eventsdir, Path.GetFileName(x))));
                    }

                    try
                    {
                        if (!File.Exists(newname))
                        {
                            Directory.Move(dir, newname);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    List <string> lines = EpItem.SetToPassport(item);
                    File.WriteAllLines(Path.Combine(newname, EpItem.p_PassportName), lines);
                }
            }
        }