diff options
author | wr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-03-01 18:32:30 +0000 |
---|---|---|
committer | wr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-03-01 18:32:30 +0000 |
commit | e395c75e0aabea55a4c39440da306ef43ca969c5 (patch) | |
tree | 4e9ce9e919a2c96eb0206c2befc04abe03e3a1c8 | |
parent | 6d50a31dc66fadb6b8d4689e6cc229076090b127 (diff) | |
download | vdr-plugin-muggle-e395c75e0aabea55a4c39440da306ef43ca969c5.tar.gz vdr-plugin-muggle-e395c75e0aabea55a4c39440da306ef43ca969c5.tar.bz2 |
mugglei -c works, mugglei -v, remove option -f, instead any number of files/directories can be specified
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/branches/0.1.3-wr@524 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r-- | mg_mysql.c | 94 | ||||
-rw-r--r-- | mg_mysql.h | 4 | ||||
-rw-r--r-- | mg_selection.h | 8 | ||||
-rw-r--r-- | mg_sync.c | 42 | ||||
-rw-r--r-- | mg_sync.h | 7 | ||||
-rwxr-xr-x | mugglei.c | 28 | ||||
-rw-r--r-- | vdr_actions.c | 2 |
7 files changed, 124 insertions, 61 deletions
@@ -20,10 +20,12 @@ static bool needGenre2_set; char *db_cmds[] = { - "DROP DATABASE IF EXISTS GiantDisc; CREATE DATABASE GiantDisc;", + "DROP DATABASE IF EXISTS GiantDisc", + "CREATE DATABASE GiantDisc", "grant all privileges on GiantDisc.* to vdr@localhost;", "use GiantDisc;", - "drop table if exists album; CREATE TABLE album ( " + "drop table if exists album;", + "CREATE TABLE album ( " "artist varchar(255) default NULL, " "title varchar(255) default NULL, " "cddbid varchar(20) NOT NULL default '', " @@ -37,25 +39,29 @@ char *db_cmds[] = "KEY genre (genre), " "KEY modified (modified)) " "TYPE=MyISAM;", - "drop table if exists genre; CREATE TABLE genre (" + "drop table if exists genre;", + "CREATE TABLE genre (" "id varchar(10) NOT NULL default '', " "id3genre smallint(6) default NULL, " "genre varchar(255) default NULL, " "freq int(11) default NULL, " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists language; CREATE TABLE language (" + "drop table if exists language;", + "CREATE TABLE language (" "id varchar(4) NOT NULL default '', " "language varchar(40) default NULL, " "freq int(11) default NULL, " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists musictype; CREATE TABLE musictype (" + "drop table if exists musictype;", + "CREATE TABLE musictype (" "musictype varchar(40) default NULL, " "id tinyint(3) unsigned NOT NULL auto_increment, " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists player;CREATE TABLE player ( " + "drop table if exists player;", + "CREATE TABLE player ( " "ipaddr varchar(255) NOT NULL default '', " "uichannel varchar(255) NOT NULL default '', " "logtarget int(11) default NULL, " @@ -66,7 +72,8 @@ char *db_cmds[] = "id int(11) NOT NULL default '0', " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists playerstate;CREATE TABLE playerstate ( " + "drop table if exists playerstate;", + "CREATE TABLE playerstate ( " "playerid int(11) NOT NULL default '0', " "playertype int(11) NOT NULL default '0', " "snddevice varchar(255) default NULL, " @@ -83,7 +90,8 @@ char *db_cmds[] = "anchortime bigint(20) default NULL, " "PRIMARY KEY (playerid,playertype)) " "TYPE=HEAP;", - "drop table if exists playlist;CREATE TABLE playlist ( " + "drop table if exists playlist;", + "CREATE TABLE playlist ( " "title varchar(255) default NULL, " "author varchar(255) default NULL, " "note varchar(255) default NULL, " @@ -91,19 +99,22 @@ char *db_cmds[] = "id int(10) unsigned NOT NULL auto_increment, " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists playlistitem;CREATE TABLE playlistitem ( " + "drop table if exists playlistitem;", + "CREATE TABLE playlistitem ( " "playlist int(11) NOT NULL default '0', " "tracknumber mediumint(9) NOT NULL default '0', " "trackid int(11) default NULL, " "PRIMARY KEY (playlist,tracknumber)) " "TYPE=MyISAM;", - "drop table if exists playlog;CREATE TABLE playlog ( " + "drop table if exists playlog;", + "CREATE TABLE playlog ( " "trackid int(11) default NULL, " "played date default NULL, " "id tinyint(3) unsigned NOT NULL auto_increment, " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists recordingitem;CREATE TABLE recordingitem ( " + "drop table if exists recordingitem;", + "CREATE TABLE recordingitem ( " "trackid int(11) default NULL, " "recdate date default NULL, " "rectime time default NULL, " @@ -117,19 +128,22 @@ char *db_cmds[] = "id int(11) NOT NULL default '0', " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists source; CREATE TABLE source ( " + "drop table if exists source", + "CREATE TABLE source ( " "source varchar(40) default NULL, " "id tinyint(3) unsigned NOT NULL auto_increment, " "PRIMARY KEY (id)) " "TYPE=MyISAM;", - "drop table if exists tracklistitem;CREATE TABLE tracklistitem ( " + "drop table if exists tracklistitem;", + "CREATE TABLE tracklistitem ( " "playerid int(11) NOT NULL default '0', " "listtype smallint(6) NOT NULL default '0', " "tracknb int(11) NOT NULL default '0', " "trackid int(11) NOT NULL default '0', " "PRIMARY KEY (playerid,listtype,tracknb)) " "TYPE=MyISAM;", - "drop table if exists tracks;CREATE TABLE tracks ( " + "drop table if exists tracks;", + "CREATE TABLE tracks ( " "artist varchar(255) default NULL, " "title varchar(255) default NULL, " "genre1 varchar(10) default NULL, " @@ -178,6 +192,7 @@ char *db_cmds[] = mgmySql::mgmySql() { m_db = 0; + m_database_found=false; m_hasfolderfields=false; Connect(); } @@ -197,7 +212,7 @@ mgmySql::exec_sql( string query) { if (!m_db || query.empty()) return 0; - mgDebug(3,"exec_sql(%X,%s)",m_db,query.c_str()); + mgDebug(4,"exec_sql(%X,%s)",m_db,query.c_str()); if (mysql_query (m_db, (query + ';').c_str ())) { mgError("SQL Error in %s: %s",query.c_str(),mysql_error (m_db)); @@ -235,11 +250,14 @@ mgmySql::exec_count( const string query) void mgmySql::Create() { // create database and tables + mgDebug(1,"Dropping and recreating database %s",the_setup.DbName); int len = sizeof( db_cmds ) / sizeof( char* ); for( int i=0; i < len; i ++ ) { exec_sql( string( db_cmds[i] ) ); } + m_database_found=true; + Use(); } string @@ -282,6 +300,12 @@ mgmySql::sql_Cstring( const char *s, char *buf) return b; } +bool +mgmySql::Connected () const +{ + return m_database_found; +} + void mgmySql::Connect () { @@ -297,31 +321,29 @@ mgmySql::Connect () bool success; if (the_setup.DbSocket != NULL) { - mgDebug(1,"Using socket %s for connecting to Database %s as user %s.", + mgDebug(1,"Using socket %s for connecting to server as user %s.", the_setup.DbSocket, - the_setup.DbName, the_setup.DbUser); mgDebug(3,"DbPassword is: '%s'",the_setup.DbPass); success = (mysql_real_connect( m_db, "", the_setup.DbUser, the_setup.DbPass, - the_setup.DbName, + 0, 0, the_setup.DbSocket, 0 ) != 0 ); } else { - mgDebug(1,"Using TCP-%s for connecting to Database %s as user %s.", + mgDebug(1,"Using TCP for connecting to server %s as user %s.", the_setup.DbHost, - the_setup.DbName, the_setup.DbUser); mgDebug(3,"DbPassword is: '%s'",the_setup.DbPass); success = ( mysql_real_connect( m_db, the_setup.DbHost, the_setup.DbUser, the_setup.DbPass, - the_setup.DbName, + 0, the_setup.DbPort, 0, 0 ) != 0 ); } @@ -332,7 +354,26 @@ mgmySql::Connect () mysql_close (m_db); m_db = 0; } - if (!needGenre2_set && m_db) + if (m_db) + { + mysql_query(m_db,"SHOW DATABASES"); + MYSQL_RES * rows = mysql_store_result(m_db); + if (rows) + { + MYSQL_ROW row; + while ((row = mysql_fetch_row (rows)) != 0) + if (!strcmp(row[0],the_setup.DbName)) + { + m_database_found=true; + break; + } + } + if (m_database_found) + Use(); + else + mgWarning("Database %s does not exist",the_setup.DbName); + } + if (!needGenre2_set && Connected()) { needGenre2_set=true; needGenre2=exec_count("SELECT COUNT(DISTINCT genre2) from tracks")>1; @@ -341,6 +382,15 @@ mgmySql::Connect () } void +mgmySql::Use() +{ + char b[100]; + sprintf(b,"USE %s;",the_setup.DbName); + mysql_query(m_db,b); + mgDebug(1,"found database %s",the_setup.DbName); +} + +void mgmySql::CreateFolderFields() { if (!Connected()) @@ -55,15 +55,17 @@ class mgmySql long thread_id() { return mysql_thread_id(m_db);} long affected_rows() { return mysql_affected_rows(m_db);} - bool Connected() const { return m_db;} + bool Connected() const; bool HasFolderFields() const { return m_hasfolderfields;} void Connect(); + void Use(); //! \brief create database and tables void Create(); void CreateFolderFields(); private: MYSQL *m_db; + bool m_database_found; bool m_hasfolderfields; }; diff --git a/mg_selection.h b/mg_selection.h index 7ad6648..ff6b288 100644 --- a/mg_selection.h +++ b/mg_selection.h @@ -302,14 +302,6 @@ class mgSelection */ string exportM3U (); - /*! import/export tags like - * \par path can be a file or a directory. If directory, - * sync all files within - * \par assorted see mugglei -h - * \par delete_missing if the file does not exist, delete the - * data base entry. If the file is unreadable, do not delete. - */ - void Sync(const char * path, bool assorted=false,bool delete_missing=false); /*! \brief go to a position in the current level. If we are at the * most detailled level this also sets the track position since @@ -132,7 +132,9 @@ mgSync::getAlbum(const char *c_album,const char *c_artist,const char *c_director mgSync::mgSync() { - m_genre_rows = m_db.exec_sql ("SELECT id,genre from genre"); + if (!m_db.Connected()) + return; + m_genre_rows = m_db.exec_sql ("SELECT id,genre from genre"); MYSQL_ROW rx; while ((rx = mysql_fetch_row (m_genre_rows)) != 0) m_Genres[rx[1]]=rx[0]; @@ -281,7 +283,7 @@ mgSync::SyncFile(const char *filename) } void -mgSync::Sync(const char * path, bool delete_missing) +mgSync::Sync(char * const * path_argv, bool delete_missing) { if (!m_db.Connected()) { @@ -297,21 +299,27 @@ mgSync::Sync(const char * path, bool delete_missing) chdir(the_setup.ToplevelDir); FTS *fts; FTSENT *ftsent; - const char * paths[2]; - paths[0]=path; - paths[1]=0; - fts = fts_open( const_cast<char *const *>(paths), FTS_LOGICAL, 0); - while ( (ftsent = fts_read(fts)) != NULL) + fts = fts_open( path_argv, FTS_LOGICAL, 0); + if (fts) { - if (!((ftsent->fts_statp->st_mode)||S_IFREG)) - continue; - char *extension = strrchr(ftsent->fts_path,'.'); - if (!extension) - continue; - strcpy(c_extension,extension+1); - lower(c_extension); - if (!strcmp(c_extension,"flac") || !strcmp(c_extension,"ogg") || !strcmp(c_extension,"mp3")) - SyncFile(ftsent->fts_path); + while ( (ftsent = fts_read(fts)) != NULL) + { + if (!((ftsent->fts_statp->st_mode)||S_IFREG)) + continue; + char *extension = strrchr(ftsent->fts_path,'.'); + if (!extension) + continue; + strcpy(c_extension,extension+1); + lower(c_extension); + if (!strcmp(c_extension,"flac") || !strcmp(c_extension,"ogg") || !strcmp(c_extension,"mp3")) + SyncFile(ftsent->fts_path); + } + fts_close(fts); } - fts_close(fts); +} + +void +mgSync::Create() +{ + m_db.Create(); } @@ -23,14 +23,17 @@ class mgSync public: mgSync(); ~mgSync(); - /*! import/export tags like + //! \brief drop and create the data base GiantDisc + void Create(); + + /*! \brief import/export tags like * \par path can be a file or a directory. If directory, * sync all files within * \par assorted see mugglei -h * \par delete_missing if the file does not exist, delete the * data base entry. If the file is unreadable, do not delete. */ - void Sync(const char * path, bool delete_missing=false); + void Sync(char * const * path_argv, bool delete_missing=false); private: mgmySql m_db; @@ -74,7 +74,6 @@ int main( int argc, char *argv[] ) { exit(1); } - char *filename; if( argc < 2 ) { // we need at least a filename! @@ -82,6 +81,12 @@ int main( int argc, char *argv[] ) std::cout << "(C) Lars von Wedel" << std::endl; std::cout << "This is free software; see the source for copying conditions." << std::endl; std::cout << "" << std::endl; + std::cout << "Usage: mugglei [OPTION]... [FILE]..." << std::endl; + std::cout << "" << std::endl; + std::cout << " all FILE arguments will be imported. If they are directories, their content is imported"<< std::endl; + std::cout << "" << std::endl; + std::cout << "Only files ending in .flac, .mp3, .ogg (ignoring case) will be imported" << std::endl; + std::cout << "" << std::endl; std::cout << "Options:" << std::endl; std::cout << " -h <hostname> - specify host of mySql database server (default is 'localhost')" << std::endl; std::cout << " -s <socket> - specify a socket for mySQL communication (default is TCP)" << std::endl; @@ -89,9 +94,10 @@ int main( int argc, char *argv[] ) std::cout << " -u <username> - specify user of mySql database (default is empty)" << std::endl; std::cout << " -p <password> - specify password of user (default is empty password)" << std::endl; std::cout << " -t <topleveldir> - name of music top level directory" << std::endl; - std::cout << " -f <filename> - name of music file or directory to import or update relative to topleveldir" << std::endl; std::cout << " -z - scan all database entries and delete entries for files not found" << std::endl; - std::cout << " -c - create a new database entry deleting existing entries" << std::endl; + std::cout << " -z is not yet implemented" << std::endl; + std::cout << " -c - delete the entire database and recreate a new empty one" << std::endl; + std::cout << " -v - the wanted log level, the higher the more. Default is 1" << std::endl; exit( 1 ); } @@ -100,12 +106,11 @@ int main( int argc, char *argv[] ) import_assorted = false; delete_mode = false; create_mode = false; - filename = ""; // parse command line options while( 1 ) { - int c = getopt(argc, argv, "h:s:n:u:p:t:f:z"); + int c = getopt(argc, argv, "h:s:n:u:p:t:zcv:"); if (c == -1) break; @@ -140,10 +145,6 @@ int main( int argc, char *argv[] ) { the_setup.ToplevelDir = optarg; } break; - case 'f': - { - filename = optarg; - } break; case 'z': { delete_mode = true; @@ -152,11 +153,18 @@ int main( int argc, char *argv[] ) { create_mode = true; } break; + case 'v': + { + mgSetDebugLevel(atol(optarg)); + } break; } } mgSync sync; - sync.Sync(filename,false); + if (create_mode) + sync.Create(); + if (optind<argc) + sync.Sync(argv+optind,delete_mode); return 0; } diff --git a/vdr_actions.c b/vdr_actions.c index 5ba6275..b389e38 100644 --- a/vdr_actions.c +++ b/vdr_actions.c @@ -687,7 +687,7 @@ class mgSync : public mgCommand void mgSync::Execute() { - selection()->Sync("."); + // selection()->Sync("."); } //! \brief sets the default collection selection |