Bug 133931

Summary: No support for %year in "Guess Tags from Filename"
Product: [Applications] amarok Reporter: Carey <amarok>
Component: generalAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Adds %year support to "Guess Tags from Filename"
Adds %year support to "Guess Tags from Filename"
Adds %year support to "Guess Tags from Filename"
Adds %year support to "Guess Tags from Filename"

Description Carey 2006-09-11 20:37:16 UTC
Version:            (using KDE KDE 3.5.4)
Installed from:    Fedora RPMs
Compiler:          gcc 4.1.1 
OS:                Linux

When using the "Guess Tags from Filename" feature to automatically insert ID3 tags into a file, there is currently no support for %year.
Comment 1 Carey 2006-09-11 20:41:24 UTC
Created attachment 17722 [details]
Adds %year support to "Guess Tags from Filename"
Comment 2 Carey 2006-09-11 20:41:49 UTC
Created attachment 17723 [details]
Adds %year support to "Guess Tags from Filename"
Comment 3 Carey 2006-09-11 20:42:12 UTC
Created attachment 17724 [details]
Adds %year support to "Guess Tags from Filename"
Comment 4 Carey 2006-09-11 20:42:32 UTC
Created attachment 17725 [details]
Adds %year support to "Guess Tags from Filename"
Comment 5 Carey 2006-09-11 20:48:48 UTC
This is my first patch ever submitted to an open-source project, so I hope I followed protocol correctly. I'll also be the first to admit that I'm not a very good C programmer, but the above changes did seem to add %year support in the "Guess Tags from Filename" feature, after recompiling. The above patch files were created against Amarok 1.4.3

tagdialog.cpp.patch  
tagguesserconfigdialog.ui.patch  
tagguesser.cpp.patch  
tagguesser.h.patch
Comment 6 Alexandre Oliveira 2006-09-11 22:58:43 UTC
SVN commit 583249 by aoliveira:

Support year in Guess Tags from Filename.
Patch by someone whose email is <amarok@digitalforplay.com>. Thanks.
BUG: 133931


 M  +9 -9      metabundle.h  
 M  +2 -0      tagdialog.cpp  
 M  +14 -1     tagguesser.cpp  
 M  +4 -0      tagguesser.h  
 M  +2 -0      tagguesserconfigdialog.ui  


--- trunk/extragear/multimedia/amarok/src/metabundle.h #583248:583249
@@ -169,7 +169,7 @@
     bool save( TagLib::FileRef* fileref = 0 );
 
     /** Saves the MetaBundle's data as XML to a text stream. */
-    bool save( QTextStream &stream, const QStringList &attributes = QStringList(), int indent = 0 ) const;
+    bool save( QTextStream &stream, const QStringList &attributes = QStringList() ) const;
 
     bool isFile() const;
 
@@ -210,7 +210,7 @@
 
     /** PlaylistItem reimplements this so it can be informed of moodbar
         data events without having to use signals */
-    virtual void moodbarJobEvent( int newState ) 
+    virtual void moodbarJobEvent( int newState )
         { (void) newState; }
 
 public:
@@ -431,18 +431,18 @@
 inline int MetaBundle::filesize()   const { return m_filesize == Undetermined ? 0 : m_filesize; }
 inline int MetaBundle::fileType()   const { return m_type; }
 
-inline Moodbar &MetaBundle::moodbar() 
+inline Moodbar &MetaBundle::moodbar()
 {
-  if( m_moodbar == 0 ) m_moodbar = new Moodbar( this ); 
-  return *m_moodbar; 
+  if( m_moodbar == 0 ) m_moodbar = new Moodbar( this );
+  return *m_moodbar;
 }
 inline const Moodbar &MetaBundle::moodbar_const() const
 {
   // Anyone know of a better way to do this?
-  if( m_moodbar == 0 ) 
-    const_cast<MetaBundle*>(this)->m_moodbar 
-      = new Moodbar( const_cast<MetaBundle*>(this) ); 
-  return *m_moodbar; 
+  if( m_moodbar == 0 )
+    const_cast<MetaBundle*>(this)->m_moodbar
+      = new Moodbar( const_cast<MetaBundle*>(this) );
+  return *m_moodbar;
 }
 
 inline KURL     MetaBundle::url()        const { return m_url; }
--- trunk/extragear/multimedia/amarok/src/tagdialog.cpp #583248:583249
@@ -273,6 +273,8 @@
         kIntSpinBox_track->setValue( guesser.track().toInt() );
     if( !guesser.comment().isNull() )
         kTextEdit_comment->setText( guesser.comment() );
+    if( !guesser.year().isNull() )
+        kIntSpinBox_year->setValue( guesser.year().toInt() );
 }
 
 void
--- trunk/extragear/multimedia/amarok/src/tagguesser.cpp #583248:583249
@@ -26,12 +26,14 @@
     , m_albumField( -1 )
     , m_trackField( -1 )
     , m_commentField( -1 )
+    , m_yearField( -1 )
 {
     int artist  = s.find( "%artist" );
     int title   = s.find( "%title" );
     int track   = s.find( "%track" );
     int album   = s.find( "%album" );
     int comment = s.find( "%comment" );
+    int year    = s.find( "%year" );
 
     int fieldNumber = 1;
     int i = s.find( '%' );
@@ -46,6 +48,8 @@
             m_trackField = fieldNumber++;
         if ( comment == i )
             m_commentField = fieldNumber++;
+        if ( year == i )
+             m_yearField = fieldNumber++;
         i = s.find('%', i + 1);
     }
     m_regExp.setPattern( composeRegExp( s ) );
@@ -96,6 +100,13 @@
     return m_regExp.capturedTexts()[ m_commentField ];
 }
 
+QString FileNameScheme::year() const
+{
+    if( m_yearField == -1 )
+        return QString::null;
+    return m_regExp.capturedTexts()[ m_yearField ];
+}
+
 QString FileNameScheme::composeRegExp( const QString &s ) const
 {
     QMap<QString, QString> substitutions;
@@ -107,6 +118,7 @@
     substitutions[ "album" ] = config.readEntry( "Album regexp", "([\\w\\s'&_,\\.]+)" );
     substitutions[ "track" ] = config.readEntry( "Track regexp", "(\\d+)" );
     substitutions[ "comment" ] = config.readEntry( "Comment regexp", "([\\w\\s_]+)" );
+    substitutions[ "year" ] = config.readEntry( "Year regexp", "(\\d+)" );
 
     QString regExp = QRegExp::escape( s.simplifyWhiteSpace() );
     regExp = ".*" + regExp;
@@ -187,7 +199,7 @@
 
 void TagGuesser::guess( const QString &absFileName )
 {
-    m_title = m_artist = m_album = m_track = m_comment = QString::null;
+    m_title = m_artist = m_album = m_track = m_comment = m_year = QString::null;
 
     FileNameScheme::List::ConstIterator it = m_schemes.begin();
     FileNameScheme::List::ConstIterator end = m_schemes.end();
@@ -200,6 +212,7 @@
             m_album = capitalizeWords( schema.album().replace( '_', " " ) ).stripWhiteSpace();
             m_track = schema.track().stripWhiteSpace();
             m_comment = schema.comment().replace( '_', " " ).stripWhiteSpace();
+            m_year = schema.year().stripWhiteSpace();
             break;
         }
     }
--- trunk/extragear/multimedia/amarok/src/tagguesser.h #583248:583249
@@ -22,6 +22,7 @@
         QString album() const;
         QString track() const;
         QString comment() const;
+        QString year() const;
 
         QString pattern() const { return m_cod; };
     private:
@@ -35,6 +36,7 @@
         int m_albumField;
         int m_trackField;
         int m_commentField;
+        int m_yearField;
 };
 
 class TagGuesser
@@ -56,6 +58,7 @@
         QString album() const { return m_album; }
         QString track() const { return m_track; }
         QString comment() const { return m_comment; }
+        QString year() const { return m_year; }
 
     private:
         void loadSchemes();
@@ -67,6 +70,7 @@
         QString m_album;
         QString m_track;
         QString m_comment;
+        QString m_year;
 };
 
 #endif /* TAGGUESSER_H */
--- trunk/extragear/multimedia/amarok/src/tagguesserconfigdialog.ui #583248:583249
@@ -50,6 +50,7 @@
 &lt;li&gt;%artist: Artist&lt;/li&gt;
 &lt;li&gt;%album: Album&lt;/li&gt;
 &lt;li&gt;%track: Track Number&lt;/li&gt;
+&lt;li&gt;%year: Year&lt;/li&gt;
 &lt;li&gt;%comment: Comment&lt;/li&gt;
 &lt;/ul&gt;
 For example, the file name scheme "[%track] %artist - %title" would match "[01] Deep Purple - Smoke on the water" but not "(Deep Purple) Smoke on the water". For that second name, you would use the scheme "(%artist) %title".&lt;p/&gt;
@@ -61,6 +62,7 @@
 &lt;li&gt;%artist: Artist&lt;/li&gt;
 &lt;li&gt;%album: Album&lt;/li&gt;
 &lt;li&gt;%track: Track Number&lt;/li&gt;
+&lt;li&gt;%year: Year&lt;/li&gt;
 &lt;li&gt;%comment: Comment&lt;/li&gt;
 &lt;/ul&gt;
 For example, the file name scheme "[%track] %artist - %title" would match "[01] Deep Purple - Smoke on the water" but not "(Deep Purple) Smoke on the water". For that second name, you would use the scheme "(%a) %t".&lt;p/&gt;