00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #if defined HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00032 #include "tag_impl.h"
00033 #include "helpers.h"
00034 #include "utils.h"
00035 #include "io_decorators.h"
00036 #include "io_helpers.h"
00037 #include "io_strings.h"
00038
00039 using namespace dami;
00040
00041 bool id3::v1::parse(ID3_TagImpl& tag, ID3_Reader& reader)
00042 {
00043 io::ExitTrigger et(reader);
00044
00045 ID3_Reader::pos_type end = reader.getCur();
00046
00047 if (end < reader.getBeg() + ID3_V1_LEN)
00048 {
00049 ID3D_NOTICE( "id3::v1::parse: not enough bytes to parse, pos = " << end );
00050 return false;
00051 }
00052 reader.setCur(end - ID3_V1_LEN);
00053 ID3_Reader::pos_type beg = reader.getCur();
00054
00055 if (end != beg + ID3_V1_LEN)
00056 {
00057 ID3D_WARNING( "id3::v1::parse: failed to reposition " << ID3_V1_LEN <<
00058 " bytes" );
00059 return false;
00060 }
00061
00062
00063 String id = io::readText(reader, ID3_V1_LEN_ID);
00064
00065
00066 if (id != "TAG")
00067 {
00068 return false;
00069 }
00070 et.setExitPos(beg);
00071
00072
00073
00074
00075
00076 ID3D_NOTICE("id3::v1::parse: read bytes: " << reader.getCur() - beg);
00077 String title = io::readTrailingSpaces(reader, ID3_V1_LEN_TITLE);
00078 if (title.size() > 0)
00079 {
00080 id3::v2::setTitle(tag, title);
00081 }
00082 ID3D_NOTICE( "id3::v1::parse: title = \"" << title << "\"" );
00083
00084 ID3D_NOTICE("id3::v1::parse: read bytes: " << reader.getCur() - beg);
00085 String artist = io::readTrailingSpaces(reader, ID3_V1_LEN_ARTIST);
00086 if (artist.size() > 0)
00087 {
00088 id3::v2::setArtist(tag, artist);
00089 }
00090 ID3D_NOTICE( "id3::v1::parse: artist = \"" << artist << "\"" );
00091
00092 ID3D_NOTICE("id3::v1::parse: read bytes: " << reader.getCur() - beg);
00093 String album = io::readTrailingSpaces(reader, ID3_V1_LEN_ALBUM);
00094 if (album.size() > 0)
00095 {
00096 id3::v2::setAlbum(tag, album);
00097 }
00098 ID3D_NOTICE( "id3::v1::parse: album = \"" << title << "\"" );
00099
00100 ID3D_NOTICE("id3::v1::parse: read bytes: " << reader.getCur() - beg);
00101 String year = io::readTrailingSpaces(reader, ID3_V1_LEN_YEAR);
00102 if (year.size() > 0)
00103 {
00104 id3::v2::setYear(tag, year);
00105 }
00106 ID3D_NOTICE( "id3::v1::parse: year = \"" << year << "\"" );
00107
00108 ID3D_NOTICE("id3::v1::parse: read bytes: " << reader.getCur() - beg);
00109 String comment = io::readTrailingSpaces(reader, ID3_V1_LEN_COMMENT);
00110 if (comment.length() == ID3_V1_LEN_COMMENT &&
00111 '\0' == comment[ID3_V1_LEN_COMMENT - 2] ||
00112 '\0' != comment[ID3_V1_LEN_COMMENT - 1])
00113 {
00114
00115
00116 size_t track = comment[ID3_V1_LEN_COMMENT - 1];
00117 id3::v2::setTrack(tag, track, 0);
00118 ID3D_NOTICE( "id3::v1::parse: track = \"" << track << "\"" );
00119
00120 ID3D_NOTICE( "id3::v1::parse: comment length = \"" << comment.length() << "\"" );
00121 io::StringReader sr(comment);
00122 comment = io::readTrailingSpaces(sr, ID3_V1_LEN_COMMENT - 2);
00123 }
00124 ID3D_NOTICE( "id3::v1::parse: comment = \"" << comment << "\"" );
00125 if (comment.size() > 0)
00126 {
00127 id3::v2::setComment(tag, comment, STR_V1_COMMENT_DESC, "XXX");
00128 }
00129
00130 ID3D_NOTICE("id3::v1::parse: read bytes: " << reader.getCur() - beg);
00131
00132 uchar genre = reader.readChar();
00133 if (genre != 0xFF)
00134 {
00135 id3::v2::setGenre(tag, genre);
00136 }
00137 ID3D_NOTICE( "id3::v1::parse: genre = \"" << (int) genre << "\"" );
00138
00139 ID3D_NOTICE("id3::v1::parse: read bytes: " << reader.getCur() - beg);
00140 return true;
00141 }