Esempio n. 1
0
        /*public override void CopyTrackTo (DatabaseTrackInfo track, SafeUri uri, UserJob job)
         * {
         *  Banshee.IO.File.Copy (track.Uri, uri, false);
         * }*/

        protected override void AddTrack(DatabaseTrackInfo track)
        {
            // Ignore if already have it
            if (track.PrimarySourceId == DbId)
            {
                return;
            }

            PrimarySource source = track.PrimarySource;

            // If it's from a local primary source, change its PrimarySource
            if (source.IsLocal || source is LibrarySource)
            {
                track.PrimarySource = this;

                if (!(source is LibrarySource))
                {
                    track.CopyToLibraryIfAppropriate(false);
                }

                track.Save(false);

                // TODO optimize, remove this?  I think it makes moving items
                // between local libraries very slow.
                //source.NotifyTracksChanged ();
            }
            else
            {
                // Figure out where we should put it if were to copy it
                var     pattern = this.PathPattern ?? MusicLibrarySource.MusicFileNamePattern;
                string  path    = pattern.BuildFull(BaseDirectory, track);
                SafeUri uri     = new SafeUri(path);

                // Make sure it's not already in the library
                // TODO optimize - no need to recreate this int [] every time
                if (DatabaseTrackInfo.ContainsUri(uri, new int [] { DbId }))
                {
                    return;
                }

                // Since it's not, copy it and create a new TrackInfo object
                track.PrimarySource.CopyTrackTo(track, uri, AddTrackJob);

                // Create a new entry in CoreTracks for the copied file
                DatabaseTrackInfo new_track = new DatabaseTrackInfo(track);
                new_track.Uri           = uri;
                new_track.PrimarySource = this;
                new_track.Save(false);
            }
        }
Esempio n. 2
0
        private void TryToFixNonMp3Metadata()
        {
            if (already_fixed || mp3_imported_tracks.Count != mp3_count || non_mp3_queue.Count <= 0)
            {
                return;
            }

            already_fixed = true;
            // FIXME: this is all pretty lame. Amazon doesn't have any metadata on the PDF
            // files, which is a shame. So I attempt to figure out the best common metadata
            // from the already imported tracks in the album, and then forcefully persist
            // this in the database. When Taglib# supports reading/writing PDF, we can
            // persist this back the the PDF file, and support it for importing like normal.

            var artist_name =
                MostCommon <TrackInfo, string> (mp3_imported_tracks, track => track.AlbumArtist) ??
                MostCommon <TrackInfo, string> (mp3_imported_tracks, track => track.ArtistName);
            var album_title =
                MostCommon <TrackInfo, string> (mp3_imported_tracks, track => track.AlbumTitle);
            var genre =
                MostCommon <TrackInfo, string> (mp3_imported_tracks, track => track.Genre);
            var copyright =
                MostCommon <TrackInfo, string> (mp3_imported_tracks, track => track.Copyright);
            var year =
                MostCommon <TrackInfo, int> (mp3_imported_tracks, track => track.Year);
            var track_count =
                MostCommon <TrackInfo, int> (mp3_imported_tracks, track => track.TrackCount);
            var disc_count =
                MostCommon <TrackInfo, int> (mp3_imported_tracks, track => track.DiscCount);

            while (non_mp3_queue.Count > 0)
            {
                var downloader = non_mp3_queue.Dequeue();
                var track      = new DatabaseTrackInfo()
                {
                    AlbumArtist     = artist_name,
                    ArtistName      = artist_name,
                    AlbumTitle      = album_title,
                    TrackTitle      = downloader.Track.Title,
                    TrackCount      = track_count,
                    DiscCount       = disc_count,
                    Year            = year,
                    Genre           = genre,
                    Copyright       = copyright,
                    Uri             = new SafeUri(downloader.LocalPath),
                    MediaAttributes = TrackMediaAttributes.ExternalResource,
                    PrimarySource   = ServiceManager.SourceManager.MusicLibrary
                };

                track.CopyToLibraryIfAppropriate(true);

                if (downloader.FileExtension == "pdf")
                {
                    track.MimeType = "application/pdf";
                    Application.Invoke(delegate {
                        ServiceManager.DbConnection.BeginTransaction();
                        try {
                            track.Save();
                            ServiceManager.DbConnection.CommitTransaction();
                        } catch {
                            ServiceManager.DbConnection.RollbackTransaction();
                            throw;
                        }
                    });
                }
            }
        }