// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddOptions(); services.Configure <PlayerSettings>(Configuration.GetSection("Settings")); var settings = Configuration.GetSection("Settings").Get <PlayerSettings>(); // configure to use sqlite Dapper.SimpleCRUD.SetDialect(Dapper.SimpleCRUD.Dialect.SQLite); // make sure databases exist EnsureDatabasesExist(settings); // scan for files MusicScanner.Scan(settings, false); // setup last fm manager LastFMManager lastFMManager = new LastFMManager(settings); services.AddSingleton <LastFMManager>(lastFMManager); // load default playlist using (DAL.DALManager mgr = new DAL.DALManager(settings.DatabasePath)) { var tracks = mgr.GetTrackItems(Domain.Objects.Playlist.ALL_ID); Player.Instance.LoadPlaylist(new Player.Playlist() { Id = Domain.Objects.Playlist.ALL_ID, Tracks = tracks }); } }
private static void MigrateOldMusicCache() { // configure to use sqlite Dapper.SimpleCRUD.SetDialect(Dapper.SimpleCRUD.Dialect.SQLite); using (DAL.DALManager mgr = new DAL.DALManager(newDatabasePath)) { using (Microsoft.Data.Sqlite.SqliteConnection conn = new Microsoft.Data.Sqlite.SqliteConnection(string.Format("Data Source={0}", oldDatabasePath))) { conn.Open(); var cmd = new Microsoft.Data.Sqlite.SqliteCommand("SELECT * FROM MusicCache", conn); var reader = cmd.ExecuteReader(); while (reader.Read()) { string filename = reader["Filename"] + ""; string md5 = reader["MD5"] + ""; int played = Convert.ToInt32(reader["Played"]); int playedToEnd = Convert.ToInt32(reader["PlayedToEnd"]); DateTime lastPlayed = reader["LastPlayed"] == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(reader["LastPlayed"]); LikeStatus likeStatus = (LikeStatus)Convert.ToInt32(reader["LikeStatus"]); if (filename.StartsWith("/media/hdd/Dwight/Music/")) { filename = filename.Substring("/media/hdd/Dwight/Music/".Length); } var track = mgr.GetTrackByFilename(filename); if (track != null) { track.NrPlayed = played; track.NrPlayedToEnd = playedToEnd; track.LastPlayed = lastPlayed; track.LikeStatus = likeStatus; mgr.Set(track); var oldScrobbles = GetScrobblesFromOldTrack(md5, track.Id); mgr.SetAll(oldScrobbles); } else { Console.Error.WriteLine("Track with relative path " + filename + " not found"); } } } } }