summaryrefslogtreecommitdiff
path: root/music.cpp
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 /music.cpp
parent5799070fea8f11ced32d57c6c38017c7671b0773 (diff)
Added a simple artist lookup from a database using SOCI.
Diffstat (limited to 'music.cpp')
-rw-r--r--music.cpp37
1 files changed, 31 insertions, 6 deletions
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()) {