注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Nihui's Blog

nihui的私人空间和日志

 
 
 

日志

 
 

Amarok tag 编码补丁失效  

2007-08-25 20:37:59|  分类: magic 栏 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
自从 Amarok >= 1.4.0 以来,就没有文件 tag 编码选项了,那个时候,yunfan 写了一个补丁来解决这个困难。
但是最近发觉它工作已经不太正常了。
虽然我应急把补丁修改了一下,以适应 Amarok 1.4.7,但仍然有问题  :(
具体状况如下:
对于 tag 为 gbk 字符的文件可以正确识别,并能正确显示在播放列表、收藏、音轨信息对话框中。
然而,只要编辑一下文件的 id3 的标签信息,就出现问题了。
对于任何 cjk 的字符串,只要修改了标签,并点击 音轨信息 对话框的“保存并关闭”,播放列表和收藏中是编辑之后的信息了,显示正常,但是再次右键该音轨编辑其信息,打开的对话框中的 cjk 字符串都会变成“????”,而且这种编码错误是不可逆的,一旦保存修改,就全为“????”,再次更新收藏,该音轨也变成“?????”(未知)。在 Amarok 外部,如 Konqueror 中查看该文件属性,其标签内容也变成了“?????”。。
注:一个“?”对应一个 cjk 字符。




附上改写后的补丁:amarok-1.4.7-cjk.patch

diff -Nur amarok-1.4.7/amarok/src/contextbrowser.cpp amarok-1.4.7locale/amarok/src/contextbrowser.cpp
--- amarok-1.4.7/amarok/src/contextbrowser.cpp    2007-08-08 01:48:28.000000000 +0800
+++ amarok-1.4.7locale/amarok/src/contextbrowser.cpp    2007-08-24 17:14:57.000000000 +0800
@@ -793,7 +793,10 @@
     QFile exportedDocument( Amarok::saveLocation() + "contextbrowser.html" );
     exportedDocument.open(IO_WriteOnly);
     QTextStream stream( &exportedDocument );
-    stream.setEncoding( QTextStream::UnicodeUTF8 );
+        if(getenv("AMAROK_ORIG")=="1")
+            stream.setEncoding( QTextStream::UnicodeUTF8 );
+        else
+            stream.setEncoding( QTextStream::Locale );
     stream << m_HTMLSource // the pure html data..
         .replace( "<html>", QString( "<html><head><style type=\"text/css\">%1</style></head>" ).arg( HTMLView::loadStyleSheet() ) ); // and the stylesheet code
     exportedDocument.close();
diff -Nur amarok-1.4.7/amarok/src/metabundle.cpp amarok-1.4.7locale/amarok/src/metabundle.cpp
--- amarok-1.4.7/amarok/src/metabundle.cpp    2007-08-08 01:48:28.000000000 +0800
+++ amarok-1.4.7locale/amarok/src/metabundle.cpp    2007-08-24 17:18:11.000000000 +0800
@@ -511,11 +511,22 @@
         if ( tag )
         {
             #define strip( x ) TStringToQString( x ).stripWhiteSpace()
-            setTitle( strip( tag->title() ) );
-            setArtist( strip( tag->artist() ) );
-            setAlbum( strip( tag->album() ) );
-            setComment( strip( tag->comment() ) );
-            setGenre( strip( tag->genre() ) );
+            if(getenv("AMAROK_ORIG")=="1")
+                {
+                    setTitle( strip( tag->title() ) );
+                    setArtist( strip( tag->artist() ) );
+                    setAlbum( strip( tag->album() ) );
+                    setComment( strip( tag->comment() ) );
+                    setGenre( strip( tag->genre() ) );
+                }
+            else
+                {
+                    setTitle( QString::fromLocal8Bit(strip( tag->title()).latin1()) );
+                    setArtist( QString::fromLocal8Bit(strip( tag->artist() ).latin1()) );
+                    setAlbum( QString::fromLocal8Bit(strip( tag->album() ).latin1()) );
+                    setComment( QString::fromLocal8Bit(strip( tag->comment() ).latin1()) );
+                    setGenre( QString::fromLocal8Bit(strip( tag->genre() ).latin1()) );
+                }
             setYear( tag->year() );
             setTrack( tag->track() );
             #undef strip
diff -Nur amarok-1.4.7/amarok/src/playlist.cpp amarok-1.4.7locale/amarok/src/playlist.cpp
--- amarok-1.4.7/amarok/src/playlist.cpp    2007-08-08 01:48:28.000000000 +0800
+++ amarok-1.4.7locale/amarok/src/playlist.cpp    2007-08-24 17:23:09.000000000 +0800
@@ -4889,10 +4889,16 @@
     switch ( m_tagType )
     {
         case PlaylistItem::Title:
-            mb.setTitle( m_newTagString );
+            if(getenv("AMAROK_ORIG")=="1")
+                mb.setTitle( m_newTagString );
+            else
+                mb.setTitle( QString::fromLocal8Bit(m_newTagString.latin1()) );
             break;
         case PlaylistItem::Artist:
-            mb.setArtist( m_newTagString );
+            if(getenv("AMAROK_ORIG")=="1")
+                mb.setArtist( m_newTagString );
+            else
+                mb.setArtist( QString::fromLocal8Bit(m_newTagString.latin1()) );
             break;
         case PlaylistItem::Composer:
             if ( !mb.hasExtendedMetaInformation() )
@@ -4910,7 +4916,10 @@
             mb.setBpm( m_newTagString.toFloat() );
             break;
         case PlaylistItem::Album:
-            mb.setAlbum( m_newTagString );
+            if(getenv("AMAROK_ORIG")=="1")
+                mb.setAlbum( m_newTagString );
+            else
+                mb.setAlbum( QString::fromLocal8Bit(m_newTagString.latin1()) );
             break;
         case PlaylistItem::Year:
             mb.setYear( m_newTagString.toInt() );
@@ -4919,10 +4928,16 @@
             //FIXME how does this work for vorbis files?
             //Are we likely to overwrite some other comments?
             //Vorbis can have multiple comment fields..
-            mb.setComment( m_newTagString );
+            if(getenv("AMAROK_ORIG")=="1")
+                mb.setComment( m_newTagString );
+            else
+                mb.setComment( QString::fromLocal8Bit(m_newTagString.latin1()) );
             break;
         case PlaylistItem::Genre:
-            mb.setGenre( m_newTagString );
+            if(getenv("AMAROK_ORIG")=="1")
+                mb.setGenre( m_newTagString );
+            else
+                mb.setGenre( QString::fromLocal8Bit(m_newTagString.latin1()) );
             break;
         case PlaylistItem::Track:
             mb.setTrack( m_newTagString.toInt() );
diff -Nur amarok-1.4.7/amarok/src/tagdialog.cpp amarok-1.4.7locale/amarok/src/tagdialog.cpp
--- amarok-1.4.7/amarok/src/tagdialog.cpp    2007-08-08 01:48:28.000000000 +0800
+++ amarok-1.4.7locale/amarok/src/tagdialog.cpp    2007-08-24 19:50:29.000000000 +0800
@@ -19,6 +19,21 @@
 #include "trackpickerdialog.h"
 
 #include <taglib/tfile.h> //TagLib::File::isWritable
+#include <taglib/fileref.h>
+#include <taglib/id3v1genres.h> //used to load genre list
+#include <taglib/mpegfile.h>
+#include <taglib/tag.h>
+#include <taglib/tstring.h>
+#include <taglib/id3v2tag.h>
+#include <taglib/id3v1tag.h>
+#include <taglib/xiphcomment.h>
+#include <taglib/mpegfile.h>
+#include <taglib/oggfile.h>
+#include <taglib/vorbisfile.h>
+#include <taglib/flacfile.h>
+#include <taglib/textidentificationframe.h>
+#include <taglib/xiphcomment.h>
+#include <taglib/tbytevector.h>
 
 #include <qdom.h>
 #include <qfile.h>
@@ -1415,26 +1430,70 @@
 bool
 TagDialog::writeTag( MetaBundle &mb, bool updateCB )
 {
-    QCString path = QFile::encodeName( mb.url().path() );
-    if ( !TagLib::File::isWritable( path ) ) {
-        Amarok::StatusBar::instance()->longMessage( i18n(
-           "The file %1 is not writable." ).arg( mb.url().fileName() ), KDE::StatusBar::Error );
-        return false;
-    }
-
-    //visual feedback
-    QApplication::setOverrideCursor( KCursor::waitCursor() );
+    #define QStringToCJKTString(s) TagLib::String(s.local8Bit().data(), TagLib::String::Latin1)
+    if(getenv("AMAROK_ORIG")=="1")
+        {
+            QCString path = QFile::encodeName( mb.url().path() );
+            if ( !TagLib::File::isWritable( path ) ) {
+                Amarok::StatusBar::instance()->longMessage( i18n(
+                   "The file %1 is not writable." ).arg( mb.url().fileName() ), KDE::StatusBar::Error );
+                return false;
+            }
+
+            //visual feedback
+            QApplication::setOverrideCursor( KCursor::waitCursor() );
+
+            bool result = mb.save();
+            mb.updateFilesize();
+
+            if( result )
+                //update the collection db
+                CollectionDB::instance()->updateTags( mb.url().path(), mb, updateCB );
 
-    bool result = mb.save();
-    mb.updateFilesize();
+            QApplication::restoreOverrideCursor();
 
-    if( result )
-        //update the collection db
-        CollectionDB::instance()->updateTags( mb.url().path(), mb, updateCB );
+            return result;
+        }
+    else
+        {
+            //Set default codec to UTF-8 (see bugs 111246 and 111232)
+            TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding(TagLib::String::UTF8);
 
-    QApplication::restoreOverrideCursor();
+            QCString path = QFile::encodeName( mb.url().path() );
+                if ( !TagLib::File::isWritable( path ) )
+                {
+                    Amarok::StatusBar::instance()->longMessage( i18n(
+                    "TagLib claims %1 file is not writable." ).arg( path ), KDE::StatusBar::Error );
+
+                return false;
+                }
+
+            TagLib::FileRef f( path, false );
+
+            if ( !f.isNull() )
+                {
+                    //visual feedback
+                    QApplication::setOverrideCursor( KCursor::waitCursor() );
+                    TagLib::Tag * t = f.tag();
+                    t->setTitle( QStringToCJKTString( mb.title() ) );
+                    t->setArtist( QStringToCJKTString( mb.artist().string() ) );
+                    t->setAlbum( QStringToCJKTString( mb.album().string() ) );
+                    t->setTrack( mb.track() );
+                    t->setYear( mb.year());
+                    t->setComment( QStringToCJKTString( mb.comment().string() ) );
+                    t->setGenre( QStringToCJKTString( mb.genre().string() ) );
+                    bool result = f.save();
+                    if( result )
+                        //update the collection db
+                        CollectionDB::instance()->updateTags( mb.url().path(), mb, updateCB );
+
+                        QApplication::restoreOverrideCursor();
+
+                    return result;
+                }
+    else return false;
+        }
 
-    return result;
 }
 
 TagDialogWriter::TagDialogWriter( const QMap<QString, MetaBundle> tagsToChange )

  评论这张
 
阅读(617)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017