summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b>2005-01-10 07:30:54 +0000
committerLarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b>2005-01-10 07:30:54 +0000
commit37e5ef3df27d40608d7b34f5fcb09234c7906295 (patch)
treecff7c83e4f08b0b4155206b091d641a29de3ae98
parent6c1699dd3c79d70872d9c4f6a391386e7f5e0f31 (diff)
downloadvdr-plugin-muggle-37e5ef3df27d40608d7b34f5fcb09234c7906295.tar.gz
vdr-plugin-muggle-37e5ef3df27d40608d7b34f5fcb09234c7906295.tar.bz2
Mugglei now provides defaults for missing tags
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@341 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r--README12
-rwxr-xr-xmugglei.c125
2 files changed, 108 insertions, 29 deletions
diff --git a/README b/README
index 1ec00c8..ea2046f 100644
--- a/README
+++ b/README
@@ -34,7 +34,7 @@ parameters are descibed in Section 5.
\section prereq PREREQUISITES
-The plugin is written for VDR 1.2.6. In addition, the following pieces of
+The plugin currently runs on VDR 1.3.7+. In addition, the following pieces of
software are required:
- mySQL server (tested with 4.0.18) (Debian packages mysql-server, mysql-client)
@@ -69,7 +69,7 @@ For example (paths and version numbers may vary)
Establish a symlink as you would for other plugins:
\verbatim
- ln -s muggle-0.1.7 muggle
+ ln -s muggle-0.1.0 muggle
\endverbatim
Within the VDR main directory (e.g. /usr/local/src/VDR) issue
@@ -182,6 +182,14 @@ Speed should not be an issue: on my machine, it takes about 10 secs to run the i
albums with more than 600 tracks. Further 1200 tracks or so require 20 more secs. This depends on machine
configuration, of course.
+If a track has no ID3 tags, the following defaults will be applied:
+
+- Title: Filename will be used
+- Artist: "Unknown"
+- Album: "Unassigned"
+- Track: 0
+- Year: 0
+
\section config MUGGLE CONFIGURATION
Muggle uses a small set of command line parameters in order to control the interaction with the mySQL server.
diff --git a/mugglei.c b/mugglei.c
index 0abc856..7e284d7 100755
--- a/mugglei.c
+++ b/mugglei.c
@@ -5,7 +5,7 @@
* \author Lars von Wedel
*/
-// #define VERBOSE
+#define VERBOSE
#include <string>
#include <stdlib.h>
@@ -45,6 +45,10 @@ MYSQL_RES* mgSqlReadQuery(MYSQL *db, const char *fmt, ...)
{
mgError( "SQL error in MUGGLE:\n%s\n", querybuf );
}
+
+#ifdef VERBOSE
+ std::cout << querybuf << std::endl;
+#endif
MYSQL_RES *result = mysql_store_result(db);
@@ -63,6 +67,10 @@ void mgSqlWriteQuery(MYSQL *db, const char *fmt, ...)
mgError( "SQL error in MUGGLE:\n%s\n", querybuf );
}
+#ifdef VERBOSE
+ std::cout << querybuf << std::endl;
+#endif
+
va_end(ap);
}
@@ -134,14 +142,23 @@ time_t get_db_modification_time( long uid )
TagLib::String escape_string( MYSQL *db, TagLib::String s )
{
- char *buf = strdup( s.toCString() );
- char *escbuf = (char *) malloc( 2*strlen( buf ) + 1 );
+ TagLib::String r;
- mysql_real_escape_string( db, escbuf, s.toCString(), s.size() );
- TagLib::String r = TagLib::String( escbuf );
+ if( !s.isNull() && !s.isEmpty() )
+ {
+ char *buf = strdup( s.toCString() );
+ char *escbuf = (char *) malloc( 2*strlen( buf ) + 1 );
- free( escbuf );
- free( buf);
+ mysql_real_escape_string( db, escbuf, s.toCString(), s.size() );
+ r = TagLib::String( escbuf );
+
+ free( escbuf );
+ free( buf);
+ }
+ else
+ {
+ r = s;
+ }
return r;
}
@@ -193,18 +210,82 @@ void update_db( long uid, std::string filename )
// ID3_Tag filetag( filename.c_str() );
TagLib::FileRef f( filename.c_str() );
- if( !f.isNull() && f.tag() )
+ if( !f.isNull() )
{
- // std::cout << "Evaluating " << filename << std::endl;
+#ifdef VERBOSE
+ std::cout << "Evaluating " << filename << std::endl;
+#endif
TagLib::Tag *tag = f.tag();
+ if( tag )
+ {
+ // obtain tag information
+ title = tag->title();
+ album = tag->album();
+ year = tag->year();
+ artist = tag->artist();
+ trackno = tag->track();
+ genre = tag->genre();
+
+#ifdef VERBOSE
+ std::cout << "-- TAG --" << std::endl;
+ std::cout << "title - '" << tag->title() << "'" << std::endl;
+ std::cout << "artist - '" << tag->artist() << "'" << std::endl;
+ std::cout << "album - '" << tag->album() << "'" << std::endl;
+ std::cout << "year - '" << tag->year() << "'" << std::endl;
+ std::cout << "comment - '" << tag->comment() << "'" << std::endl;
+ std::cout << "track - '" << tag->track() << "'" << std::endl;
+ std::cout << "genre - '" << tag->genre() << "'" << std::endl;
+#endif
+ }
+ else
+ {
+#ifdef VERBOSE
+ std::cerr << "No id3 tag found." << std::endl;
+#endif
+
+ // use basename
+ TagLib::String file( filename.c_str() );
+
+ int pos = title.size();
+ while( pos > 0 && title[pos] != '\\' )
+ {
+ pos --;
+ }
+
+ title = file.substr( pos );
+
+ // will be associated to an Unassigned album for Unknown
+ album = "";
+ artist = "Unknown";
+
+ year = 0;
+ trackno = 0;
+ }
+
+ if( title.isNull() || title.isEmpty() )
+ {
+#ifdef VERBOSE
+ std::cout << "No title tag found." << std::endl;
+#endif
+ // use basename
+ TagLib::String file( filename.c_str() );
+
+ int pos = title.size();
+ while( pos > 0 && title[pos] != '\\' )
+ {
+ pos --;
+ }
+
+ title = file.substr( pos );
+ }
- // obtain tag information
- title = tag->title();
- album = tag->album();
- year = tag->year();
- artist = tag->artist();
- trackno = tag->track();
- genre = tag->genre();
+ if( artist.isNull() || artist.isEmpty() )
+ {
+ artist = "Unknown";
+#ifdef VERBOSE
+ std::cout << "No artist tag found." << std::endl;
+#endif
+ }
TagLib::String gid = find_genre_id( genre );
@@ -223,7 +304,7 @@ void update_db( long uid, std::string filename )
// finally update the database
// obtain associated album or create
- if( album == "" )
+ if( album.isNull() || album.isEmpty() )
{ // no album found, create default album for artist
MYSQL_RES *result = mgSqlReadQuery( db, "SELECT cddbid FROM album WHERE title=\"Unassigned\" AND artist=\"%s\"", artist.toCString() );
MYSQL_ROW row = mysql_fetch_row( result );
@@ -318,16 +399,6 @@ void update_db( long uid, std::string filename )
artist.toCString(), title.toCString(), year, cddbid.toCString(),
trackno, filename.c_str(), len, bitrate, sample, channels, gid.toCString() );
-#ifdef VERBOSE
- std::cout << "-- TAG --" << std::endl;
- std::cout << "title - '" << tag->title() << "'" << std::endl;
- std::cout << "artist - '" << tag->artist() << "'" << std::endl;
- std::cout << "album - '" << tag->album() << "'" << std::endl;
- std::cout << "year - '" << tag->year() << "'" << std::endl;
- std::cout << "comment - '" << tag->comment() << "'" << std::endl;
- std::cout << "track - '" << tag->track() << "'" << std::endl;
- std::cout << "genre - '" << tag->genre() << "'" << std::endl;
-#endif
}
}
}