2 * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
3 * Copyright (C) 2009,2010 Nokia Corporation.
5 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
6 * <zeeshan.ali@nokia.com>
8 * This file is part of Rygel.
10 * Rygel is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * Rygel is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 * Creates item for external plugins.
31 public class Rygel.External.ItemFactory {
32 public async MediaItem create (string id,
35 HashTable<string,Variant> props,
38 MediaContainer parent)
42 if (type.has_prefix ("audio")) {
43 item = new AudioItem (id, parent, title);
45 this.set_audio_metadata (item as AudioItem,
49 } else if (type.has_prefix ("music")) {
50 item = new MusicItem (id, parent, title);
52 yield this.set_music_metadata (item as MusicItem,
56 } else if (type.has_prefix ("video")) {
57 item = new VideoItem (id, parent, title);
59 yield this.set_video_metadata (item as VideoItem,
64 item = new ImageItem (id, parent, title);
66 yield this.set_visual_metadata (item as VisualItem,
72 this.set_generic_metadata (item, props, service_name, host_ip);
74 if (parent is DummyContainer) {
75 item.parent_ref = parent;
81 private async void set_music_metadata (
83 HashTable<string,Variant> props,
87 music.artist = this.get_string (props, "Artist");
88 music.album = this.get_string (props, "Album");
89 music.genre = this.get_string (props, "Genre");
91 var value = props.lookup ("AlbumArt");
93 var cover_factory = new AlbumArtFactory ();
95 music.album_art = yield cover_factory.create ((string) value,
100 this.set_audio_metadata (music, props, service_name, host_ip);
103 private void set_audio_metadata (AudioItem audio,
104 HashTable<string,Variant> props,
108 audio.duration = this.get_int (props, "Duration");
109 audio.bitrate = this.get_int (props, "Bitrate");
110 audio.sample_freq = this.get_int (props, "SampleRate");
111 audio.bits_per_sample = this.get_int (props, "BitsPerSample");
114 private async void set_visual_metadata (
116 HashTable<string,Variant> props,
120 visual.width = this.get_int (props, "Width");
121 visual.height = this.get_int (props, "Height");
122 visual.color_depth = this.get_int (props, "ColorDepth");
123 visual.pixel_width = this.get_int (props, "PixelWidth");
124 visual.pixel_height = this.get_int (props, "PixelHeight");
126 var value = props.lookup ("Thumbnail");
128 var factory = new ThumbnailFactory ();
129 var thumbnail = yield factory.create ((string) value,
132 visual.thumbnails.add (thumbnail);
136 private async void set_video_metadata (
138 HashTable<string,Variant> props,
142 yield this.set_visual_metadata (video, props, service_name, host_ip);
143 this.set_audio_metadata (video, props, service_name, host_ip);
146 private void set_generic_metadata (MediaItem item,
147 HashTable<string,Variant> props,
150 item.mime_type = this.get_string (props, "MIMEType");
152 var uris = (string[]) props.lookup ("URLs");
154 for (var i = 0; uris[i] != null; i++) {
155 item.add_uri (uris[i].replace ("@ADDRESS@", host_ip));
159 // Optional properties
161 item.dlna_profile = this.get_string (props, "DLNAProfile");
163 var value = props.lookup ("Size");
165 item.size = (int64) value;
168 item.date = this.get_string (props, "Date");
171 private string? get_string (HashTable<string,Variant> props, string prop) {
172 var value = props.lookup (prop);
175 return (string) value;
181 private int get_int (HashTable<string,Variant> props, string prop) {
182 var value = props.lookup (prop);