1 |
douglas |
475 |
// Media File |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
douglas |
553 |
#include <menes/c++/standard.hh> |
8 |
douglas |
476 |
|
9 |
douglas |
549 |
#include <menes/dbi/resultset.hpp> |
10 |
douglas |
489 |
|
11 |
douglas |
516 |
#include "MediaFile.hpp" |
12 |
|
|
|
13 |
douglas |
542 |
MediaFile::MediaFile(const _R<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path) |
14 |
douglas |
476 |
{ |
15 |
douglas |
541 |
_R<dbi::ResultSet> info(connection->Parse(_B("SELECT artist, title, album, genre FROM files WHERE path = ?"))->Execute(path.GetPath())); |
16 |
douglas |
488 |
|
17 |
|
|
if (info->MoveNext()) |
18 |
|
|
{ |
19 |
|
|
artist = info->GetString(_B("artist")); |
20 |
|
|
title = info->GetString(_B("title")); |
21 |
|
|
album = info->GetString(_B("album")); |
22 |
|
|
genre = info->GetString(_B("genre")); |
23 |
|
|
} |
24 |
douglas |
476 |
} |
25 |
douglas |
478 |
|
26 |
douglas |
542 |
MediaFile::MediaFile(const _R<dbi::Connection>& connection, const api::Path& path, const cse::String& artist, const cse::String& title, const cse::String& album, const cse::String& genre, const api::Path& root) : connection(connection), path(path), artist(artist), title(title), album(album), genre(genre) |
27 |
douglas |
478 |
{ |
28 |
douglas |
541 |
_R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM files WHERE path = ?"))->Execute(path.GetPath())); |
29 |
douglas |
500 |
|
30 |
|
|
if (path_->MoveNext()) |
31 |
|
|
{ |
32 |
douglas |
514 |
connection->Parse(_B("UPDATE files SET live = TRUE WHERE path = ?"))->Execute(path.GetPath()); |
33 |
|
|
|
34 |
douglas |
500 |
if (!artist.IsEmpty()) |
35 |
|
|
connection->Parse(_B("UPDATE files SET artist = ? WHERE path = ?"))->Execute(artist, path.GetPath()); |
36 |
|
|
|
37 |
|
|
if (!title.IsEmpty()) |
38 |
|
|
connection->Parse(_B("UPDATE files SET title = ? WHERE path = ?"))->Execute(title, path.GetPath()); |
39 |
|
|
|
40 |
|
|
if (!album.IsEmpty()) |
41 |
|
|
connection->Parse(_B("UPDATE files SET album = ? WHERE path = ?"))->Execute(album, path.GetPath()); |
42 |
|
|
|
43 |
|
|
if (!genre.IsEmpty()) |
44 |
|
|
connection->Parse(_B("UPDATE files SET genre = ? WHERE path = ?"))->Execute(genre, path.GetPath()); |
45 |
|
|
|
46 |
|
|
connection->Parse(_B("UPDATE files SET root = ? WHERE path = ?"))->Execute(root.GetPath(), path.GetPath()); |
47 |
|
|
} |
48 |
|
|
else |
49 |
|
|
connection->Parse(_B("INSERT INTO files (path, artist, title, album, genre, folder, root) VALUES (?, ?, ?, ?, ?, ?, ?)"))->Execute(path.GetPath(), artist, title, album, genre, path.GetParent().GetPath(), root.GetPath()); |
50 |
douglas |
478 |
} |