[mythtv-users] myth video file naming issues

Tony Lill ajlill at ajlc.waterloo.on.ca
Fri Mar 18 01:56:23 UTC 2011


Raymond Wagner <raymond at wagnerrp.com> writes:

> On 3/14/2011 12:58, Dan Armbrust wrote:
>>>> Alternatively, what are the formats that it expects, what can it parse?
>>> http://www.mythtv.org/wiki/MythVideo_File_Parsing
>>>
>> Thanks.
>>
>> Hmm.  Must be the brackets that many of my files have which is hosing
>> the parser.
>>
>> Title [01x05] - Subtitle
>>
>> I don't suppose I can modify the parser without recompiling things?
>
> Nope.  It will require a recompile of libmythmetadata.  The relevant 
> code can be found here...
>
> https://github.com/MythTV/mythtv/blob/master/mythtv/libs/libmythmetadata/videometadata.cpp#L974
>
> The problem is that use of parentheses, brackets, and braces in the 
> title and subtitle are assumed to be release years or dates or other 
> unwanted information.  Those are carried through and handled after the 
> primary regular expression, with the entire contents being removed.  As 
> such, they could not be handled like the other spacer characters which 
> are outright removed.
>
> Proper handling of season and episode in brackets would require that the 
> regular expression match opening and closing of those characters, which 
> will involve back references and other more complex capabilities of 
> regular expressions.  If you are good with regular expressions, feel 
> free to try to make this work and submit a patch.

I had a problem where the metadata parsing often mistook hash values,
resolution, etc for season/episode pairs. I fixed this by simply
stripping out stuff in brackets (uless it looked like a year).

works for me, ymmv, etc.

diff --git a/mythtv/libs/libmythmetadata/videometadata.cpp b/mythtv/libs/libmythmetadata/videometadata.cpp
index 581ae2c..d603c38 100644
--- a/mythtv/libs/libmythmetadata/videometadata.cpp
+++ b/mythtv/libs/libmythmetadata/videometadata.cpp
@@ -973,10 +973,15 @@ QString VideoMetadata::FilenameToMeta(const QString &file_name, int position)
     cleanFilename.replace(QRegExp("_"), " ");
     cleanFilename.replace(QRegExp("\\."), " ");
 
+    // Many filenames contain extraneous junk contained in brackets,
+    // like checksums, resolution, etc, get rid of these, but beware
+    // its also common to see a year or year range, which we want to keep
+    cleanFilename.replace(QRegExp("[\\[\\(\\{](?![0-9]{4,4}(:-[0-9]{4,4})?[\\]\\}\\)])[^\\]}\\)]+[\\]\\}\\)]"), " ");
+
     QString season_translation = QObject::tr("Season");
     QString episode_translation = QObject::tr("Episode");
 
-    // Primary Regexp
+    // Primary Regexp - break up filename into title s2e3 subtitle
     QString separator = "(?:\\s?(?:-|/)?\\s?)?";
     QString regexp = QString(
                   "^(.*[^s0-9])" // Title
@@ -995,7 +1000,7 @@ QString VideoMetadata::FilenameToMeta(const QString &file_name, int position)
     QRegExp filename_parse(regexp,
                   Qt::CaseInsensitive, QRegExp::RegExp2);
 
-    // Cleanup Regexp
+    // Cleanup Regexp - get rid or any season info stuff stuck to the title
     QString regexp2 = QString("(%1(?:%2%1\\d*%1)*%1)$")
                              .arg(separator).arg(season_translation);
     QRegExp title_parse(regexp2, Qt::CaseInsensitive, QRegExp::RegExp2);
@@ -1003,12 +1008,14 @@ QString VideoMetadata::FilenameToMeta(const QString &file_name, int position)
     int pos = filename_parse.indexIn(cleanFilename);
     if (pos > -1)
     {
+      // If the regex worked, grab the stuff captured
+
         QString title = filename_parse.cap(1);
         QString season = filename_parse.cap(2);
         QString episode = filename_parse.cap(3);
         QString subtitle = filename_parse.cap(4);
 
-        // Clean up the title
+        // Clean up the title - why not grab the season info when we do this?
         int pos2 = title_parse.indexIn(title);
         if (pos2 > -1)
             title = title.left(pos2);
@@ -1025,6 +1032,8 @@ QString VideoMetadata::FilenameToMeta(const QString &file_name, int position)
         else if (position == 4)
             return subtitle.trimmed();
     }
+
+    // Our fancy regex didn't work, cleanup the filename and call it a title
     else if (position == 1)
     {
         QString title = cleanFilename;


More information about the mythtv-users mailing list