banshee r4084 - in trunk/banshee: . src/Extensions/Banshee.CoverArt/Banshee.CoverArt
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4084 - in trunk/banshee: . src/Extensions/Banshee.CoverArt/Banshee.CoverArt
- Date: Tue, 3 Jun 2008 16:38:01 +0000 (UTC)
Author: gburt
Date: Tue Jun 3 16:38:01 2008
New Revision: 4084
URL: http://svn.gnome.org/viewvc/banshee?rev=4084&view=rev
Log:
2008-06-03 Gabriel Burt <gabriel burt gmail com>
* src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs:
* src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtService.cs: Add
a CoverArtDownloads table to keep track of when we last tried to download
cover art for an album and if we were successful. With this information,
we can avoid trying to download artwork for an album more than once a
week. Fixes BGO #535988. Should also fix issue with the cover art job
saying it's at 100% while it keeps going for many more minutes.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs
trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtService.cs
Modified: trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs Tue Jun 3 16:38:01 2008
@@ -3,6 +3,7 @@
//
// Authors:
// James Willcox <snorp novell com>
+// Gabriel Burt <gburt novell com>
//
// Copyright (C) 2005-2008 Novell, Inc.
//
@@ -31,17 +32,21 @@
using System.Data;
using System.IO;
using System.Threading;
+
using Mono.Unix;
+using Gtk;
+
+using Hyena;
+using Hyena.Data.Sqlite;
using Banshee.Base;
using Banshee.Collection;
+using Banshee.Collection.Database;
using Banshee.Collection.Gui;
using Banshee.Kernel;
using Banshee.Metadata;
using Banshee.ServiceStack;
using Banshee.Library;
-using Hyena;
-using Gtk;
namespace Banshee.CoverArt
{
@@ -50,6 +55,29 @@
private const int BatchSize = 10;
private DateTime last_scan = DateTime.MinValue;
+ private TimeSpan retry_every = TimeSpan.FromDays (7);
+
+ private static string query = @"
+ SELECT {0}
+ FROM CoreAlbums, CoreArtists, CoreTracks
+ WHERE
+ CoreAlbums.ArtistID = CoreArtists.ArtistID AND
+ CoreTracks.AlbumID = CoreAlbums.AlbumID AND
+ CoreTracks.DateUpdatedStamp > ? AND
+ CoreTracks.PrimarySourceID = ? AND
+ CoreTracks.AlbumID NOT IN (
+ SELECT AlbumID FROM CoverArtDownloads WHERE
+ LastAttempt > ? OR Downloaded = 1)
+ {1}";
+
+ private static HyenaSqliteCommand count_query = new HyenaSqliteCommand (String.Format (query,
+ "count(DISTINCT CoreAlbums.AlbumID)", null
+ ));
+
+ private static HyenaSqliteCommand select_query = new HyenaSqliteCommand (String.Format (query,
+ "DISTINCT CoreAlbums.AlbumID, CoreAlbums.Title, CoreArtists.Name",
+ "LIMIT ?"
+ ));
public CoverArtJob (DateTime lastScan) : base (Catalog.GetString ("Downloading Cover Art"))
{
@@ -62,87 +90,72 @@
Register ();
Scheduler.Schedule (this);
}
-
- private IDataReader RunQuery (int iteration, bool count)
+
+ private IDataReader RunQuery ()
{
- string query = String.Format (@"
- SELECT {0}, CoreAlbums.Title, CoreArtists.Name
- FROM CoreAlbums, CoreArtists, CoreTracks
- WHERE
- CoreAlbums.ArtistID = CoreArtists.ArtistID AND
- CoreTracks.AlbumID = CoreAlbums.AlbumID AND
- CoreTracks.DateUpdatedStamp > ? AND
- CoreTracks.PrimarySourceID = ?
- ORDER BY CoreAlbums.Title ASC
- LIMIT {1} OFFSET {2}
- ", count ? "count(DISTINCT CoreAlbums.AlbumID)" : "DISTINCT CoreAlbums.AlbumID",
- BatchSize, iteration * BatchSize);
-
- return ServiceManager.DbConnection.Query (query, last_scan,
- ServiceManager.SourceManager.MusicLibrary.DbId);
- }
-
- private void FetchForTrack (TrackInfo track)
- {
- try {
- IMetadataLookupJob job = MetadataService.Instance.CreateJob (track);
- job.Run ();
- } catch (Exception e) {
- Log.Exception (e);
- }
+ return ServiceManager.DbConnection.Query (select_query,
+ last_scan, ServiceManager.SourceManager.MusicLibrary.DbId, last_scan - retry_every, BatchSize
+ );
}
public void Run ()
{
- this.Status = Catalog.GetString ("Preparing...");
- this.IconNames = new string [] {Stock.Network};
-
- int current_track_count = 0;
- int total_track_count = 0;
- int offset = 0;
- using (IDataReader reader = RunQuery (offset, true)) {
- if (reader.Read ()) {
- total_track_count = reader.GetInt32 (0);
- }
- }
+ Status = Catalog.GetString ("Preparing...");
+ IconNames = new string [] {Stock.Network};
- if (total_track_count == 0) {
- Finish ();
- return;
- }
-
- TrackInfo track = new TrackInfo ();
+ int current = 0;
+ int total = 0;
+ DatabaseTrackInfo track = new DatabaseTrackInfo ();
while (true) {
- using (IDataReader reader = RunQuery (offset++, false)) {
- int batch_count = 0;
+ total = current + ServiceManager.DbConnection.Query<int> (count_query, last_scan, ServiceManager.SourceManager.MusicLibrary.DbId, last_scan - retry_every);
+ if (total == 0 || total <= current) {
+ break;
+ }
+
+ using (IDataReader reader = RunQuery ()) {
while (reader.Read ()) {
if (IsCancelRequested) {
Finish ();
return;
}
- batch_count++;
- if (!CoverArtSpec.CoverExists (reader.GetString (2),
- reader.GetString (1))) {
- track.AlbumTitle = reader.GetString (1);
- track.ArtistName = reader.GetString (2);
-
- Log.DebugFormat ("Downloading cover art for {0} - {1}", track.ArtistName, track.AlbumTitle);
- this.Progress = (double) current_track_count / (double) total_track_count;
- this.Status = String.Format (Catalog.GetString ("{0} - {1}"), track.ArtistName, track.AlbumTitle);
- FetchForTrack (track);
- }
-
- current_track_count++;
+ track.AlbumTitle = reader.GetString (1);
+ track.ArtistName = reader.GetString (2);
+ track.AlbumId = Convert.ToInt32 (reader[0]);
+
+ Log.DebugFormat ("Downloading cover art for {0} - {1}", track.ArtistName, track.AlbumTitle);
+
+ Progress = (double) current / (double) total;
+ Status = String.Format (Catalog.GetString ("{0} - {1}"), track.ArtistName, track.AlbumTitle);
+
+ FetchForTrack (track);
+ current++;
}
-
- if (batch_count != BatchSize)
- break;
}
}
Finish ();
}
+
+ private void FetchForTrack (DatabaseTrackInfo track)
+ {
+ 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 (Exception e) {
+ Log.Exception (e);
+ } finally {
+ 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);
+ }
+ }
}
}
Modified: trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtService.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtService.cs Tue Jun 3 16:38:01 2008
@@ -3,6 +3,7 @@
//
// Authors:
// James Willcox <snorp novell com>
+// Gabriel Burt <gburt novell com>
//
// Copyright (C) 2005-2008 Novell, Inc.
//
@@ -61,6 +62,15 @@
void IExtensionService.Initialize ()
{
+ if (!ServiceManager.DbConnection.TableExists ("CoverArtDownloads")) {
+ ServiceManager.DbConnection.Execute (@"
+ CREATE TABLE CoverArtDownloads (
+ AlbumID INTEGER UNIQUE,
+ Downloaded BOOLEAN,
+ LastAttempt INTEGER NOT NULL
+ )");
+ }
+
action_service = ServiceManager.Get<InterfaceActionService> ();
if (!ServiceStartup ()) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]