[rygel] media-export: Refactor extracting into own class



commit bd47af50f5193d6f47b0483aadb4a12fd1e5a911
Author: Jens Georg <mail jensge org>
Date:   Sun Jun 26 22:51:20 2016 +0200

    media-export: Refactor extracting into own class
    
    This adds a generic base class that does the collection of basic information
    and introduces a generic extractor that just uses GstDiscoverer for
    everything, same as before.
    
    Signed-off-by: Jens Georg <mail jensge org>

 src/plugins/media-export/Makefile.am               |    5 +-
 .../media-export/rygel-media-export-extract.vala   |  101 +------
 .../media-export/rygel-media-export-extractor.vala |  146 ++++++++++
 .../rygel-media-export-generic-extractor.vala      |  283 ++++++++++++++++++++
 .../rygel-media-export-item-factory.vala           |   85 ------
 5 files changed, 446 insertions(+), 174 deletions(-)
---
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 257a080..550d001 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -10,8 +10,9 @@ include $(top_srcdir)/common.am
 pkglibexec_PROGRAMS = mx-extract
 mx_extract_SOURCES = \
        rygel-media-export-extract.vala \
-       rygel-media-export-info-serializer.vala \
-       rygel-media-export-dvd-parser.vala
+       rygel-media-export-dvd-parser.vala \
+       rygel-media-export-extractor.vala \
+       rygel-media-export-generic-extractor.vala
 
 mx_extract_VALAFLAGS = \
        --enable-experimental \
diff --git a/src/plugins/media-export/rygel-media-export-extract.vala 
b/src/plugins/media-export/rygel-media-export-extract.vala
index 97c38a4..445a9f3 100644
--- a/src/plugins/media-export/rygel-media-export-extract.vala
+++ b/src/plugins/media-export/rygel-media-export-extract.vala
@@ -24,6 +24,8 @@ using Gst.PbUtils;
 using GUPnPDLNA;
 using Gst;
 
+using Rygel.MediaExport;
+
 const string UPNP_CLASS_PHOTO = "object.item.imageItem.photo";
 const string UPNP_CLASS_MUSIC = "object.item.audioItem.musicTrack";
 const string UPNP_CLASS_VIDEO = "object.item.videoItem";
@@ -41,7 +43,6 @@ static bool metadata = false;
 static MainLoop loop;
 static DataInputStream input_stream;
 static OutputStream output_stream;
-static Rygel.InfoSerializer serializer;
 static MediaArt.Process media_art;
 static Discoverer discoverer;
 static ProfileGuesser guesser;
@@ -75,32 +76,28 @@ async void run () {
 
                     continue;
                 }
-                DiscovererInfo? info = null;
+
                 try {
+                    var file = File.new_for_uri (parts[0]);
+                    Extractor extractor;
                     // Copy current URI to statically allocated memory area to
                     // dump to fd in the signal handler
                     if (metadata) {
                         var is_text = parts[1].has_prefix ("text/") ||
                                       parts[1].has_suffix ("xml");
                         if (parts[1] == "application/x-cd-image") {
-                            var file = File.new_for_uri (parts[0]);
-                            var parser = new Rygel.DVDParser (file);
-                            yield parser.run ();
+                            extractor = new Extractor (file);
                         } else if (!is_text) {
-                            var file = File.new_for_uri (parts[0]);
-                            var path = file.get_path ();
-                            var uri = parts[0];
-
-                            if (path != null) {
-                                uri = Filename.to_uri (path);
-                            }
-
-                            info = discoverer.discover_uri (uri);
-
-                            debug ("Finished discover on URI %s", parts[0]);
+                            extractor = new GenericExtractor (file);
+                        } else {
+                            extractor = new Extractor (file);
                         }
+                    } else {
+                        extractor = new Extractor (file);
                     }
-                    yield process_meta_data (parts[0], info);
+                    yield extractor.run ();
+
+                    send_extraction_done (file, extractor.get ());
                 } catch (Error error) {
                     if (error is DVDParserError.NOT_AVAILABLE) {
                         send_skip (File.new_for_uri (parts[0]));
@@ -109,12 +106,8 @@ async void run () {
                                  parts[0],
                                  error.message);
                         send_error (File.new_for_uri (parts[0]), error);
-
-                        // Recreate the discoverer on error
-                        discoverer = new Discoverer (10 * Gst.SECOND);
                     }
                 }
-                //discoverer.discover_uri_async (uri);
             } else if (line.has_prefix ("METADATA ")) {
                 var command = line.replace ("METADATA ", "").strip ();
                 metadata = bool.parse (command);
@@ -167,71 +160,6 @@ static void send_error (File file, Error err) {
     }
 }
 
-static async void process_meta_data (string uri, DiscovererInfo? info) {
-    debug ("Discovered %s", uri);
-    var file = File.new_for_uri (uri);
-    if (info != null) {
-        if (info.get_result () == DiscovererResult.TIMEOUT ||
-            info.get_result () == DiscovererResult.BUSY ||
-            info.get_result () == DiscovererResult.MISSING_PLUGINS) {
-            if (info.get_result () == DiscovererResult.MISSING_PLUGINS) {
-                debug ("Plugins are missing for extraction of file %s",
-                       info.get_uri ());
-            } else {
-                debug ("Extraction timed out on %s", file.get_uri ());
-            }
-            yield extract_basic_information (file, null, null);
-
-            return;
-        }
-
-        var dlna_info = GUPnPDLNAGst.utils_information_from_discoverer_info (info);
-        var dlna = guesser.guess_profile_from_info (dlna_info);
-        yield extract_basic_information (file, info, dlna);
-    } else {
-        yield extract_basic_information (file, null, null);
-    }
-}
-
-static async void extract_basic_information (File               file,
-                                             DiscovererInfo?    info,
-                                             GUPnPDLNA.Profile? dlna) {
-    FileInfo file_info;
-
-    try {
-        file_info = yield file.query_info_async (FileAttribute.STANDARD_TYPE + "," +
-                                                 FileAttribute.STANDARD_CONTENT_TYPE
-                                                 + "," +
-                                                 FileAttribute.STANDARD_SIZE + "," +
-                                                 FileAttribute.TIME_MODIFIED + "," +
-                                                 FileAttribute.STANDARD_DISPLAY_NAME,
-                                                 FileQueryInfoFlags.NONE);
-    } catch (Error error) {
-        var uri = file.get_uri ();
-
-        warning (_("Failed to extract basic metadata from %s: %s"),
-                 uri,
-                 error.message);
-
-        // signal error to parent
-        send_error (file, error);
-
-        return;
-    }
-
-    if (file_info.get_file_type () == FileType.DIRECTORY) {
-        file_info.set_file_type (FileType.REGULAR);
-        file_info.set_content_type ("application/x-cd-image");
-    }
-
-    try {
-        send_extraction_done (file,
-                              serializer.serialize (file, file_info, info, dlna));
-    } catch (Error error) {
-        send_error (file, error);
-    }
-}
-
 int main (string[] args) {
     var ctx = new OptionContext (_("- helper binary for Rygel to extract metadata"));
     ctx.add_main_entries (options, null);
@@ -251,7 +179,6 @@ int main (string[] args) {
         warning (_("Failed to create media art extractor: %s"),
                 error.message);
     }
-    serializer = new Rygel.InfoSerializer (media_art);
     Posix.nice (19);
 
     message ("Started with descriptors %d (in) %d (out)", in_fd, out_fd);
diff --git a/src/plugins/media-export/rygel-media-export-extractor.vala 
b/src/plugins/media-export/rygel-media-export-extractor.vala
new file mode 100644
index 0000000..89aef91
--- /dev/null
+++ b/src/plugins/media-export/rygel-media-export-extractor.vala
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2016 Jens Georg <mail jensge org>
+ *
+ * Author: Jens Georg <mail jensge org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+public errordomain ExtractorError {
+    GENERAL
+}
+
+public class Rygel.MediaExport.Extractor : Object {
+    private const string INVALID_CHARS = "()[]<>{}! #$^&*+=|\\/\"'?~";
+    private const string CONVERT_CHARS = "\t_\\.";
+    private const string BLOCK_PATTERN = "%s[^%s]*%s";
+    private const string[] BLOCKS = { "()", "{}", "[]", "<>" };
+    private const string[] BLACKLIST = {
+        "720p", "1080p", "x264", "ws", "proper", "real.repack", "repack",
+        "hdtv", "pdtv", "notv", "dsr", "DVDRip", "divx", "xvid"
+    };
+
+    private const string[] VIDEO_SUFFIXES = {
+        "webm", "mkv", "flv", "ogv", "ogg", "avi", "mov", "wmv", "mp4",
+        "m4v", "mpeg", "mpg", "iso"
+    };
+
+    private static Regex char_remove_regex;
+    private static Regex char_convert_regex;
+    private static Regex space_compress_regex;
+    private static Regex[] block_regexes;
+    private static Regex[] blacklist_regexes;
+    private static Regex[] video_suffix_regexes;
+
+    public File file { get; construct set; }
+    protected VariantDict serialized_info;
+
+    public Extractor (File file) {
+        Object (file: file);
+    }
+
+    public override void constructed () {
+        this.serialized_info = new VariantDict ();
+    }
+
+    public virtual async void run () throws Error {
+        var file_info = yield file.query_info_async (FileAttribute.STANDARD_TYPE + "," +
+                                                     FileAttribute.STANDARD_CONTENT_TYPE
+                                                 + "," +
+                                                 FileAttribute.STANDARD_SIZE + "," +
+                                                 FileAttribute.TIME_MODIFIED + "," +
+                                                 FileAttribute.STANDARD_DISPLAY_NAME,
+                                                 FileQueryInfoFlags.NONE);
+        var display_name = file_info.get_display_name ();
+        this.serialized_info.insert ("DisplayName", "s", display_name);
+
+        var title = this.strip_invalid_entities (display_name);
+        this.serialized_info.insert ("Title", "s", title);
+
+        this.serialized_info.insert ("MTime", "t", file_info.get_attribute_uint64
+                                        (FileAttribute.TIME_MODIFIED));
+        var content_type = ContentType.get_mime_type
+                                        (file_info.get_content_type ());
+        this.serialized_info.insert ("MimeType", "s", content_type);
+        this.serialized_info.insert ("Size", "t", file_info.get_size ());
+     }
+
+    public new Variant? @get () {
+        return this.serialized_info.end ();
+    }
+
+    private string strip_invalid_entities (string original) {
+        if (char_remove_regex == null) {
+            try {
+                var regex_string = Regex.escape_string (INVALID_CHARS);
+                char_remove_regex = new Regex ("[%s]".printf (regex_string));
+                regex_string = Regex.escape_string (CONVERT_CHARS);
+                char_convert_regex = new Regex ("[%s]".printf (regex_string));
+                space_compress_regex = new Regex ("\\s+");
+                block_regexes = new Regex[0];
+
+                foreach (var block in BLOCKS) {
+                    var block_re = BLOCK_PATTERN.printf (
+                                      Regex.escape_string ("%C".printf (block[0])),
+                                      Regex.escape_string ("%C".printf (block[1])),
+                                      Regex.escape_string ("%C".printf (block[1])));
+                    block_regexes += new Regex (block_re);
+                }
+
+                foreach (var blacklist in BLACKLIST) {
+                    blacklist_regexes += new Regex (Regex.escape_string
+                                                    (blacklist));
+                }
+
+                foreach (var suffix in VIDEO_SUFFIXES) {
+                    video_suffix_regexes += new Regex (Regex.escape_string
+                                                        (suffix));
+                }
+            } catch (RegexError error) {
+                assert_not_reached ();
+            }
+        }
+
+        string p;
+
+        p = original;
+
+        try {
+            foreach (var re in blacklist_regexes) {
+                p = re.replace_literal (p, -1, 0, "");
+            }
+
+            foreach (var re in video_suffix_regexes) {
+                p = re.replace_literal (p, -1, 0, "");
+            }
+
+            foreach (var re in block_regexes) {
+                p = re.replace_literal (p, -1, 0, "");
+            }
+
+            p = char_remove_regex.replace_literal (p, -1, 0, "");
+            p = char_convert_regex.replace_literal (p, -1, 0, " ");
+            p = space_compress_regex.replace_literal (p, -1, 0, " ");
+
+            p._strip ();
+
+            return p;
+        } catch (RegexError error) {
+            assert_not_reached ();
+        }
+    }
+}
diff --git a/src/plugins/media-export/rygel-media-export-generic-extractor.vala 
b/src/plugins/media-export/rygel-media-export-generic-extractor.vala
new file mode 100644
index 0000000..35cd65d
--- /dev/null
+++ b/src/plugins/media-export/rygel-media-export-generic-extractor.vala
@@ -0,0 +1,283 @@
+/*
+ * Copyright (C) 2016 Jens Georg <mail jensge org>
+ *
+ * Author: Jens Georg <mail jensge org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+using Gst.PbUtils;
+using GUPnPDLNA;
+using Gst;
+
+internal class Rygel.MediaExport.GenericExtractor: Extractor {
+    private static Discoverer discoverer;
+    private static ProfileGuesser guesser;
+    private static MediaArt.Process media_art;
+    private string upnp_class;
+    private string mime_type;
+
+    public GenericExtractor (File file) {
+        GLib.Object (file: file);
+    }
+
+    static construct {
+        try {
+            GenericExtractor.discoverer = new Discoverer (10 * Gst.SECOND);
+            GenericExtractor.discoverer.start ();
+        } catch (Error error) {
+            debug ("Generic extractor unavailable: %s", error.message);
+        }
+        GenericExtractor.guesser = new ProfileGuesser (true, true);
+
+        try {
+            GenericExtractor.media_art = new MediaArt.Process ();
+        } catch (Error error) {
+            warning (_("Failed to create media art extractor: %s"),
+                     error.message);
+        }
+    }
+
+    public override async void run () throws Error {
+        yield base.run ();
+
+        if (GenericExtractor.discoverer == null) {
+            throw new ExtractorError.GENERAL ("Backend not avaliable");
+        }
+
+        Error error = null;
+        DiscovererInfo? info = null;
+
+        var id = GenericExtractor.discoverer.discovered.connect (
+            (_info, _error) => {
+                info = _info;
+                error = _error;
+                run.callback ();
+        });
+
+        var path = this.file.get_path ();
+        var uri = this.file.get_uri ();
+
+        if (path != null) {
+            warning ("Using local path %s instead of %s",
+                    path, uri);
+            uri = Filename.to_uri (path);
+        }
+
+        GenericExtractor.discoverer.discover_uri_async (uri);
+        yield;
+        GenericExtractor.discoverer.disconnect (id);
+
+        if (error != null) {
+            // Re-create discoverer, in error case it tends to get really
+            // slow.
+            GenericExtractor.discoverer.stop ();
+            GenericExtractor.discoverer = null;
+            GenericExtractor.discoverer = new Discoverer (10 * Gst.SECOND);
+            GenericExtractor.discoverer.start ();
+
+            var result = info.get_result ();
+            if (result == DiscovererResult.TIMEOUT) {
+                debug ("Extraction timed out on %s", file.get_uri ());
+            } else if (result == DiscovererResult.MISSING_PLUGINS) {
+                debug ("Plugins are missing for extraction of file %s",
+                       file.get_uri ());
+            }
+
+            throw error;
+        }
+
+        // Guess UPnP profile
+        var audio_streams = (GLib.List<DiscovererAudioInfo>)
+                                            info.get_audio_streams ();
+        var video_streams = (GLib.List<DiscovererVideoInfo>)
+                                            info.get_video_streams ();
+        if (audio_streams == null && video_streams == null) {
+            debug ("%s had neither audio nor video/picture streams. Ignoring.",
+                   this.file.get_uri ());
+
+            throw new ExtractorError.GENERAL ("No stream information");
+        }
+
+        this.upnp_class = "object.item";
+        if (audio_streams == null && video_streams.data.is_image ()) {
+            this.upnp_class = UPNP_CLASS_PHOTO;
+        } else if (video_streams != null) {
+            this.upnp_class = UPNP_CLASS_VIDEO;
+        } else if (audio_streams != null) {
+            this.upnp_class = UPNP_CLASS_MUSIC;
+        }
+
+        this.serialized_info.insert ("UPnPClass", "s", upnp_class);
+
+        var dlna_info = GUPnPDLNAGst.utils_information_from_discoverer_info
+                                        (info);
+        var dlna = GenericExtractor.guesser.guess_profile_from_info
+                                        (dlna_info);
+
+        if (dlna != null) {
+            this.serialized_info.insert ("DLNAProfile", "s", dlna.name,
+                                         "MimeType", "s", dlna.mime);
+        }
+        this.serialized_info.lookup ("MimeType", "s", out this.mime_type);
+
+        long duration = -1;
+        if (info.get_duration () > 0) {
+            duration = (long) (info.get_duration () / Gst.SECOND);
+            this.serialized_info.insert ("Duration", "i", duration);
+        }
+
+        // Info has several tags, general and on audio info for music files
+        var tags = info.get_tags ();
+        if (tags != null) {
+            string? title = null;
+            if (tags.get_string (Tags.TITLE, out title)) {
+                // If not AVI file, replace title we guessed from filename
+                if (this.mime_type != "video/x-msvideo" && title != null) {
+                    this.serialized_info.insert ("Title", "s", title);
+                }
+            }
+
+            string date = null;
+            Gst.DateTime? dt = null;
+            if (tags.get_date_time (Tags.DATE_TIME, out dt)) {
+                // Make a minimal valid iso8601 date - bgo#702231
+                // This mostly happens with MP3 files which only have a year
+                if (!dt.has_day () || !dt.has_month ()) {
+                    date = "%d-%02d-%02d".printf (dt.get_year (),
+                                                  dt.has_month () ?
+                                                      dt.get_month () : 1,
+                                                  dt.has_day () ?
+                                                      dt.get_day () : 1);
+                } else {
+                    date = dt.to_iso8601_string ();
+                }
+
+                this.serialized_info.insert ("Date", "s", date);
+            }
+        }
+
+        if (video_streams != null && video_streams.data != null) {
+            var vinfo = (DiscovererVideoInfo) video_streams.data;
+            this.serialized_info.insert ("VideoWidth", "i",
+                                         (int) vinfo.get_width ());
+            this.serialized_info.insert ("VideoHeight", "i",
+                                         (int) vinfo.get_height ());
+            this.serialized_info.insert ("VideoDepth", "i",
+                                         vinfo.get_depth () > 0 ?
+                                         vinfo.get_depth () : -1);
+        }
+
+        if (audio_streams != null && audio_streams.data != null) {
+            var ainfo = (DiscovererAudioInfo) audio_streams.data;
+            this.serialized_info.insert ("AudioChannels", "i",
+                                         (int) ainfo.get_channels ());
+            this.serialized_info.insert ("AudioRate", "i",
+                                         (int) ainfo.get_sample_rate ());
+            var atags = ainfo.get_tags ();
+            if (atags != null) {
+                string artist = null;
+                if (atags.get_string (Tags.ARTIST, out artist) &&
+                    this.mime_type != "video/x-msvideo") {
+                    this.serialized_info.insert ("Artist", "s", artist);
+                }
+
+                string album = null;
+                if (atags.get_string (Tags.ALBUM, out album)) {
+                    this.serialized_info.insert ("Album", "s", album);
+                }
+
+                string genre = null;
+                if (atags.get_string (Tags.GENRE, out genre)) {
+                    this.serialized_info.insert ("Genre", "s", genre);
+                }
+
+                uint volume = uint.MAX;
+                if (atags.get_uint (Tags.ALBUM_VOLUME_NUMBER, out volume)) {
+                    this.serialized_info.insert ("VolumeNumber", "i", volume);
+                }
+
+                uint track = uint.MAX;
+                if (atags.get_uint (Tags.TRACK_NUMBER, out track)) {
+                    this.serialized_info.insert ("Track", "i", track);
+                }
+
+                uint bitrate = uint.MAX;
+                if (atags.get_uint (Tags.BITRATE, out bitrate)) {
+                    this.serialized_info.insert ("AudioBitrate", "i",
+                                                 ((int) bitrate) / 8);
+                }
+
+                if (GenericExtractor.media_art != null) {
+                    Sample sample;
+                    atags.get_sample (Tags.IMAGE, out sample);
+                    if (sample == null) {
+                        atags.get_sample (Tags.PREVIEW_IMAGE, out sample);
+                    }
+
+                    if (sample == null) {
+                        try {
+                            if (artist != null || album != null) {
+                                GenericExtractor.media_art.file
+                                                    (MediaArt.Type.ALBUM,
+                                                     MediaArt.ProcessFlags.NONE,
+                                                     file,
+                                                     artist,
+                                                     album);
+                            }
+                        } catch (Error error) {
+                            debug ("Failed to add external media art: %s",
+                                   error.message);
+                        }
+                    } else {
+                        var caps = sample.get_caps ();
+                        unowned Structure structure = caps.get_structure (0);
+                        int image_type;
+                        structure.get_enum ("image-type",
+                                            typeof (Gst.Tag.ImageType),
+                                            out image_type);
+                        if (image_type == Tag.ImageType.UNDEFINED ||
+                            image_type == Tag.ImageType.FRONT_COVER) {
+                            MapInfo map_info;
+                            sample.get_buffer ().map (out map_info,
+                                                      Gst.MapFlags.READ);
+
+                            // work-around for bgo#739915
+                            weak uint8[] data = map_info.data;
+                            data.length = (int) map_info.size;
+
+                            try {
+                                GenericExtractor.media_art.buffer
+                                                      (MediaArt.Type.ALBUM,
+                                                       MediaArt.ProcessFlags.NONE,
+                                                       file,
+                                                       data,
+                                                       structure.get_name (),
+                                                       artist,
+                                                       album);
+                            } catch (Error error) {
+                                debug ("Failed to add media art to cache: %s",
+                                        error.message);
+                            }
+                            sample.get_buffer ().unmap (map_info);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/src/plugins/media-export/rygel-media-export-item-factory.vala 
b/src/plugins/media-export/rygel-media-export-item-factory.vala
index 2cd1312..c872810 100644
--- a/src/plugins/media-export/rygel-media-export-item-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-item-factory.vala
@@ -38,27 +38,6 @@ namespace Rygel.MediaExport.ItemFactory {
         MISMATCH
     }
 
-    private const string INVALID_CHARS = "()[]<>{}! #$^&*+=|\\/\"'?~";
-    private const string CONVERT_CHARS = "\t_\\.";
-    private const string BLOCK_PATTERN = "%s[^%s]*%s";
-    private const string[] BLOCKS = { "()", "{}", "[]", "<>" };
-    private const string[] BLACKLIST = {
-        "720p", "1080p", "x264", "ws", "proper", "real.repack", "repack",
-        "hdtv", "pdtv", "notv", "dsr", "DVDRip", "divx", "xvid"
-    };
-
-    private const string[] VIDEO_SUFFIXES = {
-        "webm", "mkv", "flv", "ogv", "ogg", "avi", "mov", "wmv", "mp4",
-        "m4v", "mpeg", "mpg", "iso"
-    };
-
-    private static Regex char_remove_regex;
-    private static Regex char_convert_regex;
-    private static Regex space_compress_regex;
-    private static Regex[] block_regexes;
-    private static Regex[] blacklist_regexes;
-    private static Regex[] video_suffix_regexes;
-
     private static bool check_variant_type (Variant v,
                                             string typestring) throws Error {
         if (!v.is_of_type (new VariantType (typestring))) {
@@ -200,7 +179,6 @@ namespace Rygel.MediaExport.ItemFactory {
 
                 if (file_info != null) {
                     apply_file_info (object, file_info);
-                    object.title = strip_invalid_entities (object.title);
                 }
 
                 // If the DVD has a single track, just export that as a plain
@@ -240,9 +218,6 @@ namespace Rygel.MediaExport.ItemFactory {
                 apply_file_info (item, file_info);
             }
 
-            if (strip_title) {
-                item.title = strip_invalid_entities (item.title);
-            }
         }
 
         if (audio_info != null) {
@@ -388,64 +363,4 @@ namespace Rygel.MediaExport.ItemFactory {
         }
     }
 
-    private string strip_invalid_entities (string original) {
-        if (char_remove_regex == null) {
-            try {
-                var regex_string = Regex.escape_string (INVALID_CHARS);
-                char_remove_regex = new Regex ("[%s]".printf (regex_string));
-                regex_string = Regex.escape_string (CONVERT_CHARS);
-                char_convert_regex = new Regex ("[%s]".printf (regex_string));
-                space_compress_regex = new Regex ("\\s+");
-                block_regexes = new Regex[0];
-
-                foreach (var block in BLOCKS) {
-                    var block_re = BLOCK_PATTERN.printf (
-                                      Regex.escape_string ("%C".printf (block[0])),
-                                      Regex.escape_string ("%C".printf (block[1])),
-                                      Regex.escape_string ("%C".printf (block[1])));
-                    block_regexes += new Regex (block_re);
-                }
-
-                foreach (var blacklist in BLACKLIST) {
-                    blacklist_regexes += new Regex (Regex.escape_string
-                                                    (blacklist));
-                }
-
-                foreach (var suffix in VIDEO_SUFFIXES) {
-                    video_suffix_regexes += new Regex (Regex.escape_string
-                                                        (suffix));
-                }
-            } catch (RegexError error) {
-                assert_not_reached ();
-            }
-        }
-
-        string p;
-
-        p = original;
-
-        try {
-            foreach (var re in blacklist_regexes) {
-                p = re.replace_literal (p, -1, 0, "");
-            }
-
-            foreach (var re in video_suffix_regexes) {
-                p = re.replace_literal (p, -1, 0, "");
-            }
-
-            foreach (var re in block_regexes) {
-                p = re.replace_literal (p, -1, 0, "");
-            }
-
-            p = char_remove_regex.replace_literal (p, -1, 0, "");
-            p = char_convert_regex.replace_literal (p, -1, 0, " ");
-            p = space_compress_regex.replace_literal (p, -1, 0, " ");
-
-            p._strip ();
-
-            return p;
-        } catch (RegexError error) {
-            assert_not_reached ();
-        }
-    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]