Exemple #1
0
        protected override void DoClose()
        {
            if (reader != null)
            {
                reader.Close();
            }

            if (bib_process != null)
            {
                bib_process.Close();
            }
        }
Exemple #2
0
        static FilterBibTex()
        {
            // Check if bibparse is present
            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string [] { "bibparse" };
            pc.RedirectStandardOutput = false;
            pc.RedirectStandardError  = false;

            try {
                pc.Start();
                bibparse_installed = true;
            } catch (SafeProcessException) {
                Log.Warn("bibparse is not found; bibtex files will not be indexed");
                bibparse_installed = false;
            }

            pc.Close();
        }
        protected override void RegisterSupportedTypes()
        {
            // 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;
            pc.UseLangC = true;

            try {
                pc.Start();
            } catch (SafeProcessException e) {
                if (Debug)
                {
                    Log.Debug(e.Message);
                }

                return;
            }

            StreamReader pout = new StreamReader(pc.StandardOutput);
            string       str;

            while ((str = pout.ReadLine()) != null)
            {
                FilterFlavor flavor = FilterFlavor.NewFromMimeType(str);
                flavor.Priority = Priority;

                AddSupportedFlavor(flavor);

                if (Debug)
                {
                    Log.Debug("Added {0} as a supported mime type for Totem video filter", str);
                }
            }

            pout.Close();
            pc.Close();
        }
Exemple #4
0
        override protected void DoClose()
        {
            if (!pull_started)
            {
                return;
            }

            pout.Close();
#if false
            // FIXME: See FIXME above.
            pout = new StreamReader(pc.StandardError);

            string str;
            while ((str = pout.ReadLine()) != null)
            {
                Log.Warn("pdftotext [{0}]: {1}", Uri, str);
            }

            pout.Close();
#endif
            pc.Close();
        }
Exemple #5
0
        override protected void DoPull()
        {
            // create new external process
            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string [] { "ssindex", "-i", FileInfo.FullName };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            // Let ssindex run for 10 seconds, max.
            pc.CpuLimit = 10;

            try {
                pc.Start();
            } catch (SafeProcessException e) {
                Log.Warn(e.Message);
                Error();
                return;
            }

            // process ssindex output
            StreamReader pout = new StreamReader(pc.StandardOutput);

            xmlReader = new XmlTextReader(pout);

            try {
                WalkContentNodes(xmlReader);
            } catch (Exception e) {
                Logger.Log.Debug("Exception occurred while indexing {0}.", FileInfo.FullName);
                Logger.Log.Debug(e);
            }

            pout.Close();
            pc.Close();

            Finished();
        }
Exemple #6
0
        override protected void DoClose()
        {
            base.DoClose();

            if (!pull_started)
            {
                return;
            }

            pout.Close();

            pout = new StreamReader(pc.StandardError);

            string line;

            while ((line = pout.ReadLine()) != null)
            {
                Log.Warn("doc extractor [{0}]: {1}", Indexable.Uri, line);
            }

            pout.Close();
            pc.Close();
        }
Exemple #7
0
        protected override bool PullPackageProperties()
        {
            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string [] { "rpm", "-qp", "--queryformat", property_queryformat, FileInfo.FullName };
            pc.RedirectStandardOutput = true;
            pc.UseLangC = true;

            // Let rpm run for 15 seconds for properties, max.
            pc.CpuLimit = 15;

            try {
                pc.Start();
            } catch (SafeProcessException e) {
                Log.Warn(e.Message);
                return(false);
            }

            StreamReader pout = new StreamReader(pc.StandardOutput);

            // Order is dependent on the queryformat string
            PackageName    = ReadString(pout);
            PackageVersion = ReadString(pout);
            Summary        = ReadString(pout);
            Category       = ReadString(pout);
            License        = ReadString(pout);
            Packager       = ReadString(pout);
            Homepage       = ReadString(pout);
            string size = ReadString(pout);

            Size = Convert.ToInt64(size);

            pout.Close();
            pc.Close();

            return(true);
        }
Exemple #8
0
        protected override void DoPull()
        {
            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string [] { "rpm", "-qp", "--queryformat", text_queryformat, FileInfo.FullName };
            pc.RedirectStandardOutput = true;

            // Let rpm run for 90 seconds for text, max.
            pc.CpuLimit = 90;

            try {
                pc.Start();
            } catch (SafeProcessException e) {
                Log.Warn(e.Message);
                Error();
                return;
            }

            StreamReader pout = new StreamReader(pc.StandardOutput);

            string s;

            while ((s = pout.ReadLine()) != null)
            {
                if (s == "(none)")
                {
                    continue;
                }
                AppendWord(s);
            }

            pout.Close();
            pc.Close();

            Finished();
        }
        protected override void DoPull()
        {
            ExternalFilterInfo efi = GetFilterInfo(this.Extension, this.MimeType);

            if (efi == null)
            {
                Logger.Log.Warn("Unable to find a match for extension {0}, mime type {1} when one should have matched", this.Extension, this.MimeType);
                Error();
            }

            // FIXME: Need to deal with quotation marks in the XML file, probably.
            string[] tmp_argv = efi.Arguments.Split(' ');
            string[] argv     = new string [tmp_argv.Length + 1];

            argv [0] = efi.Command;

            int j = 1;

            for (int i = 0; i < tmp_argv.Length; i++)
            {
                if (tmp_argv [i] == String.Empty)
                {
                    continue;
                }

                if (tmp_argv [i] == "%s")
                {
                    argv [j] = FileInfo.FullName;
                }
                else
                {
                    argv [j] = tmp_argv [i];
                }
                j++;
            }

            SafeProcess pc = new SafeProcess();

            pc.Arguments = argv;
            pc.RedirectStandardOutput = true;
            pc.UseLangC = true;

            // Let the external filter run for 2 minutes, max.
            pc.CpuLimit = 120;

            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)
            {
                AppendText(str);
                AppendStructuralBreak();
            }

            pout.Close();
            pc.Close();
            Finished();
        }
Exemple #10
0
        public void DoQuery(Query query, IQueryResult result, IQueryableChangeData data)
        {
            string search = null;

            foreach (QueryPart qp in query.Parts)
            {
                if (qp is QueryPart_Text)
                {
                    search = ((QueryPart_Text)qp).Text;
                    break;
                }
            }

            if (String.IsNullOrEmpty(search))
            {
                return;
            }

            SafeProcess pc = new SafeProcess();

            // Double the max-hits since it is hard to tell locate to ignore
            // hidden files and directories; so we prune them later.
            // So if hidden files are returned first, you are doomed
            pc.Arguments = new string[] { "locate", "-P", "-e", "-l", (2 * query.MaxHits).ToString(), search };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            try {
                pc.Start();
            } catch (Beagle.Util.SafeProcessException e) {
                Log.Error(e, "Error while running 'locate -P -e -l {0} {1}'", (2 * query.MaxHits), search);
                return;
            }

            string    match           = null;
            ArrayList result_batch    = new ArrayList();
            const int MAX_QUEUED_HITS = 25;
            Hit       hit;
            int       count = 0;

            using (StreamReader pout = new StreamReader(pc.StandardOutput)) {
                while (count < query.MaxHits && !pout.EndOfStream)
                {
                    match = pout.ReadLine();
                    hit   = PathToHit(match);
                    if (hit == null)
                    {
                        continue;
                    }

                    result_batch.Add(hit);

                    if (result_batch.Count >= MAX_QUEUED_HITS)
                    {
                        result.Add(result_batch);
                        result_batch.Clear();
                    }
                    count++;
                }
            }

            result.Add(result_batch, count);

            pc.Close();
        }
Exemple #11
0
        protected override void DoPullProperties()
        {
            if (FileInfo == null)
            {
                Log.Error("FilterTotem: Unable to extract properties for non-file data");
                Error();
                return;
            }

            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string [] { "totem-video-indexer", FileInfo.FullName };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = true;

            // Let totem run for 10 seconds, max.
            pc.CpuLimit = 10;

            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();
        }
        protected override void DoPullProperties()
        {
            if (FileInfo == null)
            {
                Log.Error("FilterMPlayerVideo: Unable to extract properties for non-file data");
                Error();
                return;
            }

            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string [] { "mplayer", "-vo", "null", "-ao", "null", "-frames", "0", "-identify", FileInfo.FullName };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = true;
            pc.UseLangC = true;

            // Let mplayer run for 10 seconds, max.
            pc.CpuLimit = 10;

            // There have been reports of mplayer eating tons of
            // memory.  So limit it to 100 megs too.
            pc.MemLimit = 100 * 1024 * 1024;

            try {
                pc.Start();
            } catch (SafeProcessException e) {
                Log.Warn(e.Message);
                Error();
                return;
            }

            StreamReader pout = new StreamReader(pc.StandardOutput);
            string       str;
            string       name = String.Empty;

            while ((str = pout.ReadLine()) != null)
            {
                if (!str.StartsWith("ID_"))
                {
                    continue;
                }

                string[] tokens = str.Split('=');

                if (tokens.Length != 2)
                {
                    continue;
                }

                if (str.StartsWith("ID_CLIP_INFO_NAME"))
                {
                    name = tokens [1].ToLower();
                }
                else if (str.StartsWith("ID_CLIP_INFO_VALUE"))
                {
                    switch (name)
                    {
                    case "":
                        break;

                    case "name":
                        AddProperty(Beagle.Property.New("dc:title", tokens [1]));
                        break;

                    case "language":
                        AddProperty(Beagle.Property.NewUnsearched("dc:language", tokens [1]));
                        break;

                    case "copyright":
                        AddProperty(Beagle.Property.NewUnsearched("dc:copyright", tokens [1]));
                        break;

                    case "comments":
                        AddProperty(Beagle.Property.New("dc:description", tokens [1]));
                        break;

                    default:
                        AddProperty(Beagle.Property.NewUnsearched("fixme:info:" + name, tokens [1]));
                        break;
                    }
                }
                else
                {
                    switch (tokens [0])
                    {
                    case "ID_VIDEO_WIDTH":
                        width = Convert.ToInt32(tokens [1]);
                        break;

                    case "ID_VIDEO_HEIGHT":
                        height = Convert.ToInt32(tokens [1]);
                        break;

                    case "ID_VIDEO_ASPECT":
                        aspect = Convert.ToSingle(tokens [1], CultureInfo.InvariantCulture);
                        break;

                    case "ID_VIDEO_FPS":
                        fps = Convert.ToSingle(tokens [1], CultureInfo.InvariantCulture);
                        break;

                    case "ID_VIDEO_FORMAT":
                        AddProperty(Beagle.Property.NewKeyword("fixme:video:codec", tokens [1]));
                        break;

                    case "ID_LENGTH":
                        length_seconds = (int)Convert.ToSingle(tokens [1], CultureInfo.InvariantCulture);
                        break;

                    case "ID_AUDIO_NCH":
                        audio_channels = Convert.ToInt32(tokens [1]);
                        break;

                    case "ID_AUDIO_CODEC":
                        AddProperty(Beagle.Property.NewKeyword("fixme:audio:codec", tokens [1]));
                        break;

                    case "ID_DEMUXER":
                        AddProperty(Beagle.Property.NewUnsearched("fixme:video:container", tokens [1]));
                        break;
                    }
                }
            }

            pout.Close();
            pc.Close();

            // If an aspect ratio wasn't set in the file then work out the
            // pixel aspect ratio
            if (aspect <= 0.0f)
            {
                if (width > 0 && height > 0)
                {
                    aspect = (float)width / (float)height;
                }
            }

            if (aspect > 0.0f)
            {
                AddProperty(Beagle.Property.NewUnsearched("fixme:video:aspect", aspect));
            }

            AddProperty(Beagle.Property.NewUnsearched("fixme:video:aspect", AspectString(aspect)));

            if (width > 0)
            {
                AddProperty(Beagle.Property.NewUnsearched("fixme:video:width", width));
            }

            if (height > 0)
            {
                AddProperty(Beagle.Property.NewUnsearched("fixme:video:height", height));
            }

            if (fps > 0.0f)
            {
                AddProperty(Beagle.Property.NewUnsearched("fixme:video:fps", fps));
            }

            if (length_seconds > 0)
            {
                AddProperty(Beagle.Property.NewUnsearched("dc:extent", length_seconds));
            }

            switch (audio_channels)
            {
            case 0:
                AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channel_setup", "none"));
                break;

            case 1:
                AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channel_setup", "mono"));
                break;

            case 2:
                AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channel_setup", "stereo"));
                break;

            case 5:
                AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channel_setup", "4.1"));
                break;

            case 6:
                AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channel_setup", "5.1"));
                break;

            case 7:
                AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channel_setup", "6.1"));
                break;

            case 8:
                AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channel_setup", "7.1"));
                break;
            }

            AddProperty(Beagle.Property.NewUnsearched("fixme:audio:channels", audio_channels));

            Finished();
        }
Exemple #13
0
        protected override void DoPullProperties()
        {
            // create new external process
            pc           = new SafeProcess();
            pc.Arguments = new string [] { "pdfinfo", "-meta", FileInfo.FullName };
            pc.RedirectStandardOutput = true;
            // See FIXME below for why this is false.
            pc.RedirectStandardError = false;

            // Let pdfinfo run for at most 10 CPU seconds, and not
            // use more than 100 megs memory.
            pc.CpuLimit = 90;
            pc.MemLimit = 100 * 1024 * 1024;
            pc.UseLangC = true;

            try {
                pc.Start();
            } catch (SafeProcessException e) {
                Log.Warn(e.Message);
                Error();
                return;
            }

            // add pdfinfo's output to pool
            pout = new StreamReader(pc.StandardOutput);
            string str        = null;
            int    idx        = -1;
            string strMetaTag = null;
            bool   bKeyword   = false;
            string prop       = null;
            string val        = null;

            while ((str = pout.ReadLine()) != null)
            {
                bKeyword   = false;
                strMetaTag = null;
                idx        = str.IndexOf(':');
                if (idx > 0)
                {
                    prop = str.Substring(0, idx);
                    val  = str.Substring(idx + 1);
                    switch (prop)
                    {
                    case "Title":
                        strMetaTag = "dc:title";
                        break;

                    case "Author":
                        strMetaTag = "dc:author";
                        break;

                    case "Pages":
                        strMetaTag = "fixme:page-count";
                        bKeyword   = true;
                        break;

                    case "Creator":
                        strMetaTag = "dc:creator";
                        break;

                    case "Keywords":
                        strMetaTag = "dc:keyword";
                        break;

                    case "Producer":
                        strMetaTag = "dc:appname";
                        break;

                    case "Metadata":
                        string  xmpString = pout.ReadToEnd();
                        XmpFile xmp       = new XmpFile(new MemoryStream(System.Text.Encoding.ASCII.GetBytes(xmpString)));
                        AddXmpProperties(xmp);
                        break;
                    }
                    if (strMetaTag != null)
                    {
                        if (bKeyword)
                        {
                            AddProperty(Beagle.Property.NewUnsearched(strMetaTag,
                                                                      val.Trim()));
                        }
                        else
                        {
                            AddProperty(Beagle.Property.New(strMetaTag,
                                                            val.Trim()));
                        }
                    }
                }
            }
            pout.Close();

#if false
            // Log any errors or warnings from stderr
            pout = new StreamReader(pc.StandardError);
            while ((str = pout.ReadLine()) != null)
            {
                Log.Warn("pdfinfo [{0}]: {1}", Indexable.Uri, str);
            }

            pout.Close();
#endif
            pc.Close();
        }
Exemple #14
0
        protected override bool PullPackageProperties()
        {
            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string [] { "dpkg-deb", "-I", FileInfo.FullName };
            pc.RedirectStandardOutput = true;
            pc.UseLangC = true;

            try {
                pc.Start();
            } catch (SafeProcessException e) {
                Log.Warn(e.Message);
                return(false);
            }

            StreamReader pout = new StreamReader(pc.StandardOutput);

            string str = null;

            string[] tokens = null;
            char[]   splits = { ',', '|' };
            string[] list   = null;

            while ((str = pout.ReadLine()) != null)
            {
                tokens = str.Split(':');
                if (tokens.Length <= 1)
                {
                    continue;
                }

                switch (tokens[0].Trim())
                {
                case "Package":
                    PackageName = tokens [1];
                    break;

                case "Maintainer":
                    Packager = tokens [1];
                    break;

                case "Version":
                    PackageVersion = tokens [1];
                    break;

                case "Section":
                    Category = tokens [1];
                    break;

                case "Architecture":
                    AddProperty(Beagle.Property.NewUnsearched("fixme:arch", tokens [1]));
                    break;

                case "Depends":
                    list = tokens [1].Split(splits);
                    foreach (string s in list)
                    {
                        AddProperty(Beagle.Property.NewUnsearched("fixme:depends", s));
                    }
                    break;

                case "Recommends":
                    list = tokens [1].Split(splits);
                    foreach (string s in list)
                    {
                        AddProperty(Beagle.Property.NewUnsearched("fixme:recommend", s));
                    }
                    break;

                case "Conflicts":
                    list = tokens [1].Split(splits);
                    foreach (string s in list)
                    {
                        AddProperty(Beagle.Property.NewUnsearched("fixme:conflict", s));
                    }
                    break;

                case "Replaces":
                    list = tokens [1].Split(splits);
                    foreach (string s in list)
                    {
                        AddProperty(Beagle.Property.NewUnsearched("fixme:replaces", s));
                    }
                    break;

                case "Provides":
                    list = tokens [1].Split(splits);
                    foreach (string s in list)
                    {
                        AddProperty(Beagle.Property.NewUnsearched("fixme:provides", s));
                    }
                    break;

                case "Installed-Size":
                    // Installed-Size is given in number of KBs
                    AddProperty(Beagle.Property.NewUnsearched("fixme:size", tokens [1] + "000"));
                    break;

                case "Description":
                    AppendText(tokens [1]);
                    AppendStructuralBreak();
                    while ((str = pout.ReadLine()) != null)
                    {
                        if (str.Trim() == ".")
                        {
                            AppendStructuralBreak();
                        }
                        else
                        {
                            AppendText(str);
                        }
                    }
                    break;
                }
            }

            pout.Close();
            pc.Close();
            return(true);
        }