2006年11月13日 星期一 13:45
把代码分离一下吧 比方说http下载的东西,放到单独的模块中 On 11/13/06, Xupeng Yun <recordus at gmail.com> wrote: > > 在06-11-13,nmweizi <nmweizi at 163.com> 写道: > > > > python-chinese,你好 > > > > 当线程HttpGetThread,在这个地方 > > conn = urllib2.urlopen(request) > > startTime = time.time() > > data = conn.read(self.bufferSize) > > 出错重试10次后,没有产生需要的文件*.mp3_?。这时在 > > > > MyHttpGet函数的 > > f = open(filename, 'wb') > > for n in names: > > f.write(open(n,'rb').read()) (出错)会中断退出程序,请修正。 > > > > 谢谢,我已经修正了。 > 最新的代码在啄木鸟的软件仓库中: > http://cvs.woodpecker.org.cn/svn/woodpecker/pygetsong/ > -- > I like Python & Linux. > Blog: http://recordus.cublog.cn > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Best Regards Shixin Zeng -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061113/f1c31550/attachment-0001.html
2006年11月13日 星期一 13:52
2006/11/13, Shixin Zeng <zeng.shixin at gmail.com>: > > 把代码分离一下吧 > 比方说http下载的东西,放到单独的模块中 > ok,其实最初写的时候没打算弄多强大,能完成基本的下载就好了,所以尽管各个模块原本是分开来一个一个写的,最后放出的时候都又合成了一个文件,为的是他人使用方便,多人开发的话的确很有必要分离一下。 你对URLChecker做了修改么?欢迎加入项目组对它进行改进:) -- I like Python & Linux. Blog: http://recordus.cublog.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061113/47a5b701/attachment.htm
2006年11月13日 星期一 14:16
下载的部分建议做成可替换的,比如可以使用pycurl替换掉现在使用的urllib2。 我现在在写一个从sourceforge上面下载东西的小程序,主要特点是跨多个镜像站点下载文件。就是使用pycurl。效率比urllib2好多了。 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061113/957e2fa1/attachment.html
2006年11月13日 星期一 18:37
On 11/13/06, Xupeng Yun <recordus at gmail.com> wrote: > > 2006/11/13, Shixin Zeng <zeng.shixin at gmail.com>: > > > > 把代码分离一下吧 > > 比方说http下载的东西,放到单独的模块中 > > > > > ok,其实最初写的时候没打算弄多强大,能完成基本的下载就好了,所以尽管各个模块原本是分开来一个一个写的,最后放出的时候都又合成了一个文件,为的是他人使用方便,多人开发的话的确很有必要分离一下。 > > 你对URLChecker做了修改么?欢迎加入项目组对它进行改进:) 你之前的算法是等所有的url都测试完了之后,再比较连接速度得出最快的url。这样有个问题就是,如果其中的某个url没法连上的话,就只有等到超时(你设置为10s)才能判断出连接速度。 我现在的算法是:不等所有的连接都完成,只要有一个连接完成就行了。当然我这没有考虑线程启动时的差别了,我假设它们都是同时启动的(不知这个假设合理不?)。 然后它们的速度不仅仅是由连接确定的,我还让它先尝试下载一定长度的数据(比方说1K)。这样,哪个先完成这个"连接,下载",就认为是最快的url。这样,就不用等到所有的都完成就能判断出最好的url了。 现在的代码还需要一些清理,如果你觉得这个算法可行的话,我稍后整理好给出。 > -- > I like Python & Linux. > Blog: http://recordus.cublog.cn > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Best Regards Shixin Zeng -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061113/66b8bf9e/attachment.htm
2006年11月13日 星期一 21:14
2006/11/13, Shixin Zeng <zeng.shixin at gmail.com>: > > > 你之前的算法是等所有的url都测试完了之后,再比较连接速度得出最快的url。这样有个问题就是,如果其中的某个url没法连上的话,就只有等到超时(你设置为10s)才能判断出连接速度。 > 我现在的算法是:不等所有的连接都完成,只要有一个连接完成就行了。当然我这没有考虑线程启动时的差别了,我假设它们都是同时启动的(不知这个假设合理不?)。 > 然后它们的速度不仅仅是由连接确定的,我还让它先尝试下载一定长度的数据(比方说1K)。这样,哪个先完成这个"连接,下载",就认为是最快的url。这样,就不用等到所有的都完成就能判断出最好的url了。 > > > 现在的代码还需要一些清理,如果你觉得这个算法可行的话,我稍后整理好给出。 > 好啊,不妨整理一下你的算法,有必要的话可以做一个性能对比测试。我使用的简单算法其实原本也是为了实现方便,不过在我这里测试的状况还算好,找到的URL在下载时基本上都可以让我的2M ADSL满载,就没有再想其他更优的算法了。期待你的算法,如果性能更好的话当然要用它来取代我现在使用的了:) -- I like Python & Linux. Blog: http://recordus.cublog.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061113/7d162076/attachment.html
2006年11月13日 星期一 22:17
2006/11/13, 3751 <lwm3751 at gmail.com>: > > 下载的部分建议做成可替换的,比如可以使用pycurl替换掉现在使用的urllib2。 > 我现在在写一个从sourceforge上面下载东西的小程序,主要特点是跨多个镜像站点下载文件。就是使用pycurl。效率比urllib2好多了。 > 看了一下pycurl,是个好东东,要研究一下,谢谢推荐。 -- I like Python & Linux. Blog: http://recordus.cublog.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061113/ace3bc92/attachment.html
2006年11月13日 星期一 23:39
下面给出我改都之后的部分。 AnalysisHeader是新增的函数 其他的都是修改原来的函数。 On 11/13/06, Xupeng Yun <recordus at gmail.com> wrote: > 2006/11/13, Shixin Zeng <zeng.shixin at gmail.com>: > > > > > > > 你之前的算法是等所有的url都测试完了之后,再比较连接速度得出最快的url。这样有个问题就是,如果其中的某个url没法连上的话,就只有等到超时(你设置为10s)才能判断出连接速度。 > > 我现在的算法是:不等所有的连接都完成,只要有一个连接完成就行了。当然我这没有考虑线程启动时的差别了,我假设它们都是同时启动的(不知这个假设合理不?)。 然后它们的速度不仅仅是由连接确定的,我还让它先尝试下载一定长度的数据(比方说1K)。这样,哪个先完成这个"连接,下载",就认为是最快的url。这样,就不用等到所有的都完成就能判断出最好的url了。 > > > > 现在的代码还需要一些清理,如果你觉得这个算法可行的话,我稍后整理好给出。 > > > > 好啊,不妨整理一下你的算法,有必要的话可以做一个性能对比测试。我使用的简单算法其实原本也是为了实现方便,不过在我这里测试的状况还算好,找到的URL在下载时基本上都可以让我的2M ADSL满载,就没有再想其他更优的算法了。期待你的算法,如果性能更好的话当然要用它来取代我现在使用的了:) def AnalysysHttpHeader(headers): ret = {} for header in headers: if header.find('Length') != -1: length = header.split(':')[-1].strip() ret['length'] = int(length) return ret class URLChecker(threading.Thread): fastest_url_cond = threading.Condition() fastest_url = '' failed_url = 0 total_url = 0 def __init__(self, fakeurl): threading.Thread.__init__(self, name='') self.url = GetRealMp3URL(fakeurl) def run(self): if not self.url: URLChecker.fastest_url_cond.acquire() URLChecker.failed_url += 1 if URLChecker.failed_url == URLChecker.total_url: URLChecker.fastest_url_cond.notify() URLChecker.fastest_url_cond.release() return socket.setdefaulttimeout(10) try: conn = urllib2.urlopen(self.url) length = AnalysysHttpHeader(conn.info().headers)['length'] if length < 1024 * 1024: raise TooSmall("The file is smaller than 1 M, considered as a broken file") conn.read(1024) #read 1024 bytes before concluding which is the fastest one. URLChecker.fastest_url_cond.acquire() if URLChecker.fastest_url != '': # the URLChecker.fastest url was detected already by other threads URLChecker.fastest_url_cond.release() return print "%s detected the fastest url" % self.getName() URLChecker.fastest_url = self.url URLChecker.fastest_url_cond.notify() URLChecker.fastest_url_cond.release() except Exception, e: URLChecker.fastest_url_cond.acquire() URLChecker.failed_url += 1 if URLChecker.failed_url == URLChecker.total_url: URLChecker.fastest_url_cond.notify() URLChecker.fastest_url_cond.release() def GetBestUrl(urls): cthreads = [] URLChecker.total_url = len(urls) URLChecker.fastest_url = '' URLChecker.failed_url = 0 if URLChecker.total_url == 0: print "urls is empty, return now" sys.stdout.flush() return '' if URLChecker.total_url == 1: print "There is only one available url" sys.stdout.flush() return urls[0] sys.stdout.flush() for url in urls: t = URLChecker(url) cthreads.append(t) t.start() URLChecker.fastest_url_cond.acquire() while URLChecker.fastest_url == '' \ and URLChecker.failed_url < URLChecker.total_url: URLChecker.fastest_url_cond.wait() URLChecker.fastest_url_cond.release() return URLChecker.fastest_url > > -- > I like Python & Linux. > Blog: http://recordus.cublog.cn > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Best Regards Shixin Zeng
2006年11月14日 星期二 00:05
2006/11/13, Shixin Zeng <zeng.shixin at gmail.com>: > > 下面给出我改都之后的部分。 > AnalysisHeader是新增的函数 > 其他的都是修改原来的函数。 > > def AnalysysHttpHeader(headers): > ret = {} > for header in headers: > if header.find('Length') != -1: > length = header.split(':')[-1].strip() > ret['length'] = int(length) > return ret > > class URLChecker(threading.Thread): > fastest_url_cond = threading.Condition() > fastest_url = '' > failed_url = 0 > total_url = 0 > def __init__(self, fakeurl): > threading.Thread.__init__(self, name='') > self.url = GetRealMp3URL(fakeurl) > > def run(self): > if not self.url: > URLChecker.fastest_url_cond.acquire() > URLChecker.failed_url += 1 > if URLChecker.failed_url == URLChecker.total_url: > URLChecker.fastest_url_cond.notify() > URLChecker.fastest_url_cond.release() > return > socket.setdefaulttimeout(10) > try: > conn = urllib2.urlopen(self.url) > length = AnalysysHttpHeader(conn.info().headers)['length'] > if length < 1024 * 1024: > raise TooSmall("The file is smaller than 1 M, considered > as a broken file") > conn.read(1024) #read 1024 bytes before concluding which > is the fastest one. > URLChecker.fastest_url_cond.acquire() > if URLChecker.fastest_url != '': # the URLChecker.fastest url > was > detected already by other threads > URLChecker.fastest_url_cond.release() > return > print "%s detected the fastest url" % self.getName() > URLChecker.fastest_url = self.url > URLChecker.fastest_url_cond.notify() > URLChecker.fastest_url_cond.release() > except Exception, e: > URLChecker.fastest_url_cond.acquire() > URLChecker.failed_url += 1 > if URLChecker.failed_url == URLChecker.total_url: > URLChecker.fastest_url_cond.notify() > URLChecker.fastest_url_cond.release() > > def GetBestUrl(urls): > cthreads = [] > URLChecker.total_url = len(urls) > URLChecker.fastest_url = '' > URLChecker.failed_url = 0 > if URLChecker.total_url == 0: > print "urls is empty, return now" > sys.stdout.flush() > return '' > if URLChecker.total_url == 1: > print "There is only one available url" > sys.stdout.flush() > return urls[0] > sys.stdout.flush() > for url in urls: > t = URLChecker(url) > cthreads.append(t) > t.start() > > URLChecker.fastest_url_cond.acquire() > while URLChecker.fastest_url == '' \ > and URLChecker.failed_url < URLChecker.total_url: > URLChecker.fastest_url_cond.wait() > URLChecker.fastest_url_cond.release() > return URLChecker.fastest_url > 这个应该会更好,明天再好好看看放进去。 -- I like Python & Linux. Blog: http://recordus.cublog.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061114/9fd33416/attachment.htm
2006年11月16日 星期四 20:50
写一个xmms的插件吧。 On Sun, 2006-11-12 at 22:05 +0800, Xupeng Yun wrote: > 在06-11-12,boyeestudio <boyee118在gmail.com> 写道: > 太棒了。建议做成一个项目出来,大家一起来完善。 > 1。进行功能完善。 > 2。加入GUI界面。 > 还有...... > > > > 谢谢,我也有计划以后加入GUI的,就是现在在匹配精确度上还有一些问题,以 > 及其他的一些小问题在绊脚,等脚本基本上稳定了会考虑加入GUI支持,如果有 > 人能帮忙完善一下脚本、加一个GUI前端就更好了:) > > 其实我前几天在googlecode上注册了一个名为getsong的项目,只是我这里使用 > svn连接googlecode经常有问题使用不太方便,如果有必要做一个小项目的话能 > 否推荐一个好用些的仓库? > > > -- > I like Python & Linux. > Blog: http://recordus.cublog.cn > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年11月19日 星期日 17:32
ÔÚ×ÄľÄñÉÏÔõô¼ÓÈëÕâ¸öÏîÄ¿. ÎÒÊÔÁËÒ»ÏÂ.û³É¹¦. ÕâÀïÓÐÁ½¸öÐèÇó£º 1.¼ÓÈë¸è´ÊËÑË÷¹¦ÄÜ¡£Ôõ¸ö¿ÉÒԲο¼lyrics²å¼þµÄ¹¦ÄÜ¡£ 2.ÍøÂç·½Ãæ£¬Ï£Íû¼ÓÈë´úÀíµÄ¹¦ÄÜ¡£¼´´úÀí·þÎñÆ÷¼°¶Ë¿ÚÊäÈ룬Óû§Ãû¼°ÃÜÂëÊäÈë¡£ 2006/11/16, WangXinxi <wangxinxi在cs.hit.edu.cn>: > > дһ¸öxmmsµÄ²å¼þ°É¡£ > > On Sun, 2006-11-12 at 22:05 +0800, Xupeng Yun wrote: > > ÔÚ06-11-12£¬boyeestudio <boyee118在gmail.com> дµÀ£º > > Ì«°ôÁË¡£½¨Òé×ö³ÉÒ»¸öÏîÄ¿³öÀ´£¬´ó¼ÒÒ»ÆðÀ´ÍêÉÆ¡£ > > 1¡£½øÐй¦ÄÜÍêÉÆ¡£ > > 2¡£¼ÓÈëGUI½çÃæ¡£ > > »¹ÓÐ...... > > > > > > > > лл£¬ÎÒÒ²Óмƻ®ÒÔºó¼ÓÈëGUIµÄ£¬¾ÍÊÇÏÖÔÚÔÚÆ¥Å侫ȷ¶ÈÉÏ»¹ÓÐһЩÎÊÌ⣬ÒÔ > > ¼°ÆäËûµÄһЩСÎÊÌâÔÚ°í½Å£¬µÈ½Å±¾»ù±¾ÉÏÎȶ¨Á˻ῼÂǼÓÈëGUIÖ§³Ö£¬Èç¹ûÓÐ > > ÈËÄܰïæÍêÉÆÒ»Ï½ű¾¡¢¼ÓÒ»¸öGUIǰ¶Ë¾Í¸üºÃÁË:) > > > > ÆäʵÎÒǰ¼¸ÌìÔÚgooglecodeÉÏ×¢²áÁËÒ»¸öÃûΪgetsongµÄÏîÄ¿£¬Ö»ÊÇÎÒÕâÀïʹÓà > > svnÁ¬½Ógooglecode¾³£ÓÐÎÊÌâʹÓò»Ì«·½±ã£¬Èç¹ûÓбØÒª×öÒ»¸öСÏîÄ¿µÄ»°ÄÜ > > ·ñÍÆ¼öÒ»¸öºÃÓÃЩµÄ²Ö¿â£¿ > > > > > > -- > > I like Python & Linux. > > Blog: http://recordus.cublog.cn > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061119/ceddc8be/attachment.html
2006年11月19日 星期日 18:31
在06-11-19,boyeestudio <boyee118 at gmail.com> 写道: > > 在啄木鸟上怎么加入这个项目. > 我试了一下.没成功. > 这里有两个需求: > 1.加入歌词搜索功能。怎个可以参考lyrics插件的功能。 > 2.网络方面,希望加入代理的功能。即代理服务器及端口输入,用户名及密码输入。 可以给Zoom Quiet发mail说要加入pygetsong,Zoom Quiet给你创建一个svn帐号。 歌词搜索我以前做过,本来是做mpd的歌词显示插件的就写了一个,只是我最近在参加一个培训每天只有可怜的一点点空闲时间没有机会来整理,欢迎你加入进来对pygetsong进行改进,加入更多的功能。 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061119/b8aa6975/attachment.html
2006年11月19日 星期日 21:16
On 日, 11月 19, 2006 at 05:32:37下午 +0800, boyeestudio wrote: > > 在啄木鸟上怎么加入这个项目. > 我试了一下.没成功. > 这里有两个需求: > 1.加入歌词搜索功能。怎个可以参考lyrics插件的功能。 > 2.网络方面,希望加入代理的功能。即代理服务器及端口输入,用户名及密码输 > 入。 > > 2006/11/16, WangXinxi <[1] wangxinxi at cs.hit.edu.cn>: > > 写一个xmms的插件吧。 > On Sun, 2006-11-12 at 22:05 +0800, Xupeng Yun wrote: > > 在06-11-12,boyeestudio <[2]boyee118 at gmail.com> 写道: > > 太棒了。建议做成一个项目出来,大家一起来完善。 > > 1。进行功能完善。 > > 2。加入GUI界面。 > > 还有...... > > > > > > > > > 谢谢,我也有计划以后加入GUI的,就是现在在匹配精确度上还有一些问题, > 以 > > 最好能加入mp3的id3tag的转码功能,gb2312 gbk的编码太恶心了,现在很多程序只支持utf8了. > 及其他的一些小问题在绊脚,等脚本基本上稳定了会考虑加入GUI支持,如果 > 有 > > 人能帮忙完善一下脚本、加一个GUI前端就更好了:) > > > > > 其实我前几天在googlecode上注册了一个名为getsong的项目,只是我这里使 > 用 > > svn连接googlecode经 > 常有问题使用不太方便,如果有必要做一个小项目的话能 > > 否推荐一个好用些的仓库? > > > > > > -- > > I like Python & Linux. > > Blog: [3]http://recordus.cublog.cn > > _______________________________________________ > > python-chinese > > Post: send [4]python-chinese at lists.python.cn > > Subscribe: send subscribe to > [5]python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe > to [6]python-chinese-request at lists.python.cn > > Detail Info: [7]http://python.cn/mailman/listinfo/python-chinese > _______________________________________________ > python-chinese > Post: send [8]python-chinese at lists.python.cn > Subscribe: send subscribe to > [9]python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to [10] > python-chinese-request at lists.python.cn > Detail Info: [11]http://python.cn/mailman/listinfo/python-chinese > > References > > 1. mailto:wangxinxi at cs.hit.edu.cn > 2. mailto:boyee118 at gmail.com > 3. http://recordus.cublog.cn/ > 4. mailto:python-chinese at lists.python.cn > 5. mailto:python-chinese-request at lists.python.cn > 6. mailto:python-chinese-request at lists.python.cn > 7. http://python.cn/mailman/listinfo/python-chinese > 8. mailto:python-chinese at lists.python.cn > 9. mailto:python-chinese-request at lists.python.cn > 10. mailto:python-chinese-request at lists.python.cn > 11. http://python.cn/mailman/listinfo/python-chinese > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://python.cn/pipermail/python-chinese/attachments/20061119/ff0e65cf/attachment.pgp
2006年11月20日 星期一 00:25
ID3编码的转换可以试试eyeD3这个模块,
我练习用optparse做解析参数时利用eyeD3写了一个简单的id3编码转换的脚本。
大家可以参考一下(好像不用自己写,直接用eyeD3也能完成编码转换吧?):
import eyeD3
import os
import sys
from optparse import OptionParser,OptionGroup
class ConsoleColors(dict):
use = 1;
def __init__(self):
self["normal"] = chr(0x1b) + "[0m";
self["header"] = chr(0x1b) + "[32m";
self["warning"] = chr(0x1b) + "[33m";
self["error"] = chr(0x1b) + "[31m";
self["bold"] = chr(0x1b) + "[1m";
def enabled(self, b):
self.use = b;
# Accessor override.
def __getitem__(self, key):
if self.use:
return dict.__getitem__(self, key);
else:
return "";
colors = ConsoleColors();
def printWarning(s):
print colors["warning"] + str(s) + colors["normal"];
def printError(s):
print colors["error"] + str(s) + colors["normal"];
def dirVisit(fileList, dirname, files):
for f in files:
if eyeD3.isMp3File(f) or os.path.splitext(f)[1] == ".tag":
fileList.append(os.path.join(dirname, f));
def get_opt():
MSG_USAGE = "%prog [OPTIONS] file [file...]"
parser = OptionParser(MSG_USAGE, version="%prog "+__version__)
parser.add_option("-e", "--encoding", action = "store", type =
"string",
dest = "encoding", metavar="gb18030|iso-8859-1", default =
"gb18030",
help="指定文件的编码")
parser.add_option("-f", "--fixed", action = "store_true",
dest = "fixed", default = False,
help="是否修复ID3")
parser.add_option("-r", "--remove", action = "store_true",
dest = "remove", default = False,
help="是否删除ID3")
return parser
def trans_txt(string, encoding):
try:
new_string=string.encode("iso-8859-1").decode(encoding).encode("utf8")
except:
new_string=string
return new_string
def main():
parser = get_opt()
(options, args) = parser.parse_args()
if len(args) == 0:
parser.error("File/directory argument(s) required");
return 1;
tag = eyeD3.Tag()
files = [];
for a in args:
if os.path.isfile(a):
files.append(a);
elif os.path.isdir(a):
os.path.walk(a, dirVisit, files);
else:
printError("File Not Found: %s" % a);
for file in files:
try:
tag.link(file)
#except eyeD3.tag.TagException:
except:
continue
artist = trans_txt(tag.getArtist(), options.encoding)
album = trans_txt(tag.getAlbum(), options.encoding)
title = trans_txt(tag.getTitle(), options.encoding)
comm=tag.getComments()
c_lang='chi'
c_desc=''
c_txt=''
for c in comm:
c_lang = trans_txt(c.lang, options.encoding)
c_desc = trans_txt(c.description, options.encoding)
c_txt = trans_txt(c.comment, options.encoding)
if options.fixed:
tag.setVersion(eyeD3.ID3_V2)
tag.setTextEncoding(eyeD3.UTF_8_ENCODING)
tag.setArtist(artist)
tag.setAlbum(album)
tag.setTitle(title)
tag.addComment(c_txt, c_desc, c_lang)
tag.update(eyeD3.ID3_V2)
elif options.remove:
tag.setVersion(eyeD3.ID3_V2)
tag.setTextEncoding(eyeD3.UTF_8_ENCODING)
tag.setArtist("")
tag.setAlbum("")
tag.setTitle("")
tag.addComment("","","")
tag.update(eyeD3.ID3_V2)
else:
print "\n\n", "="*80, "\n", file, "\n", "-"*80
print "Artist: %s \t Album: %s \t Title: %s" %
(artist,album,title)
print ("Comment: [Description: %s] [Lang: %s]\n%s" %
(c_desc, c_lang, c_txt))
import sys
sys.exit()
if __name__=="__main__":
main()
在 2006-11-19日的 21:16 +0800,ZhengPeng Hou写道:
> On 日, 11月 19, 2006 at 05:32:37下午 +0800, boyeestudio wrote:
> >
> > 在啄木鸟上怎么加入这个项目.
> > 我试了一下.没成功.
> > 这里有两个需求:
> > 1.加入歌词搜索功能。怎个可以参考lyrics插件的功能。
> > 2.网络方面,希望加入代理的功能。即代理服务器及端口输入,用户名及密码输
> > 入。
> >
> > 2006/11/16, WangXinxi <[1] wangxinxi at cs.hit.edu.cn>:
> >
> > 写一个xmms的插件吧。
> > On Sun, 2006-11-12 at 22:05 +0800, Xupeng Yun wrote:
> > > 在06-11-12,boyeestudio <[2]boyee118 at gmail.com> 写道:
> > > 太棒了。建议做成一个项目出来,大家一起来完善。
> > > 1。进行功能完善。
> > > 2。加入GUI界面。
> > > 还有......
> > >
> > >
> > >
> > >
> > 谢谢,我也有计划以后加入GUI的,就是现在在匹配精确度上还有一些问题,
> > 以
> > >
> 最好能加入mp3的id3tag的转码功能,gb2312
> gbk的编码太恶心了,现在很多程序只支持utf8了.
> > 及其他的一些小问题在绊脚,等脚本基本上稳定了会考虑加入GUI支持,如果
> > 有
> > > 人能帮忙完善一下脚本、加一个GUI前端就更好了:)
> > >
> > >
> > 其实我前几天在googlecode上注册了一个名为getsong的项目,只是我这里使
> > 用
> > > svn连接googlecode经
> > 常有问题使用不太方便,如果有必要做一个小项目的话能
> > > 否推荐一个好用些的仓库?
> > >
> > >
> > > --
> > > I like Python & Linux.
> > > Blog: [3]http://recordus.cublog.cn
> > > _______________________________________________
> > > python-chinese
> > > Post: send [4]python-chinese at lists.python.cn
> > > Subscribe: send subscribe to
> > [5]python-chinese-request at lists.python.cn
> > > Unsubscribe: send unsubscribe
> > to [6]python-chinese-request at lists.python.cn
> > > Detail Info: [7]http://python.cn/mailman/listinfo/python-chinese
> > _______________________________________________
> > python-chinese
> > Post: send [8]python-chinese at lists.python.cn
> > Subscribe: send subscribe to
> > [9]python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to [10]
> > python-chinese-request at lists.python.cn
> > Detail Info: [11]http://python.cn/mailman/listinfo/python-chinese
> >
> > References
> >
> > 1. mailto:wangxinxi at cs.hit.edu.cn
> > 2. mailto:boyee118 at gmail.com
> > 3. http://recordus.cublog.cn/
> > 4. mailto:python-chinese at lists.python.cn
> > 5. mailto:python-chinese-request at lists.python.cn
> > 6. mailto:python-chinese-request at lists.python.cn
> > 7. http://python.cn/mailman/listinfo/python-chinese
> > 8. mailto:python-chinese at lists.python.cn
> > 9. mailto:python-chinese-request at lists.python.cn
> > 10. mailto:python-chinese-request at lists.python.cn
> > 11. http://python.cn/mailman/listinfo/python-chinese
>
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
Zeuux © 2025
京ICP备05028076号