[rygel/wip/739692: 4/7] server, media-export: Extract media art for videos
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/739692: 4/7] server, media-export: Extract media art for videos
- Date: Tue, 11 Nov 2014 21:25:29 +0000 (UTC)
commit b0a112a97ff2092ee64038cb7ceea951bd971ac9
Author: Jens Georg <mail jensge org>
Date: Tue Nov 11 09:16:40 2014 +0100
server,media-export: Extract media art for videos
Either use embedded art for files that support it (OGG, MP4,…) or by
using the same heuristics as for music.
Signed-off-by: Jens Georg <mail jensge org>
src/librygel-server/rygel-media-art-store.vala | 50 +++++++++++++++++---
.../rygel-media-export-item-factory.vala | 19 ++++++-
2 files changed, 59 insertions(+), 10 deletions(-)
---
diff --git a/src/librygel-server/rygel-media-art-store.vala b/src/librygel-server/rygel-media-art-store.vala
index b022716..b469881 100644
--- a/src/librygel-server/rygel-media-art-store.vala
+++ b/src/librygel-server/rygel-media-art-store.vala
@@ -88,19 +88,26 @@ public class Rygel.MediaArtStore : GLib.Object {
return thumb;
}
- public void add (MusicItem item, File file, uint8[] data, string mime) {
+ public void add (MediaItem item, File file, uint8[] data, string mime) {
if (this.media_art_process == null) {
return;
}
+ MediaArt.Type type;
+ string title;
+ if (!this.get_type_and_title (item, out type, out title)) {
+ return;
+ }
+
try {
- this.media_art_process.buffer (MediaArt.Type.ALBUM,
+ // Setting artist to " " is a work-around for bgo#739942
+ this.media_art_process.buffer (type,
MediaArt.ProcessFlags.NONE,
file,
data,
mime,
- item.artist,
- item.album);
+ item.artist ?? " ",
+ title);
} catch (Error error) {
warning (_("Failed to add album art for %s: %s"),
file.get_uri (),
@@ -108,13 +115,23 @@ public class Rygel.MediaArtStore : GLib.Object {
}
}
- public void search_media_art_for_file (MusicItem item, File file) {
+ public void search_media_art_for_file (MediaItem item, File file) {
+ if (this.media_art_process == null) {
+ return;
+ }
+
+ MediaArt.Type type;
+ string title;
+ if (!this.get_type_and_title (item, out type, out title)) {
+ return;
+ }
+
try {
- this.media_art_process.file (MediaArt.Type.ALBUM,
+ this.media_art_process.file (type,
MediaArt.ProcessFlags.NONE,
file,
item.artist,
- item.album);
+ title);
} catch (Error error) {
warning (_("Failed to find media art for %s: %s"),
file.get_uri (),
@@ -122,6 +139,25 @@ public class Rygel.MediaArtStore : GLib.Object {
}
}
+ private bool get_type_and_title (MediaItem item,
+ out MediaArt.Type type,
+ out string title) {
+ type = MediaArt.Type.NONE;
+ title = null;
+
+ if (item is MusicItem) {
+ type = MediaArt.Type.ALBUM;
+ title = (item as MusicItem).album;
+ } else if (item is VideoItem) {
+ type = MediaArt.Type.VIDEO;
+ title = item.title;
+ } else {
+ return false;
+ }
+
+ return true;
+ }
+
private MediaArtStore () throws MediaArtStoreError {
try {
this.media_art_process = new MediaArt.Process ();
diff --git a/src/plugins/media-export/rygel-media-export-item-factory.vala
b/src/plugins/media-export/rygel-media-export-item-factory.vala
index a04b455..d6df025 100644
--- a/src/plugins/media-export/rygel-media-export-item-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-item-factory.vala
@@ -211,6 +211,8 @@ namespace Rygel.MediaExport.ItemFactory {
var color_depth = (int) video_info.get_depth ();
item.color_depth = (color_depth == 0) ? -1 : color_depth;
+ extract_media_art (item, file, audio_info.get_tags ());
+
return item;
}
@@ -268,6 +270,17 @@ namespace Rygel.MediaExport.ItemFactory {
tags.get_uint (Tags.TRACK_NUMBER, out tmp);
item.track_number = (int) tmp;
+ extract_media_art (item, file, tags);
+
+ return item;
+ }
+
+ static void extract_media_art (MediaItem item,
+ File file,
+ Gst.TagList? tags) {
+ if (tags == null) {
+ return;
+ }
var store = MediaArtStore.get_default ();
@@ -277,10 +290,12 @@ namespace Rygel.MediaExport.ItemFactory {
tags.get_sample (Tags.PREVIEW_IMAGE, out sample);
}
+ // Nothing embedded. Do some media art guessing using files located
+ // next to our media file.
if (sample == null) {
store.search_media_art_for_file (item, file);
- return item;
+ return;
}
unowned Structure structure = sample.get_caps ().get_structure (0);
@@ -305,8 +320,6 @@ namespace Rygel.MediaExport.ItemFactory {
default:
break;
}
-
- return item;
}
private static void fill_media_item (MediaItem item,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]