コード例 #1
0
        public Pixbuf LookupScalePixbuf(string id, int size)
        {
            if (id == null || (size != 0 && size < 10))
            {
                return(null);
            }

            // Find the scaled, cached file
            string path = CoverArtSpec.GetPathForSize(id, size);

            if (File.Exists(path))
            {
                try {
                    return(new Pixbuf(path));
                } catch {
                    return(null);
                }
            }

            string orig_path   = CoverArtSpec.GetPathForSize(id, 0);
            bool   orig_exists = File.Exists(orig_path);

            if (!orig_exists)
            {
                // It's possible there is an image with extension .cover that's waiting
                // to be converted into a jpeg
                string unconverted_path = Path.ChangeExtension(orig_path, "cover");
                if (File.Exists(unconverted_path))
                {
                    try {
                        Pixbuf pixbuf = new Pixbuf(unconverted_path);
                        if (pixbuf.Width < 50 || pixbuf.Height < 50)
                        {
                            Hyena.Log.DebugFormat("Ignoring cover art {0} because less than 50x50", unconverted_path);
                            return(null);
                        }

                        pixbuf.Save(orig_path, "jpeg");
                        orig_exists = true;
                    } catch {
                    } finally {
                        File.Delete(unconverted_path);
                    }
                }
            }

            if (orig_exists && size >= 10)
            {
                try {
                    Pixbuf pixbuf        = new Pixbuf(orig_path);
                    Pixbuf scaled_pixbuf = pixbuf.ScaleSimple(size, size, Gdk.InterpType.Bilinear);
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    scaled_pixbuf.Save(path, "jpeg");
                    DisposePixbuf(pixbuf);
                    return(scaled_pixbuf);
                } catch {}
            }

            return(null);
        }
コード例 #2
0
        private Actor GetActorForAlbumInfo(AlbumInfo info)
        {
            Actor actor = null;

            if (info == null || info.ArtworkId == null)
            {
                return(null);
            }

            if (actor_cache.TryGetValue(info.ArtworkId, out actor))
            {
                return(actor);
            }

            if (!CoverArtSpec.CoverExists(info.ArtworkId))
            {
                return(null);
            }

            actor = new AlbumArtActor(info, ActorSize)
            {
                Parent = this
            };
            actor_cache.Add(info.ArtworkId, actor);
            return(actor);
        }
コード例 #3
0
ファイル: ArtworkManager.cs プロジェクト: thoja21/banshee-1
        public void ClearCacheFor(string id, bool inMemoryCacheOnly)
        {
            if (String.IsNullOrEmpty(id))
            {
                return;
            }

            // Clear from the in-memory cache
            foreach (int size in scale_caches.Keys)
            {
                scale_caches[size].Remove(id);
            }

            null_artwork_ids.Remove(id);

            if (inMemoryCacheOnly)
            {
                return;
            }

            // And delete from disk
            foreach (int size in CachedSizes())
            {
                var uri = new SafeUri(CoverArtSpec.GetPathForSize(id, size));
                if (File.Exists(uri))
                {
                    File.Delete(uri);
                }
            }
        }
コード例 #4
0
ファイル: EmbeddedQueryJob.cs プロジェクト: thoja21/banshee-1
        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);
                }
            }
        }
コード例 #5
0
ファイル: CoverArtEditor.cs プロジェクト: thoja21/banshee-1
            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);
                    }
                }
            }
コード例 #6
0
 private void UpdateCover()
 {
     cover.LoadImage(
         TrackMediaAttributes.AudioStream | TrackMediaAttributes.AudioBook,
         CoverArtSpec.CreateArtistAlbumId(Book.ArtistName, Book.Title)
         );
 }
コード例 #7
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
     {
     }
 }
コード例 #8
0
        private void FetchForTrack(DatabaseTrackInfo track)
        {
            bool save = true;

            try {
                if (String.IsNullOrEmpty(track.AlbumTitle) || track.AlbumTitle == Catalog.GetString("Unknown Album") ||
                    String.IsNullOrEmpty(track.ArtistName) || track.ArtistName == Catalog.GetString("Unknown Artist"))
                {
                    // Do not try to fetch album art for these
                }
                else
                {
                    IMetadataLookupJob job = MetadataService.Instance.CreateJob(track);
                    job.Run();
                }
            } catch (System.Threading.ThreadAbortException) {
                save = false;
                throw;
            } catch (Exception e) {
                Log.Exception(e);
            } finally {
                if (save)
                {
                    bool have_cover_art = CoverArtSpec.CoverExists(track.ArtistName, track.AlbumTitle);
                    ServiceManager.DbConnection.Execute(
                        "INSERT OR REPLACE INTO CoverArtDownloads (AlbumID, Downloaded, LastAttempt) VALUES (?, ?, ?)",
                        track.AlbumId, have_cover_art, DateTime.Now);
                }
            }
        }
コード例 #9
0
 private void RefreshArtworkFor(Feed feed)
 {
     if (feed.LastDownloadTime != DateTime.MinValue && !CoverArtSpec.CoverExists(PodcastService.ArtworkIdFor(feed)))
     {
         Banshee.Kernel.Scheduler.Schedule(new PodcastImageFetchJob(feed), Banshee.Kernel.JobPriority.BelowNormal);
     }
 }
コード例 #10
0
        public void TestSizePath()
        {
            var    png_file_path = ExtractPngFromResource();
            string jpg_file_path = null;

            try {
                var artist_album_id = CoverArtSpec.CreateArtistAlbumId("Metallica", "Master Of Puppets");
                jpg_file_path = CoverArtSpec.GetPathForSize(artist_album_id, CustomArtworkManager.SizeTest);  // i.e.: /home/knocte/.cache/media-art/36/album-d33f25dbd7dfb4817a7e99f6bc2de49e.jpg"
                var pixbuf = new Pixbuf(png_file_path);

                var dir = System.IO.Path.GetDirectoryName(jpg_file_path);
                if (!System.IO.Directory.Exists(dir))
                {
                    System.IO.Directory.CreateDirectory(dir);
                }

                pixbuf.Save(jpg_file_path, "jpeg");

                var artwork_manager = new CustomArtworkManager();
                Assert.IsNull(artwork_manager.LookupScaleSurface(artist_album_id, 1, false),
                              "Should have got null at the first request, with an invalid size");
                Assert.IsNotNull(artwork_manager.LookupScaleSurface(artist_album_id, CustomArtworkManager.SizeTest, false),
                                 "Null at the second request, was null cached incorrectly?");
            } finally {
                File.Delete(png_file_path);
                if (File.Exists(jpg_file_path))
                {
                    File.Delete(jpg_file_path);
                }
            }
        }
コード例 #11
0
 private void RefreshArtworkFor(Feed feed)
 {
     if (!String.IsNullOrEmpty(feed.ImageUrl) && !CoverArtSpec.CoverExists(PodcastService.ArtworkIdFor(feed)))
     {
         Banshee.Kernel.Scheduler.Schedule(new PodcastImageFetchJob(feed), Banshee.Kernel.JobPriority.BelowNormal);
     }
 }
コード例 #12
0
        public string getArtId()
        {
            string aaid = CoverArtSpec.CreateArtistAlbumId(_performer, _title);

            if (!CoverArtSpec.CoverExists(aaid))
            {
                if (File.Exists(_img_full_path))
                {
                    string path = CoverArtSpec.GetPathForNewFile(aaid, _img_full_path);
                    if (!File.Exists(path))
                    {
                        File.Copy(_img_full_path, path);
                    }
                }
            }
            else
            {
                if (File.Exists(_img_full_path))
                {
                    string path = CoverArtSpec.GetPathForNewFile(aaid, _img_full_path);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    if (!File.Exists(path))
                    {
                        File.Copy(_img_full_path, path);
                    }
                }
            }
            return(aaid);
        }
コード例 #13
0
ファイル: CoverArtEditor.cs プロジェクト: thoja21/banshee-1
            private void SetCoverArt(TrackInfo track, string path)
            {
                if (track == null)
                {
                    return;
                }

                var from_uri = new SafeUri(new System.Uri(path));

                var to_uri = new SafeUri(CoverArtSpec.GetPathForNewFile(track.ArtworkId, from_uri.AbsoluteUri));

                if (to_uri != null)
                {
                    // Make sure it's not the same file we already have
                    if (from_uri.Equals(to_uri))
                    {
                        return;
                    }

                    // Make sure the incoming file exists
                    if (!Banshee.IO.File.Exists(from_uri))
                    {
                        Hyena.Log.WarningFormat("New cover art file not found: {0}", path);
                        return;
                    }

                    DeleteCoverArt(track);
                    Banshee.IO.File.Copy(from_uri, to_uri, true);
                    NotifyUpdated(track);

                    Hyena.Log.DebugFormat("Got new cover art file for {0}: {1}", track.DisplayAlbumTitle, path);
                }
            }
コード例 #14
0
        public void Fetch()
        {
            if (feed.ImageUrl == null)
            {
                return;
            }

            string cover_art_id = PodcastService.ArtworkIdFor(feed);

            if (cover_art_id == null)
            {
                return;
            }
            else if (CoverArtSpec.CoverExists(cover_art_id))
            {
                return;
            }
            else if (!InternetConnected)
            {
                return;
            }

            if (SaveHttpStreamCover(new Uri(feed.ImageUrl), cover_art_id, null))
            {
                Banshee.Sources.Source src = ServiceManager.SourceManager.ActiveSource;
                if (src != null && (src is PodcastSource || src.Parent is PodcastSource))
                {
                    (src as Banshee.Sources.DatabaseSource).Reload();
                }
                return;
            }
        }
コード例 #15
0
        public override void Run()
        {
            if (!OnlineMetadataServiceJob.TrackConditionsMet(Track) ||
                GetAlbumUrl(Track) == null)
            {
                return;
            }

            string artwork_id = Track.ArtworkId;

            if (artwork_id == null || CoverArtSpec.CoverExists(artwork_id) || !InternetConnected)
            {
                return;
            }

            Uri data_uri = new Uri(base_uri, String.Format("/{0}/data.xml", GetAlbumUrl(Track)));

            XmlDocument     doc      = new XmlDocument();
            HttpWebResponse response = GetHttpStream(data_uri);

            if (response == null)
            {
                return;
            }

            string [] content_types = response.Headers.GetValues("Content-Type");
            if (content_types.Length == 0 || content_types[0] != "text/xml")
            {
                response.Close();
                return;
            }

            using (Stream stream = response.GetResponseStream()) {
                doc.Load(stream);
            }

            XmlNode art_node = doc.DocumentElement.SelectSingleNode("/album/art/album-art[@size='large']/img");

            if (art_node != null && art_node.Attributes["src"] != null)
            {
                // awesome hack to get high resolution cover art from Rhapsody
                string second_attempt = art_node.Attributes["src"].Value;
                string first_attempt  = second_attempt.Replace("170x170", "500x500");

                if (SaveHttpStreamCover(new Uri(first_attempt), artwork_id, null) ||
                    SaveHttpStreamCover(new Uri(second_attempt), artwork_id, null))
                {
                    Log.Debug("Downloaded cover art from Rhapsody", artwork_id);
                    StreamTag tag = new StreamTag();
                    tag.Name  = CommonTags.AlbumCoverId;
                    tag.Value = artwork_id;

                    AddTag(tag);
                }
            }

            response.Close();
        }
コード例 #16
0
ファイル: CoverArtEditor.cs プロジェクト: thoja21/banshee-1
            private SafeUri GetCoverArtPath(TrackInfo track)
            {
                if (track != null)
                {
                    return(new SafeUri(CoverArtSpec.GetPath(track.ArtworkId)));
                }

                return(null);
            }
コード例 #17
0
ファイル: EmbeddedQueryJob.cs プロジェクト: thoja21/banshee-1
        public override void Run()
        {
            if (track == null || CoverArtSpec.CoverExists(track.ArtworkId))
            {
                return;
            }

            Fetch();
        }
コード例 #18
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)));
            }
        }
コード例 #19
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);
            }
        }
コード例 #20
0
        public void TestEmpty()
        {
            AssertDigested(null, null);
            AssertDigested("", null);
            AssertDigested(" ", "7215ee9c7d9dc229d2921a40e899ec5f");

            // Test that bgo#620010 is fixed
            Assert.AreEqual(null, CoverArtSpec.CreateArtistAlbumId(null, null));
            Assert.AreEqual(null, CoverArtSpec.CreateArtistAlbumId(null, "All Albums (6)"));
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
        public bool Lookup()
        {
            if (Track == null || (Track.MediaAttributes & TrackMediaAttributes.Podcast) != 0)
            {
                return(false);
            }

            string artwork_id = Track.ArtworkId;

            if (artwork_id == null)
            {
                return(false);
            }
            else if (CoverArtSpec.CoverExists(artwork_id))
            {
                return(false);
            }
            else if (!InternetConnected)
            {
                return(false);
            }

            if (asin == null)
            {
                asin = FindAsin();
                if (asin == null)
                {
                    return(false);
                }
            }

            if (SaveHttpStreamCover(new Uri(String.Format(AmazonUriFormat, asin)), artwork_id,
                                    new string [] { "image/gif" }))
            {
                Log.Debug("Downloaded cover art from Amazon", artwork_id);
                StreamTag tag = new StreamTag();
                tag.Name  = CommonTags.AlbumCoverId;
                tag.Value = artwork_id;

                AddTag(tag);

                return(true);
            }

            return(false);
        }
コード例 #23
0
 public void  resetArt()
 {
     if (_img_full_path != null && _img_full_path != "")
     {
         if (File.Exists(_img_full_path))
         {
             string aaid = CoverArtSpec.CreateArtistAlbumId(_performer, _title);
             string path = CoverArtSpec.GetPathForNewFile(aaid, _img_full_path);
             if (File.Exists(path))
             {
                 File.Delete(path);
             }
             File.Copy(_img_full_path, path);
             int i, N;
             for (i = 0, N = nEntries(); i < N; i++)
             {
                 entry(i).setArtWorkId(aaid);
             }
         }
     }
 }
コード例 #24
0
ファイル: CoverArtJob.cs プロジェクト: thoja21/banshee-1
        private void FetchForTrack(DatabaseTrackInfo track)
        {
            bool save = true;

            try {
                IMetadataLookupJob job = MetadataService.Instance.CreateJob(track);
                job.Run();
            } catch (System.Threading.ThreadAbortException) {
                save = false;
                throw;
            } catch (Exception e) {
                Log.Error(e);
            } finally {
                if (save)
                {
                    bool have_cover_art = CoverArtSpec.CoverExists(track.ArtistName, track.AlbumTitle);
                    ServiceManager.DbConnection.Execute(
                        "INSERT OR REPLACE INTO CoverArtDownloads (AlbumID, Downloaded, LastAttempt) VALUES (?, ?, ?)",
                        track.AlbumId, have_cover_art, DateTime.Now);
                }
            }
        }
コード例 #25
0
ファイル: ArtworkManager.cs プロジェクト: thoja21/banshee-1
        private void MigrateCacheDir()
        {
            int version = CacheVersion;

            if (version == CUR_VERSION)
            {
                return;
            }

            var legacy_root_path = CoverArtSpec.LegacyRootPath;

            if (version < 1)
            {
                string legacy_artwork_path = Paths.Combine(LegacyPaths.ApplicationData, "covers");

                if (!Directory.Exists(legacy_root_path))
                {
                    Directory.Create(legacy_root_path);

                    if (Directory.Exists(legacy_artwork_path))
                    {
                        Directory.Move(new SafeUri(legacy_artwork_path), new SafeUri(legacy_root_path));
                    }
                }

                if (Directory.Exists(legacy_artwork_path))
                {
                    Log.InformationFormat("Deleting old (Banshee < 1.0) artwork cache directory {0}", legacy_artwork_path);
                    Directory.Delete(legacy_artwork_path, true);
                }
            }

            if (version < 2)
            {
                int deleted = 0;
                foreach (string dir in Directory.GetDirectories(legacy_root_path))
                {
                    int    size;
                    string dirname = System.IO.Path.GetFileName(dir);
                    if (Int32.TryParse(dirname, out size) && !IsCachedSize(size))
                    {
                        Directory.Delete(dir, true);
                        deleted++;
                    }
                }

                if (deleted > 0)
                {
                    Log.InformationFormat("Deleted {0} extraneous album-art cache directories", deleted);
                }
            }

            if (version < 3)
            {
                Log.Information("Migrating album-art cache directory");
                var started = DateTime.Now;
                int count   = 0;

                var root_path = CoverArtSpec.RootPath;
                if (!Directory.Exists(root_path))
                {
                    Directory.Create(root_path);
                }

                string sql = "SELECT Title, ArtistName FROM CoreAlbums";
                using (var reader = new HyenaDataReader(ServiceManager.DbConnection.Query(sql))) {
                    while (reader.Read())
                    {
                        var album    = reader.Get <string>(0);
                        var artist   = reader.Get <string>(1);
                        var old_file = CoverArtSpec.CreateLegacyArtistAlbumId(artist, album);
                        var new_file = CoverArtSpec.CreateArtistAlbumId(artist, album);

                        if (String.IsNullOrEmpty(old_file) || String.IsNullOrEmpty(new_file))
                        {
                            continue;
                        }

                        old_file = String.Format("{0}.jpg", old_file);
                        new_file = String.Format("{0}.jpg", new_file);

                        var old_path = new SafeUri(Paths.Combine(legacy_root_path, old_file));
                        var new_path = new SafeUri(Paths.Combine(root_path, new_file));

                        if (Banshee.IO.File.Exists(old_path) && !Banshee.IO.File.Exists(new_path))
                        {
                            Banshee.IO.File.Move(old_path, new_path);
                            count++;
                        }
                    }
                }

                if (ServiceManager.DbConnection.TableExists("PodcastSyndications"))
                {
                    sql = "SELECT Title FROM PodcastSyndications";
                    foreach (var title in ServiceManager.DbConnection.QueryEnumerable <string> (sql))
                    {
                        var old_digest = CoverArtSpec.LegacyEscapePart(title);
                        var new_digest = CoverArtSpec.Digest(title);

                        if (String.IsNullOrEmpty(old_digest) || String.IsNullOrEmpty(new_digest))
                        {
                            continue;
                        }

                        var old_file = String.Format("podcast-{0}.jpg", old_digest);
                        var new_file = String.Format("podcast-{0}.jpg", new_digest);

                        var old_path = new SafeUri(Paths.Combine(legacy_root_path, old_file));
                        var new_path = new SafeUri(Paths.Combine(root_path, new_file));

                        if (Banshee.IO.File.Exists(old_path) && !Banshee.IO.File.Exists(new_path))
                        {
                            Banshee.IO.File.Move(old_path, new_path);
                            count++;
                        }
                    }
                }

                if (count == 0)
                {
                    ResetScanResultCache();
                }

                Directory.Delete(legacy_root_path, true);
                Log.InformationFormat("Migrated {0} files in {1}s", count, DateTime.Now.Subtract(started).TotalSeconds);
            }

            CacheVersion = CUR_VERSION;
        }
コード例 #26
0
 protected bool SaveHttpStreamCover(Uri uri, string albumArtistId, string [] ignoreMimeTypes)
 {
     return(SaveHttpStream(uri, CoverArtSpec.GetPath(albumArtistId), ignoreMimeTypes));
 }
コード例 #27
0
ファイル: ArtworkManager.cs プロジェクト: thoja21/banshee-1
        public Pixbuf LookupScalePixbuf(string id, int size)
        {
            if (id == null || (size != 0 && size < 10))
            {
                // explicitly don't add this id into null_artwork_ids here,
                // otherwise it would blacklist all other non-invalid sizes
                return(null);
            }

            if (null_artwork_ids.Contains(id))
            {
                return(null);
            }

            // Find the scaled, cached file
            string path = CoverArtSpec.GetPathForSize(id, size);

            if (File.Exists(new SafeUri(path)))
            {
                try {
                    return(new Pixbuf(path));
                } catch {
                    null_artwork_ids.Add(id);
                    return(null);
                }
            }

            string orig_path   = CoverArtSpec.GetPathForSize(id, 0);
            bool   orig_exists = File.Exists(new SafeUri(orig_path));

            if (!orig_exists)
            {
                // It's possible there is an image with extension .cover that's waiting
                // to be converted into a jpeg
                string unconverted_path = System.IO.Path.ChangeExtension(orig_path, "cover");
                if (File.Exists(new SafeUri(unconverted_path)))
                {
                    try {
                        Pixbuf pixbuf = new Pixbuf(unconverted_path);
                        if (pixbuf.Width < 50 || pixbuf.Height < 50)
                        {
                            Hyena.Log.DebugFormat("Ignoring cover art {0} because less than 50x50", unconverted_path);
                            null_artwork_ids.Add(id);
                            return(null);
                        }

                        pixbuf.Save(orig_path, "jpeg");
                        orig_exists = true;
                    } catch {
                    } finally {
                        File.Delete(new SafeUri(unconverted_path));
                    }
                }
            }

            if (orig_exists && size >= 10)
            {
                try {
                    Pixbuf pixbuf = new Pixbuf(orig_path);

                    // Make it square if width and height difference is within 20%
                    const double max_ratio = 1.2;
                    double       ratio = (double)pixbuf.Height / pixbuf.Width;
                    int          width = size, height = size;
                    if (ratio > max_ratio)
                    {
                        width = (int)Math.Round(size / ratio);
                    }
                    else if (ratio < 1d / max_ratio)
                    {
                        height = (int)Math.Round(size * ratio);
                    }

                    Pixbuf scaled_pixbuf = pixbuf.ScaleSimple(width, height, Gdk.InterpType.Bilinear);

                    if (IsCachedSize(size))
                    {
                        Directory.Create(System.IO.Path.GetDirectoryName(path));
                        scaled_pixbuf.Save(path, "jpeg");
                    }
                    else
                    {
                        Log.InformationFormat("Uncached artwork size {0} requested", size);
                    }

                    DisposePixbuf(pixbuf);
                    if (scaled_pixbuf == null || scaled_pixbuf.Handle == IntPtr.Zero)
                    {
                        null_artwork_ids.Add(id);
                    }
                    return(scaled_pixbuf);
                } catch {}
            }

            null_artwork_ids.Add(id);
            return(null);
        }
コード例 #28
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);
            }
        }
コード例 #29
0
        protected override void AddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri)
        {
            if (track.PrimarySourceId == DbId)
            {
                return;
            }

            SafeUri new_uri = new SafeUri(GetTrackPath(track, System.IO.Path.GetExtension(fromUri)));

            // If it already is on the device but it's out of date, remove it
            //if (File.Exists(new_uri) && File.GetLastWriteTime(track.Uri.LocalPath) > File.GetLastWriteTime(new_uri))
            //RemoveTrack(new MassStorageTrackInfo(new SafeUri(new_uri)));

            if (!File.Exists(new_uri))
            {
                Directory.Create(System.IO.Path.GetDirectoryName(new_uri.LocalPath));
                File.Copy(fromUri, new_uri, false);

                DatabaseTrackInfo copied_track = new DatabaseTrackInfo(track);
                copied_track.PrimarySource = this;
                copied_track.Uri           = new_uri;

                // Write the metadata in db to the file on the DAP if it has changed since file was modified
                // to ensure that when we load it next time, it's data will match what's in the database
                // and the MetadataHash will actually match.  We do this by comparing the time
                // stamps on files for last update of the db metadata vs the sync to file.
                // The equals on the inequality below is necessary for podcasts who often have a sync and
                // update time that are the same to the second, even though the album metadata has changed in the
                // DB to the feedname instead of what is in the file.  It should be noted that writing the metadata
                // is a small fraction of the total copy time anyway.

                if (track.LastSyncedStamp >= Hyena.DateTimeUtil.ToDateTime(track.FileModifiedStamp))
                {
                    Log.DebugFormat("Copying Metadata to File Since Sync time >= Updated Time");
                    bool write_metadata = Metadata.SaveTrackMetadataService.WriteMetadataEnabled.Value;
                    bool write_ratings_and_playcounts = Metadata.SaveTrackMetadataService.WriteRatingsAndPlayCountsEnabled.Value;
                    Banshee.Streaming.StreamTagger.SaveToFile(copied_track, write_metadata, write_ratings_and_playcounts);
                }

                copied_track.Save(false);
            }

            if (CoverArtSize > -1 && !String.IsNullOrEmpty(CoverArtFileType) &&
                !String.IsNullOrEmpty(CoverArtFileName) && (FolderDepth == -1 || FolderDepth > 0))
            {
                SafeUri cover_uri = new SafeUri(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(new_uri.LocalPath),
                                                                       CoverArtFileName));
                string coverart_id = track.ArtworkId;

                if (!File.Exists(cover_uri) && CoverArtSpec.CoverExists(coverart_id))
                {
                    Gdk.Pixbuf pic = null;

                    if (CoverArtSize == 0)
                    {
                        if (CoverArtFileType == "jpg" || CoverArtFileType == "jpeg")
                        {
                            SafeUri local_cover_uri = new SafeUri(Banshee.Base.CoverArtSpec.GetPath(coverart_id));
                            Banshee.IO.File.Copy(local_cover_uri, cover_uri, false);
                        }
                        else
                        {
                            pic = artwork_manager.LookupPixbuf(coverart_id);
                        }
                    }
                    else
                    {
                        pic = artwork_manager.LookupScalePixbuf(coverart_id, CoverArtSize);
                    }

                    if (pic != null)
                    {
                        try {
                            byte []          bytes          = pic.SaveToBuffer(CoverArtFileType);
                            System.IO.Stream cover_art_file = File.OpenWrite(cover_uri, true);
                            cover_art_file.Write(bytes, 0, bytes.Length);
                            cover_art_file.Close();
                        } catch (GLib.GException) {
                            Log.DebugFormat("Could not convert cover art to {0}, unsupported filetype?", CoverArtFileType);
                        } finally {
                            Banshee.Collection.Gui.ArtworkManager.DisposePixbuf(pic);
                        }
                    }
                }
            }
        }
コード例 #30
0
 private void AssertEscaped(string original, string expected)
 {
     Assert.AreEqual(expected, CoverArtSpec.EscapePart(original));
 }