扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
mldonkey.py
# -*- coding: cp936 -*- ############################################################ # convert mldonkey's chinese # Version: 0.1 # Author: kongxx # Email: kongxxcn@yahoo.com.cn ############################################################ import os ,sys ,string ,urllib ,telnetlib ,operator
# define the mldonkey incoming dir sdir='/usr/local/mldonkey/incoming/'
#flag the num sNum='0123456789'
#length len8 = 8 len12 = 12 lengths = [len8 ,len12]
def convert(): filenames=os.listdir(sdir) for filename in filenames : for length in lengths : s1 = filename s2 = convertName(filename ,length) try : if s1 != s2 : print '############################################################' print 'The source name is:' + s1 print 'The target name is:' + s2 print '' confirm = raw_input('Do you confirm rename the file[yes or no]? ') if confirm == 'yes' : os.rename(sdir + s1 ,sdir + s2) break except UnicodeDecodeError: print ''
# convert ths file name # param s the filename # param length def convertName(s ,length) : location = 0 ret = ''
if length not in lengths: return s
while True : if location + length <= len(s) : subStr = s[location:location + length] if check(subStr) : if length == len8 : ret += "%" + hex((int)(subStr[1:4]))[2:4] + "%" + hex((int)(subStr[5:8]))[2:4] if length == len12 : ret += "%" + hex((int)(subStr[1:4]))[2:4] + "%" + hex((int)(subStr[5:8]))[2:4] + "%" + hex((int)(subStr[9:12]))[2:4] location = location + length else : ret += s[location :location + 1] location = location + 1 else : ret += s[location:] break
ret = urllib.unquote(ret) if ret == s : return s
try : if length == len8 : return ret.decode('GBK') if length == len12 : return ret.decode('UTF-8') except UnicodeDecodeError: return ret
def check(s): if len(s) != len8 and len(s) != len12: return False
if s[0] != '_' or s[4] != '_' : return False
if len(s) == len12 and s[8] != '_': return False
s = s.replace('_','') for c in s : if (c not in sNum) :return False
return True
convert()
|
在命令行输入python mldonkey.py即可以转换。
在命令行输入python mldonkey.py即可以转换。如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者