int main( int argc, char** argv ) { if ( argc < 2 ) { std::cerr << "usage: " << argv[0] << " <entrypoint>" << std::endl; return 1; } auto testCb = std::make_unique<TestCb>(); std::unique_ptr<medialibrary::IMediaLibrary> ml( NewMediaLibrary() ); ml->setVerbosity( medialibrary::LogLevel::Info ); ml->initialize( "/tmp/test.db", "/tmp/ml_thumbnails", testCb.get() ); ml->setDiscoverNetworkEnabled( true ); ml->start(); ml->discover( argv[1] ); auto res = testCb->waitForCompletion(); return res == true ? 0 : 1; }
bool MediaLibrary::Start() { if ( m_ml != nullptr ) return true; std::unique_ptr<medialibrary::IMediaLibrary> ml( NewMediaLibrary() ); m_logger.reset( new Logger( VLC_OBJECT( m_vlc_ml ) ) ); ml->setVerbosity( medialibrary::LogLevel::Info ); ml->setLogger( m_logger.get() ); auto userDir = vlc::wrap_cptr( config_GetUserDir( VLC_USERDATA_DIR ) ); std::string mlDir = std::string{ userDir.get() } + "/ml/"; auto thumbnailsDir = mlDir + "thumbnails/"; auto initStatus = ml->initialize( mlDir + "ml.db", thumbnailsDir, this ); switch ( initStatus ) { case medialibrary::InitializeResult::AlreadyInitialized: msg_Info( m_vlc_ml, "MediaLibrary was already initialized" ); return true; case medialibrary::InitializeResult::Failed: msg_Err( m_vlc_ml, "Medialibrary failed to initialize" ); return false; case medialibrary::InitializeResult::DbReset: msg_Info( m_vlc_ml, "Database was reset" ); break; case medialibrary::InitializeResult::Success: msg_Dbg( m_vlc_ml, "MediaLibrary successfully initialized" ); break; } ml->addParserService( std::make_shared<MetadataExtractor>( VLC_OBJECT( m_vlc_ml ) ) ); try { ml->addThumbnailer( std::make_shared<Thumbnailer>( m_vlc_ml, std::move( thumbnailsDir ) ) ); } catch ( const std::runtime_error& ex ) { msg_Err( m_vlc_ml, "Failed to provide a thumbnailer module to the " "medialib: %s", ex.what() ); return false; } if ( ml->start() == false ) { msg_Err( m_vlc_ml, "Failed to start the MediaLibrary" ); return false; } // Reload entry points we already know about, and then add potential new ones. // Doing it the other way around would cause the initial scan to be performed // twice, as we start discovering the new folders, then reload them. ml->reload(); auto folders = vlc::wrap_cptr( var_InheritString( m_vlc_ml, "ml-folders" ) ); if ( folders != nullptr && strlen( folders.get() ) > 0 ) { std::istringstream ss( folders.get() ); std::string folder; while ( std::getline( ss, folder, ';' ) ) ml->discover( folder ); } else { std::string varValue; for( auto&& target : { VLC_VIDEOS_DIR, VLC_MUSIC_DIR } ) { auto folder = vlc::wrap_cptr( config_GetUserDir( target ) ); if( folder == nullptr ) continue; auto folderMrl = vlc::wrap_cptr( vlc_path2uri( folder.get(), nullptr ) ); ml->discover( folderMrl.get() ); varValue += std::string{ ";" } + folderMrl.get(); } if ( varValue.empty() == false ) config_PutPsz( "ml-folders", varValue.c_str()+1 ); /* skip initial ';' */ } m_ml = std::move( ml ); return true; }