Ejemplo n.º 1
0
 //根据 视频后缀文件大小筛选
 public static List <string> FirstFilter(List <string> FilePathList, string ID = "")
 {
     if (FilePathList == null || FilePathList.Count == 0)
     {
         return(new List <string>());
     }
     try
     {
         if (ID == "")
         {
             return(FilePathList
                    .Where(s => FilePattern.Contains(Path.GetExtension(s).ToLower()))
                    .Where(s => !File.Exists(s) || new FileInfo(s).Length >= MinFileSize).
                    OrderBy(s => s).ToList());
         }
         else
         {
             return(FilePathList
                    .Where(s => FilePattern.Contains(Path.GetExtension(s).ToLower()))
                    .Where(s => !File.Exists(s) || new FileInfo(s).Length >= MinFileSize)
                    .Where(s => { try { return Identify.GetFanhao(new FileInfo(s).Name).ToUpper() == ID.ToUpper(); } catch { Logger.LogScanInfo($"错误路径:{s}"); return false; } })
                    .OrderBy(s => s).ToList());
         }
     }
     catch (Exception ex)
     {
         Logger.LogF(ex);
     }
     return(new List <string>());
 }
Ejemplo n.º 2
0
        public static string[] ToFileName(this DetailMovie movie)
        {
            string          txt      = Properties.Settings.Default.RenameFormat;
            FileInfo        fileInfo = new FileInfo(movie.filepath);
            string          oldName  = movie.filepath;
            string          name     = Path.GetFileNameWithoutExtension(movie.filepath);
            string          dir      = fileInfo.Directory.FullName;
            string          ext      = fileInfo.Extension;
            string          newName  = "";
            MatchCollection matches  = Regex.Matches(txt, "\\{[a-z]+\\}");

            if (matches != null && matches.Count > 0)
            {
                newName = txt;
                foreach (Match match in matches)
                {
                    string property = match.Value.Replace("{", "").Replace("}", "");
                    ReplaceWithValue(property, movie, ref newName);
                }
            }

            //替换掉特殊字符
            foreach (char item in BANFILECHAR)
            {
                newName = newName.Replace(item.ToString(), "");
            }

            if (Properties.Settings.Default.DelRenameTitleSpace)
            {
                newName = newName.Replace(" ", "");
            }
            if (movie.hassubsection)
            {
                string[] result = new string[movie.subsectionlist.Count];
                for (int i = 0; i < movie.subsectionlist.Count; i++)
                {
                    if (Properties.Settings.Default.AddLabelTagWhenRename && Identify.IsCHS(oldName))
                    {
                        result[i] = Path.Combine(dir, $"{newName}-{i + 1}_{Jvedio.Language.Resources.Translated}{ext}");
                    }
                    else
                    {
                        result[i] = Path.Combine(dir, $"{newName}-{i + 1}{ext}");
                    }
                }
                return(result);
            }
            else
            {
                if (Properties.Settings.Default.AddLabelTagWhenRename && Identify.IsCHS(oldName))
                {
                    return(new string[] { Path.Combine(dir, $"{newName}_{Jvedio.Language.Resources.Translated}{ext}") });
                }
                else
                {
                    return(new string[] { Path.Combine(dir, $"{newName}{ext}") });
                }
            }
        }
Ejemplo n.º 3
0
        private void SaveInfo(string filepath)
        {
            if (vieModel.DetailMovie == null)
            {
                return;
            }
            if (!string.IsNullOrEmpty(vieModel.DetailMovie.id))
            {
                //视频类型、文件大小、创建时间
                vieModel.DetailMovie.filepath = filepath;

                FileInfo fileInfo = new FileInfo(filepath);

                string id = Identify.GetFanhao(fileInfo.Name);
                int    vt = (int)Identify.GetVedioType(id);
                if (vt > 0)
                {
                    vieModel.DetailMovie.vediotype = vt;
                }
                if (File.Exists(filepath))
                {
                    vieModel.DetailMovie.filesize = fileInfo.Length;
                    string createDate = "";
                    try { createDate = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); }
                    catch { }
                    if (createDate == "")
                    {
                        createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    vieModel.DetailMovie.otherinfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    vieModel.DetailMovie.scandate  = createDate;
                }

                vieModel.SaveModel();

                string table = ((Main)Jvedio.GetWindow.Get("Main")).GetCurrentList();
                if (string.IsNullOrEmpty(table))
                {
                    vieModel.Query(vieModel.id);
                }
                else
                {
                    vieModel.Query(vieModel.id, table);
                }
                HandyControl.Controls.Growl.Success("路径、视频类型、文件大小、创建时间、导入时间成功更新!", "EditGrowl");
            }
            else
            {
                vieModel.Refresh(filepath);
            }
        }
Ejemplo n.º 4
0
 private void InitAppData()
 {
     try
     {
         InitDataBase();//初始化数据库
         Identify.InitFanhaoList();
         Scan.InitSearchPattern();
         GlobalVariable.InitVariable();
     }
     catch (Exception ex)
     {
         Logger.LogE(ex);
     }
 }
Ejemplo n.º 5
0
 public static void addTag(ref DetailMovie movie)
 {
     //添加标签戳
     if (Identify.IsHDV(movie.filepath) || movie.genre?.IndexOf("高清") >= 0 || movie.tag?.IndexOf("高清") >= 0 || movie.label?.IndexOf("高清") >= 0)
     {
         movie.tagstamps += "高清";
     }
     if (Identify.IsCHS(movie.filepath) || movie.genre?.IndexOf("中文") >= 0 || movie.tag?.IndexOf("中文") >= 0 || movie.label?.IndexOf("中文") >= 0)
     {
         movie.tagstamps += "中文";
     }
     if (Identify.IsFlowOut(movie.filepath) || movie.genre?.IndexOf("流出") >= 0 || movie.tag?.IndexOf("流出") >= 0 || movie.label?.IndexOf("流出") >= 0)
     {
         movie.tagstamps += "流出";
     }
 }
Ejemplo n.º 6
0
 public static void addTag(ref DetailMovie movie)
 {
     //添加标签戳
     if (Identify.IsHDV(movie.filepath) || movie.genre?.IndexOfAnyString(TagStrings_HD) >= 0 || movie.tag?.IndexOfAnyString(TagStrings_HD) >= 0 || movie.label?.IndexOfAnyString(TagStrings_HD) >= 0)
     {
         movie.tagstamps += Jvedio.Language.Resources.HD;
     }
     if (Identify.IsCHS(movie.filepath) || movie.genre?.IndexOfAnyString(TagStrings_Translated) >= 0 || movie.tag?.IndexOfAnyString(TagStrings_Translated) >= 0 || movie.label?.IndexOfAnyString(TagStrings_Translated) >= 0)
     {
         movie.tagstamps += Jvedio.Language.Resources.Translated;
     }
     if (Identify.IsFlowOut(movie.filepath) || movie.genre?.IndexOfAnyString(TagStrings_FlowOut) >= 0 || movie.tag?.IndexOfAnyString(TagStrings_FlowOut) >= 0 || movie.label?.IndexOfAnyString(TagStrings_FlowOut) >= 0)
     {
         movie.tagstamps += Jvedio.Language.Resources.FlowOut;
     }
 }
Ejemplo n.º 7
0
 //根据 视频后缀文件大小筛选
 public static List <string> FirstFilter(List <string> FilePathList, string ID = "")
 {
     if (ID == "")
     {
         return(FilePathList
                .Where(s => SearchPattern.Contains(Path.GetExtension(s).ToLower()))
                .Where(s => !File.Exists(s) || new FileInfo(s).Length >= MinFileSize).OrderBy(s => s).ToList());
     }
     else
     {
         return(FilePathList
                .Where(s => SearchPattern.Contains(Path.GetExtension(s).ToLower()))
                .Where(s => !File.Exists(s) || new FileInfo(s).Length >= MinFileSize)
                .Where(s => Identify.GetFanhao(new FileInfo(s).Name).ToUpper() == ID.ToUpper())
                .OrderBy(s => s).ToList());
     }
 }
Ejemplo n.º 8
0
        private string GetLinkFromSearchResult(string html)
        {
            string result = "";

            if (string.IsNullOrEmpty(html))
            {
                return(result);
            }
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//p[@class='tmb']/a");

            if (nodes != null)
            {
                foreach (HtmlNode node in nodes)
                {
                    if (node == null)
                    {
                        continue;
                    }
                    string link = node.Attributes["href"]?.Value;
                    if (link.IsProperUrl())
                    {
                        string fanhao = Identify.GetFanhaoFromDMMUrl(link);
                        if (Identify.GetEng(fanhao).ToUpper() == Identify.GetEng(ID).ToUpper())
                        {
                            string str1 = Identify.GetNum(fanhao);
                            string str2 = Identify.GetNum(ID);
                            int    num1 = 0;
                            int    num2 = 1;
                            int.TryParse(str1, out num1);
                            int.TryParse(str2, out num2);
                            if (num1 == num2)
                            {
                                result = link;
                                break;
                            }
                        }
                    }
                }
            }


            return(result);
        }
Ejemplo n.º 9
0
        public static string GetFanhaoFromDMMUrl(string url)
        {
            string result = "";
            var    values = url.Split('/').ToList();
            string cid    = "";

            foreach (var item in values)
            {
                if (!string.IsNullOrEmpty(item) && item.IndexOf("cid=") >= 0)
                {
                    cid = item;
                    break;
                }
            }
            if (cid.IndexOf("cid=") >= 0)
            {
                return(Identify.GetFanhao(cid.Replace("cid=", "")));
            }
            return(result);
        }
Ejemplo n.º 10
0
        public static string GetFanhaoFromDMMUrl(string url)
        {
            string result = "";
            //https://www.dmm.co.jp/mono/dvd/-/detail/=/cid=apns006dod/?i3_ref=search&amp;i3_ord=1
            //https://www.dmm.co.jp/mono/dvd/-/detail/=/cid=mmus032/?i3_ref=search&amp;i3_ord=1
            var    values = url.Split('/').ToList();
            string cid    = "";

            foreach (var item in values)
            {
                if (!string.IsNullOrEmpty(item) && item.IndexOf("cid=") >= 0)
                {
                    cid = item;
                    break;
                }
            }
            if (cid.IndexOf("cid=") >= 0)
            {
                return(Identify.GetFanhao(cid.Replace("cid=", "")));
            }
            return(result);
        }
Ejemplo n.º 11
0
        private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                TextBox tb = sender as TextBox;

                string result = Identify.SearchSimilarityAnalysis(tb.Text, vieModel.MovieIDList.ToList()); //相似度分析


                if (result != "")
                {
                    for (int i = 0; i <= IdListBox.Items.Count - 1; i++)
                    {
                        if (IdListBox.Items[i].ToString().ToUpper() == result.ToUpper())
                        {
                            IdListBox.SelectedItem = IdListBox.Items[i];
                            IdListBox.ScrollIntoView(IdListBox.Items[i]);
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        //HACK
        private string GetLinkFromSearchResult(string html)
        {
            string result = "";

            if (string.IsNullOrEmpty(html))
            {
                return(result);
            }
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//p[@class='tmd']/a");

            if (nodes != null)
            {
                foreach (HtmlNode node in nodes)
                {
                    if (node == null)
                    {
                        continue;
                    }
                    string link = node.Attributes["href"]?.Value;
                    if (link.IsProperUrl())
                    {
                        if (Identify.GetFanhaoFromDMMUrl(link) == ID)
                        {
                            result = link;
                            break;
                        }
                    }
                }
            }


            return(result);
        }
Ejemplo n.º 13
0
        public static async Task <bool> ParseSpecifiedInfo(WebSite webSite, string id, string url)
        {
            string content    = "";
            int    StatusCode = 404;

            if (webSite == WebSite.DB)
            {
                (content, StatusCode) = await Net.Http(url, Cookie : Properties.Settings.Default.DBCookie);
            }
            if (webSite == WebSite.DMM)
            {
                (content, StatusCode) = await Net.Http(url, Cookie : Properties.Settings.Default.DMMCookie);
            }
            else
            {
                (content, StatusCode) = await Net.Http(url);
            }

            if (StatusCode != 200 || content == "")
            {
                return(false);
            }
            else
            {
                Dictionary <string, string> Info = new Dictionary <string, string>();

                if (webSite == WebSite.Bus)
                {
                    Info = new BusParse(id, content, Identify.GetVedioType(id)).Parse();
                    Info.Add("source", "javbus");
                }
                else if (webSite == WebSite.BusEu)
                {
                    Info = new BusParse(id, content, VedioType.欧美).Parse();
                    Info.Add("source", "javbus");
                }
                else if (webSite == WebSite.DB)
                {
                    Info = new JavDBParse(id, content, url.Split('/').Last()).Parse();
                    Info.Add("source", "javdb");
                }
                else if (webSite == WebSite.Library)
                {
                    Info = new LibraryParse(id, content).Parse();
                    Info.Add("source", "javlibrary");
                }
                Info.Add("sourceurl", url);
                if (Info.Count > 2)
                {
                    //保存信息
                    Info["id"] = id;
                    DataBase.UpdateInfoFromNet(Info);
                    DetailMovie detailMovie = DataBase.SelectDetailMovieById(id);


                    //nfo 信息保存到视频同目录
                    if (Properties.Settings.Default.SaveInfoToNFO)
                    {
                        if (Directory.Exists(Properties.Settings.Default.NFOSavePath))
                        {
                            //固定位置
                            nfo.SaveToNFO(detailMovie, Path.Combine(Properties.Settings.Default.NFOSavePath, $"{id}.nfo"));
                        }
                        else
                        {
                            //与视频同路径
                            string path = detailMovie.filepath;
                            if (System.IO.File.Exists(path))
                            {
                                nfo.SaveToNFO(detailMovie, Path.Combine(new FileInfo(path).DirectoryName, $"{id}.nfo"));
                            }
                        }
                    }
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 14
0
        public Movie GetInfoFromNfo(string path)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(path);
            }
            catch { return(null); }
            XmlNode rootNode = doc.SelectSingleNode("movie");

            if (rootNode == null)
            {
                return(null);
            }
            Movie movie = new Movie();

            foreach (XmlNode node in rootNode.ChildNodes)
            {
                try
                {
                    switch (node.Name)
                    {
                    case "id": movie.id = node.InnerText.ToUpper(); break;

                    case "title": movie.title = node.InnerText; break;

                    case "release": movie.releasedate = node.InnerText; break;

                    case "director": movie.director = node.InnerText; break;

                    case "studio": movie.studio = node.InnerText; break;

                    case "rating": movie.rating = node.InnerText == "" ? 0 : float.Parse(node.InnerText); break;

                    case "plot": movie.plot = node.InnerText; break;

                    case "outline": movie.outline = node.InnerText; break;

                    case "year": movie.year = node.InnerText == "" ? 1970 : int.Parse(node.InnerText); break;

                    case "runtime": movie.runtime = node.InnerText == "" ? 0 : int.Parse(node.InnerText); break;

                    case "country": movie.country = node.InnerText; break;

                    case "source": movie.sourceurl = node.InnerText; break;

                    default: break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine(ex.Message);
                    continue;
                }
            }
            if (movie.id == "")
            {
                return(null);
            }
            //视频类型

            movie.vediotype = (int)Identify.GetVedioType(movie.id);

            //扫描视频获得文件大小
            if (File.Exists(path))
            {
                string   fatherpath = new FileInfo(path).DirectoryName;
                string[] files      = null;
                try
                {
                    files = Directory.GetFiles(fatherpath, "*.*", SearchOption.TopDirectoryOnly);
                }
                catch (Exception e)
                {
                    Logger.LogE(e);
                }

                if (files != null)
                {
                    var movielist = Scan.FirstFilter(files.ToList(), movie.id);
                    if (movielist.Count == 1)
                    {
                        movie.filepath = movielist[0];
                    }
                    else if (movielist.Count > 1)
                    {
                        //分段视频
                        movie.filepath = movielist[0];
                        string subsection = "";
                        movielist.ForEach(arg => { subsection += arg + ";"; });
                        movie.subsection = subsection;
                    }
                }
            }

            //tag
            XmlNodeList tagNodes = doc.SelectNodes("/movie/tag");

            if (tagNodes != null)
            {
                string tags = "";
                foreach (XmlNode item in tagNodes)
                {
                    if (item.InnerText != "")
                    {
                        tags += item.InnerText + " ";
                    }
                }
                if (tags.Length > 0)
                {
                    if (movie.id.IndexOf("FC2") >= 0)
                    {
                        movie.genre = tags.Substring(0, tags.Length - 1);
                    }
                    else
                    {
                        movie.tag = tags.Substring(0, tags.Length - 1);
                    }
                }
            }

            //genre
            XmlNodeList genreNodes = doc.SelectNodes("/movie/genre");

            if (genreNodes != null)
            {
                string genres = "";
                foreach (XmlNode item in genreNodes)
                {
                    if (item.InnerText != "")
                    {
                        genres += item.InnerText + " ";
                    }
                }
                if (genres.Length > 0)
                {
                    movie.genre = genres.Substring(0, genres.Length - 1);
                }
            }

            //actor
            XmlNodeList actorNodes = doc.SelectNodes("/movie/actor/name");

            if (actorNodes != null)
            {
                string actors = "";
                foreach (XmlNode item in actorNodes)
                {
                    if (item.InnerText != "")
                    {
                        actors += item.InnerText + " ";
                    }
                }
                if (actors.Length > 0)
                {
                    movie.actor = actors.Substring(0, actors.Length - 1);
                }
            }

            //fanart
            XmlNodeList fanartNodes = doc.SelectNodes("/movie/fanart/thumb");

            if (fanartNodes != null)
            {
                string extraimageurl = "";
                foreach (XmlNode item in fanartNodes)
                {
                    if (item.InnerText != "")
                    {
                        extraimageurl += item.InnerText + ";";
                    }
                }
                if (extraimageurl.Length > 0)
                {
                    movie.extraimageurl = extraimageurl.Substring(0, extraimageurl.Length - 1);
                }
            }


            return(movie);
        }
Ejemplo n.º 15
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //更新配置文件
            if (Properties.Settings.Default.UpgradeRequired)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeRequired = false;
                Properties.Settings.Default.Save();
            }


            //判断文件是否存在
            CheckFile();


            //修复设置错误
            CheckSettings();


            //Properties.Settings.Default.Reset();
            if (!Directory.Exists(Properties.Settings.Default.BasePicPath))
            {
                Properties.Settings.Default.BasePicPath = AppDomain.CurrentDomain.BaseDirectory + "Pic\\";
            }


            //创建 Log文件夹
            if (!Directory.Exists("log"))
            {
                Directory.CreateDirectory("log");
            }
            //创建 ScanLog 文件夹
            if (!Directory.Exists("log\\scanlog"))
            {
                Directory.CreateDirectory("log\\scanlog");
            }
            //创建 DataBase 文件夹
            if (!Directory.Exists("DataBase"))
            {
                Directory.CreateDirectory("DataBase");
            }

            //创建备份文件夹
            if (!Directory.Exists("BackUp"))
            {
                Directory.CreateDirectory("BackUp");
            }



            SetSkin();
            //初始化数据库
            InitDataBase();
            statusText.Text = "启动中……";



            //初始化参数
            Identify.InitFanhaoList();
            Scan.InitSearchPattern();
            StaticVariable.InitVariable();

            //创建图片文件夹
            if (!Directory.Exists(StaticVariable.BasePicPath + "ScreenShot\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "ScreenShot\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "SmallPic\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "SmallPic\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "BigPic\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "BigPic\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "ExtraPic\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "ExtraPic\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "Actresses\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "Actresses\\");
            }



            //输入密码
            //DialogInput dialogInput = new DialogInput(this,"请输入密码", "123");
            //if (dialogInput .ShowDialog()== false) { this.Close(); } else
            //{
            //    string password = dialogInput.Text;
            //    if (password != "123")
            //    {
            //        this.Close();
            //    }
            //}



            if (Properties.Settings.Default.OpenDataBaseDefault)
            {
                if (Properties.Settings.Default.ScanGivenPath)
                {
                    await Task.Run(() =>
                    {
                        this.Dispatcher.BeginInvoke(new Action(() => { statusText.Text = $"扫描指定文件夹"; }), System.Windows.Threading.DispatcherPriority.Render);
                        List <string> filepaths = Scan.ScanPaths(ReadScanPathFromConfig(Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First()), ct);
                        DataBase cdb            = new DataBase();
                        Scan.DistinctMovieAndInsert(filepaths, ct);
                    }, cts.Token);
                }



                //启动主窗口
                Main main = new Main();
                statusText.Text = "初始化影片";
                main.InitMovie();


                main.Show();
                this.Close();
            }
            else
            {
                SelectDbBorder.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 分类视频并导入
        /// </summary>
        /// <param name="MoviePaths"></param>
        /// <param name="ct"></param>
        /// <param name="IsEurope"></param>
        /// <returns></returns>
        public static double DistinctMovieAndInsert(List <string> MoviePaths, CancellationToken ct, bool IsEurope = false)
        {
            Logger.LogScanInfo("\n-----【" + DateTime.Now.ToString() + "】-----");
            Logger.LogScanInfo($"\n扫描出 => {MoviePaths.Count}  个 \n");

            DataBase cdb = new DataBase();

            //检查未识别出番号的视频
            List <string> r1             = new List <string>();
            string        c1             = "";
            string        id             = "";
            VedioType     vt             = 0;
            double        totalinsertnum = 0;
            double        unidentifynum  = 0;

            foreach (var item in MoviePaths)
            {
                if (File.Exists(item))
                {
                    id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name);
                    //Console.WriteLine($"{id}=>{item}");
                    if (IsEurope)
                    {
                        if (string.IsNullOrEmpty(id))
                        {
                            vt = 0;
                        }
                        else
                        {
                            vt = VedioType.欧美;
                        }
                    }
                    else
                    {
                        vt = Identify.GetVedioType(id);
                    }

                    if (vt != 0)
                    {
                        r1.Add(item);
                    }
                    else
                    {
                        //写日志
                        c1 += "   " + item + "\n";
                        unidentifynum++;
                    }
                }
            }
            Logger.LogScanInfo($"\n【未识别出的视频:{unidentifynum}个】\n" + c1);

            //检查 重复|分段 视频
            Dictionary <string, List <string> > repeatlist = new Dictionary <string, List <string> >();
            string c2 = "";

            foreach (var item in r1)
            {
                if (File.Exists(item))
                {
                    id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name);
                    if (!repeatlist.ContainsKey(id))
                    {
                        List <string> pathlist = new List <string>();
                        pathlist.Add(item);
                        repeatlist.Add(id, pathlist);
                    }
                    else
                    {
                        repeatlist[id].Add(item);
                    }
                }
            }

            Console.WriteLine("repeatlist:" + repeatlist.Count);

            List <string>         removelist     = new List <string>();
            List <List <string> > subsectionlist = new List <List <string> >();

            foreach (KeyValuePair <string, List <string> > kvp in repeatlist)
            {
                if (kvp.Value.Count > 1)
                {
                    bool issubsection = IsSubSection(kvp.Value);
                    if (issubsection)
                    {
                        subsectionlist.Add(kvp.Value);
                    }
                    else
                    {
                        c2 += $"   识别码为:{kvp.Key}\n";
                        (string maxfilepath, List <string> Excludelsist) = ExcludeMaximumSize(kvp.Value);
                        removelist.AddRange(Excludelsist);
                        c2 += $"      导入的:{maxfilepath},文件大小:{new FileInfo(maxfilepath).Length}\n";
                        Excludelsist.ForEach(arg =>
                        {
                            c2 += $"      未导入:{arg},文件大小:{new FileInfo(arg).Length}\n";
                        });
                    }
                }
                else
                {
                }
            }
            Logger.LogScanInfo($"\n【重复的视频:{removelist.Count + subsectionlist.Count}个】\n" + c2);
            List <string> insertList = r1.Except(removelist).ToList();

            Console.WriteLine("removelist:" + removelist.Count);
            Console.WriteLine("subsectionlist:" + subsectionlist.Count);


            //导入分段视频
            foreach (var item in subsectionlist)
            {
                insertList = insertList.Except(item).ToList();

                try
                {
                    ct.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException ex)
                {
                    Logger.LogE(ex);
                    break;
                }
                string   subsection = "";
                FileInfo fileinfo   = new FileInfo(item[0]);
                id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name);
                if (IsEurope)
                {
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }
                    else
                    {
                        vt = VedioType.欧美;
                    }
                }
                else
                {
                    vt = Identify.GetVedioType(id);
                }
                if (string.IsNullOrEmpty(id) | vt == 0)
                {
                    continue;
                }

                //文件大小视为所有文件之和
                double filesize = 0;
                for (int i = 0; i < item.Count; i++)
                {
                    if (!File.Exists(item[i]))
                    {
                        continue;
                    }
                    FileInfo fi = new FileInfo(item[i]);
                    subsection += item[i] + ";";
                    filesize   += fi.Length;
                }

                //获取创建日期
                string createDate = "";
                try { createDate = fileinfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); }
                catch { }
                if (createDate == "")
                {
                    createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }

                Movie movie = new Movie()
                {
                    filepath   = item[0],
                    id         = id,
                    filesize   = filesize,
                    vediotype  = (int)vt,
                    subsection = subsection.Substring(0, subsection.Length - 1),
                    scandate   = createDate
                };
                cdb.InsertScanMovie(movie); totalinsertnum += 1;
            }

            Console.WriteLine("insertList:" + insertList.Count);


            //导入所有视频


            foreach (var item in insertList)
            {
                try
                {
                    ct.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException ex)
                {
                    Logger.LogE(ex);
                    break;
                }
                if (!File.Exists(item))
                {
                    continue;
                }
                FileInfo fileinfo = new FileInfo(item);

                string createDate = "";
                try { createDate = fileinfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); }
                catch { }
                if (createDate == "")
                {
                    createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }

                id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name);
                if (IsEurope)
                {
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }
                    else
                    {
                        vt = VedioType.欧美;
                    }
                }
                else
                {
                    vt = Identify.GetVedioType(id);
                }
                Movie movie = new Movie()
                {
                    filepath  = item,
                    id        = id,
                    filesize  = fileinfo.Length,
                    vediotype = (int)vt,
                    scandate  = createDate
                };
                cdb.InsertScanMovie(movie); totalinsertnum += 1;
            }
            cdb.CloseDB();
            Logger.LogScanInfo($"\n总计导入 => {totalinsertnum}个\n");


            //从 主数据库中 复制信息
            if (Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First().ToLower() != "info")
            {
                try
                {
                    //待修复 的 bug
                    CopyDatabaseInfo(Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First().ToLower());
                }
                catch { }
            }



            return(totalinsertnum);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 分类视频并导入
        /// </summary>
        /// <param name="MoviePaths"></param>
        /// <param name="ct"></param>
        /// <param name="IsEurope"></param>
        /// <returns></returns>
        public static double DistinctMovieAndInsert(List <string> MoviePaths, CancellationToken ct, bool IsEurope = false)
        {
            Logger.LogScanInfo(Environment.NewLine + "-----【" + DateTime.Now.ToString() + "】-----");
            Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ScanVideo} => {MoviePaths.Count} " + Environment.NewLine);

            List <string> properIdList    = new List <string>();
            StringBuilder logStr          = new StringBuilder();
            string        id              = "";
            VedioType     vt              = 0;
            double        insertCount     = 0; //总的导入数目
            double        unidentifyCount = 0; //无法识别的数目

            //检查未识别出番号的视频
            foreach (var item in MoviePaths)
            {
                if (File.Exists(item))
                {
                    id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name);

                    if (IsEurope)
                    {
                        if (string.IsNullOrEmpty(id))
                        {
                            vt = 0;
                        }
                        else
                        {
                            vt = VedioType.欧美;
                        }
                    }
                    else
                    {
                        vt = Identify.GetVideoType(id);
                    }


                    if (vt != 0)
                    {
                        properIdList.Add(item);
                    }
                    else
                    {
                        logStr.Append("   " + item + Environment.NewLine);
                        unidentifyCount++;
                    }
                }
            }
            Logger.LogScanInfo(Environment.NewLine + $"【{Jvedio.Language.Resources.NotRecognizeNumber} :{unidentifyCount}】" + Environment.NewLine + logStr.ToString());

            //检查 重复|分段 视频
            Dictionary <string, List <string> > repeatlist = new Dictionary <string, List <string> >();
            StringBuilder logSubSection = new StringBuilder();

            foreach (var item in properIdList)
            {
                if (File.Exists(item))
                {
                    id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name);
                    if (!repeatlist.ContainsKey(id))
                    {
                        List <string> pathlist = new List <string> {
                            item
                        };
                        repeatlist.Add(id, pathlist);
                    }
                    else
                    {
                        repeatlist[id].Add(item);//每个 id 对应一组视频路径,视频路径最多的视为分段视频
                    }
                }
            }

            List <string>         removelist     = new List <string>();
            List <List <string> > subsectionlist = new List <List <string> >();

            foreach (KeyValuePair <string, List <string> > kvp in repeatlist)
            {
                if (kvp.Value.Count > 1)
                {
                    //路径个数大于1 才为分段视频
                    (bool issubsection, List <string> filepathlist, List <string> notsubsection) = IsSubSection(kvp.Value);
                    if (issubsection)
                    {
                        subsectionlist.Add(filepathlist);
                        if (filepathlist.Count < kvp.Value.Count)
                        {
                            //其中几个不是分段视频
                            logSubSection.Append($"   {Jvedio.Language.Resources.ID} :{kvp.Key}" + Environment.NewLine);
                            removelist.AddRange(notsubsection);
                            logSubSection.Append($"      {Jvedio.Language.Resources.ImportSubSection}: {filepathlist.Count} ,:{string.Join(";", filepathlist)}" + Environment.NewLine);
                            notsubsection.ForEach(arg =>
                            {
                                logSubSection.Append($"      {Jvedio.Language.Resources.NotImport} :{arg}" + Environment.NewLine);
                            });
                        }
                    }
                    else
                    {
                        //TODO
                        logSubSection.Append($"   {Jvedio.Language.Resources.ID}:{kvp.Key}" + Environment.NewLine);
                        (string maxfilepath, List <string> Excludelsist) = ExcludeMaximumSize(kvp.Value);
                        removelist.AddRange(Excludelsist);
                        logSubSection.Append($"      {Jvedio.Language.Resources.ImportFile} :{maxfilepath},{Jvedio.Language.Resources.FileSize} :{new FileInfo(maxfilepath).Length}" + Environment.NewLine);
                        Excludelsist.ForEach(arg =>
                        {
                            logSubSection.Append($"      {Jvedio.Language.Resources.NotImport} :{arg},{Jvedio.Language.Resources.FileSize} :{new FileInfo(arg).Length}" + Environment.NewLine);
                        });
                    }
                }
            }
            Logger.LogScanInfo(Environment.NewLine + $"【 {Jvedio.Language.Resources.RepeatVideo}:{removelist.Count + subsectionlist.Count}】" + Environment.NewLine + logSubSection.ToString());

            List <string> insertList = properIdList.Except(removelist).ToList();//需要导入的视频

            //导入分段视频
            foreach (var item in subsectionlist)
            {
                insertList = insertList.Except(item).ToList();
                ct.ThrowIfCancellationRequested();
                string   subsection = "";
                FileInfo fileinfo   = new FileInfo(item[0]);//获得第一个视频的文件信息
                id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name);
                if (IsEurope)
                {
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }
                    else
                    {
                        vt = VedioType.欧美;
                    }
                }
                else
                {
                    vt = Identify.GetVideoType(id);
                }
                if (string.IsNullOrEmpty(id) || vt == 0)
                {
                    continue;
                }

                //文件大小视为所有文件之和
                double filesize = 0;
                for (int i = 0; i < item.Count; i++)
                {
                    if (!File.Exists(item[i]))
                    {
                        continue;
                    }
                    FileInfo fi = new FileInfo(item[i]);
                    subsection += item[i] + ";";
                    filesize   += fi.Length;
                }

                //获取创建日期
                //TODO 国际化
                string createDate = "";
                try { createDate = fileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); }
                catch { }
                if (createDate == "")
                {
                    createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }

                Movie movie = new Movie()
                {
                    filepath   = item[0],
                    id         = id,
                    filesize   = filesize,
                    vediotype  = (int)vt,
                    subsection = subsection.Substring(0, subsection.Length - 1),
                    otherinfo  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    scandate   = createDate
                };

                DataBase.InsertScanMovie(movie);
                insertCount += 1;
            }

            //导入剩余的所有视频
            foreach (var item in insertList)
            {
                ct.ThrowIfCancellationRequested();
                if (!File.Exists(item))
                {
                    continue;
                }
                FileInfo fileinfo = new FileInfo(item);

                string createDate = "";
                try { createDate = fileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); }
                catch { }
                if (createDate == "")
                {
                    createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }

                id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name);
                if (string.IsNullOrEmpty(id))
                {
                    continue;
                }

                if (IsEurope)
                {
                    vt = VedioType.欧美;
                }
                else
                {
                    vt = Identify.GetVideoType(id);
                }

                if (vt == 0)
                {
                    continue;
                }

                Movie movie = new Movie()
                {
                    filepath  = item,
                    id        = id,
                    filesize  = fileinfo.Length,
                    vediotype = (int)vt,
                    otherinfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    scandate  = createDate
                };
                DataBase.InsertScanMovie(movie);
                insertCount += 1;
            }

            Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.TotalImport} => {insertCount},{Jvedio.Language.Resources.ImportAttention}" + Environment.NewLine);

            //TODO 从主数据库中复制信息
            //从 主数据库中 复制信息
            //if (Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath).ToLower() != "info")
            //{
            //    try
            //    {
            //        string src = AppDomain.CurrentDomain.BaseDirectory + "DataBase\\info.sqlite";
            //        string dst = AppDomain.CurrentDomain.BaseDirectory + $"DataBase\\{Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath).ToLower()}.sqlite"; ;
            //        DataBase.CopyDatabaseInfo(src, dst);
            //    }
            //    catch { }
            //}
            return(insertCount);
        }
Ejemplo n.º 18
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            statusText.Text = "更新配置文件……";
            try
            {
                if (Properties.Settings.Default.UpgradeRequired)
                {
                    Properties.Settings.Default.Upgrade();
                    Properties.Settings.Default.UpgradeRequired = false;
                    Properties.Settings.Default.Save();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            statusText.Text = "修复设置错误……";
            try
            {
                CheckFile();     //判断文件是否存在
                CheckSettings(); //修复设置错误
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            if (!Directory.Exists(Properties.Settings.Default.BasePicPath))
            {
                Properties.Settings.Default.BasePicPath = AppDomain.CurrentDomain.BaseDirectory + "Pic\\";
            }


            statusText.Text = "创建文件夹……";
            try
            {
                if (!Directory.Exists("log"))
                {
                    Directory.CreateDirectory("log");
                }                                                                  //创建 Log文件夹
                if (!Directory.Exists("log\\scanlog"))
                {
                    Directory.CreateDirectory("log\\scanlog");
                }                                                                                    //创建 ScanLog 文件夹
                if (!Directory.Exists("DataBase"))
                {
                    Directory.CreateDirectory("DataBase");
                }                                                                                        //创建 DataBase 文件夹
                if (!Directory.Exists("BackUp"))
                {
                    Directory.CreateDirectory("BackUp");
                }                                                                                    //创建备份文件夹
                SetSkin();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            statusText.Text = "初始化数据库……";
            try
            {
                InitDataBase();//初始化数据库
                //InitJav321IDConverter();
                //初始化参数
                statusText.Text = "初始化识别码参数……";
                Identify.InitFanhaoList();
                statusText.Text = "初始化扫描参数……";
                Scan.InitSearchPattern();
                statusText.Text = "初始化变量……";
                InitVariable();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            statusText.Text = "修改配置到 XML……";
            try
            {
                SaveScanPathToXml();
                SaveServersToXml();
                SaveRecentWatchedToXml();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            try
            {
                statusText.Text = "清除超于10天的最近观看……";
                ClearDateBefore(DateTime.Now.AddDays(-10));
                statusText.Text = "清除超于10天的日志文件……";
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log");
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\NetWork");
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\scanlog");
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\file");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            statusText.Text = "网络配置初始化……";
            try
            {
                Net.Init();
                statusText.Text = "创建图片文件夹……";
                if (!Directory.Exists(BasePicPath + "ScreenShot\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "ScreenShot\\");
                }
                if (!Directory.Exists(BasePicPath + "SmallPic\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "SmallPic\\");
                }
                if (!Directory.Exists(BasePicPath + "BigPic\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "BigPic\\");
                }
                if (!Directory.Exists(BasePicPath + "ExtraPic\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "ExtraPic\\");
                }
                if (!Directory.Exists(BasePicPath + "Actresses\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "Actresses\\");
                }
                if (!Directory.Exists(BasePicPath + "Gif\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "Gif\\");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }

            //默认打开某个数据库
            if (Properties.Settings.Default.OpenDataBaseDefault && File.Exists(Properties.Settings.Default.DataBasePath))
            {
                try
                {
                    OpenDefaultDatabase();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Logger.LogE(ex);
                }

                //启动主窗口
                Main main = new Main();
                statusText.Text = "初始化影片……";
                try
                {
                    main.InitMovie();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Logger.LogE(ex);
                }

                main.Show();
                this.Close();
            }
            else
            {
                SelectDbBorder.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 19
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            statusText.Text = Jvedio.Language.Resources.Status_UpdateConfig;
            try
            {
                if (Properties.Settings.Default.UpgradeRequired)
                {
                    Properties.Settings.Default.Upgrade();
                    Properties.Settings.Default.UpgradeRequired = false;
                    Properties.Settings.Default.Save();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }

            //复制原有的 info.sqlite
            try
            {
                if (!Directory.Exists("DataBase"))
                {
                    Directory.CreateDirectory("DataBase");
                }
                if (File.Exists("info.sqlite"))
                {
                    FileHelper.TryCopyFile("info.sqlite", "DataBase\\info.sqlite");
                    File.Delete("info.sqlite");
                }
            }
            catch (Exception ex) { }

            statusText.Text = Jvedio.Language.Resources.Status_RepairConfig;
            try
            {
                CheckFile();     //判断文件是否存在
                CheckSettings(); //修复设置错误
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            if (!Directory.Exists(Properties.Settings.Default.BasePicPath))
            {
                Properties.Settings.Default.BasePicPath = AppDomain.CurrentDomain.BaseDirectory + "Pic\\";
            }


            statusText.Text = Jvedio.Language.Resources.Status_CreateDir;
            try
            {
                if (!Directory.Exists("log"))
                {
                    Directory.CreateDirectory("log");
                }                                                                  //创建 Log文件夹
                if (!Directory.Exists("log\\scanlog"))
                {
                    Directory.CreateDirectory("log\\scanlog");
                }                                                                                    //创建 ScanLog 文件夹
                if (!Directory.Exists("DataBase"))
                {
                    Directory.CreateDirectory("DataBase");
                }                                                                                        //创建 DataBase 文件夹
                if (!Directory.Exists("BackUp"))
                {
                    Directory.CreateDirectory("BackUp");
                }                                                                                    //创建备份文件夹
                SetSkin(Properties.Settings.Default.Themes);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            statusText.Text = Jvedio.Language.Resources.Status_InitDatabase;
            try
            {
                InitDataBase();//初始化数据库
                //InitJav321IDConverter();
                //初始化参数
                statusText.Text = Jvedio.Language.Resources.Status_InitID;
                Identify.InitFanhaoList();
                statusText.Text = Jvedio.Language.Resources.Status_InitScan;
                Scan.InitSearchPattern();
                InitVariable();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }

            try
            {
                statusText.Text = Jvedio.Language.Resources.Status_ClearRecentWatch;
                ClearDateBefore(DateTime.Now.AddDays(-10));
                statusText.Text = Jvedio.Language.Resources.Status_ClearLog;
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log");
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\NetWork");
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\scanlog");
                ClearLogBefore(DateTime.Now.AddDays(-10), AppDomain.CurrentDomain.BaseDirectory + "log\\file");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }



            statusText.Text = Jvedio.Language.Resources.Status_InitNet;
            try
            {
                statusText.Text = Jvedio.Language.Resources.Status_CreateDir;
                if (!Directory.Exists(BasePicPath + "ScreenShot\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "ScreenShot\\");
                }
                if (!Directory.Exists(BasePicPath + "SmallPic\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "SmallPic\\");
                }
                if (!Directory.Exists(BasePicPath + "BigPic\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "BigPic\\");
                }
                if (!Directory.Exists(BasePicPath + "ExtraPic\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "ExtraPic\\");
                }
                if (!Directory.Exists(BasePicPath + "Actresses\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "Actresses\\");
                }
                if (!Directory.Exists(BasePicPath + "Gif\\"))
                {
                    Directory.CreateDirectory(BasePicPath + "Gif\\");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }

            BackUp("Magnets.sqlite");   //备份文件
            BackUp("AI.sqlite");        //备份文件
            BackUp("Translate.sqlite"); //备份文件

            //默认打开某个数据库
            if (Properties.Settings.Default.OpenDataBaseDefault && File.Exists(Properties.Settings.Default.DataBasePath))
            {
                try
                {
                    OpenDefaultDatabase();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Logger.LogE(ex);
                }

                //启动主窗口
                Main main = new Main();
                statusText.Text = Jvedio.Language.Resources.Status_InitMovie;
                try
                {
                    await main.InitMovie();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Logger.LogE(ex);
                }

                main.Show();
                this.Close();
            }
            else
            {
                SelectDbBorder.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 20
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //更新配置文件
            if (Properties.Settings.Default.UpgradeRequired)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeRequired = false;
                Properties.Settings.Default.Save();
            }


            //判断文件是否存在
            CheckFile();


            //修复设置错误
            CheckSettings();


            //Properties.Settings.Default.Reset();
            if (!Directory.Exists(Properties.Settings.Default.BasePicPath))
            {
                Properties.Settings.Default.BasePicPath = AppDomain.CurrentDomain.BaseDirectory + "Pic\\";
            }


            //创建 Log文件夹
            if (!Directory.Exists("log"))
            {
                Directory.CreateDirectory("log");
            }
            //创建 ScanLog 文件夹
            if (!Directory.Exists("log\\scanlog"))
            {
                Directory.CreateDirectory("log\\scanlog");
            }
            //创建 DataBase 文件夹
            if (!Directory.Exists("DataBase"))
            {
                Directory.CreateDirectory("DataBase");
            }

            //创建备份文件夹
            if (!Directory.Exists("BackUp"))
            {
                Directory.CreateDirectory("BackUp");
            }



            SetSkin();

            statusText.Text = "初始化参数……";
            InitDataBase();//初始化数据库
            //InitJav321IDConverter();
            //初始化参数
            Identify.InitFanhaoList();
            Scan.InitSearchPattern();
            InitVariable();
            SaveScanPathToXml();
            SaveServersToXml();
            Net.Init();

            //创建图片文件夹
            if (!Directory.Exists(StaticVariable.BasePicPath + "ScreenShot\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "ScreenShot\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "SmallPic\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "SmallPic\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "BigPic\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "BigPic\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "ExtraPic\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "ExtraPic\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "Actresses\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "Actresses\\");
            }
            if (!Directory.Exists(StaticVariable.BasePicPath + "Gif\\"))
            {
                Directory.CreateDirectory(StaticVariable.BasePicPath + "Gif\\");
            }


            //默认打开某个数据库
            if (Properties.Settings.Default.OpenDataBaseDefault && File.Exists(Properties.Settings.Default.DataBasePath))
            {
                OpenDefaultDatabase();
                //启动主窗口
                Main main = new Main();
                statusText.Text = "初始化影片";
                main.InitMovie();


                main.Show();
                this.Close();
            }
            else
            {
                SelectDbBorder.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 给出一组视频路径,返回否是分段视频,并返回分段的视频列表,以及不是分段的视频列表
        /// </summary>
        /// <param name="FilePathList"></param>
        /// <returns></returns>

        public static (bool, List <string>, List <string>) IsSubSection(List <string> FilePathList)
        {
            if (Identify.GetFanhao(FilePathList[0].ToUpper()) == "FC2-1552855")
            {
                Console.WriteLine("123");
            }

            bool          result        = true;
            List <string> notSubSection = new List <string>();
            string        FatherPath    = new FileInfo(FilePathList[0]).Directory.FullName;

            bool IsAllFileSameFP = FilePathList.All(arg => new FileInfo(arg).Directory.FullName == FatherPath);

            if (!IsAllFileSameFP)
            {
                //并不是所有父目录都相同,提取出父目录最多的文件
                Dictionary <string, int> fatherpathDic = new Dictionary <string, int>();
                FilePathList.ForEach(path => {
                    string fatherPath = new FileInfo(path).Directory.FullName;
                    if (fatherpathDic.ContainsKey(fatherPath))
                    {
                        fatherpathDic[fatherPath] += 1;
                    }
                    else
                    {
                        fatherpathDic.Add(fatherPath, 1);
                    }
                });
                string maxValueKey = fatherpathDic.FirstOrDefault(x => x.Value == fatherpathDic.Values.Max()).Key;
                if (!string.IsNullOrEmpty(maxValueKey))
                {
                    try {
                        var notsub = fatherpathDic.Where(arg => arg.Key != null && new FileInfo(arg.Key)?.Directory.FullName != maxValueKey).ToList();
                        notsub.ForEach(arg => notSubSection.Add(arg.Key));
                    }
                    catch (Exception e) { Logger.LogE(e); }
                    FilePathList = FilePathList.Where(arg => new FileInfo(arg).Directory.FullName == maxValueKey).ToList();
                }
            }


            //目录都相同,判断是否分段视频的特征


            // -1  cd1  _1   fhd1
            string regexFeature = "";

            foreach (var item in GetSubSectionFeature())
            {
                regexFeature += item + "|";
            }
            regexFeature = "(" + regexFeature.Substring(0, regexFeature.Length - 1) + ")[1-9]{1}";


            string MatchesName = "";

            foreach (var item in FilePathList)
            {
                foreach (var re in Regex.Matches(item, regexFeature))
                {
                    MatchesName += re.ToString();
                }
            }

            for (int i = 1; i <= FilePathList.Count; i++)
            {
                result &= MatchesName.IndexOf(i.ToString()) >= 0;
            }


            if (!result)
            {
                result = true;
                //数字后面存在 A,B,C……
                //XXX-000-A
                //XXX-000-B
                regexFeature = "";
                foreach (var item in GetSubSectionFeature())
                {
                    regexFeature += item + "|";
                }
                regexFeature = "((" + regexFeature.Substring(0, regexFeature.Length - 1) + ")|[0-9]{1,})[a-n]{1}";

                MatchesName = "";
                foreach (var item in FilePathList)
                {
                    foreach (var re in Regex.Matches(item, regexFeature, RegexOptions.IgnoreCase))
                    {
                        MatchesName += re.ToString();
                    }
                }
                MatchesName = MatchesName.ToLower();
                string characters = "abcdefghijklmn";
                for (int i = 0; i < Math.Min(FilePathList.Count, characters.Length); i++)
                {
                    result &= MatchesName.IndexOf(characters[i]) >= 0;
                }
            }



            return(result, FilePathList, notSubSection);
        }
Ejemplo n.º 22
0
        public static async Task <bool> ParseSpecifiedInfo(WebSite webSite, string id, string url)
        {
            HttpResult httpResult = null;

            if (webSite == WebSite.Bus)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.Bus.Cookie
                });
            }
            else if (webSite == WebSite.BusEu)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.BusEurope.Cookie
                });
            }
            else if (webSite == WebSite.Library)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.Library.Cookie
                });
            }
            else if (webSite == WebSite.Jav321)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.Jav321.Cookie
                });
            }
            else if (webSite == WebSite.FC2)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.FC2.Cookie
                });
            }
            else if (webSite == WebSite.DB)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.DB.Cookie
                });
            }
            else if (webSite == WebSite.DMM)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.DMM.Cookie
                });
            }
            else if (webSite == WebSite.MOO)
            {
                httpResult = await Net.Http(url, new CrawlerHeader()
                {
                    Cookies = JvedioServers.MOO.Cookie
                });
            }
            else
            {
                httpResult = await Net.Http(url);
            }

            if (httpResult != null && httpResult.StatusCode == HttpStatusCode.OK && httpResult.SourceCode != "")
            {
                string content = httpResult.SourceCode;
                Dictionary <string, string> Info = new Dictionary <string, string>();

                if (webSite == WebSite.Bus)
                {
                    Info = new BusParse(id, content, Identify.GetVideoType(id)).Parse();
                    Info.Add("source", "javbus");
                }
                else if (webSite == WebSite.BusEu)
                {
                    Info = new BusParse(id, content, VedioType.欧美).Parse();
                    Info.Add("source", "javbus");
                }
                else if (webSite == WebSite.DB)
                {
                    Info = new JavDBParse(id, content, url.Split('/').Last()).Parse();
                    Info.Add("source", "javdb");
                }
                else if (webSite == WebSite.Library)
                {
                    Info = new LibraryParse(id, content).Parse();
                    Info.Add("source", "javlibrary");
                }
                else if (webSite == WebSite.Jav321)
                {
                    Info = new LibraryParse(id, content).Parse();
                    Info.Add("source", "Jav321");
                }
                else if (webSite == WebSite.DMM)
                {
                    Info = new LibraryParse(id, content).Parse();
                    Info.Add("source", "DMM");
                }
                else if (webSite == WebSite.MOO)
                {
                    Info = new LibraryParse(id, content).Parse();
                    Info.Add("source", "MOO");
                }
                else if (webSite == WebSite.FC2)
                {
                    Info = new LibraryParse(id, content).Parse();
                    Info.Add("source", "FC2");
                }
                Info.Add("sourceurl", url);
                if (Info.Count > 2)
                {
                    FileProcess.SaveInfo(Info, id);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 分类视频并导入
        /// </summary>
        /// <param name="MoviePaths"></param>
        /// <param name="ct"></param>
        /// <param name="IsEurope"></param>
        /// <returns></returns>
        public static double DistinctMovieAndInsert(List <string> MoviePaths, CancellationToken ct, bool IsEurope = false)
        {
            Logger.LogScanInfo(Environment.NewLine + "-----【" + DateTime.Now.ToString() + "】-----");
            Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ScanVideo} => {MoviePaths.Count} " + Environment.NewLine);


            //检查未识别出番号的视频
            List <string> r1             = new List <string>();
            string        c1             = "";
            string        id             = "";
            VedioType     vt             = 0;
            double        totalinsertnum = 0;
            double        unidentifynum  = 0;

            foreach (var item in MoviePaths)
            {
                if (File.Exists(item))
                {
                    id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name);

                    if (IsEurope)
                    {
                        if (string.IsNullOrEmpty(id))
                        {
                            vt = 0;
                        }
                        else
                        {
                            vt = VedioType.欧美;
                        }
                    }
                    else
                    {
                        vt = Identify.GetVedioType(id);
                    }


                    if (vt != 0)
                    {
                        r1.Add(item);
                    }
                    else
                    {
                        //写日志
                        c1 += "   " + item + Environment.NewLine;
                        unidentifynum++;
                    }
                }
            }
            Logger.LogScanInfo(Environment.NewLine + $"【{Jvedio.Language.Resources.NotRecognizeNumber} :{unidentifynum}】" + Environment.NewLine + c1);

            //检查 重复|分段 视频
            Dictionary <string, List <string> > repeatlist = new Dictionary <string, List <string> >();
            string c2 = "";

            foreach (var item in r1)
            {
                if (File.Exists(item))
                {
                    id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name);
                    if (!repeatlist.ContainsKey(id))
                    {
                        List <string> pathlist = new List <string> {
                            item
                        };
                        repeatlist.Add(id, pathlist);
                    }
                    else
                    {
                        repeatlist[id].Add(item);
                    }
                }
            }

            List <string>         removelist     = new List <string>();
            List <List <string> > subsectionlist = new List <List <string> >();

            foreach (KeyValuePair <string, List <string> > kvp in repeatlist)
            {
                if (kvp.Value.Count > 1)
                {
                    (bool issubsection, List <string> filepathlist, List <string> notsubsection) = IsSubSection(kvp.Value);
                    if (issubsection)
                    {
                        subsectionlist.Add(filepathlist);
                        if (filepathlist.Count < kvp.Value.Count)
                        {
                            //其中几个不是分段视频
                            c2 += $"   {Jvedio.Language.Resources.ID} :{kvp.Key}" + Environment.NewLine;
                            removelist.AddRange(notsubsection);
                            c2 += $"      {Jvedio.Language.Resources.ImportSubSection}: {filepathlist.Count} ,:{string.Join(";",filepathlist)}" + Environment.NewLine;
                            notsubsection.ForEach(arg =>
                            {
                                c2 += $"      {Jvedio.Language.Resources.NotImport} :{arg}" + Environment.NewLine;
                            });
                        }
                    }
                    else
                    {
                        c2 += $"   {Jvedio.Language.Resources.ID}:{kvp.Key}" + Environment.NewLine;
                        (string maxfilepath, List <string> Excludelsist) = ExcludeMaximumSize(kvp.Value);
                        removelist.AddRange(Excludelsist);
                        c2 += $"      {Jvedio.Language.Resources.ImportFile} :{maxfilepath},{Jvedio.Language.Resources.FileSize} :{new FileInfo(maxfilepath).Length}" + Environment.NewLine;
                        Excludelsist.ForEach(arg =>
                        {
                            c2 += $"      {Jvedio.Language.Resources.NotImport} :{arg},{Jvedio.Language.Resources.FileSize} :{new FileInfo(arg).Length}" + Environment.NewLine;
                        });
                    }
                }
                else
                {
                }
            }
            Logger.LogScanInfo(Environment.NewLine + $"【 {Jvedio.Language.Resources.RepeatVideo}:{removelist.Count + subsectionlist.Count}】" + Environment.NewLine + c2);
            List <string> insertList = r1.Except(removelist).ToList();

            Console.WriteLine("removelist:" + removelist.Count);
            Console.WriteLine("subsectionlist:" + subsectionlist.Count);


            //导入分段视频
            foreach (var item in subsectionlist)
            {
                insertList = insertList.Except(item).ToList();

                try
                {
                    ct.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException ex)
                {
                    Logger.LogE(ex);
                    break;
                }
                string   subsection = "";
                FileInfo fileinfo   = new FileInfo(item[0]);
                id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name);
                if (IsEurope)
                {
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }
                    else
                    {
                        vt = VedioType.欧美;
                    }
                }
                else
                {
                    vt = Identify.GetVedioType(id);
                }
                if (string.IsNullOrEmpty(id) | vt == 0)
                {
                    continue;
                }

                //文件大小视为所有文件之和
                double filesize = 0;
                for (int i = 0; i < item.Count; i++)
                {
                    if (!File.Exists(item[i]))
                    {
                        continue;
                    }
                    FileInfo fi = new FileInfo(item[i]);
                    subsection += item[i] + ";";
                    filesize   += fi.Length;
                }

                //获取创建日期
                string createDate = "";
                try { createDate = fileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); }
                catch { }
                if (createDate == "")
                {
                    createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }

                Movie movie = new Movie()
                {
                    filepath   = item[0],
                    id         = id,
                    filesize   = filesize,
                    vediotype  = (int)vt,
                    subsection = subsection.Substring(0, subsection.Length - 1),
                    otherinfo  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    scandate   = createDate
                };

                DataBase.InsertScanMovie(movie);
                totalinsertnum += 1;
            }

            Console.WriteLine("insertList:" + insertList.Count);


            //导入所有视频


            foreach (var item in insertList)
            {
                try
                {
                    ct.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException ex)
                {
                    Logger.LogE(ex);
                    break;
                }
                if (!File.Exists(item))
                {
                    continue;
                }
                FileInfo fileinfo = new FileInfo(item);

                string createDate = "";
                try { createDate = fileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); }
                catch { }
                if (createDate == "")
                {
                    createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }

                id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name);
                if (IsEurope)
                {
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }
                    else
                    {
                        vt = VedioType.欧美;
                    }
                }
                else
                {
                    vt = Identify.GetVedioType(id);
                }
                Movie movie = new Movie()
                {
                    filepath  = item,
                    id        = id,
                    filesize  = fileinfo.Length,
                    vediotype = (int)vt,
                    otherinfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    scandate  = createDate
                };
                DataBase.InsertScanMovie(movie);
                totalinsertnum += 1;
            }

            Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.TotalImport} => {totalinsertnum},{Jvedio.Language.Resources.ImportAttention}" + Environment.NewLine);


            //从 主数据库中 复制信息
            if (Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath).ToLower() != "info")
            {
                try
                {
                    //待修复 的 bug
                    string src = AppDomain.CurrentDomain.BaseDirectory + "info.sqlite";
                    string dst = AppDomain.CurrentDomain.BaseDirectory + $"DataBase\\{Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath).ToLower()}.sqlite";;
                    DataBase.CopyDatabaseInfo(src, dst);
                }
                catch { }
            }



            return(totalinsertnum);
        }
Ejemplo n.º 24
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            statusText.Text = Jvedio.Language.Resources.Status_UpdateConfig;
            try
            {
                if (Properties.Settings.Default.UpgradeRequired)
                {
                    Properties.Settings.Default.Upgrade();
                    Properties.Settings.Default.UpgradeRequired = false;
                    Properties.Settings.Default.Save();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }

            //复制原有的 info.sqlite
            FileHelper.TryCreateDir("DataBase");
            if (File.Exists("info.sqlite"))
            {
                FileHelper.TryCopyFile("info.sqlite", "DataBase\\info.sqlite");
                FileHelper.TryDeleteFile("info.sqlite");
            }



            CheckFile();     //判断文件是否存在
            CheckSettings(); //修复设置错误
            CreateDir();     //创建文件夹



            Jvedio.Core.ThemeLoader.loadAllThemes();
            SetSkin(Properties.Settings.Default.Themes);
            if (GlobalFont != null)
            {
                this.FontFamily = GlobalFont;
            }
            try
            {
                statusText.Text = Jvedio.Language.Resources.Status_InitDatabase;
                InitDataBase();//初始化数据库
                Identify.InitFanhaoList();
                Scan.InitSearchPattern();
                InitVariable();
            }
            catch (Exception ex)
            {
                Logger.LogE(ex);
            }

            try
            {
                statusText.Text = Jvedio.Language.Resources.Status_ClearRecentWatch;
                ClearDateBefore(-10);
                statusText.Text = Jvedio.Language.Resources.Status_ClearLog;
                ClearLogBefore(-10, "log");
                ClearLogBefore(-10, "log\\NetWork");
                ClearLogBefore(-10, "log\\scanlog");
                ClearLogBefore(-10, "log\\file");
            }
            catch (Exception ex)
            {
                Logger.LogE(ex);
            }

            try
            {
                BackUp("Magnets.sqlite");   //备份文件
                BackUp("AI.sqlite");        //备份文件
                BackUp("Translate.sqlite"); //备份文件
            }
            catch (Exception ex)
            {
                Logger.LogE(ex);
            }

            //默认打开某个数据库
            if (Properties.Settings.Default.OpenDataBaseDefault && File.Exists(Properties.Settings.Default.DataBasePath))
            {
                OpenDefaultDatabase();
                //启动主窗口
                Main main = new Main();
                statusText.Text = Jvedio.Language.Resources.Status_InitMovie;
                try
                {
                    await main.InitMovie();
                }
                catch (Exception ex)
                {
                    Logger.LogE(ex);
                }
                main.Show();
                this.Close();
            }
            else
            {
                SelectDbBorder.Visibility = Visibility.Visible;
            }
        }