public void SetBook (DatabaseAlbumInfo book)
        {
            ThreadAssist.AssertInMainThread ();
            Book = book;

            title_label.Markup = String.Format (
                "<span size=\"x-large\" weight=\"bold\">{0}</span>\n" +
                "{1}",
                GLib.Markup.EscapeText (book.Title),
                GLib.Markup.EscapeText (book.ArtistName)
            );

            var bookmark = library.GetLastPlayedBookmark (book.DbId);
            UpdateResumeButton (bookmark);

            UpdateCover ();

            /*var bookmarks = Bookmark.Provider.FetchAllMatching (
                "TrackID IN (SELECT TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND AlbumID = ?)",
                library.DbId, book.DbId
            );*/

            rating_entry.Value = (int) Math.Round (ServiceManager.DbConnection.Query<double> (
                "SELECT AVG(RATING) FROM CoreTracks WHERE PrimarySourceID = ? AND AlbumID = ?", library.DbId, book.DbId
            ));
        }
 public static DatabaseAlbumInfo FindOrCreate (DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation, string album_musicrainz_id)
 {
     DatabaseAlbumInfo album = new DatabaseAlbumInfo ();
     album.Title = title;
     album.TitleSort = title_sort;
     album.IsCompilation = isCompilation;
     album.MusicBrainzId = album_musicrainz_id;
     return FindOrCreate (artist, album);
 }
Beispiel #3
0
        public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation)
        {
            DatabaseAlbumInfo album = new DatabaseAlbumInfo();

            album.Title         = title;
            album.TitleSort     = title_sort;
            album.IsCompilation = isCompilation;
            return(FindOrCreate(artist, album));
        }
Beispiel #4
0
        public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation, string album_musicrainz_id)
        {
            DatabaseAlbumInfo album = new DatabaseAlbumInfo();

            album.Title         = title;
            album.TitleSort     = title_sort;
            album.IsCompilation = isCompilation;
            album.MusicBrainzId = album_musicrainz_id;
            return(FindOrCreate(artist, album));
        }
Beispiel #5
0
        public void Save(bool notify, params QueryField [] fields_changed)
        {
            // If either the artist or album changed,
            if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true)
            {
                DatabaseArtistInfo artist = Artist;
                ArtistId = artist.DbId;

                DatabaseAlbumInfo album = Album;
                AlbumId = album.DbId;

                // TODO get rid of unused artists/albums
            }

            // If PlayCountField is not transient we still want to update the file only if it's from the music library
            var transient = transient_fields;

            if (!transient.Contains(BansheeQuery.PlayCountField) &&
                !ServiceManager.SourceManager.MusicLibrary.Equals(PrimarySource))
            {
                transient = new HashSet <QueryField> (transient_fields);
                transient.Add(BansheeQuery.PlayCountField);
            }

            if (fields_changed.Length == 0 || !transient.IsSupersetOf(fields_changed))
            {
                DateUpdated = DateTime.Now;
            }

            bool is_new = (TrackId == 0);

            if (is_new)
            {
                LastSyncedStamp = DateAdded = DateUpdated = DateTime.Now;
            }

            ProviderSave();

            if (notify && PrimarySource != null)
            {
                if (is_new)
                {
                    PrimarySource.NotifyTracksAdded();
                }
                else
                {
                    PrimarySource.NotifyTracksChanged(fields_changed);
                }
            }
        }
Beispiel #6
0
        public static DatabaseAlbumInfo UpdateOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
        {
            DatabaseAlbumInfo found = FindOrCreate(artist, album);

            if (found != album)
            {
                // Overwrite the found album
                album.Title          = found.Title;
                album.TitleSort      = found.TitleSort;
                album.ArtistName     = found.ArtistName;
                album.ArtistNameSort = found.ArtistNameSort;
                album.IsCompilation  = found.IsCompilation;
                album.dbid           = found.DbId;
                album.ArtistId       = found.ArtistId;
                album.Save();
            }
            return(album);
        }
        public void Save(bool notify, params QueryField [] fields_changed)
        {
            // If either the artist or album changed,
            if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true)
            {
                DatabaseArtistInfo artist = Artist;
                ArtistId = artist.DbId;

                DatabaseAlbumInfo album = Album;
                AlbumId = album.DbId;

                // TODO get rid of unused artists/albums
            }

            if (fields_changed.Length == 0 || !transient_fields.IsSupersetOf(fields_changed))
            {
                DateUpdated = DateTime.Now;
            }

            bool is_new = (TrackId == 0);

            if (is_new)
            {
                DateAdded = DateUpdated = DateTime.Now;
            }

            ProviderSave();

            if (notify && PrimarySource != null)
            {
                if (is_new)
                {
                    PrimarySource.NotifyTracksAdded();
                }
                else
                {
                    PrimarySource.NotifyTracksChanged(fields_changed);
                }
            }
        }
 protected void AssertArtistNameSort(string name, string name_sort, byte[] expected)
 {
     DatabaseAlbumInfo info = new DatabaseAlbumInfo ();
     info.ArtistName = name;
     info.ArtistNameSort = name_sort;
     Assert.AreEqual (expected, info.ArtistNameSortKey);
 }
 public static DatabaseAlbumInfo UpdateOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
 {
     DatabaseAlbumInfo found = FindOrCreate (artist, album);
     if (found != album) {
         // Overwrite the found album
         album.Title = found.Title;
         album.TitleSort = found.TitleSort;
         album.ArtistName = found.ArtistName;
         album.ArtistNameSort = found.ArtistNameSort;
         album.IsCompilation = found.IsCompilation;
         album.MusicBrainzId = found.MusicBrainzId;
         album.dbid = found.DbId;
         album.ArtistId = found.ArtistId;
         album.ArtworkId = found.ArtworkId;
         album.Save ();
     }
     return album;
 }
 public static void Reset()
 {
     last_artist_id = -1;
     last_title = null;
     last_album = null;
 }
        public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
        {
            if (album.Title == last_title && artist.DbId == last_artist_id && last_album != null) {
                return last_album;
            }

            if (String.IsNullOrEmpty (album.Title) || album.Title.Trim () == String.Empty) {
                album.Title = null;
            }

            using (IDataReader reader = FindExistingArtists (artist.DbId, album.Title)) {
                if (reader.Read ()) {
                    bool save = false;
                    last_album = provider.Load (reader);

                    // If the artist name has changed since last time (but it's the same artist) then update our copy of the ArtistName
                    if (last_album.ArtistName != artist.Name) {
                        last_album.ArtistName = artist.Name;
                        save = true;
                    }

                    // Ditto artist sort name
                    if (last_album.ArtistNameSort != artist.NameSort) {
                        last_album.ArtistNameSort = artist.NameSort;
                        save = true;
                    }

                    // And album sort name
                    if (last_album.TitleSort != album.TitleSort) {
                        last_album.TitleSort = album.TitleSort;
                        save = true;
                    }

                    // If the album IsCompilation status has changed, update the saved album info
                    if (last_album.IsCompilation != album.IsCompilation) {
                        last_album.IsCompilation = album.IsCompilation;
                        save = true;
                    }

                    // If the album MusicBrainzId has changed, but is not null
                    if (last_album.MusicBrainzId != album.MusicBrainzId && !String.IsNullOrEmpty (album.MusicBrainzId)) {
                        last_album.MusicBrainzId = album.MusicBrainzId;
                        save = true;
                    }

                    // If the ArtworkId has changed, update the db
                    if (last_album.ArtworkId != album.ArtworkId) {
                        last_album.ArtworkId = album.ArtworkId;
                        save = true;
                    }

                    if (save) {
                        last_album.Save ();
                    }
                } else {
                    album.ArtistId = artist.DbId;
                    album.ArtistName = artist.Name;
                    album.ArtistNameSort = artist.NameSort;
                    album.Save ();
                    last_album = album;
                }
            }

            last_title = album.Title;
            last_artist_id = artist.DbId;
            return last_album;
        }
 protected void AssertArtistNameLowered(string name, string expected)
 {
     DatabaseAlbumInfo info = new DatabaseAlbumInfo ();
     info.ArtistName = name;
     Assert.AreEqual (expected, info.ArtistNameLowered);
 }
        public void SwitchToBookView(DatabaseAlbumInfo book)
        {
            if (CurrentViewBook == null) {
                CurrentViewBook = book;
                book_view.SetSource (this);
                book_view.Contents.SetBook (book);
                Properties.Set<ISourceContents> ("Nereid.SourceContents", book_view);

                if (BooksModel.Selection.Count != 1) {
                    var index = BooksModel.Selection.FocusedIndex;
                    BooksModel.Selection.Clear (false);
                    BooksModel.Selection.Select (index);
                }

                Actions.UpdateActions ();
            }
        }
        private void LoadDiscMetadata (object state)
        {
            try {
                LocalDisc mb_disc = (LocalDisc)state;

                OnMetadataQueryStarted (mb_disc);

                Release release = Release.Query (mb_disc).First ();

                if (release == null || release.Score < 100) {
                    OnMetadataQueryFinished (false);
                    return;
                }
                
                var tracks = release.GetTracks ();
                if (tracks.Count != Count) {
                    OnMetadataQueryFinished (false);
                    return;
                }

                disc_title = release.GetTitle ();

                int disc_number = 1;
                int i = 0;

                foreach (Disc disc in release.GetDiscs ()) {
                    i++;
                    if (disc.Id == mb_disc.Id) {
                        disc_number = i;
                    }
                }

                DateTime release_date = DateTime.MaxValue;

                foreach (Event release_event in release.GetEvents ()) {
                    if (release_event.Date != null) {
                        try {
                            // Handle "YYYY" dates
                            var date_str = release_event.Date;
                            DateTime date = DateTime.Parse (
                                date_str.Length > 4 ? date_str : date_str + "-01",
                                ApplicationContext.InternalCultureInfo
                            );

                            if (date < release_date) {
                                release_date = date;
                            }
                        } catch {
                        }
                    }
                }

                DatabaseArtistInfo artist = new DatabaseArtistInfo ();
                var mb_artist = release.GetArtist ();
                artist.Name = mb_artist.GetName ();
                artist.NameSort = mb_artist.GetSortName ();
                artist.MusicBrainzId = mb_artist.Id;
                bool is_compilation = false;

                DatabaseAlbumInfo album = new DatabaseAlbumInfo ();
                album.Title = disc_title;
                album.ArtistName = artist.Name;
                album.MusicBrainzId = release.Id;
                album.ReleaseDate = release_date == DateTime.MaxValue ? DateTime.MinValue : release_date;

                i = 0;
                foreach (Track track in tracks) {
                    AudioCdTrackInfo model_track = (AudioCdTrackInfo)this[i++];
                    var mb_track_artist = track.GetArtist ();

                    model_track.MusicBrainzId = track.Id;
                    model_track.TrackTitle = track.GetTitle ();
                    model_track.ArtistName = mb_track_artist.GetName ();
                    model_track.AlbumTitle = disc_title;
                    model_track.DiscNumber = disc_number;
                    model_track.Album = album;

                    model_track.Artist = new DatabaseArtistInfo ();
                    model_track.Artist.Name = model_track.ArtistName;
                    model_track.Artist.NameSort = mb_track_artist.GetSortName ();
                    model_track.Artist.MusicBrainzId = mb_track_artist.Id;

                    if (release_date != DateTime.MinValue) {
                        model_track.Year = release_date.Year;
                    }

                    if (!is_compilation && mb_track_artist.Id != artist.MusicBrainzId) {
                        is_compilation = true;
                    }
                }

                if (is_compilation) {
                    album.IsCompilation = true;
                    for (i = 0; i < tracks.Count; i++) {
                        AudioCdTrackInfo model_track = (AudioCdTrackInfo)this[i];
                        model_track.IsCompilation = true;
                        model_track.AlbumArtist = artist.Name;
                        model_track.AlbumArtistSort = artist.NameSort;
                    }
                }

                OnMetadataQueryFinished (true);
            } catch (Exception ex) {
                Log.DebugException (ex);
                OnMetadataQueryFinished (false);
            }
        }
 protected void AssertTitleLowered(string title, string expected)
 {
     DatabaseAlbumInfo info = new DatabaseAlbumInfo ();
     info.Title = title;
     Assert.AreEqual (expected, info.TitleLowered);
 }
 protected void AssertTitleSort(string title, string title_sort, byte[] expected)
 {
     DatabaseAlbumInfo info = new DatabaseAlbumInfo ();
     info.Title = title;
     info.TitleSort = title_sort;
     Assert.AreEqual (expected, info.TitleSortKey);
 }
Beispiel #17
0
        public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
        {
            if (album.Title == last_title && artist.DbId == last_artist_id && last_album != null)
            {
                return(last_album);
            }

            if (String.IsNullOrEmpty(album.Title) || album.Title.Trim() == String.Empty)
            {
                album.Title = null;
            }

            using (IDataReader reader = FindExistingArtists(artist.DbId, album.Title)) {
                if (reader.Read())
                {
                    bool save = false;
                    last_album = provider.Load(reader);

                    // If the artist name has changed since last time (but it's the same artist) then update our copy of the ArtistName
                    if (last_album.ArtistName != artist.Name)
                    {
                        last_album.ArtistName = artist.Name;
                        save = true;
                    }

                    // Ditto artist sort name
                    if (last_album.ArtistNameSort != artist.NameSort)
                    {
                        last_album.ArtistNameSort = artist.NameSort;
                        save = true;
                    }

                    // And album sort name
                    if (last_album.TitleSort != album.TitleSort)
                    {
                        last_album.TitleSort = album.TitleSort;
                        save = true;
                    }

                    // If the album IsCompilation status has changed, update the saved album info
                    if (last_album.IsCompilation != album.IsCompilation)
                    {
                        last_album.IsCompilation = album.IsCompilation;
                        save = true;
                    }

                    // If the album MusicBrainzId has changed, but is not null
                    if (last_album.MusicBrainzId != album.MusicBrainzId && !String.IsNullOrEmpty(album.MusicBrainzId))
                    {
                        last_album.MusicBrainzId = album.MusicBrainzId;
                        save = true;
                    }

                    // If the ArtworkId has changed, update the db
                    if (last_album.ArtworkId != album.ArtworkId)
                    {
                        last_album.ArtworkId = album.ArtworkId;
                        save = true;
                    }

                    if (save)
                    {
                        last_album.Save();
                    }
                }
                else
                {
                    album.ArtistId       = artist.DbId;
                    album.ArtistName     = artist.Name;
                    album.ArtistNameSort = artist.NameSort;
                    album.Save();
                    last_album = album;
                }
            }

            last_title     = album.Title;
            last_artist_id = artist.DbId;
            return(last_album);
        }
Beispiel #18
0
 public static void Reset()
 {
     last_artist_id = -1;
     last_title     = null;
     last_album     = null;
 }
        public void SwitchToBookView (DatabaseAlbumInfo book)
        {
            if (!book_label.Visible) {
                CurrentViewBook = book;
                book_label.Text = String.Format (" »  {0}", book.DisplayTitle);
                book_label.Visible = true;
                book_view.SetSource (this);
                book_view.Contents.SetBook (book);
                Properties.Set<ISourceContents> ("Nereid.SourceContents", book_view);

                if (BooksModel.Selection.Count != 1) {
                    var index = BooksModel.Selection.FocusedIndex;
                    BooksModel.Selection.Clear (false);
                    BooksModel.Selection.Select (index);
                }

                Actions.UpdateActions ();
            }
        }