# Lyrics and Chinese in Ruby?

**URL:** <https://www.ruby-forum.com/t/lyrics-and-chinese-in-ruby/126686>\
**Category:** Ruby\
**Created:** [January 21, 2008, 11:35am UTC](https://www.ruby-forum.com/t/lyrics-and-chinese-in-ruby/126686 "2008-01-21T11:35:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewtonApple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e0b2c6/32.png) [@NewtonApple](https://www.ruby-forum.com/u/NewtonApple)\
**Post date:** [January 21, 2008, 11:35am UTC](https://www.ruby-forum.com/t/lyrics-and-chinese-in-ruby/126686/1 "2008-01-21T11:35:51Z")

</div>

Hello, has anyone used Chinese with Ruby? I’m trying to write a  
script that would import/export my lyrics from/to [lyricwiki.org](http://lyricwiki.org).  
Since they don’t have a lot of Chinese lyrics, I thought I’d help them  
out by exporting my collection. Looking at their SOAP API wiki  
([http://lyricwiki.org/LyricWiki:SOAP](http://lyricwiki.org/LyricWiki:SOAP)), they seem have some troubles  
encoding and decoding Unicode characters using Ruby’s soap/  
wsdlDriver. I tried to run my songs’ meta data through rubyosa. But  
I have no luck.

Here’s a few songs I’ve tried out by copy-pasting the artist and song  
names into the source and fetching the lyrics:  
[http://lyricwiki.org/Category:Language/Cantonese](http://lyricwiki.org/Category:Language/Cantonese).

And here is a simple script, I’ve been testing with (w/ RubyOSA):  
[http://pastie.caboo.se/141454](http://pastie.caboo.se/141454)

My system is running on MacOS Leopard, Ruby 1.8.6. Thanks in advance  
for all your help!

David

---

<div class="post-metadata">

**Author:** ![NewtonApple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e0b2c6/32.png) [@NewtonApple](https://www.ruby-forum.com/u/NewtonApple)\
**Post date:** [January 23, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/lyrics-and-chinese-in-ruby/126686/2 "2008-01-23T12:10:38Z")

</div>

On 21 Jan, 10:34, NewtonApple [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello, has anyone used Chinese with Ruby? I’m trying to write a  
> script that would import/export my lyrics from/to [lyricwiki.org](http://lyricwiki.org).  
> Since they don’t have a lot of Chinese lyrics, I thought I’d help them  
> out by exporting my collection. Looking at their SOAP API wiki  
> ([http://lyricwiki.org/LyricWiki:SOAP](http://lyricwiki.org/LyricWiki:SOAP)), they seem have some troubles  
> encoding and decoding Unicode characters using Ruby’s soap/  
> wsdlDriver.

Looks like something’s hosed somewhere:

require ‘soap/wsdlDriver’  
driver = SOAP::WSDLDriverFactory.new(“[http://lyricwiki.org/server.php](http://lyricwiki.org/server.php)?  
wsdl”).create\_rpc\_driver

p driver.getSong(“La Mosca Ts\303\251-Ts\303\251”,“Madrid Amaneci  
\303\263”).artist

# "La Mosca Ts\303\203\302\203\303\202\302\251-Ts

\303\203\302\203\303\202\302\251" (!)

Same problem seems to happen on Python, which suggests the problem  
might be on the server side:

import LyricWiki\_services

soap = LyricWiki\_services.LyricWikiBindingSOAP(‘[http://lyricwiki.org/](http://lyricwiki.org/)  
server.php’)  
song = LyricWiki\_services.getSongRequest()  
song.Artist = unicode(‘La Mosca Ts\xc3\xa9-Ts\xc3\xa9’, ‘utf8’)  
song.Song = unicode(‘Madrid Amaneci\xc3\xb3’, ‘utf8’)  
result = soap.getSong(song)

print `result.Return.Artist.encode('utf8')`

# 'La Mosca Ts\xc3\x83\xc2\x83\xc3\x82\xc2\xa9-Ts

\xc3\x83\xc2\x83\xc3\x82\xc2\xa9’

You might want to speak to the LyricWiki folks about that.

> And here is a simple script, I’ve been testing with (w/RubyOSA):[Parked at Loopia](http://pastie.caboo.se/141454)

Note that this script won’t work as-is for non-English names since  
RubyOSA uses ASCII by default, although this can be changed.  
Alternatively, use rb-appscript, which uses UTF8 by default.

HTH

has
