summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-12-30 20:57:48 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-12-30 22:33:22 +0100
commitd141e89e7d3c7120ee163a0e01272fabe4cb5501 (patch)
tree559fed9661fdedcfddce0ad8a53d5c38cd504fff
parent5799070fea8f11ced32d57c6c38017c7671b0773 (diff)
Added a simple artist lookup from a database using SOCI.
-rw-r--r--SConstruct3
-rw-r--r--config.cpp7
-rw-r--r--music.cpp37
-rw-r--r--music.h2
4 files changed, 42 insertions, 7 deletions
diff --git a/SConstruct b/SConstruct
index baf9f5d..c2755c5 100644
--- a/SConstruct
+++ b/SConstruct
@@ -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'])
diff --git a/config.cpp b/config.cpp
index 1fbcde5..9376f10 100644
--- a/config.cpp
+++ b/config.cpp
@@ -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");
}
}
diff --git a/music.cpp b/music.cpp
index 9b840bb..1651d53 100644
--- a/music.cpp
+++ b/music.cpp
@@ -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()) {
diff --git a/music.h b/music.h
index 7f1c813..effc32c 100644
--- a/music.h
+++ b/music.h
@@ -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