Skip to content

Commit

Permalink
Remove failed attempts, leaving only the "true solution": set default…
Browse files Browse the repository at this point in the history
… frame encoding.
  • Loading branch information
inducer committed Oct 19, 2007
1 parent 82f9ff9 commit 67a5562
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 95 deletions.
46 changes: 0 additions & 46 deletions src/python/id3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Tag = _tagpy.id3v2_Tag


AttachedPictureFrameType = _tagpy.id3v2_AttachedPictureFrame_Type
AttachedPictureFrame = _tagpy.id3v2_AttachedPictureFrame
CommentsFrame = _tagpy.id3v2_CommentsFrame
Expand All @@ -21,48 +20,3 @@
UserTextIdentificationFrame = _tagpy.id3v2_UserTextIdentificationFrame
UniqueFileIdentifierFrame = _tagpy.id3v2_UniqueFileIdentifierFrame
UnkownFrame = _tagpy.id3v2_UnknownFrame




# monkey-patch Tag ------------------------------------------------------------
def _tag_get_text_frame(self, id):
flm_id = self.frameListMap[id]

if flm_id:
return flm_id[0].toString()
else:
return None

def _tag_set_text_frame(self, id, value):
if not value:
self.removeFrames(id)
return

from tagpy import StringType

print "YAAA"
flm_id = self.frameListMap[id]
if flm_id:
if isinstance(value, unicode):
flm_id[0].setTextEncoding(StringType.UTF8)
flm_id[0].setText(value)
else:
tif = TextIdentificationFrame(id, StringType.UTF8)
self.addFrame(tif)
tif.setText(value)


def _augment_Tag():
Tag.getTextFrame = _tag_get_text_frame
Tag.setTextFrame = _tag_set_text_frame

for name, frame in [
("title", "TIT2"),
("artist", "TPE1"),
("album", "TALB"),
("comment", "TALB"),
]:
setattr(Tag, name, property(
lambda tag: tag.getTextFrame(frame),
lambda tag, value: tag.setTextFrame(frame)))
50 changes: 1 addition & 49 deletions src/wrapper/basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,53 +44,6 @@ namespace
}
};

class UTF8Intermediate
{
private:
std::string m_utf8;
static const int utf8_max_len = 6;

public:
UTF8Intermediate(const std::wstring &wstr)
{
for (unsigned i = 0; i < wstr.size(); i++)
{
unsigned char buffer[utf8_max_len];
int utf8len = ucs4_to_utf8(wstr[i], buffer);
m_utf8.append(reinterpret_cast<char *>(buffer), utf8len);
}
std::cout << "AFAA" << m_utf8 << std::endl;
}

operator String() const
{
String result(m_utf8.c_str(), String::UTF8);
std::cout << "AFAA***" << result << std::endl;
return String(m_utf8, String::UTF8);
}

private:
static int ucs4_to_utf8(wchar_t ucs4, unsigned char dest[utf8_max_len])
{
int bits;
unsigned char *d = dest;

if (ucs4 < 0x80) { *d++= ucs4; bits= -6; }
else if (ucs4 < 0x800) { *d++= ((ucs4 >> 6) & 0x1F) | 0xC0; bits= 0; }
else if (ucs4 < 0x10000) { *d++= ((ucs4 >> 12) & 0x0F) | 0xE0; bits= 6; }
else if (ucs4 < 0x200000) { *d++= ((ucs4 >> 18) & 0x07) | 0xF0; bits= 12; }
else if (ucs4 < 0x4000000) { *d++= ((ucs4 >> 24) & 0x03) | 0xF8; bits= 18; }
else if (ucs4 < 0x80000000) { *d++= ((ucs4 >> 30) & 0x01) | 0xFC; bits= 24; }
else return 0;

for ( ; bits >= 0; bits-= 6) {
*d++= ((ucs4 >> bits) & 0x3F) | 0x80;
}
return d - dest;
}
};





Expand Down Expand Up @@ -157,8 +110,7 @@ BOOST_PYTHON_MODULE(_tagpy)
// -------------------------------------------------------------
to_python_converter<String, tlstring_to_unicode>();
to_python_converter<ByteVector, tlbytevector_to_string>();
implicitly_convertible<std::wstring, UTF8Intermediate>();
implicitly_convertible<UTF8Intermediate, String>();
implicitly_convertible<std::wstring, String>();
implicitly_convertible<std::string, ByteVectorIntermediate>();
implicitly_convertible<ByteVectorIntermediate, ByteVector>();

Expand Down

0 comments on commit 67a5562

Please sign in to comment.