Пример #1
0
        public void AddRange(IEnumerable <Film> films)
        {
            if (films == null)
            {
                return;
            }
            var needFilms = films.Except(Films);

            foreach (var f in needFilms)
            {
                if (f.genre != null)
                {
                    AllGenres.Add(f.genre.name);
                }
                if (f.FilmActor != null)
                {
                    foreach (var fa in f.FilmActor)
                    {
                        if (fa.Actor != null)
                        {
                            AllActors.Add(fa.Actor.fullName);
                        }
                    }
                }
            }

            Films.AddRange(needFilms);
        }
Пример #2
0
        public Collection <string> GetGenreList(int appId, int depth, bool tagFallback)
        {
            if (!Contains(appId, out DatabaseEntry entry))
            {
                return(new Collection <string>());
            }

            Collection <string> result = entry.Genres ?? new Collection <string>();

            if (tagFallback && result.Count == 0)
            {
                Collection <string> tags = GetTagList(appId, 0);
                if (tags != null && tags.Count > 0)
                {
                    result = new Collection <string>(tags.Where(tag => AllGenres.Contains(tag)).ToList());
                }
            }

            if (result.Count == 0 && depth > 0 && entry.ParentId > 0)
            {
                result = GetGenreList(entry.ParentId, depth - 1, tagFallback);
            }

            return(result);
        }
Пример #3
0
 public void Add(Film film)
 {
     if (film == null)
     {
         return;
     }
     if (!Films.Contains(film))
     {
         Films.Add(film);
         if (film.genre != null)
         {
             AllGenres.Add(film.genre.name);
         }
         if (film.FilmActor != null)
         {
             foreach (var fa in film.FilmActor)
             {
                 if (fa.Actor != null)
                 {
                     AllActors.Add(fa.Actor.fullName);
                 }
             }
         }
     }
 }
Пример #4
0
        public TagEditorViewModel(LocalTrack track, Window baseWindow)
        {
            TagFile            = File.Create(track.Path);
            Track              = track;
            baseWindow.Closed += (s, e) => TagFile.Dispose();
            _baseWindow        = baseWindow;

            AllGenres = Genres.Audio.ToList();
            AllGenres.AddRange(Enum.GetValues(typeof(Genre)).Cast <Genre>().Select(PlayableBase.GenreToString).Where(x => !AllGenres.Contains(x)));
            AllGenres.Sort();

            SelectedGenres = track.Genres.Select(PlayableBase.GenreToString).ToList();
        }
        private async Task LoadArtistsAndGenres()
        {
            var allArtistsReturned = await _artistService.Get <List <Model.Artist> >(null);

            var allGenres = await _genreService.Get <List <Model.Genre> >(null);

            var allArtistGenre = await _artistGenreService.Get <List <Model.ArtistGenre> >(null);

            foreach (var item in allArtistsReturned)
            {
                var    genres    = allArtistGenre.Where(a => a.ArtistId == item.ArtistId).ToList();
                string genresStr = "Genres: ";
                foreach (var x in genres)
                {
                    genresStr += allGenres.Where(a => a.GenreId == x.GenreId).Select(a => a.GenreName).FirstOrDefault();
                    if (x != genres.ElementAt(genres.Count - 1))
                    {
                        genresStr += ", ";
                    }
                }
                AllArtists.Add(new ArtistHelperVM()
                {
                    ArtistGenresInString = genresStr,
                    ArtistId             = item.ArtistId,
                    ArtistMembers        = item.ArtistMembers,
                    ArtistName           = item.ArtistName,
                    ArtistPhoto          = item.ArtistPhoto
                });
                QueryArtists.Add(new ArtistHelperVM()
                {
                    ArtistGenresInString = genresStr,
                    ArtistId             = item.ArtistId,
                    ArtistMembers        = item.ArtistMembers,
                    ArtistName           = item.ArtistName,
                    ArtistPhoto          = item.ArtistPhoto
                });
            }
            foreach (var item in allGenres)
            {
                AllGenres.Add(item);
                QueryGenres.Add(item);
            }
        }
Пример #6
0
        private void Process(List <File> selection, List <File> allFiles)
        {
            string currAlbum     = null;
            string currArtist    = null;
            string currAA        = null;
            string currGenre     = null;
            string currComposer  = null;
            string currConductor = null;
            string currGrouping  = null;
            string currCopyright = null;

            bool set = false;

            foreach (File f in allFiles)
            {
                if (f.Tags.Title != null && f.Tags.Title.Length > 0)
                {
                    AllTitles.Add(f.Tags.Title);
                }
                string fname = Path.GetFileName(f.FileName);
                Match  match = Regex.Match(fname, @"(?:\d+\.?)?(?:[\s_]?-[\s_]?)?(.*?)\.[^\.]+$");
                if (match.Success)
                {
                    string val = match.Groups[1].Value;
                    val = val.Replace('_', ' ');
                    val = val.Replace('.', ' ');
                    val = Regex.Replace(val, @"\s+", " ");
                    val = val.Trim();
                    if (val.Length > 0)
                    {
                        AllTitles.Add(val);
                    }

                    if (f.Tags.Album != null && f.Tags.Album.Length > 0)
                    {
                        AllAlbums.Add(f.Tags.Album);
                    }
                    if (f.Tags.Artists != null && f.Tags.Artists.Length > 0)
                    {
                        AllArtists.Add(f.Tags.Artists);
                    }
                    if (f.Tags.AlbumArtists != null && f.Tags.AlbumArtists.Length > 0)
                    {
                        AllAlbumArtists.Add(f.Tags.AlbumArtists);
                    }
                    if (f.Tags.Genres != null && f.Tags.Genres.Length > 0)
                    {
                        AllGenres.Add(f.Tags.Genres);
                    }
                    if (f.Tags.Composers != null && f.Tags.Composers.Length > 0)
                    {
                        AllComposers.Add(f.Tags.Composers);
                    }
                    if (f.Tags.Conductor != null && f.Tags.Conductor.Length > 0)
                    {
                        AllConductors.Add(f.Tags.Conductor);
                    }
                    if (f.Tags.Grouping != null && f.Tags.Grouping.Length > 0)
                    {
                        AllGroupings.Add(f.Tags.Grouping);
                    }
                    if (f.Tags.Copyright != null && f.Tags.Copyright.Length > 0)
                    {
                        AllCopyrights.Add(f.Tags.Copyright);
                    }
                }
            }

            foreach (File f in selection)
            {
                if (!set)
                {
                    currAlbum     = f.Tags.Album;
                    currArtist    = f.Tags.Artists;
                    currAA        = f.Tags.AlbumArtists;
                    currGenre     = f.Tags.Genres;
                    currComposer  = f.Tags.Composers;
                    currConductor = f.Tags.Conductor;
                    currGrouping  = f.Tags.Grouping;
                    currCopyright = f.Tags.Copyright;
                }
                else
                {
                    if (SameAlbum && currAlbum != f.Tags.Album)
                    {
                        SameAlbum = false;
                    }
                    else
                    {
                        currAlbum = f.Tags.Album;
                    }

                    if (SameArtists && currArtist != f.Tags.Artists)
                    {
                        SameArtists = false;
                    }
                    else
                    {
                        currArtist = f.Tags.Artists;
                    }

                    if (SameAlbumArtists && currAA != f.Tags.AlbumArtists)
                    {
                        SameAlbumArtists = false;
                    }
                    else
                    {
                        currAA = f.Tags.AlbumArtists;
                    }

                    if (SameGenres && currGenre != f.Tags.Genres)
                    {
                        SameGenres = false;
                    }
                    else
                    {
                        currGenre = f.Tags.Genres;
                    }

                    if (SameComposers && currComposer != f.Tags.Composers)
                    {
                        SameComposers = false;
                    }
                    else
                    {
                        currComposer = f.Tags.Composers;
                    }

                    if (SameConductor && currConductor != f.Tags.Conductor)
                    {
                        SameConductor = false;
                    }
                    else
                    {
                        currConductor = f.Tags.Conductor;
                    }

                    if (SameGrouping && currGrouping != f.Tags.Grouping)
                    {
                        SameGrouping = false;
                    }
                    else
                    {
                        currGrouping = f.Tags.Grouping;
                    }

                    if (SameCopyright && currCopyright != f.Tags.Copyright)
                    {
                        SameCopyright = false;
                    }
                    else
                    {
                        currCopyright = f.Tags.Copyright;
                    }
                }
                set = true;
            }
            SetValues(selection);
        }
Пример #7
0
        /// <summary>
        /// Add the information from the Titles file into our
        /// Titles Dictionary.
        /// </summary>
        /// <param name="line">Each line of the file.</param>
        private void AddInformationToTitles(string line)
        {
            /*
             * Variables to use for assigning information.
             * By default, the Titles file goes as follows with the index...
             * 0 = Identifier.
             * 1 = Type.
             * 2 = Primary title name.
             * 3 = Original name.
             * 4 = For adults or not.
             * 5 = The release year.
             * 6 = The end year.
             * 7 = Runtime in minutes.
             * 8 = The three (possible) genres associated with the title.
             */
            short aux;

            string[] fields = line.Split("\t");
            string   titleIdentifier = fields[0];
            string   titleType = fields[1];
            string   titlePrimaryTitle = fields[2];
            bool     titleAdult = fields[4] == "0" ? false : true;
            short?   titleStartYear, titleEndYear;

            string[] titleGenres = fields[8].Split(",");

            // Our clean Titles and Types.
            ICollection <string> cleanTitleGenres = new List <string>();
            ICollection <string> cleanTitleTypes  = new List <string>();

            // Try to get the start year.
            try
            {
                titleStartYear = short.TryParse(fields[5], out aux)
                    ? (short?)aux
                    : null;
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          $"Tried to parse '{line}', but got exception '{e.Message}'"
                          + $" with this stack trace: {e.StackTrace}");
            }

            // Try to get the end year.
            try
            {
                titleEndYear = short.TryParse(fields[6], out aux)
                    ? (short?)aux
                    : null;
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          $"Tried to parse '{line}', but got exception '{e.Message}'"
                          + $" with this stack trace: {e.StackTrace}");
            }

            // Remove the invalid types.
            if (titleType != null && titleType != @"\N")
            {
                cleanTitleTypes.Add(titleType);
            }

            // Add the valid types to the set of all types in the database.
            foreach (string type in cleanTitleTypes)
            {
                AllTypes.Add(type);
            }

            // Remove invalid genres.
            foreach (string genre in titleGenres)
            {
                if (genre != null && genre.Length > 0 && genre != @"\N")
                {
                    cleanTitleGenres.Add(genre);
                }
            }

            // Add the valid genres to the set of all genres in the database.
            foreach (string genre in cleanTitleGenres)
            {
                AllGenres.Add(genre);
            }

            // Create our Titles entry.
            StructTitle t = new StructTitle(
                titleIdentifier, titleType, titlePrimaryTitle, titleAdult,
                titleStartYear, titleEndYear, cleanTitleGenres.ToArray());

            // Add it to our Dictionary. If the one being inserted matches our
            // identifier, we will replace it with the new one in order to
            // avoid duplicates, saving up memory!
            Titles[t.TitleIdentifier] = t;
        }