Example #1
0
 private void GetFromEit(string filepath)
 {
     using (var process = new Process())
     {
         try
         {
             process.StartInfo = new ProcessStartInfo
             {
                 FileName               = Util.file,
                 Arguments              = $"\"{filepath.Replace(".program.txt", "")}\" -cbidtpg -l 10",
                 CreateNoWindow         = true,
                 UseShellExecute        = false,
                 RedirectStandardOutput = true,
             };
             process.Start();
             var infos = process.StandardOutput.ReadToEnd().Split(',');
             Company  = infos[0].Normalize(NormalizationForm.FormKC);
             Title    = infos[1];
             Subtitle = infos[2];
             var day       = infos[3];
             var starttime = infos[4];
             var genres    = infos[6].Split(' ');
             Length    = TimeSpan.Parse(infos[5]);
             Starttime = DateTime.Parse(day + " " + starttime);
             Endtime   = Starttime.Add(Length);
             Series    = Regex.Replace(Title, flag + "|" + subtitleflag + "|" + tvIndex, "");
             if (Series.Split(' ').Length > 1)
             {
                 Series = Series.Split(' ')[0];
             }
             else if (Series.Split(' ').Length > 1)
             {
                 Series = Series.Split(' ')[0];
             }
             var matche = Regex.Matches(Title, subtitleflag);
             foreach (Match ma in matche)
             {
                 SeriesInfo.Add(ma.Value);
             }
             foreach (var genre in genres)
             {
                 GenreIndex.Add(GenreIndexRet(genre));
                 Genre.Add(genre.Split(' ')[0]);
             }
             if (Regex.IsMatch(Title, tvIndex))
             {
                 var tvidex_mat = Regex.Match(Title, tvIndex);
                 Epinum = int.Parse(tvidex_mat.Groups["index"].Value.Normalize(NormalizationForm.FormKC));
             }
             else
             {
                 Epinum = 0;
             }
         }
         catch
         {
             throw new AggregateException();
         }
     }
 }
Example #2
0
        private void GetFromTxt(string filepath)
        {
            var file = File.ReadAllLines(filepath);
            var time = file[0];

            Company = file[1].Normalize(NormalizationForm.FormKC);
            Title   = file[2];

            var timesprit  = time.Split(' ');
            var day        = Regex.Replace(timesprit[0], @"\([月|火|水|木|金|土|日]\)", "");
            var time_sprit = timesprit[1].Split('~');

            Starttime = DateTime.Parse(day + " " + time_sprit[0]);
            Endtime   = DateTime.Parse(day + " " + time_sprit[1]);

            if (Endtime.CompareTo(Starttime) == -1)
            {
                Endtime = Endtime.AddDays(1);
            }

            Length = Endtime - Starttime;

            Series = Regex.Replace(Title, flag + "|" + subtitleflag + "|" + tvIndex, "");
            if (Series.Split(' ').Length > 1)
            {
                Series = Series.Split(' ')[0];
            }
            var matche = Regex.Matches(Title, subtitleflag);

            foreach (Match ma in matche)
            {
                SeriesInfo.Add(ma.Value);
            }
            var i = 4;

            while (file[i] != "")
            {
                Subtitle += "\n" + file[i];
                i++;
            }
            var genreIndexCount = Array.IndexOf(file, "ジャンル : ") + 1;

            while (file[genreIndexCount] != "")
            {
                GenreIndex.Add(GenreIndexRet(file[genreIndexCount]));
                Genre.Add(file[genreIndexCount].Split(' ')[0]);
                genreIndexCount++;
            }
            if (Regex.IsMatch(Title, tvIndex))
            {
                var tvidex_mat = Regex.Match(Title, tvIndex);
                Epinum = int.Parse(tvidex_mat.Groups["index"].Value.Normalize(NormalizationForm.FormKC));
            }
            else
            {
                Epinum = 0;
            }
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryDal"/> class.
        /// </summary>
        public InMemoryDal()
        {
            JsonSerializerOptions settings = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            };

            if (Actors?.Count == null)
            {
                // load the data from the json file
                Actors = JsonSerializer.Deserialize <List <Actor> >(File.ReadAllText("data/actors.json"), settings);

                // sort by Name
                Actors.Sort(Actor.NameCompare);
            }

            if (ActorsIndex.Count == 0)
            {
                // Loads an O(1) dictionary for retrieving by ID
                // Could also use a binary search to reduce memory usage
                foreach (Actor a in Actors)
                {
                    ActorsIndex.Add(a.ActorId, a);
                }
            }

            if (Movies?.Count == null)
            {
                // load the data from the json file
                Movies = JsonSerializer.Deserialize <List <Movie> >(File.ReadAllText("data/movies.json"), settings);

                // sort by Title
                Movies.Sort(Movie.TitleCompare);
            }

            string ge;

            if (MoviesIndex.Count == 0)
            {
                foreach (Movie m in Movies)
                {
                    // Loads an O(1) dictionary for retrieving by ID
                    // Could also use a binary search to reduce memory usage
                    MoviesIndex.Add(m.MovieId, m);

                    // Add to by year dictionary
                    if (!YearIndex.ContainsKey(m.Year))
                    {
                        YearIndex.Add(m.Year, new List <Movie>());
                    }

                    YearIndex[m.Year].Add(m);

                    // Add to by Genre dictionary
                    foreach (string g in m.Genres)
                    {
                        ge = g.ToLowerInvariant().Trim();

                        if (!GenreIndex.ContainsKey(ge))
                        {
                            GenreIndex.Add(ge, new List <Movie>());
                        }

                        GenreIndex[ge].Add(m);
                    }
                }
            }

            if (Genres.Count == 0)
            {
                // load the data from the json file
                List <Genre> list = JsonSerializer.Deserialize <List <Genre> >(File.ReadAllText("data/genres.json"), settings);

                // Convert Genre object to List<string> per API spec
                foreach (Genre g in list)
                {
                    Genres.Add(g.Name);
                }

                Genres.Sort();
            }
        }
Example #4
0
        public InMemoryDal()
        {
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver {
                    NamingStrategy = new CamelCaseNamingStrategy()
                },
            };

            // load the data from the json files
            Actors = JsonConvert.DeserializeObject <List <Actor> >(File.ReadAllText("data/actors.json"), settings);

            // sort by Name
            Actors.Sort(Actor.NameCompare);

            // Loads an O(1) dictionary for retrieving by ID
            // Could also use a binary search to reduce memory usage
            foreach (Actor a in Actors)
            {
                ActorsIndex.Add(a.ActorId, a);
            }

            Movies = JsonConvert.DeserializeObject <List <Movie> >(File.ReadAllText("data/movies.json"), settings);

            // sort by Title
            Movies.Sort(Movie.TitleCompare);

            string ge;

            foreach (Movie m in Movies)
            {
                // Loads an O(1) dictionary for retrieving by ID
                // Could also use a binary search to reduce memory usage
                MoviesIndex.Add(m.MovieId, m);

                // Create a dictionary by year
                if (!YearIndex.ContainsKey(m.Year))
                {
                    YearIndex.Add(m.Year, new List <Movie>());
                }

                YearIndex[m.Year].Add(m);

                // Create a dictionary by Genre
                foreach (string g in m.Genres)
                {
                    ge = g.ToLowerInvariant().Trim();

                    if (!GenreIndex.ContainsKey(ge))
                    {
                        GenreIndex.Add(ge, new List <Movie>());
                    }

                    GenreIndex[ge].Add(m);
                }
            }

            List <dynamic> list = JsonConvert.DeserializeObject <List <dynamic> >(File.ReadAllText("data/genres.json"), settings);

            // Convert Genre object to List<string> per API spec
            Genres = new List <string>();

            foreach (dynamic g in list)
            {
                Genres.Add(g["genre"].Value);
            }

            Genres.Sort();
        }