public static void ImportSingleMP3IntoDB(string path) { TagLib.File f = TagLib.File.Create(path); //checken of artist al in db zit, zoja artist ophalen; zo nee, nieuwe aanmaken Artist ar = null; if (!string.IsNullOrEmpty(f.Tag.FirstAlbumArtist)) ar = ArtistDA.GetArtistByName(f.Tag.FirstAlbumArtist); else { ar = (f.Tag.Artists.Length > 0) ? (ArtistDA.GetArtistByName(f.Tag.Artists[0])):(null); } if (ar == null) { if (!string.IsNullOrEmpty(f.Tag.FirstAlbumArtist)) ar = new Artist(f.Tag.FirstAlbumArtist); else if (f.Tag.Artists.Length > 0) ar = new Artist(f.Tag.Artists[0]); else ar = new Artist("Andere"); ar.ID = ArtistDA.InsertArtist(ar); Console.WriteLine("DB: created new Artist - " + ar.ArtistName); } //checken of de album al in db zit aan de hand van albumnaam en artist id, zoja, album ophalen. Zo nee, nieuwe aanmaken Album al =null; if (!string.IsNullOrEmpty(f.Tag.Album)) al = AlbumDA.GetAlbumByArtistIDAndAlbumName(ar.ID, f.Tag.Album); if(al == null) { string albumname = (!String.IsNullOrEmpty(f.Tag.Album)) ? (f.Tag.Album) : ("Andere"); al = new Album(albumname, ar.ID); al.ID = AlbumDA.InsertAlbum(al); Console.WriteLine("DB: created new Album - " + al.Name); } //checken of da et liedje al in de database zit adhb artist / album id en songname, anders in db steken Song s = SongDA.GetSongByArtistAlbumSong(ar.ID, al.ID, f.Tag.Title); if (s==null) { s = new Song(); s.AlbumID = al.ID; s.ArtistID = ar.ID; s.SongName = f.Tag.Title; s.Track = (int)f.Tag.Track; ShellFile so = ShellFile.FromFilePath(path); double nanoseconds; double.TryParse(so.Properties.System.Media.Duration.Value.ToString(), out nanoseconds); s.SongLength = (int)Math.Round((nanoseconds / 10000000), 0); s.PlayedAmmount = 0; s.FilePath = path; int songID = SongDA.InsertSong(s); s.ID = songID; Console.WriteLine("DB: created new Song - " + s.SongName); } }
public static int DeleteSongByID(Song a) { //ook albums and songs implementeren string sql = "DELETE FROM song WHERE ID=@ID"; DbParameter parID = Database.AddParameter(Database.DBNAME, "@ID", a.ID); return Database.ModifyData(Database.GetConnection(Database.DBNAME), sql, parID); }
public MP3Tag(Artist ar, Album al, Song s) { this.Artist = ar; this.Album = al; this.Song = s; }
public static int UpdateSong(Song s) { string sql = "UPDATE song SET AlbumID=@AlbumID, ArtistID=@ArtistID, Song=@Name, Track=@Track, Length=@Length, Played=@Played, Path=@Path where ID=@ID;"; DbParameter parID = Database.AddParameter(Database.DBNAME, "@ID", s.ID); DbParameter parAlbum = Database.AddParameter(Database.DBNAME, "@AlbumID", s.AlbumID); DbParameter parArtist = Database.AddParameter(Database.DBNAME, "@ArtistID", s.ArtistID); DbParameter parName = Database.AddParameter(Database.DBNAME, "@Name", s.SongName); DbParameter parTrack = Database.AddParameter(Database.DBNAME, "@Track", s.Track); DbParameter parLength = Database.AddParameter(Database.DBNAME, "@Length", s.SongLength); DbParameter parPlayed = Database.AddParameter(Database.DBNAME, "@Played", s.PlayedAmmount); DbParameter parFile = Database.AddParameter(Database.DBNAME, "@Path", s.FilePath); return Database.ModifyData(Database.GetConnection(Database.DBNAME), sql, parID, parAlbum, parArtist, parName, parTrack, parLength, parPlayed, parFile); }
public static int InsertSong(Song s) { string sql = "INSERT INTO song(AlbumID,ArtistID,Song,Track,Length,Played,Path) VALUES(@AlbumID,@ArtistID,@Name,@Track,@Length,@Played,@Path);"; DbParameter parAlbum = Database.AddParameter(Database.DBNAME, "@AlbumID", s.AlbumID); DbParameter parArtist = Database.AddParameter(Database.DBNAME, "@ArtistID", s.ArtistID); DbParameter parName = Database.AddParameter(Database.DBNAME, "@Name", s.SongName); DbParameter parTrack = Database.AddParameter(Database.DBNAME, "@Track", s.Track); DbParameter parLength = Database.AddParameter(Database.DBNAME, "@Length", s.SongLength); DbParameter parPlayed = Database.AddParameter(Database.DBNAME, "@Played", s.PlayedAmmount); DbParameter parFile = Database.AddParameter(Database.DBNAME, "@Path", s.FilePath); return Database.InsertData(Database.GetConnection(Database.DBNAME), sql, parAlbum, parArtist, parName, parTrack, parLength, parPlayed, parFile); }