From e66f99fe6f71ed517bf23fe6f4a465e0b1dff0db Mon Sep 17 00:00:00 2001 From: LarsAC Date: Thu, 26 Aug 2004 11:11:42 +0000 Subject: Import changed to use taglib git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk@120 e10066b5-e1e2-0310-b819-94efdf66514b --- muggle-plugin/TODO | 36 ++++++-- muggle-plugin/mugglei.c | 215 ++++++++++++++++++++---------------------------- 2 files changed, 118 insertions(+), 133 deletions(-) diff --git a/muggle-plugin/TODO b/muggle-plugin/TODO index 509d3cb..c2582ad 100644 --- a/muggle-plugin/TODO +++ b/muggle-plugin/TODO @@ -3,12 +3,9 @@ TODO File for Muggle Testing/bugs ============ -- Save/load playlists to database -- Export playlists -- Execute playlist commands -- Check play speed -- Playlists starts with 2nd song -- Check for getSourceFile +- Test execution of playlist commands +- Test mgPCMPlayer::getSourceFile() for GD case (find) +- Test saving/loading playlists to database Code polishing ============== @@ -16,7 +13,13 @@ Code polishing - Why do filters use pointers? - Check for (reasonably) consistent usage of char*/string - mgDatabase is not used? + - should handle a static object with a MySQL connection + - execute queries? + - + - mgPlayer used what for? + - Could save IP/host name and associate last playlist loaded + - Check for unnecessary log commands - Generate HTML documentation using doxygen, use dotty/gv for state machines of player @@ -25,6 +28,7 @@ Code polishing Short term items ================ - Import existing m3u playlists (in import) +- Import genres OSD in general -------------- @@ -47,7 +51,11 @@ Player Medium term items ================= - really abstract from specific queries etc. -- mgDatabase should abstract database (mySQL) stuff!? +- mgDatabase should completely abstract database (mySQL) stuff!? + - read/write queries + - return results (needs a homogeneous representation of results?) + +- Run import/update from within OSD? OSD --- @@ -57,13 +65,19 @@ OSD Content ------- - Save/load filter sets -- Apply filter set as dynamic playlist +- Apply filter set as dynamic playlist (i.e. show filters when loading playlists) +- Handle ratings (increase/decrease during replay) Player ------ - Shuffle: toggle and loop keys. Shuffle only songs not already played, not easy though - Display covers as still pictures - Add flac decoder +- Set ratings + +Import +------ +- Handle updates Web interface ------------- @@ -85,6 +99,9 @@ Visions Already Done ============ +- Check play speed (probably XINE related) +- Playlists starts with 2nd song (DONE) +- Export playlists - Delete selected item - Add command line option for top level directory - prepended to filename in non-GD-mode @@ -106,6 +123,9 @@ Already Done ************************************************************ * * $Log: TODO,v $ +* Revision 1.12 2004/08/26 11:11:42 LarsAC +* Import changed to use taglib +* * Revision 1.11 2004/07/29 06:18:07 lvw * Added todo entries * diff --git a/muggle-plugin/mugglei.c b/muggle-plugin/mugglei.c index bdfd765..b6cdb31 100755 --- a/muggle-plugin/mugglei.c +++ b/muggle-plugin/mugglei.c @@ -1,12 +1,16 @@ + #include using namespace std; #include - +#include #include -#include + #include +#include +#include + #include "mg_tools.h" MYSQL *db; @@ -47,7 +51,7 @@ time_t get_db_modification_time( long uid ) { time_t mt; - MYSQL_RES *result = mgSqlReadQuery( db, "SELECT modification_time FROM tracks WHERE id='%d'", uid ); + MYSQL_RES *result = mgSqlReadQuery( db, "SELECT modification_time FROM tracks WHERE id=\"%d\"", uid ); MYSQL_ROW row = mysql_fetch_row( result ); string mod_time = row[0]; @@ -58,7 +62,7 @@ time_t get_db_modification_time( long uid ) long find_file_in_database( string filename ) { - MYSQL_RES *result = mgSqlReadQuery( db, "SELECT id FROM tracks WHERE mp3file='%s'", filename.c_str() ); + MYSQL_RES *result = mgSqlReadQuery( db, "SELECT id FROM tracks WHERE mp3file=\"%s\"", filename.c_str() ); MYSQL_ROW row = mysql_fetch_row( result ); // obtain ID and return @@ -68,130 +72,94 @@ long find_file_in_database( string filename ) // read tags from the mp3 file and store them into the corresponding database entry void update_db( long uid, string filename ) { - char title[1024], album[1024], year[5], artist[1024], cddbid[20], trackno[5]; - ID3_Tag filetag( filename.c_str() ); - - printf( "ID3 tag created.\n" ); - - // obtain album value - ID3_Frame* album_frame = filetag.Find( ID3FID_ALBUM ); - printf( "Album frame obtained.\n" ); - if( NULL != album_frame ) - { - album_frame->Field( ID3FN_TEXT ).Get( album, 1024 ); - printf( "Field obtained: %s\n", album ); - } - else - { - printf( "No album info found.\n" ); - strncpy( album, "Unassigned", 1023 ); - } + // char title[1024], album[1024], year[5], artist[1024], cddbid[20], trackno[5]; + TagLib::String title, album, artist, genre; + uint trackno, year; + string cddbid; - printf( "Album frame evaluated.\n" ); + // ID3_Tag filetag( filename.c_str() ); + TagLib::FileRef f( filename.c_str() ); - // obtain title value - ID3_Frame* title_frame = filetag.Find( ID3FID_TITLE ); - if( NULL != title_frame ) - { - title_frame->Field ( ID3FN_TEXT ).Get ( title, 1024 ); - printf( "Field obtained: %s\n", title); - } - else + if( !f.isNull() && f.tag() ) { - printf( "No title info found.\n" ); - strncpy( title, "Unknown title", 1023); - } - - printf( "Title frame evaluated.\n" ); - - // obtain year value (ID3FID_YEAR) - ID3_Frame* year_frame = filetag.Find( ID3FID_YEAR ); - if( NULL != year_frame ) - { - year_frame->Field ( ID3FN_TEXT ).Get ( year, 5 ); - printf( "Field obtained: %s\n", year ); - } - else - { - printf( "No year info found.\n" ); - strncpy( title, "0", 1023); - } - - printf( "Year frame evaluated.\n" ); - - // obtain artist value (ID3FID_LEADARTIST) - ID3_Frame* artist_frame = filetag.Find( ID3FID_LEADARTIST ); - if( NULL != artist_frame ) - { - artist_frame->Field ( ID3FN_TEXT ).Get ( artist, 1023 ); - printf( "Field obtained: \n" ); - } - else - { - printf( "No artist info found.\n" ); - strncpy( artist, "Unknown artist", 1023); - } - - printf( "Artist frame evaluated.\n" ); - - // obtain track number ID3FID_TRACKNUM - ID3_Frame* trackno_frame = filetag.Find( ID3FID_TRACKNUM ); - if( NULL != trackno_frame ) - { - trackno_frame->Field ( ID3FN_TEXT ).Get ( trackno, 5 ); - printf( "Field obtained: %s\n", trackno ); - } - else - { - strncpy( trackno, "0", 5); - } - - printf( "Trackno frame evaluated.\n" ); - - printf( "ID3 frames/fields read.\n" ); - - // obtain associated album or create - if( NULL == album_frame ) - { // no album found, associate with default album - strcpy( cddbid, "0000unknown0000" ); - } - else - { // album tag found, associate or create - MYSQL_RES *result = mgSqlReadQuery( db, "SELECT cddbid FROM album WHERE title='%s' AND artist='%s'", - album, artist ); - MYSQL_ROW row = mysql_fetch_row( result ); - printf( "\nAlbum query set.\n" ); - - // num rows == 0 ? - int nrows = mysql_num_rows(result); - if( nrows == 0 ) - { - // create new album entry - long id = random(); - snprintf( cddbid, 19, "%d-%s", id, album ); + cout << "Evaluating " << filename << endl; + TagLib::Tag *tag = f.tag(); + + // obtain tag information + title = tag->title(); + album = tag->album(); + year = tag->year(); + artist = tag->artist(); + trackno = tag->track(); + genre = tag->genre(); + + // TODO: CD identifier (?), playcounter, popularimeter?, volume adjustment + + // finally update the database + + // obtain associated album or create + if( album == "" ) + { // no album found, associate with default album + cddbid = "0000unknown0000"; + } + else + { // album tag found, associate or create + MYSQL_RES *result = mgSqlReadQuery( db, "SELECT cddbid FROM album WHERE title=\"%s\" AND artist=\"%s\"", + album.toCString(), artist.toCString() ); + MYSQL_ROW row = mysql_fetch_row( result ); + + // num rows == 0 ? + int nrows = mysql_num_rows(result); + if( nrows == 0 ) + { + // create new album entry + long id = random(); + char *buf; + asprintf( &buf, "%d-%s", id, album.toCString() ); + cddbid = buf; + free( buf ); - mgSqlWriteQuery( db, "INSERT INTO album (artist,title,cddbid) VALUES ('%s', '%s', '%s')", artist, title, cddbid ); + mgSqlWriteQuery( db, "INSERT INTO album (artist,title,cddbid) VALUES (\"%s\", \"%s\", \"%s\")", artist.toCString(), album.toCString(), cddbid.c_str() ); + } + else + { // use first album found as source id for the track + cddbid = row[0]; + } + } + + // update tracks table + if( uid > 0 ) + { // the entry is known to exist already, hence update it + mgSqlWriteQuery( db, "UPDATE tracks SET artist=\"%s\", title=\"%s\", year=\"%s\", sourceid=\"%s\", mp3file=\"%s\"" + "WHERE id=%d", artist.toCString(), title.toCString(), year, cddbid.c_str(), filename.c_str(), uid ); } else - { // use first album found as source id for the track - strncpy( cddbid, row[0], 19 ); + { // the entry does not exist, create it + // int t = title.find( "'" ); + // int a = artist.find( "'" ); + mgSqlWriteQuery( db, + "INSERT INTO tracks (artist,title,year,sourceid,tracknb,mp3file)" + " VALUES (\"%s\", \"%s\", %d, \"%s\", %d, \"%s\")", + artist.toCString(), title.toCString(), year, cddbid.c_str(), trackno, filename.c_str() ); + /* + if( !( t > 0 || a > 0 ) ) + { + } + else + { + cout << filename << " skipped." << endl; + cout << "-- TAG --" << endl; + cout << "title - \"" << tag->title() << "\"" << endl; + cout << "artist - \"" << tag->artist() << "\"" << endl; + cout << "album - \"" << tag->album() << "\"" << endl; + cout << "year - \"" << tag->year() << "\"" << endl; + cout << "comment - \"" << tag->comment() << "\"" << endl; + cout << "track - \"" << tag->track() << "\"" << endl; + cout << "genre - \"" << tag->genre() << "\"" << endl; + } + */ } } - - // TODO: genre(s), CD identifier (?), playcounter, popularimeter?, volume adjustment - - // finally update the database - - // update tracks table - if( uid > 0 ) - { // the entry is known to exist already, hence update it - mgSqlWriteQuery( db, "UPDATE tracks SET artist='%s', title='%s', year='%s', sourceid='%s'" - "WHERE id=%d", artist, title, year, cddbid, uid ); - } - else - { // the entry does not exist, create it - mgSqlWriteQuery( db, "INSERT INTO tracks (artist,title,year,sourceid,tracknb,mp3file) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')", artist, title, year, cddbid, trackno, filename.c_str() ); - } } void update_tags( long uid, string filename ) @@ -237,24 +205,21 @@ void evaluate_file( string filename ) int main( int argc, char *argv[] ) { - /* host = "134.130.124.222"; user = "root"; dbname = "giantdisc"; pass = NULL; - */ + /* host = "localhost"; user = "vdr"; dbname = "GiantDisc"; pass = NULL; + */ int res = init_database(); - printf( "Database initialized.\n" ); - if( !res ) { - printf( "Evaluating %s\n", argv[1] ); update_db( 0, string( argv[1] ) ); } else -- cgit v1.2.3