[rygel] media-export: Deduce DVD title from file name
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Deduce DVD title from file name
- Date: Sat, 13 Feb 2016 20:04:54 +0000 (UTC)
commit e790df5b0da584c096f4d45ca5364a91d613fd12
Author: Jens Georg <mail jensge org>
Date: Sat Feb 13 17:10:20 2016 +0100
media-export: Deduce DVD title from file name
Do not use information from volume label, it is apparently more often
broken than helpful.
Signed-off-by: Jens Georg <mail jensge org>
.../rygel-media-export-dvd-container.vala | 4 +-
.../rygel-media-export-item-factory.vala | 122 +++++++++++++++++---
2 files changed, 108 insertions(+), 18 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-dvd-container.vala
b/src/plugins/media-export/rygel-media-export-dvd-container.vala
index af1c78a..6c05896 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-container.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-container.vala
@@ -55,9 +55,7 @@ internal class Rygel.MediaExport.DVDContainer : SimpleContainer, UpdatableObject
var child_count = 0;
while (it != null) {
- if (it->name == "title") {
- this.title = it->children->content;
- } else if (it->name == "track") {
+ if (it->name == "track") {
child_count++;
}
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 f04a83b..2520203 100644
--- a/src/plugins/media-export/rygel-media-export-item-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-item-factory.vala
@@ -38,6 +38,27 @@ 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))) {
@@ -173,6 +194,12 @@ namespace Rygel.MediaExport.ItemFactory {
case DVDContainer.UPNP_CLASS:
object = new DVDContainer ("dvd:" + id, parent, "", file.get_path ());
object.add_uri (file.get_uri ());
+
+ if (file_info != null) {
+ apply_file_info (object, file_info);
+ object.title = strip_invalid_entities (object.title);
+ }
+
return object;
default:
return null;
@@ -184,14 +211,14 @@ namespace Rygel.MediaExport.ItemFactory {
apply_dlna_profile (item, dlna_profile);
}
- if (file_info != null) {
- apply_file_info (item, file_info);
- }
-
if (info != null) {
apply_info (item, info);
}
+ if (file_info != null) {
+ apply_file_info (item, file_info);
+ }
+
if (audio_info != null) {
apply_audio_info (item, audio_info);
}
@@ -306,7 +333,7 @@ namespace Rygel.MediaExport.ItemFactory {
item.mime_type = it.next_value ().dup_string ();
}
- private static void apply_file_info (MediaFileItem item, Variant v)
+ private static void apply_file_info (MediaObject object, Variant v)
throws Error {
ItemFactory.check_variant_type (v, "(sstt)");
@@ -314,20 +341,85 @@ namespace Rygel.MediaExport.ItemFactory {
Variant display_name;
display_name = it.next_value ();
- if (item.title == null || item.title == "") {
- item.title = display_name.dup_string ();
+ if (object.title == null || object.title == "") {
+ object.title = display_name.dup_string ();
+ }
+
+ if (object is MediaFileItem) {
+ var item = object as MediaFileItem;
+
+ var mime = it.next_value ();
+ if (item.mime_type == null) {
+ item.mime_type = mime.dup_string ();
+ }
+
+ item.modified = (int64) it.next_value ().get_uint64 ();
+ if (item.date == null) {
+ TimeVal tv = { (long) item.modified, 0 };
+ item.date = tv.to_iso8601 ();
+ }
+ item.size = (int64) it.next_value ().get_uint64 ();
}
+ }
- var mime = it.next_value ();
- if (item.mime_type == null) {
- item.mime_type = mime.dup_string ();
+ 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 ();
+ }
}
- item.modified = (int64) it.next_value ().get_uint64 ();
- if (item.date == null) {
- TimeVal tv = { (long) item.modified, 0 };
- item.date = tv.to_iso8601 ();
+ 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 ();
}
- item.size = (int64) it.next_value ().get_uint64 ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]