banshee r4640 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Metadata src/Core/Banshee.Services/Banshee.Metadata.Embedded src/Core/Banshee.Services/Banshee.Metadata.FileSystem
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4640 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Metadata src/Core/Banshee.Services/Banshee.Metadata.Embedded src/Core/Banshee.Services/Banshee.Metadata.FileSystem
- Date: Wed, 1 Oct 2008 18:43:58 +0000 (UTC)
Author: gburt
Date: Wed Oct 1 18:43:58 2008
New Revision: 4640
URL: http://svn.gnome.org/viewvc/banshee?rev=4640&view=rev
Log:
2008-10-01 Gabriel Burt <gabriel burt gmail com>
* src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs: Factor
out the save-to-temp-file-then-move logic into a method, SaveAtomically,
that takes any input Stream and saves it to a file with that save
strategy.
* src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs:
If the file is already a JPG, save it directly as a JPG but using the new
SaveAtomically method. If it's not a JPG, save it with .cover extension
as before.
* src/Core/Banshee.Services/Banshee.Metadata.FileSystem/FileSystemQueryJob.cs:
Look for PNG and BMP files too (BGO #547841), and save as .cover if not
JPG, and use SaveAtomically method to avoid race. Also, increase to 30
the threshold number of files in a folder above which we don't take any
image from it.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.FileSystem/FileSystemQueryJob.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs Wed Oct 1 18:43:58 2008
@@ -116,11 +116,14 @@
if (picture == null || picture.Data == null || picture.Data.Count == 0) {
return false;
}
-
- Banshee.IO.StreamAssist.Save (new MemoryStream (picture.Data.Data),
- new FileStream (Path.ChangeExtension (image_path, "cover"),
- FileMode.Create, FileAccess.ReadWrite));
-
+
+ // Set the extension as .cover unless it's already a JPG
+ string extension = "cover";
+ if (picture.MimeType != null && (picture.MimeType.Contains ("jpeg") || picture.MimeType.Contains ("jpg"))) {
+ extension = "jpg";
+ }
+
+ SaveAtomically (Path.ChangeExtension (image_path, extension), new MemoryStream (picture.Data.Data));
return true;
}
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.FileSystem/FileSystemQueryJob.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.FileSystem/FileSystemQueryJob.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.FileSystem/FileSystemQueryJob.cs Wed Oct 1 18:43:58 2008
@@ -57,7 +57,7 @@
Fetch ();
}
- private static string [] extensions = new string [] { ".jpg", ".jpeg" };
+ private static string [] extensions = new string [] { ".jpg", ".jpeg", ".png", ".bmp" };
private static string [] filenames = new string [] { "cover", "folder", "front" };
protected void Fetch ()
@@ -74,7 +74,7 @@
string best_file = null;
int items_in_directory = 0;
bool found_definite_best = false;
- int max_acceptable_items = Math.Max (20, track.TrackCount + 8);
+ int max_acceptable_items = Math.Max (30, track.TrackCount + 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.
@@ -107,8 +107,14 @@
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
- Banshee.IO.File.Copy (new SafeUri (best_file), new SafeUri (CoverArtSpec.GetPath (Track.ArtworkId)), false);
+ SaveAtomically (Path.ChangeExtension (CoverArtSpec.GetPath (Track.ArtworkId), extension), Banshee.IO.File.OpenRead (new SafeUri (best_file)));
// Send the new StreamTag
StreamTag tag = new StreamTag ();
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs Wed Oct 1 18:43:58 2008
@@ -140,14 +140,8 @@
}
return false;
}
-
- // Save the file to a temporary path while downloading, so that nobody sees it
- // and thinks it's ready for use before it is
- string tmp_path = String.Format ("{0}.part", path);
- Banshee.IO.StreamAssist.Save (from_stream, new FileStream (tmp_path,
- FileMode.Create, FileAccess.ReadWrite));
-
- Banshee.IO.File.Move (new SafeUri (tmp_path), new SafeUri (path));
+
+ SaveAtomically (path, from_stream);
from_stream.Close ();
@@ -158,5 +152,27 @@
{
return SaveHttpStream (uri, CoverArtSpec.GetPath (albumArtistId), ignoreMimeTypes);
}
+
+ protected void SaveAtomically (string path, Stream from_stream)
+ {
+ if (String.IsNullOrEmpty (path) || from_stream == null || !from_stream.CanRead) {
+ return;
+ }
+
+ SafeUri path_uri = new SafeUri (path);
+ if (Banshee.IO.File.Exists (path_uri)) {
+ return;
+ }
+
+ // Save the file to a temporary path while downloading/copying,
+ // so that nobody sees it and thinks it's ready for use before it is
+ SafeUri tmp_uri = new SafeUri (String.Format ("{0}.part", path));
+ try {
+ Banshee.IO.StreamAssist.Save (from_stream, Banshee.IO.File.OpenWrite (tmp_uri, true));
+ Banshee.IO.File.Move (tmp_uri, path_uri);
+ } catch (Exception e) {
+ Hyena.Log.Exception (e);
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]