-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtokgl.py
35 lines (26 loc) · 1013 Bytes
/
tokgl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
from lxml import etree
import argparse
import codecs
def to_kgl(songs, name, output):
root = etree.Element("List", ListName=name)
for song in songs:
songname = song + ".mp3"
file_node = etree.SubElement(root, "File")
name_node = etree.SubElement(file_node, "FileName")
name_node.text = songname
etree.ElementTree(root).write(output,
xml_declaration=True,
encoding="utf8",
pretty_print=True)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("file", help="歌单列表文件")
parser.add_argument("name", help="歌单名称")
parser.add_argument("out", help="输出文件")
args = parser.parse_args()
songs = []
with codecs.open(args.file, "r", encoding="utf-8") as f:
for line in f:
songs.append(line.rstrip("\n"))
to_kgl(songs, args.name, args.out)