I got a Chinese file named 005大禹治水.lrc, and I want to print out the filename with its directory, like: /home/user/lrc/005大禹治水.lrc
Here is what I tried in Python 2.7:
# -*- coding: utf-8 -*-
from __future__ import print_function
import argparse
import os
from pydub import AudioSegment
def main():
wd= os.path.split(os.path.realpath(__file__))[0]
parser = argparse.ArgumentParser()
parser.add_argument('--lrc', default=os.path.expanduser(wd + '/lrc'))
args = parser.parse_args()
'''
saving lrc files path and name into list
'''
lrc_files_path = []
for file in os.listdir(args.lrc):
if file.endswith(".lrc"):
lrc_files_path.append(os.path.join(args.lrc, file))
print(lrc_files_path)
print("*" * 38)
if __name__ == "__main__":
main()
the output is:
['/home/user/lrc/005\xe5\xa4\xa7\xe7\xa6\xb9\xe6\xb2\xbb\xe6\xb0\xb4.lrc']
Which is not as I expected as run by Python 3.0+:
['/home/user/lrc/005大禹治水.lrc']
Actually, this problem will not be disturbed in Python 3.0+. However, the task I am handling is required using pydub (Not supports with Python 3.0+) in order to editing the mp3 file based on the time line from lrc file. :(
I did some researches about the UTF-8 converting of Chinese, and tried out some potential solutions, but nothing comes up at last. :(
Any suggestion greatly appreciate!