diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-30 20:57:48 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-30 22:33:22 +0100 |
commit | d141e89e7d3c7120ee163a0e01272fabe4cb5501 (patch) | |
tree | 559fed9661fdedcfddce0ad8a53d5c38cd504fff | |
parent | 5799070fea8f11ced32d57c6c38017c7671b0773 (diff) |
Added a simple artist lookup from a database using SOCI.
-rw-r--r-- | SConstruct | 3 | ||||
-rw-r--r-- | config.cpp | 7 | ||||
-rw-r--r-- | music.cpp | 37 | ||||
-rw-r--r-- | music.h | 2 |
4 files changed, 42 insertions, 7 deletions
@@ -12,7 +12,10 @@ else: conf.CheckLib('boost_thread-mt') conf.CheckLib('boost_program_options-mt') conf.CheckLib('mp3lame') + conf.CheckLib('soci_core') env = conf.Finish() + # scons' CheckLib doesn't seem to find soci_core + env.Append(LIBS = ['soci_core']) if GetOption('release'): env.Append(CCFLAGS = ['-O2']) @@ -11,12 +11,17 @@ void config::init() { desc.add_options() ("audist.music_root", po::value<std::string>(), "music root") ("audist.httpd_port", po::value<int>()->default_value(8000), "httpd port") + ("audist.database", po::value<std::string>(), "database string") ; std::ifstream is("audist.conf", std::ios::in); po::store(po::parse_config_file(is, desc, true), vm); po::notify(vm); if(!vm.count("audist.music_root")) { - throw std::runtime_error("audist.music_root music be specified in audist.conf"); + throw std::runtime_error("audist.music_root must be specified in audist.conf"); + } + + if(!vm.count("audist.database")) { + throw std::runtime_error("audist.database must be specified in audist.conf"); } } @@ -2,23 +2,30 @@ #include "decoder.h" #include "encoder.h" #include "transcode.h" +#include "tag.h" +#include "config.h" #include <boost/format.hpp> #include <boost/algorithm/string/predicate.hpp> #include <boost/filesystem/fstream.hpp> +#include <soci/soci.h> -namespace music { +fs::path music::root_directory; -fs::path root_directory; - -void init(std::string root) { +void music::init(std::string root) { // remove trailing slash if(boost::algorithm::ends_with(root, "/")) root = root.substr(0, root.size()-1); root_directory = root; + + // find_artist test + std::vector<MusicListing::p> ml = find_artist("a"); + for(std::vector<MusicListing::p>::iterator it = ml.begin(); it != ml.end(); it++) { + std::cout << "result: " << (*it)->path << std::endl; + } } -MusicListing::p get(const std::string path) { +MusicListing::p music::get(const std::string path) { // prefix path with our root_directory fs::path p = root_directory / path; @@ -38,7 +45,21 @@ MusicListing::p get(const std::string path) { return MusicListing::p(); } -}; // namespace music +std::vector<MusicListing::p> music::find_artist(const std::string artist) { + soci::session sql(config::vm["audist.database"].as<std::string>()); + + soci::rowset<std::string> rs = (sql.prepare << "SELECT file_name FROM tracks WHERE artist_id IN (SELECT id FROM artists WHERE name ILIKE :name)", + soci::use("%"+artist+"%")); + + std::vector<MusicListing::p> results; + for(soci::rowset<std::string>::const_iterator it = rs.begin(); it != rs.end(); it++) { + boost::shared_ptr<MusicListing> ml(new MusicTrack(*it)); + results.push_back(ml); + } + std::cout << "results size: " << results.size() << std::endl; + + return results; +} void MusicDirectory::render(HTTPRequest& req, HTTPResponse& res) { res.add_header("content-type", "text/html"); @@ -75,6 +96,10 @@ MusicDirectory::MusicDirectory(const fs::path root) { void MusicTrack::render(HTTPRequest& req, HTTPResponse& res) { res.add_header("content-type", "application/octet-stream"); + // tag test + Tag *t = new ID3Tag(path.string()); + delete t; + fs::ifstream is(path, std::ios::binary | std::ios::in); if(req.query.find("decoder") != req.query.end() && req.query.find("encoder") != req.query.end()) { @@ -33,8 +33,10 @@ class MusicDirectory : public MusicListing { }; namespace music { + extern fs::path root_directory; void init(std::string root); MusicListing::p get(const std::string path); + std::vector<MusicListing::p> find_artist(const std::string artist); }; #endif |