2
* Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
3
* Copyright (C) 2008 Nokia Corporation.
5
* Author: Zeeshan Ali <zeenix@gmail.com>
7
* This file is part of Rygel.
9
* Rygel is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* Rygel is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with this program; if not, write to the Free Software Foundation,
21
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
* Represents MediaExport item.
30
public class Rygel.MediaExportItem : Rygel.MediaItem {
31
public MediaExportItem (MediaContainer parent,
34
string content_type = info.get_content_type ();
35
string item_class = null;
36
string id = Checksum.compute_for_string (ChecksumType.MD5,
39
// use heuristics based on content type; will use MediaHarvester
42
if (content_type.has_prefix ("video/")) {
43
item_class = MediaItem.VIDEO_CLASS;
44
} else if (content_type.has_prefix ("audio/")) {
45
item_class = MediaItem.AUDIO_CLASS;
46
} else if (content_type.has_prefix ("image/")) {
47
item_class = MediaItem.IMAGE_CLASS;
50
if (item_class == null) {
51
item_class = MediaItem.AUDIO_CLASS;
52
warning ("Failed to detect UPnP class for '%s', assuming it's '%s'",
53
file.get_uri (), item_class);
56
base (id, parent, info.get_name (), item_class);
58
this.mime_type = content_type;
59
this.add_uri (file.get_uri (), null);
62
private void fill_from_tags_as_image (Gst.TagList tag_list) {
64
tag_list.get_string (MetadataExtractor.TAG_RYGEL_MIME, out this.mime_type);
66
tag_list.get_int64 (MetadataExtractor.TAG_RYGEL_SIZE, out size);
67
this.size = (long) size;
68
tag_list.get_int (MetadataExtractor.TAG_RYGEL_WIDTH, out this.width);
69
tag_list.get_int (MetadataExtractor.TAG_RYGEL_HEIGHT, out this.height);
70
tag_list.get_int (MetadataExtractor.TAG_RYGEL_DEPTH, out this.color_depth);
73
private void fill_from_tags_as_audio (Gst.TagList tag_list) {
75
tag_list.get_int64 (MetadataExtractor.TAG_RYGEL_DURATION, out duration);
76
this.duration = (long) (duration / 1000000000);
78
tag_list.get_int (MetadataExtractor.TAG_RYGEL_CHANNELS, out this.n_audio_channels);
79
tag_list.get_string (MetadataExtractor.TAG_RYGEL_MIME, out this.mime_type);
82
tag_list.get_int64 (MetadataExtractor.TAG_RYGEL_SIZE, out size);
83
this.size = (long) size;
85
tag_list.get_string (TAG_ARTIST, out this.author);
86
tag_list.get_string (TAG_ALBUM, out this.album);
89
tag_list.get_uint (TAG_TRACK_NUMBER, out tmp);
90
this.track_number = (int)tmp;
91
tag_list.get_uint (TAG_BITRATE, out tmp);
92
this.bitrate = (int)tmp / 8;
93
tag_list.get_int (MetadataExtractor.TAG_RYGEL_RATE, out this.sample_freq);
96
if (tag_list.get_date (TAG_DATE, out date)) {
97
char[] datestr = new char[30];
98
date.strftime(datestr, "%F");
99
this.date = (string)datestr;
103
private void fill_from_tags_as_video (Gst.TagList tag_list) {
104
tag_list.get_string (MetadataExtractor.TAG_RYGEL_MIME,
107
tag_list.get_int64 (MetadataExtractor.TAG_RYGEL_SIZE,
109
this.size = (long) size;
110
tag_list.get_int (MetadataExtractor.TAG_RYGEL_WIDTH,
112
tag_list.get_int (MetadataExtractor.TAG_RYGEL_HEIGHT,
114
tag_list.get_int (MetadataExtractor.TAG_RYGEL_DEPTH,
115
out this.color_depth);
116
tag_list.get_int (MetadataExtractor.TAG_RYGEL_CHANNELS,
117
out this.n_audio_channels);
118
tag_list.get_int (MetadataExtractor.TAG_RYGEL_RATE,
119
out this.sample_freq);
122
public static MediaItem? create_from_taglist (MediaContainer parent,
124
Gst.TagList tag_list) {
125
string id = Checksum.compute_for_string (ChecksumType.MD5,
129
string class_guessed = null;
131
if (tag_list != null) {
134
if (!tag_list.get_string (TAG_VIDEO_CODEC, out codec)) {
135
if (!tag_list.get_string (TAG_AUDIO_CODEC, out codec)) {
136
if (tag_list.get_int (MetadataExtractor.TAG_RYGEL_WIDTH, out width) ||
137
tag_list.get_int (MetadataExtractor.TAG_RYGEL_HEIGHT, out height)) {
138
class_guessed = MediaItem.IMAGE_CLASS;
140
warning("There's no codec inside and file is no image: " +
141
"%s", file.get_uri ());
145
class_guessed = MediaItem.AUDIO_CLASS;
148
class_guessed = MediaItem.VIDEO_CLASS;
151
// throw error. Taglist can't be empty
152
warning("Got empty taglist for file %s", file.get_uri ());
156
return new MediaExportItem.from_taglist (parent,
163
private MediaExportItem.from_taglist (MediaContainer parent,
166
Gst.TagList tag_list,
169
if (upnp_class == MediaItem.AUDIO_CLASS ||
170
upnp_class == MediaItem.MUSIC_CLASS) {
172
if (!tag_list.get_string (TAG_TITLE, out title)) {
173
title = file.get_basename ();
177
title = file.get_basename ();
179
base (id, parent, title, upnp_class);
180
switch (upnp_class) {
181
case MediaItem.AUDIO_CLASS:
182
case MediaItem.MUSIC_CLASS:
183
fill_from_tags_as_audio (tag_list);
185
case MediaItem.VIDEO_CLASS:
186
fill_from_tags_as_video (tag_list);
188
case MediaItem.IMAGE_CLASS:
189
fill_from_tags_as_image (tag_list);
196
tag_list.get_uint64 (MetadataExtractor.TAG_RYGEL_MTIME,
199
this.modified = (int64) mtime;
201
this.add_uri (file.get_uri (), null);