public async void run () {
try {
- var file = yield this.prepare_file ();
+ string urn;
- var urn = yield this.create_entry_in_store ();
+ if (this.item.uris.size == 0) {
+ var file = yield this.prepare_file ();
- var uris = new string[] { this.item.uris[0] };
- yield this.miner.ignore_next_update (uris);
- yield file.create_async (FileCreateFlags.NONE,
- Priority.DEFAULT,
- cancellable);
+ urn = yield this.create_entry_in_store ();
+
+ var uris = new string[] { this.item.uris[0] };
+ yield this.miner.ignore_next_update (uris);
+ yield file.create_async (FileCreateFlags.NONE,
+ Priority.DEFAULT,
+ cancellable);
+ } else {
+ urn = yield this.create_entry_in_store ();
+ }
this.item.id = this.container.create_child_id_for_urn (urn);
this.item.parent = this.container;
didl_item.upnp_class);
var resources = didl_item.get_resources ();
- if (resources != null) {
- var info = resources.nth (0).data.protocol_info;
+ if (resources != null && resources.length () > 0) {
+ var resource = resources.nth (0).data;
+ var info = resource.protocol_info;
if (info != null) {
if (info.dlna_profile != null) {
this.item.mime_type = info.mime_type;
}
}
+
+ if (this.is_valid_uri (resource.uri)) {
+ this.item.add_uri (resource.uri);
+ }
+
+ if (resource.size >= 0) {
+ this.item.size = resource.size;
+ }
}
if (item.mime_type == null) {
this.item.mime_type = this.get_generic_mime_type ();
}
- this.item.size = 0;
+ if (item.size < 0) {
+ this.item.size = 0;
+ }
yield container.add_item (this.item, this.cancellable);
this.item.serialize (didl_writer, this.content_dir.http_server);
upnp_class);
}
}
+
+ // FIXME: This function is hardly completely. Perhaps we should just make
+ // use of a regex here.
+ private bool is_valid_uri (string? uri) {
+ if (uri == null || uri == "") {
+ return false;
+ }
+
+ for (var next = uri.next_char ();
+ next != "";
+ next = next.next_char ()) {
+ if (next.get_char ().isspace ()) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
*
* return nothing.
*
- * This implementation is very basic: It only creates the file under the
- * first writable URI it can find for this container & sets the ID of the
- * item to that of the URI of the newly created item. If your subclass
- * doesn't ID the items by their original URIs, you definitely want to
- * override this method.
+ * This implementation is very basic: If no URI is provided for the item,
+ * it creates the file under the first writable URI it can find for this
+ * container. It also sets the ID of the item to that of the URI of the
+ * item. If your subclass doesn't ID the items by their original URIs, you
+ * definitely want to override this method.
*/
public async virtual void add_item (MediaItem item,
Cancellable? cancellable)
throws Error {
- var dir = yield this.get_writable (cancellable);
- if (dir == null) {
- throw new ContentDirectoryError.RESTRICTED_PARENT (
- _("Object creation in %s not allowed"),
- this.id);
+ if (item.uris.size == 0) {
+ var file = yield create_child (item.title, cancellable);
+ item.uris.add (file.get_uri ());
+ item.size = 0;
}
- var file = dir.get_child_for_display_name (item.title);
- yield file.create_async (FileCreateFlags.NONE,
- Priority.DEFAULT,
- cancellable);
- var uri = file.get_uri ();
- item.id = uri;
- item.size = 0;
- item.uris.add (uri);
+ item.id = item.uris[0];
}
/**
this.parent.container_updated (updated_container);
}
}
+
+ private async File create_child (string title, Cancellable? cancellable)
+ throws Error {
+ var dir = yield this.get_writable (cancellable);
+ if (dir == null) {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object creation in %s not allowed"),
+ this.id);
+ }
+
+ var file = dir.get_child_for_display_name (title);
+ yield file.create_async (FileCreateFlags.NONE,
+ Priority.DEFAULT,
+ cancellable);
+
+ return file;
+ }
}