protected override void AddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri) { if (track.PrimarySourceId == DbId) { return; } lock (mtp_device) { Track mtp_track = TrackInfoToMtpTrack(track, fromUri); bool video = track.HasAttribute(TrackMediaAttributes.VideoStream); mtp_device.UploadTrack(fromUri.LocalPath, mtp_track, GetFolderForTrack(track), OnUploadProgress); // Add/update album art if (!video) { string key = MakeAlbumKey(track.AlbumArtist, track.AlbumTitle); if (!album_cache.ContainsKey(key)) { Album album = new Album(mtp_device, track.AlbumTitle, track.AlbumArtist, track.Genre, track.Composer); album.AddTrack(mtp_track); if (supports_jpegs && can_sync_albumart) { try { Gdk.Pixbuf pic = ServiceManager.Get <Banshee.Collection.Gui.ArtworkManager> ().LookupScalePixbuf( track.ArtworkId, thumb_width ); if (pic != null) { byte [] bytes = pic.SaveToBuffer("jpeg"); album.Save(bytes, (uint)pic.Width, (uint)pic.Height); Banshee.Collection.Gui.ArtworkManager.DisposePixbuf(pic); } album_cache[key] = album; } catch (Exception e) { Log.Debug("Failed to create MTP Album", e.Message); } } else { album.Save(); album_cache[key] = album; } } else { Album album = album_cache[key]; album.AddTrack(mtp_track); album.Save(); } } MtpTrackInfo new_track = new MtpTrackInfo(mtp_device, mtp_track); new_track.PrimarySource = this; new_track.Save(false); track_map[new_track.TrackId] = mtp_track; } }
protected override void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri) { if (track.PrimarySourceId == DbId) return; lock (mtp_device) { Track mtp_track = TrackInfoToMtpTrack (track, fromUri); bool video = track.HasAttribute (TrackMediaAttributes.VideoStream); mtp_device.UploadTrack (fromUri.LocalPath, mtp_track, GetFolderForTrack (track), OnUploadProgress); // Add/update album art if (!video) { string key = MakeAlbumKey (track.AlbumArtist, track.AlbumTitle); if (!album_cache.ContainsKey (key)) { // LIBMTP 1.0.3 BUG WORKAROUND // In libmtp.c the 'LIBMTP_Create_New_Album' function invokes 'create_new_abstract_list'. // The latter calls strlen on the 'name' parameter without null checking. If AlbumTitle is // null, this causes a sigsegv. Lets be safe and always pass non-null values. Album album = new Album (mtp_device, track.AlbumTitle ?? "", track.AlbumArtist ?? "", track.Genre ?? "", track.Composer ?? ""); album.AddTrack (mtp_track); if (supports_jpegs && can_sync_albumart) { try { Gdk.Pixbuf pic = ServiceManager.Get<Banshee.Collection.Gui.ArtworkManager> ().LookupScalePixbuf ( track.ArtworkId, thumb_width ); if (pic != null) { byte [] bytes = pic.SaveToBuffer ("jpeg"); album.Save (bytes, (uint)pic.Width, (uint)pic.Height); Banshee.Collection.Gui.ArtworkManager.DisposePixbuf (pic); } album_cache[key] = album; } catch (Exception e) { Log.Debug ("Failed to create MTP Album", e.Message); } } else { album.Save (); album_cache[key] = album; } } else { Album album = album_cache[key]; album.AddTrack (mtp_track); album.Save (); } } MtpTrackInfo new_track = new MtpTrackInfo (mtp_device, mtp_track); new_track.PrimarySource = this; new_track.Save (false); track_map[new_track.TrackId] = mtp_track; } }
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 (); }
protected override void AddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri) { if (track.PrimarySourceId == DbId) { return; } lock (mtp_device) { Track mtp_track = TrackInfoToMtpTrack(track, fromUri); bool video = track.HasAttribute(TrackMediaAttributes.VideoStream); Folder folder = GetFolderForTrack(track); mtp_device.UploadTrack(fromUri.LocalPath, mtp_track, folder, OnUploadProgress); // Add/update album art if (!video) { string key = MakeAlbumKey(track); if (!album_cache.ContainsKey(key)) { // LIBMTP 1.0.3 BUG WORKAROUND // In libmtp.c the 'LIBMTP_Create_New_Album' function invokes 'create_new_abstract_list'. // The latter calls strlen on the 'name' parameter without null checking. If AlbumTitle is // null, this causes a sigsegv. Lets be safe and always pass non-null values. Album album = new Album(mtp_device, track.AlbumTitle ?? "", track.AlbumArtist ?? "", track.Genre ?? "", track.Composer ?? ""); album.AddTrack(mtp_track); if (supports_jpegs && can_sync_albumart) { ArtworkManager art = ServiceManager.Get <ArtworkManager> (); Exception ex = null; Gdk.Pixbuf pic = null; byte[] bytes = null; uint width = 0, height = 0; ThreadAssist.BlockingProxyToMain(() => { try { pic = art.LookupScalePixbuf(track.ArtworkId, thumb_width); if (pic != null) { bytes = pic.SaveToBuffer("jpeg"); width = (uint)pic.Width; height = (uint)pic.Height; } } catch (Exception e) { ex = e; } }); try { if (ex != null) { throw ex; } if (bytes != null) { ArtworkManager.DisposePixbuf(pic); album.Save(bytes, width, height); album_cache [key] = Tuple.Create(album, folder); } } catch (Exception e) { Log.Debug("Failed to create MTP Album", e.Message); } } else { album.Save(); album_cache[key] = Tuple.Create(album, folder); } } else { Album album = album_cache[key].Item1; album.AddTrack(mtp_track); album.Save(); } } MtpTrackInfo new_track = new MtpTrackInfo(mtp_device, mtp_track); new_track.PrimarySource = this; new_track.Save(false); track_map[new_track.TrackId] = mtp_track; } }
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(); }
protected override void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri) { if (track.PrimarySourceId == DbId) return; lock (mtp_device) { Track mtp_track = TrackInfoToMtpTrack (track, fromUri); bool video = track.HasAttribute (TrackMediaAttributes.VideoStream); mtp_device.UploadTrack (fromUri.LocalPath, mtp_track, GetFolderForTrack (track), OnUploadProgress); // Add/update album art if (!video) { string key = MakeAlbumKey (track.AlbumArtist, track.AlbumTitle); if (!album_cache.ContainsKey (key)) { Album album = new Album (mtp_device, track.AlbumTitle, track.AlbumArtist, track.Genre, track.Composer); album.AddTrack (mtp_track); if (supports_jpegs && can_sync_albumart) { try { Gdk.Pixbuf pic = ServiceManager.Get<Banshee.Collection.Gui.ArtworkManager> ().LookupScalePixbuf ( track.ArtworkId, thumb_width ); if (pic != null) { byte [] bytes = pic.SaveToBuffer ("jpeg"); album.Save (bytes, (uint)pic.Width, (uint)pic.Height); Banshee.Collection.Gui.ArtworkManager.DisposePixbuf (pic); } album_cache[key] = album; } catch (Exception e) { Log.Debug ("Failed to create MTP Album", e.Message); } } else { album.Save (); album_cache[key] = album; } } else { Album album = album_cache[key]; album.AddTrack (mtp_track); album.Save (); } } MtpTrackInfo new_track = new MtpTrackInfo (mtp_device, mtp_track); new_track.PrimarySource = this; new_track.Save (false); track_map[new_track.TrackId] = mtp_track; } }
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(); }