示例#1
0
        public AlbumArtist AlbumArtistForNameOrCreate(string albumArtistName)
        {
            if (albumArtistName == null || albumArtistName == "")
            {
                return(new AlbumArtist());
            }

            // check to see if the artist exists
            AlbumArtist anAlbumArtist = this.AlbumArtistForName(albumArtistName);

            // if not, create it.
            if (anAlbumArtist.AlbumArtistId == null)
            {
                anAlbumArtist = null;
                if (this.InsertAlbumArtist(albumArtistName))
                {
                    anAlbumArtist = this.AlbumArtistForNameOrCreate(albumArtistName);
                }
                else
                {
                    // The insert failed because this album was inserted by another
                    // thread, so grab the artist id, it will exist this time
                    anAlbumArtist = this.AlbumArtistForName(albumArtistName);
                }
            }

            // then return the artist object retrieved or created.
            return(anAlbumArtist);
        }
示例#2
0
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = TrackId;
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Artist != null ? Artist.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AlbumArtist != null ? AlbumArtist.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Composer != null ? Composer.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Album != null ? Album.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Genre != null ? Genre.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Kind != null ? Kind.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Size.GetHashCode();
         hashCode = (hashCode * 397) ^ (PlayingTime != null ? PlayingTime.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ TrackNumber.GetHashCode();
         hashCode = (hashCode * 397) ^ Year.GetHashCode();
         hashCode = (hashCode * 397) ^ DateModified.GetHashCode();
         hashCode = (hashCode * 397) ^ DateAdded.GetHashCode();
         hashCode = (hashCode * 397) ^ BitRate.GetHashCode();
         hashCode = (hashCode * 397) ^ SampleRate.GetHashCode();
         hashCode = (hashCode * 397) ^ PlayCount.GetHashCode();
         hashCode = (hashCode * 397) ^ PlayDate.GetHashCode();
         hashCode = (hashCode * 397) ^ PartOfCompilation.GetHashCode();
         return(hashCode);
     }
 }
示例#3
0
        public ActionResult DeleteConfirmed(int id)
        {
            AlbumArtist albumArtist = db.AlbumArtists.Find(id);

            db.AlbumArtists.Remove(albumArtist);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
        public IActionResult Create(AlbumArtist albumArtist)
        {
            if (!UserIsInRole(UserTypeEnum.Admin))
            {
                return(Unauthorized("You are not in role to permit this action"));
            }

            _service.Insert(albumArtist);
            return(Ok());
        }
示例#5
0
 public ActionResult Edit([Bind(Include = "AlbumArtistId,ArtistId,AlbumId")] AlbumArtist albumArtist)
 {
     if (ModelState.IsValid)
     {
         db.Entry(albumArtist).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AlbumId  = new SelectList(db.Albums, "AlbumId", "Name", albumArtist.AlbumId);
     ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "FirstName", albumArtist.ArtistId);
     return(View(albumArtist));
 }
示例#6
0
        internal Album(List <Track> trackList, string title, string albumArtist, int year)
        {
            Contract.Requires(trackList != null);
            Contract.Requires(!string.IsNullOrEmpty(title));
            Contract.Requires(!string.IsNullOrEmpty(albumArtist));

            _TrackList   = trackList;
            _Title       = title;
            _AlbumArtist = albumArtist;
            _Year        = year;
            _AlbumID     = (uint)(31 * Title.GetHashCode() + AlbumArtist.GetHashCode());
            Artwork      = new LastFmArtworkProvider(this);
        }
示例#7
0
        // GET: AlbumArtists/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AlbumArtist albumArtist = db.AlbumArtists.Find(id);

            if (albumArtist == null)
            {
                return(HttpNotFound());
            }
            return(View(albumArtist));
        }
示例#8
0
        public bool CreateAlbumArtist(AlbumArtistCreate model)
        {
            var entity =
                new AlbumArtist()
            {
                AlbumId  = model.AlbumId,
                ArtistId = model.ArtistId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.AlbumArtist.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#9
0
        // GET: AlbumArtists/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AlbumArtist albumArtist = db.AlbumArtists.Find(id);

            if (albumArtist == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AlbumId  = new SelectList(db.Albums, "AlbumId", "Name", albumArtist.AlbumId);
            ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "FirstName", albumArtist.ArtistId);
            return(View(albumArtist));
        }
示例#10
0
        internal void WriteToTag(Tag tag)
        {
            tag.Label       = Label;
            tag.Album       = Name;
            tag.AlbumArtist = AlbumArtist.GetName(Artist.NameFormats.Last_First);
            tag.AlbumID     = ID;
            tag.AlbumType   = AlbumType;
            tag.IsComplete  = IsComplete;
            tag.IsInIpod    = IsInIpod;

            tag.AlbumPicture = GetAlbumCover();
            //if (IO.File.Exists(t.AssociatedAlbum.GetFilePath(Album.FilePaths.AlbumCoverPath_Auto)))
            //{
            //    tag.AlbumPicture = new Bitmap(t.AssociatedAlbum.GetFilePath(Album.FilePaths.AlbumCoverPath_Auto));
            //}
        }
示例#11
0
        public void UpdateMainGroup()
        {
            if (artist.StartsWith("the ", StringComparison.OrdinalIgnoreCase))
            {
                artistNoThe = Artist.Substring(4);
            }
            else
            {
                artistNoThe = Artist;
            }

            if (albumArtist.StartsWith("the ", StringComparison.OrdinalIgnoreCase))
            {
                albumArtistNoThe = AlbumArtist.Substring(4);
            }
            else
            {
                albumArtistNoThe = AlbumArtist;
            }

            if (Compilation)
            {
                mainGroup = Album;
            }
            else if (AlbumArtist.Length > 0)
            {
                mainGroup = AlbumArtist;
            }
            else
            {
                mainGroup = Artist;
            }

            if (mainGroup.StartsWith("the ", StringComparison.OrdinalIgnoreCase))
            {
                mainGroupNoThe = mainGroup.Substring(4);
            }
            else
            {
                mainGroupNoThe = mainGroup;
            }

            toStringDirty     = true;
            searchStringDirty = true;
        }
示例#12
0
        public bool InsertAlbumArtist(string albumArtistName, bool replace = false)
        {
            int?itemId = itemRepository.GenerateItemId(ItemType.AlbumArtist);

            if (itemId == null)
            {
                return(false);
            }

            AlbumArtist artist = new AlbumArtist();

            artist.AlbumArtistId   = itemId;
            artist.AlbumArtistName = albumArtistName;

            int affected = this.database.InsertObject <AlbumArtist>(artist, replace ? InsertType.Replace : InsertType.InsertOrIgnore);

            return(affected > 0);
        }
示例#13
0
        static void TryManyToManyContext()
        {
            using (var context = new ManyToManyContext())
            {
                Artist artist1 = new Artist()
                {
                    FirstName = "Mihai",
                    LastName  = "Luca",
                };

                Album album1 = new Album
                {
                    Name = "Blue Flower",
                    Date = DateTime.Now
                };
                AlbumArtist albumArtist1 = new AlbumArtist
                {
                    Album  = album1,
                    Artist = artist1
                };

                context.Artists.Add(artist1);
                context.Albums.Add(album1);
                context.AlbumArtists.Add(albumArtist1);
                context.SaveChanges();

                foreach (var artist in context.Artists)
                {
                    Console.WriteLine($"Name:{artist.FirstName} {artist.LastName}");

                    foreach (var albumArtist in artist.AlbumArtists)
                    {
                        Console.WriteLine($"Name: {albumArtist.Album.Name} Date: {albumArtist.Album.Date}");
                    }
                }
            }
        }
示例#14
0
        public void RenameFiles()
        {
            foreach (Track t in Tracks)
            {
                t.RenameFile();
            }

            string new_path              = "";
            string artist_part           = PathUtils.FixPathString(AlbumArtist.GetName(Artist.NameFormats.Last_First));
            string albumname_part        = PathUtils.FixPathString(this.Name);
            string artist_albumname_part = Path.Combine(artist_part, albumname_part);

            if (AlbumType == AlbumType.ArtistAlbum)
            {
                new_path = Path.Combine("Collection II", artist_albumname_part);
            }
            else if (AlbumType == AlbumType.ComposerAlbum)
            {
                albumname_part = PathUtils.FixPathString(
                    System.Text.RegularExpressions.Regex.Replace(this.Name, @"^(\w)+:\s", ""));
                artist_albumname_part = Path.Combine(artist_part, albumname_part);
                new_path = Path.Combine("Collection I", artist_albumname_part);
            }
            else if (AlbumType == AlbumType.VariousArtistAlbum)
            {
                new_path = Path.Combine("Collection III", albumname_part);
            }

            new_path = Path.Combine(Path.GetDirectoryName(Location), new_path);

            Directory.CreateDirectory(Path.GetDirectoryName(new_path));
            Directory.Move(Location, new_path);

            Location = new_path;
            Update();
        }
 public bool Update(AlbumArtist albumArtist)
 {
     _repository.Update(albumArtist);
     return(_repository.SaveChanges());
 }
示例#16
0
 public static string GetAlbumArtistInfo(AlbumArtist albumArtist)
 {
     return(GetInfo(albumArtist.AlbumArtistName));
 }
示例#17
0
        /// <summary>
        /// Process returns an AlbumArtistsResponse containing a list of artists, albums, and songs
        /// </summary>
        public void Process(UriWrapper uri, IHttpProcessor processor, User user)
        {
            // Lists of artists, albums, songs to be returned via handler
            IList <AlbumArtist>      albumArtists     = new List <AlbumArtist>();
            IList <Album>            albums           = new List <Album>();
            IList <Song>             songs            = new List <Song>();
            Dictionary <string, int> counts           = new Dictionary <string, int>();
            PairList <string, int>   sectionPositions = new PairList <string, int>();

            // Optional Last.fm info
            string lastfmInfo = null;

            // Check if an ID was passed
            if (uri.Id != null)
            {
                // Add artist by ID to the list
                AlbumArtist a = Injection.Kernel.Get <IAlbumArtistRepository>().AlbumArtistForId((int)uri.Id);
                albumArtists.Add(a);

                // Add artist's albums to response
                albums = a.ListOfAlbums();
                counts.Add("albums", albums.Count);

                // If requested, add artist's songs to response
                if (uri.Parameters.ContainsKey("includeSongs") && uri.Parameters["includeSongs"].IsTrue())
                {
                    songs = a.ListOfSongs();
                    counts.Add("songs", songs.Count);
                }
                else
                {
                    counts.Add("songs", a.ListOfSongs().Count);
                }

                // If requested, add artist's Last.fm info to response
                if (uri.Parameters.ContainsKey("lastfmInfo") && uri.Parameters["lastfmInfo"].IsTrue())
                {
                    logger.IfInfo("Querying Last.fm for artist: " + a.AlbumArtistName);
                    try
                    {
                        lastfmInfo = Lastfm.GetAlbumArtistInfo(a);
                        logger.IfInfo("Last.fm query complete!");
                    }
                    catch (Exception e)
                    {
                        logger.Error("Last.fm query failed!");
                        logger.Error(e);
                    }
                }

                // Get favorites count if available
                if (a.AlbumArtistId != null)
                {
                    int favoriteCount = Injection.Kernel.Get <IFavoriteRepository>().FavoritesForAlbumArtistId(a.AlbumArtistId, user.UserId).Count;
                    counts.Add("favorites", favoriteCount);
                }
                else
                {
                    counts.Add("favorites", 0);
                }
            }
            // Check for a request for range of artists
            else if (uri.Parameters.ContainsKey("range"))
            {
                string[] range = uri.Parameters["range"].Split(',');

                // Ensure valid range was parsed
                if (range.Length != 2)
                {
                    processor.WriteJson(new AlbumArtistsResponse("Parameter 'range' requires a valid, comma-separated character tuple", null, null, null, null, null, null));
                    return;
                }

                // Validate as characters
                char start, end;
                if (!Char.TryParse(range[0], out start) || !Char.TryParse(range[1], out end))
                {
                    processor.WriteJson(new AlbumArtistsResponse("Parameter 'range' requires characters which are single alphanumeric values", null, null, null, null, null, null));
                    return;
                }

                // Grab range of artists
                albumArtists = Injection.Kernel.Get <IAlbumArtistRepository>().RangeAlbumArtists(start, end);
            }

            // Check for a request to limit/paginate artists, like SQL
            // Note: can be combined with range or all artists
            if (uri.Parameters.ContainsKey("limit") && uri.Id == null)
            {
                string[] limit = uri.Parameters["limit"].Split(',');

                // Ensure valid limit was parsed
                if (limit.Length < 1 || limit.Length > 2)
                {
                    processor.WriteJson(new AlbumArtistsResponse("Parameter 'limit' requires a single integer, or a valid, comma-separated integer tuple", null, null, null, null, null, null));
                    return;
                }

                // Validate as integers
                int index    = 0;
                int duration = Int32.MinValue;
                if (!Int32.TryParse(limit[0], out index))
                {
                    processor.WriteJson(new AlbumArtistsResponse("Parameter 'limit' requires a valid integer start index", null, null, null, null, null, null));
                    return;
                }

                // Ensure positive index
                if (index < 0)
                {
                    processor.WriteJson(new AlbumArtistsResponse("Parameter 'limit' requires a non-negative integer start index", null, null, null, null, null, null));
                    return;
                }

                // Check for duration
                if (limit.Length == 2)
                {
                    if (!Int32.TryParse(limit[1], out duration))
                    {
                        processor.WriteJson(new AlbumArtistsResponse("Parameter 'limit' requires a valid integer duration", null, null, null, null, null, null));
                        return;
                    }

                    // Ensure positive duration
                    if (duration < 0)
                    {
                        processor.WriteJson(new AlbumArtistsResponse("Parameter 'limit' requires a non-negative integer duration", null, null, null, null, null, null));
                        return;
                    }
                }

                // Check if results list already populated by range
                if (albumArtists.Count > 0)
                {
                    // No duration?  Return just specified number of artists
                    if (duration == Int32.MinValue)
                    {
                        albumArtists = albumArtists.Skip(0).Take(index).ToList();
                    }
                    else
                    {
                        // Else, return artists starting at index, up to count duration
                        albumArtists = albumArtists.Skip(index).Take(duration).ToList();
                    }
                }
                else
                {
                    // If no artists in list, grab directly using model method
                    albumArtists = Injection.Kernel.Get <IAlbumArtistRepository>().LimitAlbumArtists(index, duration);
                }
            }

            // Finally, if no artists already in list, send the whole list
            if (albumArtists.Count == 0)
            {
                albumArtists     = Injection.Kernel.Get <IAlbumArtistRepository>().AllAlbumArtists();
                sectionPositions = Utility.SectionPositionsFromSortedList(new List <IGroupingItem>(albumArtists.Select(c => (IGroupingItem)c)));
            }

            // Send it!
            processor.WriteJson(new AlbumArtistsResponse(null, albumArtists, albums, songs, counts, lastfmInfo, sectionPositions));
            return;
        }
示例#18
0
    private static void InsertTestData(RajiNetDbContext db)
    {
        /* Series */

        var absoluteSoul = new Series {
            Name  = "Absolute Soul",
            Image = "/assets/img/series/absoluteduo.jpg",
        };
        var gochiUsa = new Series {
            Name  = "Gochuumon wa Usagi Desu Ka?",
            Image = "/assets/img/series/gochiusa.jpg",
        };
        var saeKano = new Series {
            Name  = "Saenai Heroine no Sodate Kata",
            Image = "/assets/img/series/saekano.jpg",
        };


        /* Artists */

        var iguchiYuka = new Artist {
            Name  = "Iguchi Yuka",
            Image = "/assets/images/artists/iguigu.jpg",
        };
        var asumiKana = new Artist {
            Name  = "AsumiKana",
            Image = "/assets/images/artists/asumin.jpg",
        };
        var konomiSuzuki = new Artist {
            Name  = "Konomi Suzuki",
            Image = "/assets/images/artists/konomi.jpg",
        };


        /* Albums */

        var hafaAdai = new Album {
            Name        = "Hafa Adai",
            Image       = "/assets/images/albums/hafaAdai.jpg",
            ReleaseDate = DateTime.Now,
            SingleType  = SingleType.Album,
        };
        var absoluteSoulAlbum = new Album {
            Name        = "Absolute Soul",
            Image       = "/assets/images/albums/absoluteSoul.jpg",
            ReleaseDate = DateTime.Now,
            SingleType  = SingleType.OpSingle,
        };


        /* Songs */

        var absoluteSoulSong = new Song {
            Name    = "Absolute Soul",
            FileUrl = "/assets/audio/absolutesoul.mp3",
            Album   = absoluteSoulAlbum,
        };
        var puengue = new Song {
            Name    = "Absolute Soul",
            FileUrl = "/assets/audio/absolutesoul.mp3",
            Album   = hafaAdai,
        };


        /* Album-Series joins */

        absoluteSoul.Albums.Add(absoluteSoulAlbum);


        /* Album-Song joins */

        absoluteSoulAlbum.Songs.Add(absoluteSoulSong);
        hafaAdai.Songs.Add(puengue);


        /* Album-Artist joins */

        var iguchiYukaHafaAdaiJoin = new AlbumArtist();

        iguchiYukaHafaAdaiJoin.Artist = iguchiYuka;
        iguchiYukaHafaAdaiJoin.Album  = hafaAdai;
        hafaAdai.AlbumArtist.Add(iguchiYukaHafaAdaiJoin);
        iguchiYuka.AlbumArtist.Add(iguchiYukaHafaAdaiJoin);

        var konomiSuzukiAbsoluteSoulJoin = new AlbumArtist();

        konomiSuzukiAbsoluteSoulJoin.Artist = konomiSuzuki;
        konomiSuzukiAbsoluteSoulJoin.Album  = absoluteSoulAlbum;
        konomiSuzuki.AlbumArtist.Add(konomiSuzukiAbsoluteSoulJoin);
        absoluteSoulAlbum.AlbumArtist.Add(konomiSuzukiAbsoluteSoulJoin);


        /* Artist-Song joins */

        var iguchiYukaPuengueJoin = new ArtistSong();

        iguchiYukaPuengueJoin.Artist = iguchiYuka;
        iguchiYukaPuengueJoin.Song   = puengue;
        puengue.ArtistSong.Add(iguchiYukaPuengueJoin);
        iguchiYuka.ArtistSong.Add(iguchiYukaPuengueJoin);

        var konomiSuzukiAbsoluteSoulSongJoin = new ArtistSong();

        konomiSuzukiAbsoluteSoulSongJoin.Artist = konomiSuzuki;
        konomiSuzukiAbsoluteSoulSongJoin.Song   = absoluteSoulSong;
        absoluteSoulSong.ArtistSong.Add(konomiSuzukiAbsoluteSoulSongJoin);
        konomiSuzuki.ArtistSong.Add(konomiSuzukiAbsoluteSoulSongJoin);


        /* Add all to db */

        var series = new List <Series>();

        series.Add(absoluteSoul);
        series.Add(gochiUsa);
        series.Add(saeKano);
        db.Series.AddRange(series);

        var artists = new List <Artist>();

        artists.Add(asumiKana);
        artists.Add(iguchiYuka);
        artists.Add(konomiSuzuki);
        db.Artists.AddRange(artists);

        var albums = new List <Album>();

        albums.Add(hafaAdai);
        albums.Add(absoluteSoulAlbum);
        db.Albums.AddRange(albums);

        var songs = new List <Song>();

        songs.Add(absoluteSoulSong);
        songs.Add(puengue);
        db.Songs.AddRange(songs);

        db.SaveChanges();
    }
示例#19
0
 protected override void OnModelCreating(ModelBuilder mb)
 {
     /* Mappings */
     AlbumArtist.AddMappings(mb);
     ArtistSong.AddMappings(mb);
 }
        public void LoadArtists()
        {
            AlbumArtist chk = new AlbumArtist()
            {
                Name = "!!!",
                Albums = new List<MediaLibrary.Album>()
            };

            chk.Albums.Add(new MediaLibrary.Album()
            {
                 ArtistName = "!!!",
                  Title = "!!!"
            });

            chk.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "!!!",
                Title = "Louden Up Now"
            });

            Artists.Add(chk);

            AlbumArtist trail = new AlbumArtist()
            {
                Name = "...And You Will Know Us By The Trail Of Dead",
                Albums = new List<MediaLibrary.Album>()
            };

            trail.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "...And You Will Know Us By The Trail Of Dead",
                Title = "Festival Thyme"
            });

            trail.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "...And You Will Know Us By The Trail Of Dead",
                Title = "The Century of Self"
            });

            trail.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "...And You Will Know Us By The Trail Of Dead",
                Title = "Worlds Apart"
            });

            Artists.Add(trail);

            AlbumArtist bff = new AlbumArtist()
            {
                Name = "Ben Folds Five",
                Albums = new List<MediaLibrary.Album>()
            };

            bff.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Ben Folds Five",
                Title = "Naked Baby Photos"
            });

            bff.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Ben Folds Five",
                Title = "The Unauthorized Biography of Reinhold Messner"
            });

            bff.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Ben Folds Five",
                Title = "Whatever and Ever Amen"
            });

            bff.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Ben Folds Five",
                Title = "Ben Folds Five"
            });

            Artists.Add(bff);

            AlbumArtist beck = new AlbumArtist()
            {
                Name = "Beck",
                Albums = new List<MediaLibrary.Album>()
            };

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Guero"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Guerolito"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Mellow Gold"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Midnight Vultures"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Modern Guilt"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Mutations"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Odelay"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "Sea Change"
            });

            beck.Albums.Add(new MediaLibrary.Album()
            {
                ArtistName = "Beck",
                Title = "The Information"
            });

            Artists.Add(beck);
        }
示例#21
0
        public bool InsertAlbumArtist(AlbumArtist albumArtist, bool replace = false)
        {
            int affected = this.database.InsertObject <AlbumArtist>(albumArtist, replace ? InsertType.Replace : InsertType.InsertOrIgnore);

            return(affected > 0);
        }
示例#22
0
        public Song CreateSong(string filePath, int?folderId, TagLib.File file)
        {
            int?itemId = Injection.Kernel.Get <IItemRepository>().GenerateItemId(ItemType.Song);

            if (itemId == null)
            {
                return(new Song());
            }

            Song song = new Song();

            song.ItemId   = itemId;
            song.FolderId = folderId;

            // Parse taglib tags
            TagLib.Tag tag = file.Tag;

            try
            {
                string firstPerformer = tag.FirstPerformer;
                if (firstPerformer != null)
                {
                    Artist artist = Injection.Kernel.Get <IArtistRepository>().ArtistForNameOrCreate(firstPerformer.Trim());
                    song.ArtistId   = artist.ArtistId;
                    song.ArtistName = artist.ArtistName;
                }
            }
            catch (Exception e)
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error("Error creating artist info for song: ", e);
                }
                song.ArtistId   = null;
                song.ArtistName = null;
            }

            try
            {
                string firstAlbumArtist = tag.FirstAlbumArtist;
                if (firstAlbumArtist != null)
                {
                    AlbumArtist albumArtist = Injection.Kernel.Get <IAlbumArtistRepository>().AlbumArtistForNameOrCreate(firstAlbumArtist.Trim());
                    song.AlbumArtistId   = albumArtist.AlbumArtistId;
                    song.AlbumArtistName = albumArtist.AlbumArtistName;
                }
            }
            catch (Exception e)
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error("Error creating album artist info for song: ", e);
                }
                song.AlbumArtistId   = null;
                song.AlbumArtistName = null;
            }

            // If we have an artist, but not an albumArtist, then use the artist info for albumArtist
            if (song.AlbumArtistId == null && song.ArtistName != null)
            {
                AlbumArtist albumArtist = Injection.Kernel.Get <IAlbumArtistRepository>().AlbumArtistForNameOrCreate(song.ArtistName);
                song.AlbumArtistId   = albumArtist.AlbumArtistId;
                song.AlbumArtistName = albumArtist.AlbumArtistName;
            }

            try
            {
                string albumName = tag.Album;
                if (albumName != null)
                {
                    Album album = Injection.Kernel.Get <IAlbumRepository>().AlbumForName(albumName.Trim(), song.AlbumArtistId, Convert.ToInt32(tag.Year));
                    song.AlbumId     = album.AlbumId;
                    song.AlbumName   = album.AlbumName;
                    song.ReleaseYear = album.ReleaseYear;
                }
            }
            catch (Exception e)
            {
                if (logger.IsErrorEnabled)
                {
                    logger.Error("Error creating album info for song: ", e);
                }
                song.AlbumId     = null;
                song.AlbumName   = null;
                song.ReleaseYear = null;
            }

            song.FileType = song.FileType.FileTypeForTagLibMimeType(file.MimeType);

            if (song.FileType == FileType.Unknown)
            {
                logger.IfInfo("\"" + filePath + "\" Unknown file type: " + file.Properties.Description);
            }

            try
            {
                string title = tag.Title;
                if (title != null)
                {
                    song.SongName = title.Trim();
                }
            }
            catch
            {
                song.SongName = null;
            }

            try
            {
                song.TrackNumber = Convert.ToInt32(tag.Track);
            }
            catch
            {
                song.TrackNumber = null;
            }

            try
            {
                song.DiscNumber = Convert.ToInt32(tag.Disc);
            }
            catch
            {
                song.DiscNumber = null;
            }

            try
            {
                string firstGenre = tag.FirstGenre;
                if (firstGenre != null)
                {
                    song.GenreName = firstGenre.Trim();
                }
            }
            catch
            {
                song.GenreName = null;
            }

            try
            {
                song.BeatsPerMinute = tag.BeatsPerMinute;
            }
            catch
            {
                song.BeatsPerMinute = null;
            }

            try
            {
                song.Lyrics = tag.Lyrics;
            }
            catch
            {
                song.Lyrics = null;
            }

            try
            {
                song.Comment = tag.Comment;
            }
            catch
            {
                song.Comment = null;
            }

            // Dispose tag
            tag = null;

            if ((object)song.GenreName != null)
            {
                // Retreive the genre id
                song.GenreId = Injection.Kernel.Get <IGenreRepository>().GenreForName(song.GenreName).GenreId;
            }

            song.Duration = Convert.ToInt32(file.Properties.Duration.TotalSeconds);
            song.Bitrate  = file.Properties.AudioBitrate;

            // Get necessary filesystem information about file
            FileInfo fsFile = new FileInfo(filePath);

            song.FileSize     = fsFile.Length;
            song.LastModified = fsFile.LastWriteTime.ToUnixTime();
            song.FileName     = fsFile.Name;

            // If there is no song name, use the file name
            if (song.SongName == null || song.SongName == "")
            {
                song.SongName = song.FileName;
            }

            // Generate an art id from the embedded art, if it exists
            int?artId = CreateArt(file).ArtId;

            // Dispose file handles
            fsFile = null;
            file.Dispose();

            // If there was no embedded art, use the folder's art
            artId = (object)artId == null?Injection.Kernel.Get <IArtRepository>().ArtIdForItemId(song.FolderId) : artId;

            // Create the art/item relationship
            Injection.Kernel.Get <IArtRepository>().UpdateArtItemRelationship(artId, song.ItemId, true);

            return(song);
        }
示例#23
0
        public bool InsertAlbumArtist(AlbumArtist albumArtist, bool replace = false)
        {
            int affected = this.database.InsertObject<AlbumArtist>(albumArtist, replace ? InsertType.Replace : InsertType.InsertOrIgnore);

            return affected > 0;
        }
示例#24
0
        public bool InsertAlbumArtist(string albumArtistName, bool replace = false)
        {
            int? itemId = itemRepository.GenerateItemId(ItemType.AlbumArtist);
            if (itemId == null)
            {
                return false;
            }

            AlbumArtist artist = new AlbumArtist();
            artist.AlbumArtistId = itemId;
            artist.AlbumArtistName = albumArtistName;

            int affected = this.database.InsertObject<AlbumArtist>(artist, replace ? InsertType.Replace : InsertType.InsertOrIgnore);

            return affected > 0;
        }
示例#25
0
        private void MusicWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MusicLibrary library = new MusicLibrary();

            foreach (string FilePath in getAllFilesSubSearch(MusicDirectoryPath, Resources.SupportedFileFormats))
            {
                AlbumArtist albumArtist = null;
                Album       album       = null;

                using (TagLib.File tagFile = TagLib.File.Create(FilePath))
                {
                    MusicFile music = new MusicFile(FilePath)
                    {
                        Title     = tagFile.Tag.Title,
                        Performer = tagFile.Tag.FirstPerformer,
                        Disc      = tagFile.Tag.Disc,
                        Track     = tagFile.Tag.Track,
                        Year      = tagFile.Tag.Year,
                    };

                    if (tagFile.Tag.FirstAlbumArtist != null && tagFile.Tag.Album != null)
                    {
                        albumArtist = library.AlbumArtists.Find(x => x.Name.Equals(tagFile.Tag.FirstAlbumArtist, StringComparison.OrdinalIgnoreCase));
                        if (albumArtist == null)
                        {
                            albumArtist = new AlbumArtist()
                            {
                                Name = tagFile.Tag.FirstAlbumArtist
                            };
                            library.AlbumArtists.Add(albumArtist);
                        }

                        album = library.Album.Find(x => x.Name.Equals(tagFile.Tag.Album, StringComparison.OrdinalIgnoreCase));
                        if (album == null)
                        {
                            album = new Album()
                            {
                                AlbumArtist = albumArtist.GUID, Name = tagFile.Tag.Album
                            };
                            library.Album.Add(album);

                            albumArtist.AlbumID.Add(album.GUID);
                        }

                        music.Album       = album.GUID;
                        music.AlbumArtist = albumArtist.GUID;

                        if (music.Disc > album.DiscCount)
                        {
                            album.DiscCount = music.Disc;
                        }

                        if (music.Track > album.TrackCount)
                        {
                            album.TrackCount = music.Track;
                        }

                        album.MusicFiles.Add(music.GUID);
                        albumArtist.MusicFileIDs.Add(music.GUID);
                    }

                    library.MusicFiles.Add(music);
                }
            }

            // TODO: Media Player Playlist parsen und in neues Format

            e.Result = library;
        }
 public bool Insert(AlbumArtist albumArtist)
 {
     _repository.Create(albumArtist);
     return(_repository.SaveChanges());
 }