Commit b2f8cbb1 authored by Andrés G. Aragoneses's avatar Andrés G. Aragoneses

CoverArt: display embedded artwork even if tags missing (bgo#692107)

Most MetadataProvider classes cannot retrieve cover art if there
is no album name information in the track because they get retrieve
the metadata from online sources. However, there is a provider which
does it locally: EmbeddedMetadataProvider.

In this case, the restriction about album name being known doesn't
really apply, so let's move this restriction to the online providers
and remove it from the more generic MetadataService and CoverArtJob
classes.
parent 715777b2
......@@ -79,6 +79,22 @@ namespace Banshee.Base
return System.IO.Path.ChangeExtension (GetPath (aaid), extension);
}
public static string CreateArtworkId (IBasicTrackInfo track)
{
string art_id = CoverArtSpec.CreateArtistAlbumId (track.AlbumArtist, track.AlbumTitle);
if (art_id != null) {
return art_id;
}
art_id = CoverArtSpec.CreateArtistTrackId (track.ArtistName, track.TrackTitle);
if (art_id != null) {
return art_id;
}
//if track provides embedded artwork but lacks tags, try hard at not giving a null artworkId, so that it can be displayed
return CoverArtSpec.CreateUriId (track.Uri);
}
public static string CreateArtistAlbumId (string artist, string album)
{
if (String.IsNullOrEmpty (album)) {
......@@ -91,7 +107,32 @@ namespace Banshee.Base
}
string digestible = String.Format ("{0}\t{1}", artist, album);
return String.Format ("album-{0}", Digest (digestible));
return CreateId ("album", digestible);
}
private static string CreateId (string prefix, string digestible)
{
return String.Format ("{0}-{1}", prefix, Digest (digestible));
}
private static string CreateArtistTrackId (string artist, string track)
{
if (String.IsNullOrEmpty (artist)) {
return null;
}
if (String.IsNullOrEmpty (track)) {
return null;
}
string digestible = String.Format ("{0}\t{1}", artist, track);
return CreateId ("single", digestible);
}
private static string CreateUriId (SafeUri uri)
{
string digestible = uri.ToString ();
return CreateId ("unknown", digestible);
}
public static string Digest (string str)
......
......@@ -253,7 +253,7 @@ namespace Banshee.Collection
[Exportable (ExportName = "artwork-id")]
public virtual string ArtworkId {
get { return CoverArtSpec.CreateArtistAlbumId (AlbumArtist, AlbumTitle); }
get { return CoverArtSpec.CreateArtworkId (this); }
}
[Exportable]
......
......@@ -58,8 +58,7 @@ namespace Banshee.Metadata.LastFM
public override void Run ()
{
if (Track == null || (Track.MediaAttributes & TrackMediaAttributes.Podcast) != 0) {
if (!OnlineMetadataServiceJob.TrackConditionsMet (Track)) {
return;
}
......
......@@ -93,8 +93,7 @@ namespace Banshee.Metadata.MusicBrainz
public bool Lookup ()
{
if (Track == null || (Track.MediaAttributes & TrackMediaAttributes.Podcast) != 0) {
if (!OnlineMetadataServiceJob.TrackConditionsMet (Track)) {
return false;
}
......
......@@ -72,7 +72,7 @@ namespace Banshee.Metadata.Rhapsody
public override void Run()
{
if (Track == null || (Track.MediaAttributes & TrackMediaAttributes.Podcast) != 0
if (!OnlineMetadataServiceJob.TrackConditionsMet (Track)
|| GetAlbumUrl (Track) == null) {
return;
}
......
......@@ -84,11 +84,6 @@ namespace Banshee.Metadata
return;
}
if (String.IsNullOrEmpty (track.AlbumTitle) || String.IsNullOrEmpty (track.ArtistName)) {
// Do not try to fetch album art for these
return;
}
lock (((ICollection)queries).SyncRoot) {
if (!queries.ContainsKey (track)) {
IMetadataLookupJob job = CreateJob (track);
......
//
// OnlineMetadataServiceJob.cs
//
// Author:
// Andrés G. Aragoneses <knocte@gmail.com>
//
// Copyright 2014 Andrés G. Aragoneses
//
// 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 Banshee.Collection;
namespace Banshee.Metadata
{
public static class OnlineMetadataServiceJob
{
public static bool TrackConditionsMet (IBasicTrackInfo track)
{
if (track == null) {
return false;
}
if ((track.MediaAttributes & TrackMediaAttributes.Podcast) != 0) {
return false;
}
if (String.IsNullOrEmpty (track.ArtistName)) {
return false;
}
if (String.IsNullOrEmpty (track.AlbumTitle)) {
return false;
}
return true;
}
}
}
......@@ -322,6 +322,7 @@
<Compile Include="Banshee.Playlists.Formats\PlaylistElement.cs" />
<Compile Include="Banshee.Hardware\FileSystem.cs" />
<Compile Include="Banshee.Playlists.Formats\ParsedPlaylist.cs" />
<Compile Include="Banshee.Metadata\OnlineMetadataServiceJob.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Banshee.Services.addin.xml">
......
......@@ -130,6 +130,7 @@ SOURCES = \
Banshee.Metadata/IMetadataProvider.cs \
Banshee.Metadata/MetadataService.cs \
Banshee.Metadata/MetadataServiceJob.cs \
Banshee.Metadata/OnlineMetadataServiceJob.cs \
Banshee.Metadata/SaveTrackMetadataJob.cs \
Banshee.Metadata/SaveTrackMetadataService.cs \
Banshee.Metadata/Tests/TaglibReadWriteTests.cs \
......
......@@ -134,12 +134,8 @@ namespace Banshee.CoverArt
{
bool save = true;
try {
if (String.IsNullOrEmpty (track.AlbumTitle) || String.IsNullOrEmpty (track.ArtistName)) {
// Do not try to fetch album art for these
} else {
IMetadataLookupJob job = MetadataService.Instance.CreateJob (track);
job.Run ();
}
IMetadataLookupJob job = MetadataService.Instance.CreateJob (track);
job.Run ();
} catch (System.Threading.ThreadAbortException) {
save = false;
throw;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment