From 0fb4dfdab30b7d9ba728fc4d7d35734cc8659812 Mon Sep 17 00:00:00 2001 From: joeshaw Date: Tue, 17 Oct 2006 18:58:12 +0000 Subject: [PATCH] Add a totem filter, from Bastien Nocera. Change the MPlayer filter so that it has a lower priority than the Totem one --- Filters/FilterMPlayerVideo.cs | 66 +++++++++-------- Filters/FilterTotem.cs | 163 ++++++++++++++++++++++++++++++++++++++++++ Filters/Makefile.am | 1 + 3 files changed, 201 insertions(+), 29 deletions(-) create mode 100644 Filters/FilterTotem.cs diff --git a/Filters/FilterMPlayerVideo.cs b/Filters/FilterMPlayerVideo.cs index 8dade96b..90f2491a 100644 --- a/Filters/FilterMPlayerVideo.cs +++ b/Filters/FilterMPlayerVideo.cs @@ -43,37 +43,45 @@ namespace Beagle.Filters { private int length_seconds = -1; private int audio_channels = 0; + private static string[] mime_types = { + "application/x-matroska", + "video/dl", + "video/dv", + "video/fli", + "video/gl", + "video/mpeg", + "video/mp4", + "video/quicktime", + "video/mp4v-es", + "video/parityfec", + "video/pointer", + "video/vnd.fvt", + "video/vnd.motorola.video", + "video/vnd.motorola.videop", + "video/vnd.mpegurl", + "video/vnd.mts", + "video/vnd.nokia.interleaved-multimedia", + "video/vnd.vivo", + "video/x-la-asf", + "video/x-mng", + "video/x-ms-asf", + "video/x-ms-wm", + "video/x-ms-wmv", + "video/x-ms-vmx", + "video/x-msvideo", + "video/x-ogm+ogg", + "video/x-sgi-movie" + }; + public FilterMPlayerVideo () { - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/x-matroska")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/dl")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/dv")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/fli")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/gl")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/mpeg")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/mp4")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/quicktime")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/mp4v-es")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/parityfec")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/pointer")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/vnd.fvt")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/vnd.motorola.video")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/vnd.motorola.videop")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/vnd.mpegurl")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/vnd.mts")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/vnd.nokia.interleaved-multimedia")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/vnd.vivo")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-la-asf")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-mng")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-ms-asf")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-ms-wm")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-ms-wmv")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-ms-wmx")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-ms-wvx")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-msvideo")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-ogm+ogg")); - AddSupportedFlavor (FilterFlavor.NewFromMimeType ("video/x-sgi-movie")); - + foreach (string s in mime_types) { + FilterFlavor flavor = FilterFlavor.NewFromMimeType (s); + flavor.Priority = -1; // Prefer Totem over this one + + AddSupportedFlavor (flavor); + } + PreLoad = false; } diff --git a/Filters/FilterTotem.cs b/Filters/FilterTotem.cs new file mode 100644 index 00000000..ef774b11 --- /dev/null +++ b/Filters/FilterTotem.cs @@ -0,0 +1,163 @@ +// +// FilterTotem.cs +// based on FilterMPlayerVideo.cs +// Copyright (C) 2006 Alexander Macdonald +// +// Copyright (C) 2006 Bastien Nocera + +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; +using System.Diagnostics; +using System.Globalization; + +using Beagle.Util; +using Beagle.Daemon; + +namespace Beagle.Filters { + + public class FilterTotem : Beagle.Daemon.Filter { + + public FilterTotem () + { + // Get the list of mime-types from the totem-video-indexer + + SafeProcess pc = new SafeProcess (); + pc.Arguments = new string [] { "totem-video-indexer", "--mimetype" }; + pc.RedirectStandardOutput = true; + pc.RedirectStandardError = true; + + try { + pc.Start (); + } catch (SafeProcessException e) { + Log.Warn (e.Message); + Error (); + return; + } + + StreamReader pout = new StreamReader (pc.StandardOutput); + string str; + + while ((str = pout.ReadLine ()) != null) { + AddSupportedFlavor (FilterFlavor.NewFromMimeType (str)); + } + + pout.Close (); + pc.Close (); + + PreLoad = false; + } + + protected override void DoPullProperties () + { + SafeProcess pc = new SafeProcess (); + pc.Arguments = new string [] { "totem-video-indexer", UriFu.UriToEscapedString (this.Uri) }; + pc.RedirectStandardOutput = true; + pc.RedirectStandardError = true; + + try { + pc.Start (); + } catch (SafeProcessException e) { + Log.Warn (e.Message); + Error (); + return; + } + + StreamReader pout = new StreamReader (pc.StandardOutput); + string str; + + while ((str = pout.ReadLine ()) != null) { + if (!str.StartsWith ("TOTEM_INFO_")) + continue; + + string[] tokens = str.Split ('='); + + if (tokens.Length != 2) + continue; + + switch (tokens [0]) { + case "": + break; + case "TOTEM_INFO_TITLE": + AddProperty (Beagle.Property.New ("dc:title", tokens [1])); + break; + case "TOTEM_INFO_ARTIST": + AddProperty (Beagle.Property.New ("fixme:artist", tokens [1])); + break; + case "TOTEM_INFO_YEAR": + AddProperty (Beagle.Property.New ("fixme:year", tokens [1])); + break; + case "TOTEM_INFO_ALBUM": + AddProperty (Beagle.Property.New ("fixme:album", tokens [1])); + break; + case "TOTEM_INFO_DURATION": + //FIXME dc:extent or fixme:duration??? + AddProperty (Beagle.Property.NewUnsearched ("dc:extent", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_TRACK_NUMBER": + AddProperty (Beagle.Property.NewUnsearched ("fixme:tracknumber", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_HAS_VIDEO": + break; + case "TOTEM_INFO_VIDEO_WIDTH": + AddProperty (Beagle.Property.NewUnsearched ("fixme:video:width", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_VIDEO_HEIGHT": + AddProperty (Beagle.Property.NewUnsearched ("fixme:video:height", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_VIDEO_CODEC": + AddProperty (Beagle.Property.NewKeyword ("fixme:video:codec", tokens [1])); + break; + case "TOTEM_INFO_FPS": + AddProperty (Beagle.Property.NewUnsearched ("fixme:video:fps", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_VIDEO_BITRATE": + AddProperty (Beagle.Property.NewUnsearched ("fixme:video:bitrate", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_HAS_AUDIO": + break; + case "TOTEM_INFO_AUDIO_BITRATE": + AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:bitrate", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_AUDIO_CODEC": + AddProperty (Beagle.Property.NewKeyword ("fixme:audio:codec", tokens [1])); + break; + case "TOTEM_INFO_AUDIO_SAMPLE_RATE": + AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:samplerate", Convert.ToInt32 (tokens [1]))); + break; + case "TOTEM_INFO_AUDIO_CHANNELS": + //FIXME this is very broken, needs fixing in Totem + break; + default: + // Mismatching version of Totem with more information, possibly + break; + } + } + + pout.Close (); + pc.Close (); + + Finished (); + } + } +} + diff --git a/Filters/Makefile.am b/Filters/Makefile.am index 7659abc8..37b96c16 100644 --- a/Filters/Makefile.am +++ b/Filters/Makefile.am @@ -60,6 +60,7 @@ CSFILES = \ $(srcdir)/FilterShellscript.cs \ $(srcdir)/FilterRuby.cs \ $(srcdir)/FilterMPlayerVideo.cs \ + $(srcdir)/FilterTotem.cs \ $(srcdir)/FilterBmp.cs \ $(srcdir)/FilterExternal.cs \ $(srcdir)/FilterEbuild.cs \ -- 2.11.4.GIT