DCL 4.0
Loading...
Searching...
No Matches
ID3v1.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#include <string.h>
4
5#if __DCL_WINDOWS
6#include <windows.h>
7#endif
8
9#include <dcl/String.h>
10#include <dcl/Charset.h>
11#include <dcl/File.h>
12
13#include "ID3v1.h"
14
15#define __TRACE_THIS 0
16#if __TRACE_THIS
17#define __DCL_TRACE1_N __DCL_TRACE1
18#define __DCL_TRACE2_N __DCL_TRACE2
19#define __DCL_TRACE3_N __DCL_TRACE3
20#else
21#define __DCL_TRACE1_N(fmt, arg)
22#define __DCL_TRACE2_N(fmt, arg1, arg2)
23#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
24#endif
25
26__DCL_BEGIN_NAMESPACE
27
28#if __DCL_DEBUG
29#undef __THIS_FILE__
30static const char_t __THIS_FILE__[] = __T("media/ID3v1.cpp");
31#endif
32
34
35ID3v1::ID3v1()
36 : __version(0), __track(0), __genre(0)
37{
38}
39
40struct __ID3v1
41{
42 char TAG[3];
43 char Title[30];
44 char Artist[30];
45 char Album[30];
46 char Year[4];
47 char Comment[30];
48 char Genre;
49};
50
51bool ID3v1::read(File& _file)
52{
53 __DCL_ASSERT(sizeof(__ID3v1) == 128);
54 // 파일의 마지막 128 bytes를 읽는다.
55 _file.seek(-128, File::END);
56 char buf[128];
57 size_t n = _file.read(&buf, sizeof(buf));
58
59 __DCL_TRACE2_N(L"read [%zd] [%ls]\n", n,
60 String::tryString(buf, 128).data());
61
62 if (memcmp(buf, "TAG", 3) != 0) {
63 return false;
64 }
65
66 return read(buf);
67}
68
69bool ID3v1::read(const char _data[128])
70{
71 __DCL_ASSERT(_data != NULL);
72 __DCL_TRACE1_N(L"[%ls]\n", String::tryString(_data, 128).data());
73 if (memcmp(_data, "TAG", 3) != 0) {
74 return false;
75 }
76 __version = 1;
77
78 __ID3v1& buf = *(__ID3v1*)_data;
80 __title = Latin1Decoder::decode(buf.Title, ByteString::length(buf.Title, sizeof(buf.Title)));
81 __artist = Latin1Decoder::decode(buf.Artist, ByteString::length(buf.Artist, sizeof(buf.Artist)));
82 __album = Latin1Decoder::decode(buf.Album, ByteString::length(buf.Album, sizeof(buf.Album)));
83 __year = Latin1Decoder::decode(buf.Year, ByteString::length(buf.Year, sizeof(buf.Year)));
84 __comment = Latin1Decoder::decode(buf.Comment, ByteString::length(buf.Comment, sizeof(buf.Comment)));
85
86 if (__comment.length() <= 28) {
87 __track = buf.Comment[29];
88 }
89 __genre = buf.Genre;
90
91 __title = __title.trim();
92 __artist = __artist.trim();
93 __album = __album.trim();
94 __year = __year.trim();
95 __comment = __comment.trim();
96
97 return true;
98}
99
100String ID3v1::toString() const
101{
102 return String::format(L""
103 "%ls "
104 "Title[%ls] Artist[%ls] Album[%ls] Year[%ls] Comment[%ls]"
105 " Track[%d] Genre[%d]",
106 __TAG.data(),
107 __title.data(), __artist.data(), __album.data(), __year.data(), __comment.data(),
109}
110
111__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:340
wchar_t char_t
Definition Config.h:275
#define __DCL_TRACE1_N(fmt, arg)
#define __DCL_TRACE2_N(fmt, arg1, arg2)
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:228
#define __T(str)
Definition Object.h:44
ByteBuffer * buf
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
static String decode(const char *_mbs, size_t _mbslen=(size_t) -1)
Definition File.h:38
@ END
Definition File.h:207
off_t seek(off_t _offset, int _whence) __DCL_THROWS1(IOException *)
Definition File.cpp:590
virtual size_t read(void *_buf, size_t _n) __DCL_THROWS1(IOException *)
Definition File.cpp:476
Definition ID3v1.h:13
char __version
Definition ID3v1.h:75
String __album
Definition ID3v1.h:81
String __TAG
Definition ID3v1.h:78
String __artist
Definition ID3v1.h:80
String __year
Definition ID3v1.h:82
String __comment
Definition ID3v1.h:83
char __genre
Definition ID3v1.h:86
char __track
Definition ID3v1.h:85
String __title
Definition ID3v1.h:79
static String decode(const char *_mbs, size_t _nmbs=(size_t) -1)
virtual String toString() const
Definition Object.cpp:187
char TAG[3]
Definition ID3v1.cpp:42
char Artist[30]
Definition ID3v1.cpp:44
char Year[4]
Definition ID3v1.cpp:46
char Album[30]
Definition ID3v1.cpp:45
char Comment[30]
Definition ID3v1.cpp:47
char Genre
Definition ID3v1.cpp:48
char Title[30]
Definition ID3v1.cpp:43