Пример #1
0
        public static void TVShowsDirectoryList()
        {
            try
            {
                //declare variables
                MyMoviesEntities dbContext = new MyMoviesEntities();
                List<string> paths = new List<string>();
                Dictionary<string, List<string>> showName = new Dictionary<string, List<string>>();
                //get list of movies in db
                List<Show> Currentshows = new List<Show>();

                Currentshows = dbContext.Shows.Select(s => s).ToList();

                //Scan Directorys
                Utility.TreeScan(@"\\MEDIAHUB\media\videos\Downloads\tv", ref paths);
                //Put Titles and path in a map
                //List<string> showTitles = new List<string>();
                foreach (string str in paths)
                {
                    //format movie name
                    string dir = Path.GetDirectoryName(str);
                    string[] dirParts = dir.Split(Path.DirectorySeparatorChar);
                    for(int i = 0; i < dirParts.Count(); i++)
                    {
                        //Console.WriteLine(str);
                        if(dirParts[i].ToLower().Contains("tv"))
                        {
                            if (showName.ContainsKey(dirParts[i+1]))
                            {
                                showName[dirParts[i + 1]].Add(str);
                            }
                            else
                            {
                                showName.Add(dirParts[i + 1], new List<string>());
                                showName[dirParts[i + 1]].Add(str);
                            }
                        }//end if
                    }//end for

                }//end for
                //foreach (string str in paths)
                //{
                //    Regex regStyleOne = new Regex(@"[0-9]x[0-9][0-9]");
                //    Regex regStyleTwo = new Regex(@"[0-9][0-9]\w[0-9][0-9]");
                //    string[] dirParts = str.Split(Path.DirectorySeparatorChar);
                //    string name = dirParts.Last();

                //
                //    {
                //        //Console.WriteLine(name);
                //    }
                //    //Console.WriteLine(reg.Match(name));
                //}
                foreach(string showTitle in showName.Keys)
                {
                    Show currentShow = Currentshows.FirstOrDefault(s=> s.Title == showTitle);

                    if (currentShow == null)
                    {
                        string nezbinStart = @"https://www.newzbin2.es/search/query/?q=+%09";
                        string[] titlePart = showTitle.Split(' ');
                        for(int i = 0; i < titlePart.Count(); i++)
                        {
                            if(i == titlePart.Count()-1)
                            {
                                nezbinStart += titlePart[i];
                            }
                            else
                            {
                                nezbinStart += titlePart[i] + "+";
                            }
                        }
                        nezbinStart += @"&area=ss.630722&fpn=p&u_search_system=0&searchaction=Go&btnG_x=0&btnG_y=0&ss=630722&go=1&areadone=ss.630722";
                        currentShow = new Show();
                        currentShow.Title = showTitle;
                        currentShow.NewzbinSearch = nezbinStart;
                        dbContext.Shows.Add(currentShow);
                        dbContext.SaveChanges();
                    }

                    foreach (String path in showName[showTitle])
                    {
                        int season = 0;
                        int episode = 0;

                        Regex regStyleOne = new Regex(@"[0-9]x[0-9][0-9]");
                        Regex regStyleTwo = new Regex(@"[0-9][0-9]\w[0-9][0-9]");
                        if (regStyleOne.IsMatch(path))
                        {

                            string episodeReg = regStyleOne.Match(path).Value.ToLower();
                            string[] strSplit = episodeReg.Split('x');
                            season = Convert.ToInt32(strSplit[0]);
                            episode = Convert.ToInt32(strSplit[1]);
                        }
                        else if (regStyleTwo.IsMatch(path))
                        {
                            string episodeReg = regStyleTwo.Match(path).Value.ToLower();
                            string[] strSplit = episodeReg.Split('e');
                            season = Convert.ToInt32(strSplit[0]);
                            episode = Convert.ToInt32(strSplit[1]);
                        }
                        Episode currentEpisode = dbContext.Episodes.FirstOrDefault(e => e.Episode1 == episode && e.Season == season && e.ShowId == currentShow.Id);
                        if(currentEpisode ==null)
                        {
                            currentEpisode = new Episode();
                            currentEpisode.Season = season;
                            currentEpisode.Episode1 = episode;
                            currentEpisode.Path = path;
                            currentEpisode.ShowId = currentShow.Id;
                            dbContext.Episodes.Add(currentEpisode);
                            dbContext.SaveChanges();
                        }//end if
                    }//end for
                }

            }//end try
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }//end catch
        }