26#define __DCL_TRACE1_N __DCL_TRACE1
27#define __DCL_TRACE2_N __DCL_TRACE2
28#define __DCL_TRACE3_N __DCL_TRACE3
30#define __DCL_TRACE1_N(fmt, arg)
31#define __DCL_TRACE2_N(fmt, arg1, arg2)
32#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
57 String driver =
__args.database().substring(L
"DRIVER *= *[^ ;]+",
true);
58 if (!driver.isEmpty()) {
59 driver = driver.substring(driver.indexOf(L
'=') + 1).trim();
61 if (!driver.isEmpty()) {
62 __conn = new SQLConnection(driver);
63 __conn->open(__args.database());
64 __args.output() << L
"Database connected. ["
65 << __args.database() << L
"]" << endl;
75#if defined(__DCL_DEBUG) && __TRACE_THIS
77 File::off_t _n = file.
size();
95 if (memcmp(
buf,
"ID3", 3) == 0) {
98 id3v2Version = id3v2.version();
101 else if (memcmp(
buf,
"APETAGEX", 8) == 0) {
103 if (apev2.read(file,
buf, 0)) {
104 apeVersion = apev2.version() / 1000;
114 n, String::tryString(
buf, 160).data());
115 if (apeVersion == 0) {
116 if (memcmp(
buf,
"APETAGEX", 8) == 0) {
118 if (apev2.read(file,
buf, -160)) {
119 apeVersion = apev2.version() / 1000;
122 else if (memcmp(&
buf[128],
"APETAGEX", 8) == 0) {
124 if (apev2.read(file,
buf, -32)) {
125 apeVersion = apev2.version() / 1000;
130 if (memcmp(&
buf[32],
"TAG", 3) == 0) {
131 if (id3v1.read(&
buf[32])) {
132 id3v1Version = id3v1.version();
141 String path = _dirname + _filename;
144 time_t atime, mtime, ctime;
152 if (_filename.toLowerCase().endsWith(L
".mp3")) {
200 while (dir.read(entry)) {
202 String name = entry.name();
204 if (name.compare(L
"..", name.length()) != 0) {
205 readDir(dir.path() + entry.name());
209 read(dir.path(), name);
226 out.printf(L
" tags[%03d]",
227 id3v2.version() * 100 + apev2.version() / 100 + id3v1.version());
228 out << L
" size[" << _info.
size << L
"]"
230 << L
" notes[" << _info.
notes << L
"]"
233 out << L
" format[" << _info.
format << L
"]"
234 << L
" width[" << _info.
width << L
"]"
235 << L
" height[" << _info.
height << L
"]"
236 << L
" duration[" << _info.
duration << L
"]"
239 if (!
args().verbose()) {
243 if (id3v2.version() > 0) {
245 out << id3v2.toString() <<
endl;
247 for (
size_t i = 0; i < id3v2.frames().size(); i++) {
253 if (apev2.version() > 0) {
255 out << apev2.toString() <<
endl;
257 for (
size_t i = 0; i < apev2.items().size(); i++) {
259 out << item.toString() <<
endl;
263 if (id3v1.version() > 0) {
265 out << id3v1.toString() <<
endl;
279 "SELECT COALESCE(MAX(DIR_ID), 1000) FROM STOR_DIR"
289 "SELECT COALESCE(MAX(FILE_ID), 10000) FROM STOR_FILE"
302 "INSERT INTO STOR_DIR (DIR_ID, PATH, CREA_TS, MODI_TS)"
303 "\n VALUES(:DIR_ID, :PATH, CURRENT_TIMESTAMP_(), CURRENT_TIMESTAMP_())"
311 out << L
" INSERT STOR_DIR [" <<
__dirId << L
"]["
318 "INSERT INTO STOR_FILE ("
319 "FILE_ID, NAME, USER_ID, STOR_ID, TYPE_ID"
320 ", DIR_ID, FILE_NM, FILE_SZ, FILE_AT, FILE_MT, FILE_CT, FILE_ER"
321 ", MEDI_FM, MEDI_WI, MEDI_HE, MEDI_DU, MEDI_NF"
322 ", READ_CO, CREA_TS, MODI_TS"
325 ":FILE_ID, :NAME, 0, 0, 0"
326 ", :DIR_ID, :FILE_NM, :FILE_SZ, :FILE_AT, :FILE_MT, :FILE_CT, :FILE_ER"
327 ", :MEDI_FM, :MEDI_WI, :MEDI_HE, :MEDI_DU, :MEDI_NF"
328 ", 0, CURRENT_TIMESTAMP_(), CURRENT_TIMESTAMP_()"
348 out << L
" INSERT STOR_FILE [" <<
__fileId << L
"]["
351 if (_info.
id3v1.version() > 0) {
352 if (_info.
id3v1.title().length() > 0) {
354 "INSERT INTO ID3V1 ("
355 "FILE_ID, TITLE, ARTIST, ALBUM, YEAR_"
356 ", COMMENT_, TRACK, GENRE"
359 ":FILE_ID, :TITLE, :ARTIST, :ALBUM, :YEAR_"
360 ", :COMMENT_, :TRACK, :GENRE"
367 if (_info.
id3v1.artist().isEmpty())
372 if (_info.
id3v1.album().isEmpty())
377 if (_info.
id3v1.year().isEmpty())
382 if (_info.
id3v1.comment().isEmpty())
392 out << L
" INSERT ID3V1" <<
endl;
396 args().errout() << L
"Title is NULL "
397 << _info.
id3v1.toString()
402 if (_info.
id3v2.version() > 0) {
404 "INSERT INTO ID3V2 ("
405 "FILE_ID, VERSION, FLAGS, SIZE_, FSBITS"
408 ":FILE_ID, :VERSION, :FLAGS, :SIZE_, :FSBITS"
420 "INSERT INTO ID3V2_FRAME ("
421 "FILE_ID, NO_, FRAME_ID, SIZE_, FLAGS"
422 ", ENCODING, TYPE_, URL, DESCRIPTION, TEXT_, BINARY_"
425 ":FILE_ID, :NO_, :FRAME_ID, :SIZE_, :FLAGS"
426 ", :ENCODING, :TYPE_, :URL, :DESCRIPTION, :TEXT_, :BINARY_"
429 for (
size_t i = 0; i < _info.
id3v2.frames().size(); i++) {
439 if (frame.
url().isEmpty())
449 if (frame.
text().isEmpty())
454 if (frame.
binary().length() == 0 || 100 < frame.
binary().length())
464 out << L
" INSERT ID3V2 ID3V2_FRAME["
465 << _info.
id3v2.frames().size() << L
"]" <<
endl;
469 if (_info.
apev2.version() > 0) {
472 "FILE_ID, VERSION, SIZE_, COUNT_, FLAGS"
475 ":FILE_ID, :VERSION, :SIZE_, :COUNT_, :FLAGS"
487 "INSERT INTO APE_ITEM ("
488 "FILE_ID, NO_, SIZE_, FLAGS"
492 ":FILE_ID, :NO_, :SIZE_, :FLAGS"
496 for (
size_t i = 0; i < _info.
apev2.items().size(); i++) {
504 if (item.value().isEmpty())
513 out << L
" INSERT APE APE_ITEM["
514 << _info.
apev2.items().size() << L
"]" <<
endl;
#define __DCL_THROWS2(e1, e2)
#define __DCL_TRACE2_N(fmt, arg1, arg2)
#define __DCL_TRACE2(fmt, arg1, arg2)
if(!__handle->open(bs, bs.length()))
void CharsetConvertException *size_t n
virtual String toString() const
String toStringAll() const
off_t seek(off_t _offset, int _whence) __DCL_THROWS1(IOException *)
virtual size_t read(void *_buf, size_t _n) __DCL_THROWS1(IOException *)
const String & path() const
off_t size() const __DCL_THROWS1(IOException *)
static bool time(const String &_path, time_t *_atime, time_t *_mtime, time_t *_ctime)
static uint64_t size(const String &_path) __DCL_THROWS1(IOException *)
const String & url() const
const String & description() const
const String & text() const
const ByteString & binary() const
virtual String toString() const
SQLParam & byName(const wchar_t *_name) _CONST __DCL_THROWS1(InvalidIndexException *)
_CONST SQLParams & params() _CONST
void prepare(const String &_sql) __DCL_THROWS2(SQLException *
_CONST SQLFields & fields() _CONST
void CharsetConvertException *void execute() __DCL_THROWS1(SQLException *)
void CharsetConvertException *void fetch() __DCL_THROWS1(SQLException *)
TagReader(const MainArguments &_args) __DCL_THROWS2(SQLDriverException *
SQLException *void readTag(const String &_path, FileInfo &_info)
void persist(const FileInfo &_info)
const MainArguments & args() const
void read(const String &_dirname, const String &_filename)
void print(const FileInfo &_info) const
const MainArguments & __args
void readDir(const String &_path)