| 赞 | 486 |
| VIP | |
| 好人卡 | |
| 积分 | 501 |
| 经验 | |
| 最后登录 | 2026-11-22 |
| 在线时间 | 7978 小时 |
老黄鸡
- 梦石
- 4
- 星屑
- 46133
- 在线时间
- 7978 小时
- 注册时间
- 2009-7-6
- 回帖
- 13342
   
|
发表于 2013-12-15 16:37:09
|
显示全部楼层
看到这玩意真怀念啊,我以前也写过一个。
- class String
- @@MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- @@WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- def s2u
- i = @@MultiByteToWideChar.call(0, 0, self, -1, nil, 0)
- buffer = "\0" * (i*2)
- @@MultiByteToWideChar.call(0, 0, self, -1, buffer, buffer.size / 2)
- i = @@WideCharToMultiByte.call(65001, 0, buffer, -1, nil, 0, nil, nil)
- result = "\0" * i
- @@WideCharToMultiByte.call(65001, 0, buffer, -1, result, result.size, nil, nil)
- result.chop!
- return result
- end
- end
- class Lrc
-
- Terms = ["歌名:","歌手:","专辑:","制作:"]
-
- attr_accessor :title
- attr_accessor :singer
- attr_accessor :album
- attr_accessor :timeline
- attr_accessor :contents
- attr_accessor :author
-
- def initialize(filename)
- self.load(filename)
- end
-
- def load(filename)
- ori_lrc = File.open(filename,"r").read
- @timeline = ori_lrc.scan(/(?<=\[)\d{2}:\d{2}:\d{2}(?=\])/)
- @contents = ori_lrc.scan(/(?<=\d\])[^\[\]]*(?=\n)/).map{|l| l.s2u}
- @title = $1.s2u if ori_lrc[/\bti:(.+)\b/]
- @singer = $1.s2u if ori_lrc[/\bar:(.+)\b/]
- @album = $1.s2u if ori_lrc[/\bal:(.+)\b/]
- @author = $1.s2u if ori_lrc[/\bby:(.+)\b/]
- end
-
- def to_s
- ret = ""
- ret += Terms[0]+@title+"\n" if @title
- ret += Terms[1]+@singer+"\n" if @singer
- ret += Terms[2]+@album+"\n" if @album
- ret += Terms[3]+@author+"\n" if @author
- @contents.each{|l| ret += l+"\n"}
- return ret
- end
-
- end
- a = Lrc.new("1.lrc")
- File.open("lrc.txt","w"){|file| file<<a.to_s}
- p a.to_s
- msgbox a.to_s if defined?(msgbox)
- exit
复制代码 |
|