I am trying to embedded Chinese names (title, Artist, Year, Genre and Album) in a mp3 file. title names will be taken from a CSV file(which has Chinese data).
The code is working but the when i check the mp3 files details, every thing is shown in '?????' this is happening only when the data is in Chinese. But when the data is in English. its working fine. I have no idea whats going wrong in my code.
Please find the code below.
from argparse import ArgumentParser
from mutagen.easyid3 import EasyID3
from datetime import datetime
from string import Template
import os
import sys
import datetime
import codecs
import string
import shutil
import re
import logging
import io
import eyed3
import id3
import csv
UTF8Writer = codecs.getwriter('utf8')
sys.stdout = UTF8Writer(sys.stdout)
save_stdout = sys.stdout
filename_mp3_csv = "mp3_ArtTitAlbGenYer.csv"
outfile = open ('mp3_cop.cop', 'wb')
def get_args()
parser = ArgumentParser()
parser.add_argument("-t", "--mp3template", help="filename of mp3 file to be used as template",default="template.mp3")
parser.add_argument("-l", "--language", help="name of language folder e.g. enu", default="enu")
parser.add_argument("-ic", "--mp3_scv", help="filename of csv file to be used as input", default="mp3_ArtTitAlbGenYer.csv")
args = parser.parse_args()
return args
def something():
if __name__ == '__main__':
args = get_args()
i=0
while os.path.exists("%s.mp3" % i):
i+=1
fh = open("%s.mp3" % i, "w")
shutil.copy2(args.mp3template, "%s.mp3" %i)
audio = EasyID3("%s.mp3" %i)
audio["title"] =Title
audio["artist"] = Artist
audio["album"] = Album
audio["date"] = Year
audio["genre"] = Genre
audio["tracknumber"] = u"1"
audio.save()
return
try:
file = codecs.open(filename_mp3_csv, "r",encoding='utf-8-sig')
for line in file:
item = line.split(';')
Artist = item[0].rstrip()
Title = item[1].rstrip()
Album = item[2].rstrip()
Genre = item[3].rstrip()
Year = item[4].rstrip()
print(line.rstrip(';'))
something()
file.close()
except IOError as err:
mustwritesomethinghere = 0
print >> sys.stderr, "error: unable to read mandatory inputfile " + filename_mp3_csv
What I have tried:
I have no idea what to do, because the code is working when the CSV file is having English data and but when it has Chinese data it not working