Bug 600809 - Folder art in a directory is being ignored by a routine called "FileSystemdQueryJob.cs"
Folder art in a directory is being ignored by a routine called "FileSystemdQu...
Status: CLOSED INSUFFICIENT_DATA
Product: Fedora
Classification: Fedora
Component: banshee (Show other bugs)
13
All Linux
low Severity medium
: ---
: ---
Assigned To: Christian Krause
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-06-06 02:06 EDT by Steve Foster
Modified: 2010-07-27 15:57 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-07-27 15:57:24 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Steve Foster 2010-06-06 02:06:21 EDT
Description of problem:
Folder art in a directory is being ignored by a routine called "FileSystemdQueryJob.cs".   

Version-Release number of selected component (if applicable):
banshee 1.61.

How reproducible:
Every time I play a album

Steps to Reproduce:
1. Try to Play a Album, no art.
2. enabled debuging
3.
  
Actual results:
[10 Debug 22:51:23.359] Ignoring image file in folder because too many files in folder - /home/stevef/.gvfs/mp3audio on mediaserver/Bobby Darin/The Bobby Darwin Collection/Disc 1
[

Expected results:
Just work

Additional info:

//
// FileSystemdQueryJob.cs
//
// Authors:
//   Gabriel Burt <gburt@novell.com>
//
// Copyright (C) 2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System;
using System.IO;
using System.Collections.Generic;

using Hyena;

using Banshee.Base;
using Banshee.Metadata;
using Banshee.Collection;
using Banshee.Streaming;

namespace Banshee.Metadata.FileSystem
{
    public class FileSystemQueryJob : MetadataServiceJob
    {
        private TrackInfo track;
        public FileSystemQueryJob (IBasicTrackInfo track)
        {
            Track = track;
            this.track = track as TrackInfo;
        }

        public override void Run ()
        {
            if (Track == null || CoverArtSpec.CoverExists (Track.ArtworkId)) {
                return;
            }

            Fetch ();
        }

        private static string [] extensions = new string [] { ".jpg", ".jpeg", ".png", ".bmp" };
        private static string [] filenames = new string [] { "cover", "folder", "front" };

        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);
                }
            }
        }
    }
}
Comment 1 Steve Foster 2010-06-06 02:12:08 EDT
I kind of think that if the Banshee developers consider this directory
"too many files" they have no connection to reality.


01 Bobby Darin - Early In The Morning (With The Rinky Dinks).mp3
AlbumArtSmall.jpg
Bobby Darin - All the Way Home.mp3
Bobby Darin - Bullmoose.mp3
Bobby Darin - Don't Call My Name.mp3
Bobby Darin - Dream Lover (demo).mp3
Bobby Darin - Dream Lover.mp3
Bobby Darin - Easy Rider.mp3
Bobby Darin - Everywhere I Go.mp3
Bobby Darin - Funny What Love Can Do.mp3
Bobby Darin - If a Man Answers.mp3
Bobby Darin - I Got a Woman (Live).mp3
Bobby Darin - Irresistible You.mp3
Bobby Darin - Lost Love.mp3
Bobby Darin - Multiplication.mp3
Bobby Darin - Plain Jane.mp3
Bobby Darin - Queen of the Hop.mp3
Bobby Darin - Sail Away.mp3
Bobby Darin - She Knows.mp3
Bobby Darin - Somebody to Love.mp3
Bobby Darin - Splish Splash.mp3
Bobby Darin - The Right Time.mp3
Bobby Darin - Treat My Baby Good.mp3
Bobby Darin - We Didn't Ask to Be Brought Here.mp3
Bobby Darin - What'd I Say.mp3
Bobby Darin - When I Get Home.mp3
Bobby Darin - You Must Have Been a Beautiful Baby.mp3
cover.jpg
folder.jpg
Comment 2 Christian Krause 2010-06-19 11:16:31 EDT
I have investigated the issue and also reviewed the code in ./src/Core/Banshee.Services/Banshee.Metadata.FileSystem/FileSystemQueryJob.cs:

Yes, there is a upper limit, but it works like this:

1. the number of songs of the album is taken from the metadata (id3) of the currently playing song ("track_count")
2. the maximum number of files in the directory which banshee is looking at for finding the cover art is calculated by 

            int max_acceptable_items = Math.Max (30, track_count + 8);

which means, that the highest value of either 30 or the number of tracks + 8 is chosen.
3. banshee reads up to max_acceptable_items files in the directory (which contains the current song)
4. if there is no cover art found, then you'll see the error message

This means, assuming that:
- the files are correctly tagged
- each directory contains only one album
then there is no problem at all:
- if the album contains 50 tracks, then
max_acceptable_items = Max(30, 50 + 8) = 58
- as long as there are not 8 additional files not containing pictures in the directory, the cover art is found.

So far I don't see a problem with this algorithm. It prevents fetching cover art from directories containing thousands of files of different albums because then the selection of the cover art would be wrong anyway.

I can fully reproduce the behaviour of this algorithm on my system.

However, this doesn't exactly explain why it doesn't work in your example:

- if comment #2 contains really all files of the directory where the playing song was located, then the cover art should have been found (there are only 29 files and so regardless the tags of the files banshee should check all of them)

Please check:
- whether the mentioned directory "/home/stevef/.gvfs/mp3audio on mediaserver/Bobby Darin/The Bobby Darwin Collection/Disc 1" really contains only the mentioned 29 files
- additionally please check, whether the files are tagged and what's the "number of tracks of album"
Comment 3 Christian Krause 2010-07-27 15:57:24 EDT
The information we've requested above is required in order to review this problem report further and diagnose or fix the issue if it is still present. Since it has been thirty days or more since we first requested additional information, we're assuming the problem is either no longer present in the current Fedora release, or that there is no longer any interest in tracking the problem. 

Setting status to "CLOSED: INSUFFICIENT_DATA". If you still experience this problem after updating to our latest Fedora release and can provide the information previously requested, please feel free to reopen the bug report.

Note You need to log in before you can comment on or make changes to this bug.