예제 #1
0
            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);
                }
            }
예제 #2
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);
        }
예제 #3
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);
             }
         }
     }
 }
예제 #4
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 {
                    // Copy the file to the cover art directory
                    SaveAtomically(CoverArtSpec.GetPathForNewFile(Track.ArtworkId, best_file), 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.Error(e);
                }
            }
        }