[mythtv] [PATCH] Fixed problems with non ascii characters in mythvideo

Mikael Magnusson mikaelmagnusson at tjohoo.se
Mon Aug 18 18:19:45 EDT 2003


I'm reposting my mythvideo patch with diffs against current cvs.

This patch solves the following problems.

1. Expressions of the form "{" appearing in the meta data.
They are used by www.imdb.com for non ascii characters. I implemented a 
decoder for such numeric character references. 

2. Non ascii characters are changed to "?" in the meta data.
QString::sprintf expects the %s string parameters to be in utf8 format. 
Fixed

2. Can't play movies which file name contains non ascii characters.
The system command should be converted to local8Bit. Fixed

I have tested the patch on an utf8 locale and briefly on iso-8859-1, and 
it seems to work.

The program table in the mythconverg database is encoded in utf8. I 
think the meta data should changed to utf8 also. Currently latin1 is 
used.

/Mikael Magnusson
-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/Makefile,v
retrieving revision 1.8
diff -u -r1.8 Makefile
--- Makefile	13 Jun 2003 22:52:16 -0000	1.8
+++ Makefile	18 Aug 2003 13:49:07 -0000
@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: mythvideo
-# Generated by qmake (1.04a) (Qt 3.1.1) on: Fri Jun 13 17:15:04 2003
+# Generated by qmake (1.04a) (Qt 3.1.1) on: Sat Aug  2 01:19:10 2003
 # Project:  mythvideo.pro
 # Template: subdirs
 # Command: $(QMAKE) -o Makefile mythvideo.pro
@@ -21,7 +21,7 @@
 sub-mythvideo: mythvideo/$(MAKEFILE) FORCE
 	cd mythvideo && $(MAKE) -f $(MAKEFILE)
 
-Makefile: mythvideo.pro  $(QTDIR)/mkspecs/linux-g++/qmake.conf 
+Makefile: mythvideo.pro  $(QTDIR)/mkspecs/default/qmake.conf 
 	$(QMAKE) -o Makefile mythvideo.pro
 qmake: qmake_all
 	@$(QMAKE) -o Makefile mythvideo.pro
Index: mythvideo/metadata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/metadata.cpp,v
retrieving revision 1.4
diff -u -r1.4 metadata.cpp
--- mythvideo/metadata.cpp	28 Jul 2003 16:03:04 -0000	1.4
+++ mythvideo/metadata.cpp	18 Aug 2003 13:49:07 -0000
@@ -141,11 +141,12 @@
     thequery.sprintf("INSERT INTO videometadata (title,director,plot,"
                               "rating,year,userrating,length,filename,showlevel,coverfile,inetref) VALUES "
                               "(\"%s\",\"%s\",\"%s\",\"%s\",%d,%f,%d,\"%s\",%d,\"%s\",\"%s\");",
-                              title.latin1(), director.latin1(),
-                              plot.latin1(), rating.latin1(), year,
-                              userrating, length, sqlfilename.ascii(), showlevel,
-                              sqlcoverfile.ascii(), inetref.ascii());
-
+                              title.utf8().data(), director.utf8().data(),
+                              plot.utf8().data(), rating.utf8().data(), year,
+                              userrating, length, sqlfilename.utf8().data(), 
+		              showlevel,
+                              sqlcoverfile.utf8().data(),
+		              inetref.utf8().data());
     db->exec(thequery);
 
     // easiest way to ensure we've got 'id' filled.
@@ -193,10 +194,12 @@
     thequery.sprintf("UPDATE videometadata SET title=\"%s\",director=\"%s\",plot=\"%s\","
                               "rating=\"%s\",year=%d,userrating=%f,length=%d,filename=\"%s\","
                               "showlevel=%d,coverfile=\"%s\",inetref=\"%s\" WHERE intid=%d",
-                              title.latin1(), director.latin1(),
-                              plot.latin1(), rating.latin1(), year,
-                              userrating, length, sqlfilename.ascii(), showlevel,
-                              sqlcoverfile.ascii(), inetref.ascii(), id);
+                              title.utf8().data(), director.utf8().data(),
+                              plot.utf8().data(), rating.utf8().data(), year,
+                              userrating, length, sqlfilename.utf8().data(),
+		              showlevel,
+                              sqlcoverfile.utf8().data(),
+		              inetref.utf8().data(), id);
 
     db->exec(thequery);
 }
Index: mythvideo/videobrowser.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videobrowser.cpp,v
retrieving revision 1.9
diff -u -r1.9 videobrowser.cpp
--- mythvideo/videobrowser.cpp	30 Jul 2003 18:11:59 -0000	1.9
+++ mythvideo/videobrowser.cpp	18 Aug 2003 13:49:08 -0000
@@ -219,7 +219,7 @@
   else if (m_state == 4)
   {
     // Play the movie
-    system((QString("%1 ") .arg(m_cmd)).ascii());
+    system((QString("%1 ") .arg(m_cmd)).local8Bit());
 
     Metadata *childItem = new Metadata;
     Metadata *parentItem = new Metadata(*curitem);
@@ -233,7 +233,7 @@
         {
             //Load up data about this child
             selected(childItem);
-            system((QString("%1 ") .arg(m_cmd)).ascii());
+            system((QString("%1 ") .arg(m_cmd)).local8Bit());
         }
 
         delete parentItem;
@@ -520,7 +520,8 @@
 
     QString handler = gContext->GetSetting("VideoDefaultPlayer");
     QString arg;
-    arg.sprintf("\"%s\"", filename.replace(QRegExp("\""), "\\\"").ascii());
+    arg.sprintf("\"%s\"", 
+		filename.replace(QRegExp("\""), "\\\"").utf8().data());
     QString command = handler.replace(QRegExp("%s"), arg);
 
     cout << "command:" << command << endl;
Index: mythvideo/videomanager.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videomanager.cpp,v
retrieving revision 1.11
diff -u -r1.11 videomanager.cpp
--- mythvideo/videomanager.cpp	9 Aug 2003 19:37:26 -0000	1.11
+++ mythvideo/videomanager.cpp	18 Aug 2003 13:49:08 -0000
@@ -190,6 +190,41 @@
     updateML = false;
 }
 
+
+// Replace the numeric character references
+// See http://www.w3.org/TR/html4/charset.html#h-5.3.1
+static void replaceNumCharRefs(QString &str)
+{
+    QString &ret = str;
+    int pos = 0;
+    QRegExp re("&#(\\d+|(x|X)[0-9a-fA-F]+);");
+    
+    while ((pos = re.search(ret, pos)) != -1) {
+	int len = re.matchedLength();
+	QString numStr = re.cap(1);
+	bool ok = false;
+	int num = -1;
+
+	if (numStr[0] == 'x' || numStr[0] == 'X') {
+	    QString hexStr = numStr.right(numStr.length() - 1);
+	    num = hexStr.toInt(&ok, 16);
+	} else {
+	    num = numStr.toInt(&ok, 10);
+	}
+
+	QChar rep('X');
+
+	if (ok) {
+	    rep = QChar(num);
+	}
+
+	ret.replace(pos, len, rep);
+
+	pos += 1;
+    }
+}
+
+
 QString VideoManager::parseData(QString data, QString beg, QString end)
 {
     bool debug = false;
@@ -205,8 +240,7 @@
     {
         ret = data.mid(start, endint - start);
 
-        ret.replace(QRegExp("&#38;"), "&");
-        ret.replace(QRegExp("&#34;"), "\"");
+	replaceNumCharRefs(ret);
 
         if (debug == true)
             cout << "MythVideo: Parse HTML : Returning : " << ret << endl;
Index: mythvideo/videotree.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videotree.cpp,v
retrieving revision 1.9
diff -u -r1.9 videotree.cpp
--- mythvideo/videotree.cpp	30 Jul 2003 02:39:16 -0000	1.9
+++ mythvideo/videotree.cpp	18 Aug 2003 13:49:08 -0000
@@ -183,7 +183,8 @@
         QString filename = node_data->Filename();
         QString handler = gContext->GetSetting("VideoDefaultPlayer");
         QString arg;
-        arg.sprintf("\"%s\"", filename.replace(QRegExp("\""), "\\\"").ascii());
+        arg.sprintf("\"%s\"", 
+		    filename.replace(QRegExp("\""), "\\\"").utf8().data());
         QString command = handler.replace(QRegExp("%s"), arg);
 
         // cout << "command:" << command << endl;
@@ -192,7 +193,7 @@
         //  Run the player
         //
         
-        system((QString("%1 ").arg(command)).ascii());
+        system((QString("%1 ").arg(command)).local8Bit());
 
         //
         //  Go back to tree browsing


More information about the mythtv-dev mailing list