赞 | 451 |
VIP | 56 |
好人卡 | 75 |
积分 | 424 |
经验 | 124650 |
最后登录 | 2024-11-27 |
在线时间 | 7603 小时 |
Lv5.捕梦者 (管理员) 老黄鸡
- 梦石
- 0
- 星屑
- 42436
- 在线时间
- 7603 小时
- 注册时间
- 2009-7-6
- 帖子
- 13506
|
看到这玩意真怀念啊,我以前也写过一个。
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
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
|
|