Browse files

update DB schema, make scanner write file:// urls not paths

  • Loading branch information...
1 parent 64997ba commit 3fed5a88282180d735dd273e427520d8e5ae884e @RJ committed Apr 8, 2009
View
5 deps/moost_http/include/moost/http/connection.hpp
@@ -182,7 +182,7 @@ void connection<RequestHandler>::handle_write_stream
if(!ss)
{
- cout << "StreamingStrat died" << endl;
+ cout << "StreamingStrat went away?" << endl;
break;
}
const size_t maxbuf = 4096 * 2;
@@ -213,13 +213,14 @@ void connection<RequestHandler>::handle_write_stream
}
else
{
+ // this might happen if you hit stop or your browser just aborts the connection halfway.
cout << "handle_write_stream error for " << ss->debug()
<< endl;
break;
}
}while(false);
- cout << "Shutting down socket." << endl;
+ //cout << "Shutting down socket." << endl;
boost::system::error_code ignored_ec;
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
}
View
4 etc/schema.sql
@@ -58,15 +58,15 @@ CREATE UNIQUE INDEX track_search_index_ngram_track ON track_search_index(ngram,
-- files on disk and joinage with catalogue:
CREATE TABLE IF NOT EXISTS file (
id INTEGER PRIMARY KEY AUTOINCREMENT,
- path TEXT NOT NULL,
+ url TEXT NOT NULL,
size INTEGER NOT NULL,
mtime INTEGER NOT NULL,
md5 TEXT,
mimetype TEXT,
duration INTEGER NOT NULL DEFAULT 0,
bitrate INTEGER NOT NULL DEfAULT 0
);
-CREATE UNIQUE INDEX file_path_uniq ON file(path);
+CREATE UNIQUE INDEX file_url_uniq ON file(url);
CREATE TABLE IF NOT EXISTS file_join (
file INTEGER NOT NULL REFERENCES file(id) ON DELETE CASCADE ON UPDATE CASCADE,
View
1 includes/playdar/library.h
@@ -15,7 +15,6 @@ using namespace std;
#include "playdar/track.h"
#include "playdar/streaming_strategy.h"
-#include "playdar/ss_localfile.hpp"
class MyApplication;
View
2 includes/playdar/ss_curl.hpp
@@ -73,7 +73,6 @@ class CurlStreamingStrategy : public StreamingStrategy
void reset()
{
m_connected = false;
- m_bufoffset = 0;
m_bytesreceived = 0;
m_curl_finished = false;
if( m_curl ) curl_easy_cleanup( m_curl );
@@ -155,7 +154,6 @@ class CurlStreamingStrategy : public StreamingStrategy
bool m_connected;
string m_url;
deque< char > m_buffers; // received data
- size_t m_bufoffset;
boost::mutex m_mut;
boost::condition m_cond;
bool m_curl_finished;
View
33 src/library.cpp
@@ -13,11 +13,11 @@ using namespace std;
bool
-Library::remove_file( string path )
+Library::remove_file( string url )
{
boost::mutex::scoped_lock lock(m_mut);
- sqlite3pp::query qry(m_db, "SELECT id FROM file WHERE path = ?");
- qry.bind(1, path.c_str(), true);
+ sqlite3pp::query qry(m_db, "SELECT id FROM file WHERE url = ?");
+ qry.bind(1, url.c_str(), true);
int fileid = 0;
for(sqlite3pp::query::iterator i = qry.begin(); i!=qry.end(); ++i){
fileid = (*i).get<int>(0);
@@ -34,27 +34,27 @@ Library::remove_file( string path )
}
int
-Library::add_dir(string path, int mtime)
+Library::add_dir(string url, int mtime)
{
boost::mutex::scoped_lock lock(m_mut);
- remove_file( path );
- sqlite3pp::command cmd(m_db, "INSERT INTO file(path, size, mtime) VALUES (?, 0, ?)");
- cmd.bind(1, path.c_str(), true);
+ remove_file( url );
+ sqlite3pp::command cmd(m_db, "INSERT INTO file(url, size, mtime) VALUES (?, 0, ?)");
+ cmd.bind(1, url.c_str(), true);
cmd.bind(2, mtime);
return cmd.execute();
}
int
-Library::add_file( string path, int mtime, int size, string md5, string mimetype,
+Library::add_file( string url, int mtime, int size, string md5, string mimetype,
int duration, int bitrate,
string artist, string album, string track, int tracknum)
{
int fileid = 0;
- remove_file(path);
+ remove_file(url);
- sqlite3pp::command cmd(m_db, "INSERT INTO file(path, size, mtime, md5, mimetype, duration, bitrate) VALUES (?, ?, ?, ?, ?, ?, ?)");
- cmd.bind(1, path.c_str(), true);
+ sqlite3pp::command cmd(m_db, "INSERT INTO file(url, size, mtime, md5, mimetype, duration, bitrate) VALUES (?, ?, ?, ?, ?, ?, ?)");
+ cmd.bind(1, url.c_str(), true);
cmd.bind(2, size);
cmd.bind(3, mtime);
cmd.bind(4, md5.c_str(), true);
@@ -398,20 +398,22 @@ Library::num_tracks()
return db_get_one(string("SELECT count(*) FROM track"), 0);
}
+/// NB: this doesn't attach a streaming strategy, but it does set_url().
+/// so the caller should create an appropriate SS (probably a curl strat)
boost::shared_ptr<PlayableItem>
Library::playable_item_from_fid(int fid)
{
boost::mutex::scoped_lock lock(m_mut);
boost::shared_ptr<PlayableItem> pip(new PlayableItem());
ostringstream sql;
- sql << "SELECT file.path, file.size, file.mimetype, file.duration, file.bitrate, "
+ sql << "SELECT file.url, file.size, file.mimetype, file.duration, file.bitrate, "
<< "file_join.artist, file_join.album, file_join.track "
<< "FROM file, file_join "
<< "WHERE file.id = file_join.file "
<< "AND file.id = " << fid;
sqlite3pp::query qry(m_db, sql.str().c_str() );
for(sqlite3pp::query::iterator i = qry.begin(); i!=qry.end(); ++i){
- string path = string((*i).get<const char *>(0));
+ string url = string((*i).get<const char *>(0));
int size = (*i).get<int>(1);
string mimetype = string((*i).get<const char *>(2));
int duration = (*i).get<int>(3);
@@ -431,8 +433,7 @@ Library::playable_item_from_fid(int fid)
album_ptr albobj = load_album(pialbid);
pip->set_album(albobj->name());
}
- boost::shared_ptr<StreamingStrategy> ss(new LocalFileStreamingStrategy(path));
- pip->set_streaming_strategy(ss);
+ pip->set_url(url);
pip->set_mimetype(mimetype);
pip->set_size(size);
pip->set_duration(duration);
@@ -452,7 +453,7 @@ Library::file_mtimes()
{
boost::mutex::scoped_lock lock(m_mut);
map<string, int> ret;
- sqlite3pp::query qry(m_db, "SELECT path, mtime FROM file");
+ sqlite3pp::query qry(m_db, "SELECT url, mtime FROM file");
for(sqlite3pp::query::iterator i = qry.begin(); i!=qry.end(); ++i){
ret[ string((*i).get<const char *>(0)) ] = (*i).get<int>(1);
}
View
1 src/playdar/main.cpp
@@ -190,6 +190,7 @@ int main(int ac, char *av[])
try
{
+ curl_global_init( CURL_GLOBAL_ALL );
print_curl_info();
}
catch(...)
View
2 src/rs_local_library.cpp
@@ -85,6 +85,8 @@ RS_local_library::process( rq_ptr rq )
BOOST_FOREACH(int fid, fids)
{
pi_ptr pip = app()->library()->playable_item_from_fid(fid);
+ boost::shared_ptr<StreamingStrategy> ss(new CurlStreamingStrategy(pip->url()));
+ pip->set_streaming_strategy(ss);
pip->set_source(conf()->name());
final_results.push_back( pip );
}
View
37 src/scanner/scanner.cpp
@@ -23,6 +23,27 @@ Library *gLibrary;
int scanned, skipped, ignored = 0;
+string urlify(const bfs::path &p)
+{
+ // turn it into a url by prepending file://
+ // because we pass all urls to curl:
+ string urlpath = "file://";
+ if( p.string().at(0)=='/' ) // posix path starting with /
+ {
+ urlpath += p.string();
+ }
+ else if(p.string().at(1)==':') // windows style filepath
+ {
+ urlpath += "/";
+ urlpath += p.string();
+ }
+ else
+ {
+ // could be anything, hopefully something curl understands:
+ urlpath = p.string();
+ }
+ return urlpath;
+}
bool scan(const bfs::path &p, map<string,int> & mtimes)
{
@@ -44,10 +65,11 @@ bool scan(const bfs::path &p, map<string,int> & mtimes)
ext == ".mp4" ||
ext == ".aac" )
{
+ string url = urlify( itr->string() );
int mtime = bfs::last_write_time(itr->path());
- mtimeit = mtimes.find(itr->string());
+ mtimeit = mtimes.find(url);
if( mtimeit == mtimes.end() // not scanned previously
- || mtimes[itr->string()] != mtime) // modified since last time
+ || mtimes[url] != mtime) // modified since last time
{
add_file(itr->path(), mtime);
}else{
@@ -105,17 +127,22 @@ bool add_file(const bfs::path &p, int mtime)
}
string ext(bfs::extension(p));
string mimetype = ext2mime(to_lower_copy(ext));
- gLibrary->add_file( p.string(),
+
+ // turn it into a url by prepending file://
+ // because we pass all urls to curl:
+ string urlpath = urlify( p );
+
+ gLibrary->add_file( urlpath,
mtime,
filesize,
- string("md5here"),
+ string(""), //TODO file hash?
mimetype,
duration,
bitrate,
artist,
album,
track,
- tag->track());
+ tag->track() );
/* cout << "-- TAG --" << endl;
cout << "title - \"" << tag->title() << "\"" << endl;

0 comments on commit 3fed5a8

Please sign in to comment.