Exemplo n.º 1
0
 private void SetIcon()
 {
     try
     {
         if (awn != null && service != null && service.CurrentTrack != null)
         {
             string fileName = CoverArtSpec.GetPath(service.CurrentTrack.ArtworkId);
             if (File.Exists(fileName))
             {
                 for (int i = 0; i < taskName.Length; i++)
                 {
                     awn.SetTaskIconByName(taskName[i], fileName);
                 }
                 awn.SetTaskIconByName(PossibleTitle, fileName);
                 Log.Debug("BansheeAwn - Setting cover: " + fileName);
             }
             else
             {
                 UnsetIcon();
                 Log.Debug("BansheeAwn - No Cover");
             }
         }
     }
     catch
     {
     }
 }
Exemplo n.º 2
0
            private void DeleteCoverArt(TrackInfo track)
            {
                if (track != null)
                {
                    var uri = new SafeUri(CoverArtSpec.GetPath(track.ArtworkId));
                    if (Banshee.IO.File.Exists(uri))
                    {
                        Banshee.IO.File.Delete(uri);
                    }
                    var artwork_id = track.ArtworkId;
                    if (artwork_id != null)
                    {
                        ServiceManager.Get <ArtworkManager> ().ClearCacheFor(track.ArtworkId);
                    }

                    // Deleting it from this table means the cover art downloader extension will
                    // attempt to redownload it on its next run.
                    var db       = ServiceManager.DbConnection;
                    var db_track = track as DatabaseTrackInfo;
                    if (db_track != null && db.TableExists("CoverArtDownloads"))
                    {
                        db.Execute("DELETE FROM CoverArtDownloads WHERE AlbumID = ?", db_track.AlbumId);
                    }
                }
            }
Exemplo n.º 3
0
        protected void Fetch()
        {
            if (track.Uri == null || !track.Uri.IsFile || !Banshee.IO.File.Exists(track.Uri))
            {
                return;
            }

            string artist_album_id = track.ArtworkId;

            if (artist_album_id == null)
            {
                return;
            }

            IPicture [] pictures = GetEmbeddedPictures(track.Uri);

            if (pictures != null && pictures.Length > 0)
            {
                int      preferred_index = GetPictureIndexToUse(pictures);
                IPicture picture         = pictures[preferred_index];
                string   path            = CoverArtSpec.GetPath(artist_album_id);

                if (SavePicture(picture, path))
                {
                    StreamTag tag = new StreamTag();
                    tag.Name  = CommonTags.AlbumCoverId;
                    tag.Value = artist_album_id;

                    AddTag(tag);
                }
            }
        }
Exemplo n.º 4
0
            private SafeUri GetCoverArtPath(TrackInfo track)
            {
                if (track != null)
                {
                    return(new SafeUri(CoverArtSpec.GetPath(track.ArtworkId)));
                }

                return(null);
            }
Exemplo n.º 5
0
        public Metadata(TrackInfo track)
        {
            data_store = new Dictionary <string, object> ();

            if (track == null)
            {
                // Managed dbus doesn't like null or empty dictionaries
                data_store["mpris:trackid"] = String.Concat(object_path, "Empty");
                return;
            }

            // The trackid must be formatted like a dbus object path
            data_store["mpris:trackid"] = new DBus.ObjectPath(String.Concat(object_path, track.CacheModelId, track.CacheEntryId));
            SetInfo("mpris:length", (long)track.Duration.TotalMilliseconds * 1000);
            SetInfo("xesam:url", track.Uri.ToString());
            SetInfo("xesam:title", track.TrackTitle);
            SetInfo("xesam:album", track.AlbumTitle);
            if (!String.IsNullOrEmpty(track.ArtistName))
            {
                SetInfo("xesam:artist", new string [] { track.ArtistName });
            }
            if (!String.IsNullOrEmpty(track.AlbumArtist))
            {
                SetInfo("xesam:albumArtist", new string [] { track.AlbumArtist });
            }
            if (!String.IsNullOrEmpty(track.Genre))
            {
                SetInfo("xesam:genre", new string [] { track.Genre });
            }
            if (!String.IsNullOrEmpty(track.Comment))
            {
                SetInfo("xesam:comment", new string [] { track.Comment });
            }

            if (track.TrackNumber > 0)
            {
                data_store["xesam:trackNumber"] = track.TrackNumber;
            }

            if (track.ReleaseDate.Ticks > 0)
            {
                SetInfo("xesam:contentCreated", track.ReleaseDate.ToString("s"));
            }

            if (track.Rating > 0)
            {
                // Scale is 0.0 to 1.0
                SetInfo("xesam:userRating", (double)track.Rating / 5);
            }

            string artid = track.ArtworkId;

            if (artid != null)
            {
                SetInfo("mpris:artUrl", String.Concat("file://", CoverArtSpec.GetPath(artid)));
            }
        }
Exemplo n.º 6
0
        private void ResolveCoverArt(Track track)
        {
            string aaid = CoverArtSpec.CreateArtistAlbumId(track.Artist, track.Album);
            string path = CoverArtSpec.GetPath(aaid);

            if (File.Exists(path))
            {
                IpodTrackInfo.SetIpodCoverArt(source.IpodDevice, track, path);
            }
        }
        private void WriteArt(DatabaseTrackInfo track)
        {
            string ArtWorkPath = CoverArtSpec.GetPath(track.ArtworkId);
            string ext         = null;

            if (service.JPG)
            {
                ext = ".jpg";
            }
            else if (service.PNG)
            {
                ext = ".png";
            }
            else
            {
                Log.Warning("Neather JPG or PNG is set, exiting Album Art Writer");
                AbortThread();
            }
            string filename  = service.ArtName + ext;
            string WritePath = Path.Combine(Path.GetDirectoryName(track.LocalPath), filename);

            if ((File.Exists(ArtWorkPath)) || (service.ForceRecopy))
            {
                if (!File.Exists(WritePath))
                {
                    try {
                        if (!(ArtWorkPath.EndsWith(ext)))
                        {
                            ConvertFileType(ArtWorkPath, WritePath);
                        }
                        else
                        {
                            Log.DebugFormat("Copying: {0} \t\t to: {1}", ArtWorkPath, WritePath);
                            File.Copy(ArtWorkPath, WritePath, service.ForceRecopy);
                        }

                        ServiceManager.DbConnection.Execute("INSERT OR REPLACE INTO AlbumArtWriter (AlbumID, SavedOrTried,LastUpdated) VALUES (?, ?, ?)", track.AlbumId, 3, CurrentTime);
                    } catch (IOException error) {
                        ServiceManager.DbConnection.Execute("INSERT OR REPLACE INTO AlbumArtWriter (AlbumID, SavedOrTried,LastUpdated) VALUES (?, ?, ?)", track.AlbumId, 1, CurrentTime);
                        Log.Warning(error.Message);
                    }
                }
                else
                {
                    Log.DebugFormat("Album already has artwork in folder {0}", WritePath);
                    ServiceManager.DbConnection.Execute("INSERT OR REPLACE INTO AlbumArtWriter (AlbumID, SavedOrTried,LastUpdated) VALUES (?, ?, ?)", track.AlbumId, 2, CurrentTime);
                }
            }
            else
            {
                Log.DebugFormat("Artwork does not exist for album {0} - {1} - {2}", track.AlbumArtist, track.AlbumTitle, ArtWorkPath);
                ServiceManager.DbConnection.Execute("INSERT OR REPLACE INTO AlbumArtWriter (AlbumID, SavedOrTried,LastUpdated) VALUES (?, ?, ?)", track.AlbumId, 1, CurrentTime);
            }
        }
Exemplo n.º 8
0
        private void ShowTrackNotification()
        {
            // This has to happen before the next if, otherwise the last_* members aren't set correctly.
            if (current_track == null || (notify_last_title == current_track.DisplayTrackTitle &&
                                          notify_last_artist == current_track.DisplayArtistName))
            {
                return;
            }

            notify_last_title  = current_track.DisplayTrackTitle;
            notify_last_artist = current_track.DisplayArtistName;

            if (!show_notifications)
            {
                return;
            }

            foreach (var window in elements_service.ContentWindows)
            {
                if (window.HasToplevelFocus)
                {
                    return;
                }
            }

            bool is_notification_daemon = false;

            try {
                var name = Notifications.Global.ServerInformation.Name;
                is_notification_daemon = name == "notification-daemon" || name == "Notification Daemon";
            } catch {
                // This will be reached if no notification daemon is running
                return;
            }

            string message = GetByFrom(
                current_track.ArtistName, current_track.DisplayArtistName,
                current_track.AlbumTitle, current_track.DisplayAlbumTitle);

            string image = null;

            image = is_notification_daemon
                ? CoverArtSpec.GetPathForSize(current_track.ArtworkId, icon_size)
                : CoverArtSpec.GetPath(current_track.ArtworkId);

            if (!File.Exists(new SafeUri(image)))
            {
                if (artwork_manager_service != null)
                {
                    // artwork does not exist, try looking up the pixbuf to trigger scaling or conversion
                    Gdk.Pixbuf tmp_pixbuf = is_notification_daemon
                        ? artwork_manager_service.LookupScalePixbuf(current_track.ArtworkId, icon_size)
                        : artwork_manager_service.LookupPixbuf(current_track.ArtworkId);

                    if (tmp_pixbuf == null)
                    {
                        image = "audio-x-generic";
                    }
                    else
                    {
                        tmp_pixbuf.Dispose();
                    }
                }
            }

            try {
                if (current_nf == null)
                {
                    current_nf = new Notification(current_track.DisplayTrackTitle,
                                                  message, image, notif_area.Widget);
                }
                else
                {
                    current_nf.Summary  = current_track.DisplayTrackTitle;
                    current_nf.Body     = message;
                    current_nf.IconName = image;
                    current_nf.AttachToWidget(notif_area.Widget);
                }
                current_nf.Urgency = Urgency.Low;
                current_nf.Timeout = 4500;
                if (!current_track.IsLive && ActionsSupported && interface_action_service.PlaybackActions["NextAction"].Sensitive)
                {
                    current_nf.AddAction("skip-song", Catalog.GetString("Skip this item"), OnSongSkipped);
                }
                current_nf.Show();
            } catch (Exception e) {
                Hyena.Log.Warning(Catalog.GetString("Cannot show notification"), e.Message, false);
            }
        }
Exemplo n.º 9
0
 protected bool SaveHttpStreamCover(Uri uri, string albumArtistId, string [] ignoreMimeTypes)
 {
     return(SaveHttpStream(uri, CoverArtSpec.GetPath(albumArtistId), ignoreMimeTypes));
 }
Exemplo n.º 10
0
        private void ShowTrackNotification()
        {
            // This has to happen before the next if, otherwise the last_* members aren't set correctly.
            if (current_track == null || (notify_last_title == current_track.DisplayTrackTitle &&
                                          notify_last_artist == current_track.DisplayArtistName))
            {
                return;
            }

            notify_last_title  = current_track.DisplayTrackTitle;
            notify_last_artist = current_track.DisplayArtistName;

            if (!show_notifications)
            {
                return;
            }

            // If we have persistent notifications, we show a notification even if the main window has focus
            // so that the information displayed (track title, etc.) gets updated.
            if (!PersistenceSupported)
            {
                foreach (var window in elements_service.ContentWindows)
                {
                    if (window.HasToplevelFocus)
                    {
                        return;
                    }
                }
            }

            string message = GetByFrom(
                current_track.ArtistName, current_track.DisplayArtistName,
                current_track.AlbumTitle, current_track.DisplayAlbumTitle);

            string image = null;

            image = CoverArtSpec.GetPath(current_track.ArtworkId);

            if (!File.Exists(new SafeUri(image)))
            {
                if (artwork_manager_service != null)
                {
                    // artwork does not exist, try looking up the pixbuf to trigger scaling or conversion
                    Gdk.Pixbuf tmp_pixbuf = artwork_manager_service.LookupPixbuf(current_track.ArtworkId);

                    if (tmp_pixbuf == null)
                    {
                        // TODO: image should be set to "audio-x-generic", but icon names are not supported by the
                        // notification daemon in GNOME Shell. See https://bugzilla.gnome.org/show_bug.cgi?id=665957
                        image = null;
                    }
                    else
                    {
                        tmp_pixbuf.Dispose();
                    }
                }
            }

            try {
                if (current_nf == null)
                {
                    current_nf = new Notification(current_track.DisplayTrackTitle,
                                                  message, Banshee.ServiceStack.Application.IconName);
                }
                else
                {
                    current_nf.Summary  = current_track.DisplayTrackTitle;
                    current_nf.Body     = message;
                    current_nf.IconName = Banshee.ServiceStack.Application.IconName;
                    if (notif_area != null && notif_area.Widget != null)
                    {
                        current_nf.AttachToWidget(notif_area.Widget);
                    }
                }
                current_nf.Urgency = Urgency.Low;
                current_nf.Timeout = 4500;

                if (image == null)
                {
                    current_nf.RemoveHint("image-path");
                }
                else
                {
                    current_nf.AddHint("image-path", image);
                }

                if (ServiceManager.PlayerEngine.IsPlaying())
                {
                    current_nf.Category = "x-gnome.music";
                }

                if (PersistenceSupported)
                {
                    current_nf.AddHint("resident", true);
                }

                current_nf.Show();
            } catch (Exception e) {
                Log.Error(Catalog.GetString("Cannot show notification"), e);
            }
        }
Exemplo n.º 11
0
        public void CommitToIpod(IPod.Device device)
        {
            track      = track ?? device.TrackDatabase.CreateTrack();
            ExternalId = track.Id;

            try {
                track.Uri = new Uri(Uri.AbsoluteUri);
            } catch (Exception e) {
                Log.Exception("Failed to create System.Uri for iPod track", e);
                device.TrackDatabase.RemoveTrack(track);
            }

            track.AlbumArtist   = AlbumArtist;
            track.BitRate       = BitRate;
            track.BPM           = (short)Bpm;
            track.Comment       = Comment;
            track.Composer      = Composer;
            track.DateAdded     = DateAdded;
            track.TotalDiscs    = DiscCount;
            track.DiscNumber    = DiscNumber;
            track.Duration      = Duration;
            track.Size          = (int)FileSize;
            track.Grouping      = Grouping;
            track.IsCompilation = IsCompilation;
            track.LastPlayed    = LastPlayed;
            track.PlayCount     = PlayCount;
            track.TotalTracks   = TrackCount;
            track.TrackNumber   = TrackNumber;
            track.Year          = Year;
            track.DateReleased  = ReleaseDate;

            track.Album  = AlbumTitle;
            track.Artist = ArtistName;
            track.Title  = TrackTitle;
            track.Genre  = Genre;

            switch (Rating)
            {
            case 1: track.Rating = IPod.TrackRating.Zero; break;

            case 2: track.Rating = IPod.TrackRating.Two; break;

            case 3: track.Rating = IPod.TrackRating.Three; break;

            case 4: track.Rating = IPod.TrackRating.Four; break;

            case 5: track.Rating = IPod.TrackRating.Five; break;

            default: track.Rating = IPod.TrackRating.Zero; break;
            }

            if (HasAttribute(TrackMediaAttributes.Podcast))
            {
                track.DateReleased     = ReleaseDate;
                track.Description      = description;
                track.RememberPosition = true;
                track.NotPlayedMark    = track.PlayCount == 0;
            }

            if (HasAttribute(TrackMediaAttributes.VideoStream))
            {
                if (HasAttribute(TrackMediaAttributes.Podcast))
                {
                    track.Type = IPod.MediaType.VideoPodcast;
                }
                else if (HasAttribute(TrackMediaAttributes.Music))
                {
                    track.Type = IPod.MediaType.MusicVideo;
                }
                else if (HasAttribute(TrackMediaAttributes.Movie))
                {
                    track.Type = IPod.MediaType.Movie;
                }
                else if (HasAttribute(TrackMediaAttributes.TvShow))
                {
                    track.Type = IPod.MediaType.TVShow;
                }
                else
                {
                    track.Type = IPod.MediaType.Video;
                }
            }
            else
            {
                if (HasAttribute(TrackMediaAttributes.Podcast))
                {
                    track.Type = IPod.MediaType.Podcast;
                }
                else if (HasAttribute(TrackMediaAttributes.AudioBook))
                {
                    track.Type = IPod.MediaType.Audiobook;
                }
                else if (HasAttribute(TrackMediaAttributes.Music))
                {
                    track.Type = IPod.MediaType.Audio;
                }
                else
                {
                    track.Type = IPod.MediaType.Audio;
                }
            }

            if (CoverArtSpec.CoverExists(ArtworkId))
            {
                SetIpodCoverArt(device, track, CoverArtSpec.GetPath(ArtworkId));
            }
        }
Exemplo n.º 12
0
        public void CommitToIpod(GPod.ITDB database)
        {
            bool addTrack = IpodTrack == null;

            if (IpodTrack == null)
            {
                IpodTrack = new GPod.Track();
            }

            var track = IpodTrack;

            track.Compilation = IsCompilation;
            track.AlbumArtist = AlbumArtist;
            track.Bitrate     = BitRate;
            track.Samplerate  = (ushort)SampleRate;
            track.BPM         = (short)Bpm;
            track.Comment     = Comment;
            track.Composer    = Composer;
            track.TimeAdded   = DateTime.Now;
            track.CDs         = DiscCount;
            track.CDNumber    = DiscNumber;
            track.TrackLength = (int)Duration.TotalMilliseconds;
            track.Size        = (int)FileSize;
            track.Grouping    = Grouping;
            try {
                track.TimePlayed = LastPlayed;
            } catch {
                Hyena.Log.InformationFormat("Couldn't set TimePlayed to '{0}'", LastPlayed);
            }
            track.PlayCount   = (uint)PlayCount;
            track.Tracks      = TrackCount;
            track.TrackNumber = TrackNumber;
            track.Year        = Year;
            try {
                track.TimeReleased = ReleaseDate;
            } catch {
                Hyena.Log.InformationFormat("Couldn't set TimeReleased to '{0}'", ReleaseDate);
            }
            track.Album  = AlbumTitle;
            track.Artist = ArtistName;
            track.Title  = TrackTitle;
            track.Genre  = Genre;

            track.SortArtist      = ArtistNameSort;
            track.SortAlbum       = AlbumTitleSort;
            track.SortAlbumArtist = AlbumArtistSort;
            track.SortTitle       = TrackTitleSort;

            track.Rating = ((Rating >= 1) && (Rating <= 5)) ? (uint)Rating : 0;

            if (HasAttribute(TrackMediaAttributes.Podcast))
            {
                track.Description = description;
                track.RememberPlaybackPosition = true;
                track.SkipWhenShuffling        = true;
                track.Flag4        = (byte)1;
                track.MarkUnplayed = (track.PlayCount == 0);
            }

            track.MediaType = GPod.MediaType.Audio;
            if (HasAttribute(TrackMediaAttributes.VideoStream))
            {
                if (HasAttribute(TrackMediaAttributes.Podcast))
                {
                    track.MediaType = GPod.MediaType.Podcast | GPod.MediaType.Movie;
                }
                else if (HasAttribute(TrackMediaAttributes.Music))
                {
                    if (HasAttribute(TrackMediaAttributes.TvShow))
                    {
                        track.MediaType = GPod.MediaType.MusicTVShow;
                    }
                    else
                    {
                        track.MediaType = GPod.MediaType.MusicVideo;
                    }
                }
                else if (HasAttribute(TrackMediaAttributes.Movie))
                {
                    track.MediaType = GPod.MediaType.Movie;
                }
                else if (HasAttribute(TrackMediaAttributes.TvShow))
                {
                    track.MediaType = GPod.MediaType.TVShow;
                }
                else
                {
                    // I dont' think AudioVideo should be used here; upon loading the tracks
                    // into Banshee, audio files often have AudioVideo (aka MediaType == 0) too.
                    //track.MediaType = GPod.MediaType.AudioVideo;
                    track.MediaType = GPod.MediaType.Movie;
                }
            }
            else
            {
                if (HasAttribute(TrackMediaAttributes.Podcast))
                {
                    track.MediaType = GPod.MediaType.Podcast;
                }
                else if (HasAttribute(TrackMediaAttributes.AudioBook))
                {
                    track.MediaType = GPod.MediaType.Audiobook;
                }
                else if (HasAttribute(TrackMediaAttributes.Music))
                {
                    track.MediaType = GPod.MediaType.Audio;
                }
                else
                {
                    track.MediaType = GPod.MediaType.Audio;
                }
            }

            if (addTrack)
            {
                track.Filetype = mimetype;

                database.Tracks.Add(IpodTrack);
                database.MasterPlaylist.Tracks.Add(IpodTrack);

                if (HasAttribute(TrackMediaAttributes.Podcast) && database.Device.SupportsPodcast)
                {
                    database.PodcastsPlaylist.Tracks.Add(IpodTrack);
                }

                database.CopyTrackToIPod(track, Uri.LocalPath);
                Uri        = new SafeUri(GPod.ITDB.GetLocalPath(database.Device, track));
                ExternalId = (long)IpodTrack.DBID;
            }

            if (CoverArtSpec.CoverExists(ArtworkId))
            {
                string path = CoverArtSpec.GetPath(ArtworkId);
                if (!track.ThumbnailsSet(path))
                {
                    Log.Error(String.Format("Could not set cover art for {0}.", path));
                }
            }
            else
            {
                track.ThumbnailsRemoveAll();
            }
        }
Exemplo n.º 13
0
        protected void Fetch()
        {
            if (Track.Uri == null || !Track.Uri.IsFile ||
                Track.ArtworkId == null || !Banshee.IO.File.Exists(Track.Uri))
            {
                return;
            }

            string directory = System.IO.Path.GetDirectoryName(Track.Uri.AbsolutePath);

            // Get the largest (in terms of file size) JPEG in the directory
            long   max_size            = 0;
            string best_file           = null;
            int    items_in_directory  = 0;
            bool   found_definite_best = false;
            int    track_count         = track.TrackCount;

            if (track.DiscCount > 0)
            {
                track_count = track.TrackCount * track.DiscCount;
            }
            int max_acceptable_items = Math.Max(30, track_count + 8);

            foreach (string file in Banshee.IO.Directory.GetFiles(directory))
            {
                // Ignore directories with tons of songs in them; this lookup is only intended for when the
                // music file is in a directory specific to its album.
                if (++items_in_directory > max_acceptable_items)
                {
                    if (best_file != null)
                    {
                        Log.Debug("Ignoring image file in folder because too many files in folder", directory);
                    }
                    return;
                }

                if (found_definite_best)
                {
                    continue;
                }

                string extension = System.IO.Path.GetExtension(file).ToLower();
                if (Array.IndexOf(extensions, extension) != -1)
                {
                    string filename = System.IO.Path.GetFileNameWithoutExtension(file).ToLower();
                    if (Array.IndexOf(filenames, filename) != -1)
                    {
                        best_file           = file;
                        found_definite_best = true;
                    }
                    else
                    {
                        long size = Banshee.IO.File.GetSize(new SafeUri(file));
                        if (size > max_size)
                        {
                            max_size  = size;
                            best_file = file;
                        }
                    }
                }
            }

            if (best_file != null)
            {
                try {
                    string extension = "cover";
                    if (best_file.EndsWith("jpg", true, System.Globalization.CultureInfo.InvariantCulture) ||
                        best_file.EndsWith("jpeg", true, System.Globalization.CultureInfo.InvariantCulture))
                    {
                        extension = "jpg";
                    }

                    // Copy the file to the cover art directory
                    SaveAtomically(Path.ChangeExtension(CoverArtSpec.GetPath(Track.ArtworkId), extension), Banshee.IO.File.OpenRead(new SafeUri(best_file)));

                    // Send the new StreamTag
                    StreamTag tag = new StreamTag();
                    tag.Name  = CommonTags.AlbumCoverId;
                    tag.Value = Track.ArtworkId;
                    AddTag(tag);

                    Log.Debug("Got cover art from track's folder", best_file);
                } catch (Exception e) {
                    Log.Exception(e);
                }
            }
        }