예제 #1
0
 private void moveDirectory(资源 res)
 {
     try
     {
         var path = Path.Combine(Settings.Default.完结目录, res.番组.档期);
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         var di = new DirectoryInfo(res.目录);
         di.MoveTo(Path.Combine(path, di.Name));
     }
     catch
     { throw; }
 }
예제 #2
0
        private 资源 在线更新(资源 a)
        {
            var week = (int)((DateTime.Now - a.完成时间).TotalDays / 7);

            if (week < 1)
            {
                return(a);
            }
            a.计数 += week;
            if (a.番组.话数 > 0 && a.计数 > a.番组.话数)
            {
                a.计数 = a.番组.话数;
            }
            a.完成时间 = a.完成时间.AddDays(7 * week);
            return(a);
        }
예제 #3
0
        private IEnumerable <资源> onlineBgms()
        {
            var bgms = DbModel.番组.Where(b => !b.完结 && b.资源.Count == 0 && !string.IsNullOrEmpty(b.版权链接));

            foreach (var b in bgms)
            {
                var anime = new 资源()
                {
                    在线   = true,
                    完成时间 = b.首播,
                    目录   = b.版权链接,
                    计数   = 1,
                    进度   = 0,
                    番组   = b,
                };
                anime.版权字幕组();
                在线更新(anime);
                App.MainDispatcher.Invoke(() => DbModel.资源.Add(anime));
                yield return(anime);
            }
        }
예제 #4
0
        public ObservableCollection <资源> CreateList(dynamic sender)
        {
            try
            {
                string[] strs = Settings.Default.路径格式.Split('|');
                var      dirs = (new DirectoryInfo(strs[0])).GetDirectories().Where(
                    d => Regex.IsMatch(d.Name, strs[1])
                    ).ToArray();
                文件夹整理(dirs);
                string 扩展名 = Settings.Default.扩展名;

                var aniList = new List <资源>();

                foreach (var dir in dirs)
                {
                    var bgmDirs = dir.GetDirectories();
                    foreach (var bgm in bgmDirs)
                    {
                        var name  = string分割(bgm.Name);
                        var mark  = $"{dir}-{name[1]}";
                        var anime = DbModel.资源.SingleOrDefault(rs => rs.标识 == mark);
                        if (anime == null)
                        {
                            anime = new 资源()
                            {
                                字幕组 = name[0],
                                标识  = mark,
                                目录  = bgm.FullName
                            };

                            var vm = new VM新番()
                            {
                                Anime    = anime,
                                EditMode = false
                            };
                            sender.Dispatcher.Invoke(new Action(() =>
                            {
                                var window = new View.W新番(vm);
                                window.ShowDialog();
                            }));
                            if (!vm.DialogResult)
                            {
                                continue;
                            }
                        }
                        if (anime.完结)
                        {
                            continue;
                        }
                        if (anime.目录 != bgm.FullName)
                        {
                            anime.目录 = bgm.FullName;
                            DbModel.SaveChanges();
                        }
                        anime.计数 = -1;
                        var    files = bgm.GetFiles().OrderBy(f => f.CreationTime);
                        double temp  = 0;
                        foreach (var file in files)
                        {
                            if (file.Extension == ".torrent")
                            {
                                file.Delete();
                                continue;
                            }
                            if (!扩展名.Contains(file.Extension.ToLower()))
                            {
                                continue;
                            }
                            var info = string分割(file.Name);
                            if (info.Length < 3)
                            {
                                continue;
                            }
                            var macth = Regex.Match(info[2], @"\d{1,3}(\.5)?");
                            if (!macth.Success && info.Length > 3)
                            {
                                macth = Regex.Match(info[3], @"\d{1,3}(\.5)?");
                            }
                            if (macth.Success)
                            {
                                temp = double.Parse(macth.Value);
                                if (temp > anime.计数)
                                {
                                    anime.计数   = temp;
                                    anime.完成时间 = file.CreationTime;
                                    anime.路径   = file.FullName;
                                }
                            }
                        }
                        aniList.Add(anime);
                    }
                }

                var online = DbModel.资源.Where(a => !a.完结 && a.在线).ToList();
                if (online.Count > 0)
                {
                    aniList.AddRange(online.Select(a => 在线更新(a)));
                }
                aniList.AddRange(onlineBgms());
                DbModel.SaveChanges();

                return(new ObservableCollection <资源>(aniList.OrderByDescending(a => a.完成时间)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }