[mythtv] mythvideo-scan - how to develop an application against a
plugin library?
Paul Koster
mythtv at kosteronline.net
Sun Jan 16 17:34:33 EST 2005
Attached is a small application for MythVideo that allows updating the
videos for MythVideo from the command line (e.g. cron for
backend+frontend and in frontend startup-script for dedicated
frontends), because regularly new videos become available in the video
directory, which now gives quite a burden because new files are indexed
by going to the Myth configuration settings (same holds for MythMusic).
Proof of concept code is attached, but there are a number of open
questions.
Would the application as such be accepted for inclusion with the
MythTV distribution?
How to link properly against the Myth base libraries since they all
seem to have a version number in them?
How to link the application run-time against the mythvideo library?
This is a bit complicated since the mythvideo library is put in the
plugin directory which is not by default in the search path.
--
Paul
-------------- next part --------------
Index: mythvideo.pro
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo.pro,v
retrieving revision 1.2
diff -u -d -r1.2 mythvideo.pro
--- mythvideo.pro 7 Sep 2003 21:16:14 -0000 1.2
+++ mythvideo.pro 16 Jan 2005 22:18:33 -0000
@@ -5,4 +5,4 @@
TEMPLATE = subdirs
# Directories
-SUBDIRS = mythvideo i18n
+SUBDIRS = mythvideo mythvideo-scan i18n
Index: mythvideo/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/main.cpp,v
retrieving revision 1.39
diff -u -d -r1.39 main.cpp
--- mythvideo/main.cpp 25 Nov 2004 11:29:10 -0000 1.39
+++ mythvideo/main.cpp 16 Jan 2005 22:18:33 -0000
@@ -42,7 +42,7 @@
void runMenu(QString, const QString &);
void VideoCallback(void *, QString &);
-void SearchDir(QSqlDatabase *, QString &);
+void SearchDir(QSqlDatabase *, QString &, bool);
void BuildFileList(QSqlDatabase *, QString &, VideoLoadedMap &, QStringList &);
extern "C" {
@@ -223,7 +223,7 @@
{
QString startdir = gContext->GetSetting("VideoStartupDir",
"/share/Movies/dvd");
- SearchDir(QSqlDatabase::database(), startdir);
+ SearchDir(QSqlDatabase::database(), startdir, true);
VideoManager *manage = new VideoManager(QSqlDatabase::database(),
gContext->GetMainWindow(),
@@ -346,7 +346,7 @@
}
}
-void SearchDir(QSqlDatabase *db, QString &directory)
+void SearchDir(QSqlDatabase *db, QString &directory, bool gui)
{
VideoLoadedMap video_files;
VideoLoadedMap::Iterator iter;
@@ -358,7 +358,7 @@
int counter = 0;
- MythProgressDialog *file_checking =
+ MythProgressDialog *file_checking = !gui ? NULL :
new MythProgressDialog(QObject::tr("Searching for video files"),
query.numRowsAffected());
@@ -374,16 +374,19 @@
else
video_files[name] = kDatabase;
}
- file_checking->setProgress(++counter);
+ if(gui)
+ file_checking->setProgress(++counter);
}
}
- file_checking->Close();
- delete file_checking;
+ if(gui) {
+ file_checking->Close();
+ delete file_checking;
- file_checking =
- new MythProgressDialog(QObject::tr("Updating video database"),
- video_files.size());
+ file_checking =
+ new MythProgressDialog(QObject::tr("Updating video database"),
+ video_files.size());
+ }
Metadata *myNewFile = NULL;
@@ -415,10 +418,13 @@
query.exec(querystr);
}
- file_checking->setProgress(++counter);
+ if(gui)
+ file_checking->setProgress(++counter);
+ }
+ if(gui) {
+ file_checking->Close();
+ delete file_checking;
}
- file_checking->Close();
- delete file_checking;
}
bool IgnoreExtension(QSqlDatabase *db, QString extension)
-------------- next part --------------
include ( ../settings.pro )
#TODO: get LIBVERSION from somewhere instead of defining it here
LIBVERSION = 0.16
TEMPLATE = app
TARGET = mythvideo-scan
target.path = $${PREFIX}/bin
INSTALLS += target
LIBS += -L../../libs/libmythtv
LIBS += -L../mythvideo
LIBS += -lmyth-$$LIBVERSION $$EXTRA_LIBS
LIBS += -lmythvideo
SOURCES += main.cpp
-------------- next part --------------
//TODO: copyright and license notice
#include <qapplication.h>
#include <qsqldatabase.h>
#include <mythtv/mythcontext.h>
void SearchDir(QSqlDatabase *, QString &, bool);
int main(int argc, char **argv)
{
QApplication a(argc, argv, false);
gContext = new MythContext(MYTH_BINARY_VERSION, false);
QSqlDatabase *db = QSqlDatabase::addDatabase("QMYSQL3");
if (!db)
{
cerr << "Couldn't connect to database" << endl;
return -1;
}
if (!gContext->OpenDatabase(db))
{
cerr << "couldn't open db" << endl;
return -1;
}
QString startdir = gContext->GetSetting("VideoStartupDir");
if( startdir.isEmpty() ) {
cerr << "No VideoStartupDir configured for MythVideo." << endl;
return -1;
} else {
SearchDir(QSqlDatabase::database(), startdir, false);
}
return 0;
}
More information about the mythtv-dev
mailing list