old_contents: #!/usr/bin/python
  # coding=utf-8
  
  __author__ = 'luowei'
  
  import sqlite3
  import re
  import codecs
  import os.path
  import os
  import re
  
  # 获取当前目录
  # cwd = os.getcwd()
  # dir_path = os.path.dirname(os.path.realpath(__file__))
  # dir = dir_path+'/aaa'
  
  dir = raw_input("请输入文件夹名: ")
  ting = raw_input("请输入喜玛拉雅下载目录的sqlite文件名(直接回车，默认为'ting.sqlite')：")
  
  # def whatisthis(s):
  #     if isinstance(s, str):
  #         print "ordinary string"
  #     elif isinstance(s, unicode):
  #         print "unicode string"
  #     else:
  #         print "not a string"
  
  def isUnicode(s):
      if isinstance(s, unicode):
          return True
      else:
          return False
  
  
  def renameTingMp3(dirString, tingString):
      dir = unicode(dirString, "utf-8")
      ting = unicode(tingString, "utf-8")
      # pattern = re.compile("\s")
      # pattern.match(ting)
      if re.match('^\s*$',ting):
          ting = 'ting.sqlite'
  
      conn = sqlite3.connect(dir + '/' + ting)
      # print "Opened database successfully"
  
      # 输出数据库中所有的表
      # res = conn.execute("SELECT name FROM sqlite_master WHERE type='table';")
      # for name in res:
      #     print name[0]
  
      cur = conn.cursor()
      cur.execute('SELECT title,filePath FROM download_table')
  
      rows = cur.fetchall()
  
      for row in rows:
          name = row[0]
          md5Name = row[1]
          # print(row[0])
          namePath = dir + '/' + name + '.mp3'
          md5Path = dir + '/' + md5Name + '.mp3'
          if os.path.exists(md5Path):
              os.rename(md5Path, namePath)
              print('修改：' + md5Path.encode('utf8') + ' 为 ' + namePath.encode('utf8'))
  
      conn.close()
  
  renameTingMp3(dir,ting)
  
new_contents: #!/usr/bin/python
  # coding=utf-8
  
  __author__ = 'luowei'
  
  import sqlite3
  import re
  import codecs
  import os.path
  import os
  import re
  
  #批量改文件：for i in *; do mv $i $i.mp3; done;
  
  # 获取当前目录
  # cwd = os.getcwd()
  # dir_path = os.path.dirname(os.path.realpath(__file__))
  # dir = dir_path+'/aaa'
  
  dir = raw_input("请输入文件夹名: ")
  ting = raw_input("请输入喜玛拉雅下载目录的sqlite文件名(直接回车，默认为'ting.sqlite')：")
  
  # def whatisthis(s):
  #     if isinstance(s, str):
  #         print "ordinary string"
  #     elif isinstance(s, unicode):
  #         print "unicode string"
  #     else:
  #         print "not a string"
  
  def isUnicode(s):
      if isinstance(s, unicode):
          return True
      else:
          return False
  
  
  def renameTingMp3(dirString, tingString):
      dir = unicode(dirString, "utf-8")
      ting = unicode(tingString, "utf-8")
      # pattern = re.compile("\s")
      # pattern.match(ting)
      if re.match('^\s*$',ting):
          ting = 'ting.sqlite'
  
      conn = sqlite3.connect(dir + '/' + ting)
      # print "Opened database successfully"
  
      # 输出数据库中所有的表
      # res = conn.execute("SELECT name FROM sqlite_master WHERE type='table';")
      # for name in res:
      #     print name[0]
  
      cur = conn.cursor()
      cur.execute('SELECT title,filePath FROM download_table')
  
      rows = cur.fetchall()
  
      for row in rows:
          name = row[0]
          md5Name = row[1]
          # print(row[0])
          namePath = dir + '/' + name + '.mp3'
          md5Path = dir + '/' + md5Name + '.mp3'
          if os.path.exists(md5Path):
              os.rename(md5Path, namePath)
              print('修改：' + md5Path.encode('utf8') + ' 为 ' + namePath.encode('utf8'))
  
      conn.close()
  
  renameTingMp3(dir,ting)
  
subject: Update 喜玛拉雅_renameBySqlite.py