Beispiel #1
0
def main():
    global filelist
    noIntro = False
    while True:
        if len(filelist) == 0:
            ui.throw('没有提供任何文件!', True)
        if filelist[0] == '-s':
            noIntro = True
            del filelist[0]
        elif filelist[0] == '-c':
            del filelist[0]
            if len(filelist) == 0:
                ui.throw('错误的参数:-c。', True)
            ui.g.cText = filelist[0]
            del filelist[0]
        elif filelist[0] == '--help':
            ui.showCmdHelp()
            exit()
        else:
            break
    if not noIntro:
        ui.showIntro()
    while True:
        for f in filelist:
            player.play(f)
        ui.showRoll()
Beispiel #2
0
def main():
    global filelist
    noIntro = False
    while True:
        if len(filelist) == 0:
            ui.throw('没有提供任何文件!', True)
        if filelist[0] == '-s':
            noIntro = True
            del filelist[0]
        elif filelist[0] == '-c':
            del filelist[0]
            if len(filelist) == 0:
                ui.throw('错误的参数:-c。', True)
            ui.g.cText = filelist[0]
            del filelist[0]
        elif filelist[0] == '--osd':
            ui.g.enable_osd = True
            del filelist[0]
        elif filelist[0] == '--help':
            ui.showCmdHelp()
            exit()
        else:
            break
    if not noIntro:
        ui.showIntro()
    while True:
        ui.g.step = 0
        for f in filelist:
            player.play(f)
        ui.g.step = 1
        ui.showRoll()
Beispiel #3
0
def loadLrc(lrcFile):
	g.lrcds = {}  # Clear last datas
	g.timeline = []
	if not path.exists(lrcFile):
		return False
	lf = open(lrcFile)
	while True:
		line = lf.readline()
		if line == '':
			break
		line = iconv(line).strip()
		if line == '':  # Skip blank line
			continue
		if not line.startswith('['):
			ui.throw('未知的 LRC 节:' + line)
			continue
		line = line[1:]
		line = line.split(']', 1)
		if len(line) != 2:
			ui.throw('LRC 节异常:' + str(line))
			continue
		line[0] = line[0].split(':')
		# For LRC section: "[a:b]c"
		# line = [[a, b], c]
		if not line[0][0].isdigit():  # LRC data	line[1] == '' and 
			g.lrcds[line[0][0]] = line[0][1]
		else:
			offset = 0
			if g.lrcds.has_key('offset'):
				offset = int(g.lrcds['offset'])
			time = int((int(line[0][0]) * 60 + float(line[0][1])) * 1000)
			g.timeline.append([time + offset, line[1]])
	g.timeline.sort()
	return True
Beispiel #4
0
def loadLrc(lrcFile):
    g.lrcds = {}  # Clear last datas
    g.timeline = []
    if not path.exists(lrcFile):
        return False
    lf = open(lrcFile)
    while True:
        line = lf.readline()
        if line == '':
            break
        line = iconv(line).strip()
        if line == '':  # Skip blank line
            continue
        if not line.startswith('['):
            ui.throw('未知的 LRC 节:' + line)
            continue
        line = line[1:]
        line = line.split(']', 1)
        if len(line) != 2:
            ui.throw('LRC 节异常:' + str(line))
            continue
        line[0] = line[0].split(':')
        # For LRC section: "[a:b]c"
        # line = [[a, b], c]
        if not line[0][0].isdigit():  # LRC data	line[1] == '' and
            g.lrcds[line[0][0]] = line[0][1]
        else:
            offset = 0
            if g.lrcds.has_key('offset'):
                offset = int(g.lrcds['offset'])
            time = int((int(line[0][0]) * 60 + float(line[0][1])) * 1000)
            g.timeline.append([time + offset, line[1]])
    g.timeline.sort()
    return True
Beispiel #5
0
def play(f):  # f: Filename
    if not path.exists(f):
        ui.throw('文件不存在:' + f)
        return
    mf = mad.MadFile(f)
    dev = ao.AudioDevice('alsa', rate = mf.samplerate())
    ui.setInfo(f, mf.total_time())
    ui.g.lrcFile = lrc.changeExt(f)
    if not lrc.loadLrc(ui.g.lrcFile):  # No LRC file
        ui.g.lrcFile = ''
    g.skip = False
    while not g.skip:
        if not g.paused:
            buf = mf.read()
            if buf is None:
                break
            dev.play(buf, len(buf))
            ui.setTime(mf.current_time())
        else:
            time.sleep(0.1)
        ui.draw()
Beispiel #6
0
def play(f):  # f: Filename
    if not path.exists(f):
        ui.throw('文件不存在:' + f)
        return
    mf = mad.MadFile(f)
    dev = ao.AudioDevice('alsa', rate=mf.samplerate())
    ui.setInfo(f, mf.total_time())
    ui.g.lrcFile = lrc.changeExt(f)
    if not lrc.loadLrc(ui.g.lrcFile):  # No LRC file
        ui.g.lrcFile = ''
    g.skip = False
    while not g.skip:
        if not g.paused:
            buf = mf.read()
            if buf is None:
                break
            dev.play(buf, len(buf))
            ui.setTime(mf.current_time())
        else:
            time.sleep(0.1)
        ui.draw()