public void Open(SafeUri uri) { // Check if the uri exists if (uri == null || !File.Exists(uri.AbsolutePath)) { return; } bool found = false; if (ServiceManager.DbConnection != null) { // Try to find uri in the library int track_id = DatabaseTrackInfo.GetTrackIdForUri(uri); if (track_id > 0) { DatabaseTrackInfo track_db = DatabaseTrackInfo.Provider.FetchSingle(track_id); found = true; Open(track_db); } } if (!found) { // Not in the library, get info from the file TrackInfo track = new TrackInfo(); using (var file = StreamTagger.ProcessUri(uri)) { StreamTagger.TrackInfoMerge(track, file, false); } Open(track); } }
private void OnImportFinished(object o, EventArgs args) { importer.Finished -= OnImportFinished; if (CanSyncPlaylists) { var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand( "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)"); foreach (string playlist_path in PlaylistFiles) { // playlist_path has a file:// prefix, and GetDirectoryName messes it up, // so we need to convert it to a regular path string base_folder = ms_device.RootPath != null ? BaseDirectory : System.IO.Path.GetDirectoryName(SafeUri.UriToFilename(playlist_path)); IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load(playlist_path, new Uri(base_folder), ms_device.RootPath); if (loaded_playlist == null) { continue; } string name = System.IO.Path.GetFileNameWithoutExtension(SafeUri.UriToFilename(playlist_path)); PlaylistSource playlist = new PlaylistSource(name, this); playlist.Save(); //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true; foreach (PlaylistElement element in loaded_playlist.Elements) { string track_path = element.Uri.LocalPath; long track_id = DatabaseTrackInfo.GetTrackIdForUri(new SafeUri(track_path), DbId); if (track_id == 0) { Log.DebugFormat("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path); } else { ServiceManager.DbConnection.Execute(insert_cmd, playlist.DbId, track_id); } } //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false; playlist.UpdateCounts(); AddChildSource(playlist); } } import_reset_event.Set(); }
private void OnImportFinished(object o, EventArgs args) { importer.Finished -= OnImportFinished; if (CanSyncPlaylists) { var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand( "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)"); int [] psources = new int [] { DbId }; foreach (string playlist_path in PlaylistFiles) { IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load(playlist_path, new Uri(PlaylistsPath)); if (loaded_playlist == null) { continue; } PlaylistSource playlist = new PlaylistSource(System.IO.Path.GetFileNameWithoutExtension(playlist_path), this); playlist.Save(); //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true; foreach (Dictionary <string, object> element in loaded_playlist.Elements) { string track_path = (element["uri"] as Uri).LocalPath; int track_id = DatabaseTrackInfo.GetTrackIdForUri(new SafeUri(track_path), psources); if (track_id == 0) { Log.DebugFormat("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path); } else { ServiceManager.DbConnection.Execute(insert_cmd, playlist.DbId, track_id); } } //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false; playlist.UpdateCounts(); AddChildSource(playlist); } } import_reset_event.Set(); }
private void PlayEnqueued() { if (!play_enqueued || path_to_play == null) { return; } SafeUri uri = null; ServiceManager.PlaybackController.NextSource = this; try { uri = new SafeUri(path_to_play); } catch { } if (uri == null) { return; } int id = DatabaseTrackInfo.GetTrackIdForUri(uri, new int [] { DbId }); if (id >= 0) { int index = (int)TrackCache.IndexOf((long)id); if (index >= 0) { TrackInfo track = TrackModel[index]; if (track != null) { ServiceManager.PlayerEngine.OpenPlay(track); play_enqueued = false; } } } }
public int GetTrackIdForUri(string uri) { return(DatabaseTrackInfo.GetTrackIdForUri(new SafeUri(uri), DbId)); }
private void MigrateLegacyIfNeeded() { if (DatabaseConfigurationClient.Client.Get <int> ("Podcast", "Version", 0) == 0) { if (ServiceManager.DbConnection.TableExists("Podcasts") && ServiceManager.DbConnection.Query <int> ("select count(*) from podcastsyndications") == 0) { Hyena.Log.Information("Migrating Podcast Feeds and Items"); ServiceManager.DbConnection.Execute(@" INSERT INTO PodcastSyndications (FeedID, Title, Url, Link, Description, ImageUrl, LastBuildDate, AutoDownload, IsSubscribed) SELECT PodcastFeedID, Title, FeedUrl, Link, Description, Image, strftime(""%s"", LastUpdated), SyncPreference, 1 FROM PodcastFeeds "); ServiceManager.DbConnection.Execute(@" INSERT INTO PodcastItems (ItemID, FeedID, Title, Link, PubDate, Description, Author, Active, Guid) SELECT PodcastID, PodcastFeedID, Title, Link, strftime(""%s"", PubDate), Description, Author, Active, Url FROM Podcasts "); // Note: downloaded*3 is because the value was 0 or 1, but is now 0 or 3 (FeedDownloadStatus.None/Downloaded) ServiceManager.DbConnection.Execute(@" INSERT INTO PodcastEnclosures (ItemID, LocalPath, Url, MimeType, FileSize, DownloadStatus) SELECT PodcastID, LocalPath, Url, MimeType, Length, Downloaded*3 FROM Podcasts "); // Finally, move podcast items from the Music Library to the Podcast source int moved = 0; foreach (FeedEnclosure enclosure in FeedEnclosure.Provider.FetchAllMatching("LocalPath IS NOT NULL AND LocalPath != ''")) { SafeUri uri = new SafeUri(enclosure.LocalPath); int track_id = DatabaseTrackInfo.GetTrackIdForUri(uri, ServiceManager.SourceManager.MusicLibrary.DbId); if (track_id > 0) { PodcastTrackInfo pi = new PodcastTrackInfo(DatabaseTrackInfo.Provider.FetchSingle(track_id)); pi.Item = enclosure.Item; pi.Track.PrimarySourceId = source.DbId; pi.SyncWithFeedItem(); pi.Track.Save(false); moved++; } } if (moved > 0) { ServiceManager.SourceManager.MusicLibrary.Reload(); source.Reload(); } Hyena.Log.Information("Done Migrating Podcast Feeds and Items"); } DatabaseConfigurationClient.Client.Set <int> ("Podcast", "Version", 1); } if (DatabaseConfigurationClient.Client.Get <int> ("Podcast", "Version", 0) < 3) { // We were using the Link as the fallback if the actual Guid was missing, but that was a poor choice // since it is not always unique. We now use the title and pubdate combined. ServiceManager.DbConnection.Execute("UPDATE PodcastItems SET Guid = NULL"); foreach (FeedItem item in FeedItem.Provider.FetchAll()) { item.Guid = null; if (item.Feed == null || FeedItem.Exists(item.Feed.DbId, item.Guid)) { item.Delete(false); } else { item.Save(); } } DatabaseConfigurationClient.Client.Set <int> ("Podcast", "Version", 3); } // Intentionally skpping 4 here because this needs to get run again for anybody who ran it // before it was fixed, but only once if you never ran it if (DatabaseConfigurationClient.Client.Get <int> ("Podcast", "Version", 0) < 5) { ReplaceNewlines("CoreTracks", "Title"); ReplaceNewlines("CoreTracks", "TitleLowered"); ReplaceNewlines("PodcastItems", "Title"); ReplaceNewlines("PodcastItems", "Description"); DatabaseConfigurationClient.Client.Set <int> ("Podcast", "Version", 5); } // Initialize the new StrippedDescription field if (DatabaseConfigurationClient.Client.Get <int> ("Podcast", "Version", 0) < 6) { foreach (FeedItem item in FeedItem.Provider.FetchAll()) { item.UpdateStrippedDescription(); item.Save(); } DatabaseConfigurationClient.Client.Set <int> ("Podcast", "Version", 6); } }
protected override void LoadFromDevice() { if (null == mtp_device) { return; } // Translators: {0} is the file currently being loaded // and {1} is the total # of files that will be loaded. string format = Catalog.GetString("Reading File - {0} of {1}"); track_map = new Dictionary <long, Track> (); try { List <Track> files = null; lock (mtp_device) { files = mtp_device.GetAllTracks(delegate(ulong current, ulong total, IntPtr data) { SetStatus(String.Format(format, current + 1, total), false); return(0); }); } /*if (user_event.IsCancelRequested) { * return; * }*/ // Delete any empty albums lock (mtp_device) { foreach (Album album in mtp_device.GetAlbums()) { if (album.Count == 0) { album.Remove(); } } } // Translators: {0} is the track currently being loaded // and {1} is the total # of tracks that will be loaded. format = Catalog.GetString("Loading Track - {0} of {1}"); for (int current = 0, total = files.Count; current < total; ++current) { SetStatus(String.Format(format, current + 1, total), false); Track mtp_track = files [current]; long track_id; if ((track_id = DatabaseTrackInfo.GetTrackIdForUri(MtpTrackInfo.GetPathFromMtpTrack(mtp_track), DbId)) > 0) { track_map[track_id] = mtp_track; } else { MtpTrackInfo track = new MtpTrackInfo(mtp_device, mtp_track); track.PrimarySource = this; track.Save(false); track_map[track.TrackId] = mtp_track; } } Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand( @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?"); // Translators: {0} is the playlist currently being loaded // and {1} is the total # of playlists that will be loaded. format = Catalog.GetString("Loading Playlist - {0} of {1}"); lock (mtp_device) { var playlists = mtp_device.GetPlaylists(); if (playlists != null) { for (int current = 0, total = playlists.Count; current < total; ++current) { MTP.Playlist playlist = playlists [current]; SetStatus(String.Format(format, current + 1, total), false); PlaylistSource pl_src = new PlaylistSource(playlist.Name, this); pl_src.Save(); // TODO a transaction would make sense here (when the threading issue is fixed) foreach (uint id in playlist.TrackIds) { ServiceManager.DbConnection.Execute(insert_cmd, pl_src.DbId, this.DbId, id); } pl_src.UpdateCounts(); AddChildSource(pl_src); } } } } catch (Exception e) { Log.Error(e); } OnTracksAdded(); }
public void EnqueueUri(string uri, bool prepend) { EnqueueId(DatabaseTrackInfo.GetTrackIdForUri(uri), prepend, false); }
protected override void LoadFromDevice() { track_map = new Dictionary <int, Track> (); try { List <Track> files = null; lock (mtp_device) { files = mtp_device.GetAllTracks(delegate(ulong current, ulong total, IntPtr data) { //user_event.Progress = (double)current / total; // Translators: {0} is the name of the MTP audio device (eg Gabe's Zen Player), {1} is the // track currently being loaded, and {2} is the total # of tracks that will be loaded. SetStatus(String.Format(Catalog.GetString("Loading {0} - {1} of {2}"), Name, current, total), false); return(0); }); } /*if (user_event.IsCancelRequested) { * return; * }*/ // Delete any empty albums lock (mtp_device) { foreach (Album album in mtp_device.GetAlbums()) { if (album.Count == 0) { album.Remove(); } } } foreach (Track mtp_track in files) { int track_id; if ((track_id = DatabaseTrackInfo.GetTrackIdForUri(MtpTrackInfo.GetPathFromMtpTrack(mtp_track), DbId)) > 0) { track_map[track_id] = mtp_track; } else { MtpTrackInfo track = new MtpTrackInfo(mtp_device, mtp_track); track.PrimarySource = this; track.Save(false); track_map[track.TrackId] = mtp_track; } } Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand( @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?"); lock (mtp_device) { var playlists = mtp_device.GetPlaylists(); if (playlists != null) { foreach (MTP.Playlist playlist in playlists) { PlaylistSource pl_src = new PlaylistSource(playlist.Name, this); pl_src.Save(); // TODO a transaction would make sense here (when the threading issue is fixed) foreach (uint id in playlist.TrackIds) { ServiceManager.DbConnection.Execute(insert_cmd, pl_src.DbId, this.DbId, id); } pl_src.UpdateCounts(); AddChildSource(pl_src); } } } } catch (Exception e) { Log.Exception(e); } OnTracksAdded(); }