def post_biu(file): _title, _artist, _album, _flag = getID3(file) try: if _flag == 0: logging.info("码率不合 请重现检察") raise Exception # 自定义错误 if _flag == 2: logging.info("Title不完整 拒绝上传") raise Exception # 自定义错误 except Exception: return 0, "", "" logging.info("Title -> " + _title) logging.info("Artist -> " + _artist) logging.info("Album -> " + _album) _md5 = md5(file, "file") # file_md5 _uid, _key, _api = uid() _sign_str = sign(_uid, _md5, _key, _title, _artist, _album) flag, token, title = post(_uid, _md5, _title, _artist, _album, _sign_str, _api) if flag: logging.info("允许上传") return 1, token, title logging.info("上传已取消") return 0, "", title
except getopt.GetoptError: sys.exit() for argv, value in opts: if argv in "-f": file = value if not os.path.exists(file): file = os.path.split(os.path.realpath(__file__))[0] + file logging.info(file) if not os.path.exists(file): logging.info("找不到文件.请尝试用双引号将文件绝对路径包括起来.") else: logging.info("test") flag, token, title = post_biu(file) sys.exit() if not flag else confirm( title, file, md5(file, "file"), token) pass else: if file[0] != "\"": file = "\"" + file + "\"" flag, token, title = post_biu(file) if not flag == 1: sys.exit() else: confirm(title, file, md5(file, "file"), token) pass elif argv in "-d": #上传文件夹 path = value if os.path.isdir(path): cnt = 0
opts, args = getopt.getopt(sys.argv[1:], "hvf:d:", ["update"]) except getopt.GetoptError: sys.exit() for argv, value in opts: if argv in "-f": file = value if not os.path.exists(file): file = os.path.split(os.path.realpath(__file__))[0] + file logging.info(file) if not os.path.exists(file): logging.info("找不到文件.请尝试用双引号将文件绝对路径包括起来.") else: logging.info("test") flag, token, title = post_biu(file) sys.exit() if not flag else confirm(title, file, md5(file, "file"), token) pass else: if file[0] != '"': file = '"' + file + '"' flag, token, title = post_biu(file) if not flag == 1: sys.exit() else: confirm(title, file, md5(file, "file"), token) pass elif argv in "-d": # 上传文件夹 path = value if os.path.isdir(path): cnt = 0
def sign(_uid, _md5, _key, _title, _artist, _album): str = _uid + _md5 + _title + _artist + _album + _key sign_string = md5(str.encode('utf-8'), "str") return sign_string