コード例 #1
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);
                }
            }
        }
コード例 #2
0
 private void UpdateCover()
 {
     cover.LoadImage(
         TrackMediaAttributes.AudioStream | TrackMediaAttributes.AudioBook,
         CoverArtSpec.CreateArtistAlbumId(Book.ArtistName, Book.Title)
         );
 }
コード例 #3
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);
        }
コード例 #4
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)"));
        }
コード例 #5
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);
            }
        }
コード例 #6
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);
             }
         }
     }
 }
コード例 #7
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;
        }
コード例 #8
0
        /// <summary>
        /// Compress banshee database if it is not already compressed.
        /// </summary>
        /// This won't do anything if last compression is not more than  _DB_CACHED_COMPRESSION
        /// senconds ago. To avoid that you can reset _dbCompressTime to 0.
        ///
        /// See https://github.com/Knickedi/banshee-remote for more.
        public static void CompressDatabase()
        {
            if (Timestamp() - _dbCompressTime < _DB_CACHED_COMPRESSION)
            {
                return;
            }

            try {
                _dbCompressTime = Timestamp();

                File.Delete(DatabasePath(true));
                File.Delete(DatabasePath(true) + "-journal");
                File.Copy(DatabasePath(false), DatabasePath(true));

                // database was in use, unlock it or queries will just fail
                HyenaSqliteConnection db = new HyenaSqliteConnection(DatabasePath(true));
                db.BeginTransaction();
                db.CommitTransaction();
                db.Dispose();

                db = new HyenaSqliteConnection(DatabasePath(true));
                db.BeginTransaction();

                IDataReader cursor = db.Query(
                    "SELECT tbl_name FROM sqlite_master WHERE "
                    + "type='table' AND tbl_name NOT IN "
                    + "('CoreTracks', 'CoreArtists', 'CoreAlbums', 'sqlite_stat1', 'sqlite_stat2');");

                // drop unnecessary tables
                while (cursor.Read())
                {
                    db.Execute("DROP TABLE " + cursor.Get(0, typeof(string)) + ";");
                }

                // clear analytic data (if available)
                if (db.TableExists("sqlite_stat1"))
                {
                    db.Execute("DELETE FROM sqlite_stat1;");
                }
                if (db.TableExists("sqlite_stat2"))
                {
                    db.Execute("DELETE FROM sqlite_stat2;");
                }

                cursor.Dispose();

                // remove unecessary columns from tracks table
                db.Execute("CREATE TABLE tracks (\n"
                           + "	_id INTEGER PRIMARY KEY,\n"
                           + "	artistId  INTEGER,\n"
                           + "	albumId  INTEGER,\n"
                           + "	title TEXT,\n"
                           + " trackNumber INTEGER,\n"
                           + "	duration INTEGER,\n"
                           + "	year INTEGER,\n"
                           + "	genre TEXT,\n"
                           + " rating INTEGER\n"
                           + ");");
                db.Execute("INSERT INTO tracks(_id, artistId, albumId, "
                           + "title, trackNumber, duration, year, genre, rating) "
                           + "SELECT TrackID, ArtistID, AlbumId, "
                           + "Title, TrackNumber, Duration, Year, Genre, Rating "
                           + "FROM CoreTracks;");

                // remove unecessary columns from artist table
                db.Execute("CREATE TABLE artists (\n"
                           + "	_id INTEGER PRIMARY KEY,\n"
                           + "	name TEXT\n"
                           + ");");
                db.Execute("INSERT INTO artists(_id, name) "
                           + "SELECT ArtistID, Name FROM CoreArtists;");


                // remove unecessary columns from album table
                db.Execute("CREATE TABLE albums (\n"
                           + "	_id INTEGER PRIMARY KEY,\n"
                           + "	artistId INTEGER,\n"
                           + " title TEXT,\n"
                           + " artId TEXT\n"
                           + ");");

                if (db.ColumnExists("CoreAlbums", "ArtworkID"))
                {
                    db.Execute("INSERT INTO albums(_id, artistId, title, artId) "
                               + "SELECT AlbumID, ArtistID, Title, ArtworkID FROM CoreAlbums;");
                }
                else
                {
                    // old banshee versions don't cache the cover ID - fix that manually

                    Dictionary <int, string> artists = new Dictionary <int, string>();
                    IDataReader r = db.Query("SELECT ArtistId, Name FROM CoreArtists;");

                    while (r.Read())
                    {
                        artists.Add(r.Get <int>(0), r.Get <string>(1));
                    }

                    r.Dispose();
                    r = db.Query("SELECT AlbumID, ArtistID, Title FROM CoreAlbums;");

                    while (r.Read())
                    {
                        int    artistId = r.Get <int>(1);
                        string album    = r.Get <string>(2);
                        string artId    = "";
                        string artist   = null;

                        if (artists.TryGetValue(artistId, out artist))
                        {
                            artId = CoverArtSpec.CreateArtistAlbumId(artist ?? "", album ?? "").Replace("'", "''");
                        }

                        db.Execute("INSERT INTO albums(_id, artistId, title, artId) VALUES ("
                                   + r.Get <int>(0) + "," + artistId + ","
                                   + "'" + (album ?? "").Replace("'", "''") + "', "
                                   + "'" + artId + "');");
                    }

                    r.Dispose();
                }

                db.Execute("DROP TABLE CoreTracks;");
                db.Execute("DROP TABLE CoreArtists;");
                db.Execute("DROP TABLE CoreAlbums;");

                db.CommitTransaction();
                db.Execute("VACUUM;");
                db.Dispose();

                SetDbCompressTimeFromFile();
            } catch (Exception e) {
                Log.Error("remote listener failed to compress database: " + e.Message);
                File.Delete(DatabasePath(true));
            }
        }