[rygel/wip/dvd-byteseek: 392/395] wip: Add byte size to XML for DVDs with just one title
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/dvd-byteseek: 392/395] wip: Add byte size to XML for DVDs with just one title
- Date: Wed, 22 Jan 2020 10:56:34 +0000 (UTC)
commit 7da2ca29dfe051359edbc98f5c3c7b52ec696603
Author: Jens Georg <mail jensge org>
Date: Sat Feb 13 18:39:45 2016 +0100
wip: Add byte size to XML for DVDs with just one title
.../rygel-media-export-dvd-parser.vala | 54 +++++++++++++++++-----
1 file changed, 43 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
index cd65f301..f5812db7 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
@@ -147,10 +147,8 @@ internal class Rygel.MediaExport.DVDParser : Extractor {
delete doc;
}
- public async Xml.Doc* get_information () throws Error {
+ public async void get_information () throws Error {
if (!this.cache_file.query_exists ()) {
- var launcher = new SubprocessLauncher (SubprocessFlags.STDERR_SILENCE);
- launcher.set_stdout_file_path (this.cache_file.get_path ());
string[] args = {
DVDParser.lsdvd_binary_path,
"-Ox",
@@ -161,8 +159,11 @@ internal class Rygel.MediaExport.DVDParser : Extractor {
null
};
- var process = launcher.spawnv (args);
- yield process.wait_async ();
+ var process = new Subprocess.newv (args, SubprocessFlags.STDOUT_PIPE);
+
+ string buffer;
+
+ yield process.communicate_utf8_async (null, null, out buffer, null);
if (!(process.get_if_exited () &&
process.get_exit_status () == 0)) {
@@ -173,15 +174,46 @@ internal class Rygel.MediaExport.DVDParser : Extractor {
}
throw new DVDParserError.GENERAL ("lsdvd did die or file is not a DVD");
}
- }
- yield this.query_length ();
-
- return Xml.Parser.read_file (this.cache_file.get_path (),
- null,
- Xml.ParserOption.NOERROR |
+ var doc = Xml.Parser.read_memory (buffer,
+ buffer.length,
+ null,
+ "UTF-8",
+ Xml.ParserOption.NOERROR |
Xml.ParserOption.NOWARNING |
Xml.ParserOption.NONET);
+ var context = new Xml.XPath.Context (doc);
+ var result = context.eval_expression ("/lsdvd/track");
+
+ if (result != null) {
+ if (result->type == Xml.XPath.ObjectType.NODESET &&
+ result->nodesetval->length () == 1) {
+ var node = result->nodesetval->item (0);
+ try {
+ var duration = yield this.query_length ();
+ var duration_node = doc->new_node (null,
+ "rygel:bytelength",
+ "%lld".printf (duration));
+ node->add_child (duration_node);
+ } catch (Error error) {
+ warning (_("Failed to query length from DVD: %s"),
+ error.message);
+ }
+ }
+
+ delete result;
+ }
+
+ doc->dump_memory_enc_format (out buffer, null, "UTF-8", true);
+ delete doc;
+
+ yield this.cache_file.replace_contents_async (buffer.data,
+ null,
+ false,
+ FileCreateFlags.NONE,
+ null,
+ null);
+ }
}
private async int64 query_length () throws Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]