Change the GC.GetTotalMemory() threshold to 10%; otherwise there are just too many...
[beagle.git] / Filters / FilterTotem.cs
blobf516328c5c09b3e202f0f1b2a846db0ffa90a0fb
1 //
2 // FilterTotem.cs
3 // based on FilterMPlayerVideo.cs
4 // Copyright (C) 2006 Alexander Macdonald <alex@alexmac.cc>
5 //
6 // Copyright (C) 2006 Bastien Nocera <hadess@hadess.net>
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.IO;
30 using System.Diagnostics;
31 using System.Globalization;
33 using Beagle.Util;
34 using Beagle.Daemon;
36 namespace Beagle.Filters {
38 public class FilterTotem : Beagle.Daemon.Filter {
40 static bool Debug = false;
42 public FilterTotem ()
44 // Get the list of mime-types from the totem-video-indexer
46 SafeProcess pc = new SafeProcess ();
47 pc.Arguments = new string [] { "totem-video-indexer", "--mimetype" };
48 pc.RedirectStandardOutput = true;
49 pc.RedirectStandardError = true;
51 try {
52 pc.Start ();
53 } catch (SafeProcessException e) {
54 if (Debug)
55 Log.Debug (e.Message);
57 return;
60 StreamReader pout = new StreamReader (pc.StandardOutput);
61 string str;
63 while ((str = pout.ReadLine ()) != null) {
64 AddSupportedFlavor (FilterFlavor.NewFromMimeType (str));
66 if (Debug)
67 Log.Debug ("Added {0} as a supported mime type for Totem video filter", str);
70 pout.Close ();
71 pc.Close ();
73 PreLoad = false;
76 protected override void DoPullProperties ()
78 SafeProcess pc = new SafeProcess ();
79 pc.Arguments = new string [] { "totem-video-indexer", UriFu.UriToEscapedString (this.Uri) };
80 pc.RedirectStandardOutput = true;
81 pc.RedirectStandardError = true;
83 try {
84 pc.Start ();
85 } catch (SafeProcessException e) {
86 Log.Warn (e.Message);
87 Error ();
88 return;
91 StreamReader pout = new StreamReader (pc.StandardOutput);
92 string str;
94 while ((str = pout.ReadLine ()) != null) {
95 if (!str.StartsWith ("TOTEM_INFO_"))
96 continue;
98 string[] tokens = str.Split ('=');
100 if (tokens.Length != 2)
101 continue;
103 switch (tokens [0]) {
104 case "":
105 break;
106 case "TOTEM_INFO_TITLE":
107 AddProperty (Beagle.Property.New ("dc:title", tokens [1]));
108 break;
109 case "TOTEM_INFO_ARTIST":
110 AddProperty (Beagle.Property.New ("fixme:artist", tokens [1]));
111 break;
112 case "TOTEM_INFO_YEAR":
113 AddProperty (Beagle.Property.New ("fixme:year", tokens [1]));
114 break;
115 case "TOTEM_INFO_ALBUM":
116 AddProperty (Beagle.Property.New ("fixme:album", tokens [1]));
117 break;
118 case "TOTEM_INFO_DURATION":
119 //FIXME dc:extent or fixme:duration???
120 AddProperty (Beagle.Property.NewUnsearched ("dc:extent", Convert.ToInt32 (tokens [1])));
121 break;
122 case "TOTEM_INFO_TRACK_NUMBER":
123 AddProperty (Beagle.Property.NewUnsearched ("fixme:tracknumber", Convert.ToInt32 (tokens [1])));
124 break;
125 case "TOTEM_INFO_HAS_VIDEO":
126 break;
127 case "TOTEM_INFO_VIDEO_WIDTH":
128 AddProperty (Beagle.Property.NewUnsearched ("fixme:video:width", Convert.ToInt32 (tokens [1])));
129 break;
130 case "TOTEM_INFO_VIDEO_HEIGHT":
131 AddProperty (Beagle.Property.NewUnsearched ("fixme:video:height", Convert.ToInt32 (tokens [1])));
132 break;
133 case "TOTEM_INFO_VIDEO_CODEC":
134 AddProperty (Beagle.Property.NewKeyword ("fixme:video:codec", tokens [1]));
135 break;
136 case "TOTEM_INFO_FPS":
137 AddProperty (Beagle.Property.NewUnsearched ("fixme:video:fps", Convert.ToInt32 (tokens [1])));
138 break;
139 case "TOTEM_INFO_VIDEO_BITRATE":
140 AddProperty (Beagle.Property.NewUnsearched ("fixme:video:bitrate", Convert.ToInt32 (tokens [1])));
141 break;
142 case "TOTEM_INFO_HAS_AUDIO":
143 break;
144 case "TOTEM_INFO_AUDIO_BITRATE":
145 AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:bitrate", Convert.ToInt32 (tokens [1])));
146 break;
147 case "TOTEM_INFO_AUDIO_CODEC":
148 AddProperty (Beagle.Property.NewKeyword ("fixme:audio:codec", tokens [1]));
149 break;
150 case "TOTEM_INFO_AUDIO_SAMPLE_RATE":
151 AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:samplerate", Convert.ToInt32 (tokens [1])));
152 break;
153 case "TOTEM_INFO_AUDIO_CHANNELS":
154 //FIXME this is very broken, needs fixing in Totem
155 break;
156 default:
157 // Mismatching version of Totem with more information, possibly
158 break;
162 pout.Close ();
163 pc.Close ();
165 Finished ();