def upload_movie(client): while True: movie_list_path = settings.UPLOAD_FILE_PATH movie_list = os.listdir(movie_list_path) if not movie_list: print('没有可上传的电影') break for index, movie in enumerate(movie_list): print(index, movie) choice = input('请选择需要上传的电影(q退出此功能):').strip() if choice == 'q': break if not choice.isdigit(): print('请输入数字') continue choice = int(choice) if choice not in range(len(movie_list)): print('请输入正确的编号') continue movie_name = movie_list[choice] movie_path = os.path.join(movie_list_path, movie_name) movie_md5 = common.get_movie_md5(movie_path) print(movie_md5) movie_size = os.path.getsize(movie_path) send_dic = { 'type': 'check_movie', 'movie_md5': movie_md5, 'cookies': user_info.get('cookies') } back_dic = common.send_and_back_data(send_dic, client) if not back_dic.get('flag'): print(back_dic.get('msg')) break print(back_dic.get('msg')) about_free = input('请确认是否免费(y/n):') is_free = 0 if about_free == 'y': is_free = 1 send_dic = { 'type': 'upload_movie', 'movie_name': movie_name, 'movie_size': movie_size, 'movie_md5': movie_md5, 'is_free': is_free, 'cookies': user_info.get('cookies') } back_dic = common.send_and_back_data(send_dic, client, file=movie_path) print(back_dic.get('msg')) break
def upload_movie(conn): movie_list = os.listdir(settings.UPLOAD_MOVIE_PATH) if not movie_list: print("没有电影") return for index, movie in enumerate(movie_list): print(index, movie) choice = input("请输入电影编号") if choice.isdigit() and int(choice) in range(len(movie_list)): choice = int(choice) movie_name = movie_list[choice] movie_path = os.path.join(settings.UPLOAD_MOVIE_PATH, movie_name) movie_md5 = common.get_movie_md5(movie_path) movie_size = os.path.getsize(movie_path) send_dic = { "type": "check_movie", "session": user_info.get("cookies"), "movie_md5": movie_md5 } back_dic = common.send_msg(send_dic, conn) print(back_dic.get("msg")) if back_dic.get("flag"): while 1: is_vip = input("是否免费1/0") if is_vip == "1" or is_vip == "0": is_vip = int(is_vip) break send_dic = { "type": "upload_movie", "session": user_info.get("cookies"), "movie_name": movie_name, "movie_md5": movie_md5, "movie_size": movie_size, "is_vip": is_vip } back_dic = common.send_msg(send_dic, conn, movie_path) print(back_dic.get("msg")) else: print("输入错误")
def upload_movie(client): file_list = common.get_dir_movie() if file_list: for num, movie in enumerate(file_list): print(num, movie) choice = input("请选择要上传的文件(序号)>>:") if choice.isdigit(): choice = int(choice) if choice < len(file_list): is_free = input("是否免费(y/n)>>:") if is_free == 'y': is_free = 1 else: is_free = 0 file_name = file_list[choice] file_path = os.path.join(settings.BASE_UPLOAD_MOVIE_DIR, file_name) file_size = os.path.getsize(file_path) file_md5 = common.get_movie_md5(file_path) create_time = common.get_create_time() is_free = is_free is_delete = 0 send_dic = { 'type': 'upload_movie', 'session': user_dic['session'], 'file_name': file_name, 'file_size': file_size, 'file_md5': file_md5, 'is_free': is_free, 'is_delete': is_delete, 'create_time': create_time, } back_dic = common.send_back_message(send_dic, client, file_path) if back_dic['flag']: print(back_dic['msg']) else: print(back_dic['msg']) else: print("输入数字超出文件序号") else: print("请输入数字!") else: print("当前没有待上传文件")
def upload_movie(client): # 此处需注意,原文函数名应该不对 while True: # 获取上传电影目录中的所有电影,并选择 movie_list = common.get_movie_list() # 若没有可上传的电影 if not movie_list: print('没有可以上传的电影,请先后台添加后上传') break for index, movie_name in enumerate(movie_list): print(index, movie_name) choice = input('请选择要上传的电影编号(q.退出):').strip() if choice == 'q': break if not choice.isdigit(): print('请输入数字!') continue choice = int(choice) if choice not in range(len(movie_list)): print('输入的不在范围,重新输入!') continue # 电影名字 movie_name = movie_list[choice] # 电影路径 movie_path = os.path.join(setting.UPLOAD_MOVIE_PATH, movie_name) # 获取电影大小 movie_size = os.path.getsize(movie_path) # 获取电影md5值 movie_md5 = common.get_movie_md5(movie_path) # 校验电影是否存在 send_dict = { 'type': 'check_movie', 'cookies': user_info.get('cookies'), 'movie_md5': movie_md5 } back_dict = common.send_and_recv(send_dict, client) if not back_dict.get('flag'): print(back_dict.get('msg')) continue # 确认电影是否免费 is_free = input('y/n 免费/收费').strip() number = 1 if is_free == 'y': number = 0 # 电影不存在, 发送上传电影请求 send_dict = { 'type': 'upload_movie', 'cookies': user_info.get('cookies'), 'movie_md5': movie_md5, 'movie_name': movie_name, 'movie_size': movie_size, 'is_free': number } recv_dict = common.send_and_recv(send_dict, client, file=movie_path) if recv_dict.get('flag'): print(recv_dict.get('msg')) break
def upload_movie(client): flag = False while not flag: comm.back_dic = None # 1.打印所有电影名字 if os.path.exists(settings.UPLOAD_MOVIE_PATH): movie_list = os.listdir(settings.UPLOAD_MOVIE_PATH) if not movie_list: print('没有可上传的电影') break for index, movie in enumerate(movie_list): print(index, movie) choice = input('请输入上传的电影编号:').strip() if choice=='q': break if not choice.isdigit(): print('请输入数字') continue choice = int(choice) if choice not in range(len(movie_list)): print('请输入正确编号!') continue movie_name = movie_list[choice] # 上传电影的路径 movie_path = os.path.join(settings.UPLOAD_MOVIE_PATH, movie_name) # 获取电影的md5值 movie_md5 = common.get_movie_md5(movie_path) send_dic = {'type': 'check_movie', 'session': user_info.get('cookies'), 'movie_md5': movie_md5} client.tcp_client_send(send_dic) i = 0 while not comm.back_dic: i += 1 if i%7==0: print('连接失败') return print("\n正在等待服务器发送数据\n") time.sleep(1) print(comm.back_dic.get('msg')) if comm.back_dic.get('flag'): is_free = input('是否免费Y/N:').strip() free = 0 if is_free == 'y': free = 1 send_dic = { 'type': 'upload_movie', 'session': comm.user_info.get('cookies'), 'movie_md5': movie_md5, 'movie_name': movie_name, 'is_free': free, 'movie_size': os.path.getsize(movie_path) } comm.back_dic = None # 开始上传电影 client.tcp_client_send( send_dic) i = 0 while not comm.back_dic: i += 1 if i%7==0: print('连接失败') return print("\n正在等待服务器发送数据\n") time.sleep(1) print("上传中...") movie_path_server = comm.back_dic.get('movie_path') with open(movie_path, 'rb') as f1: with open(movie_path_server, 'wb') as f2: data=f1.read() f2.write(data) print(movie_path_server) flag = comm.back_dic.get('flag')
def upload_movie(client): while True: # 1.打印所有电影名字 if os.path.exists(settings.UPLOAD_MOVIE_PATH): movie_list = os.listdir(settings.UPLOAD_MOVIE_PATH) if not movie_list: print('没有可上传的电影') break for index, movie in enumerate(movie_list): print(index, movie) choice = input('请输入上传的电影编号:').strip() if not choice.isdigit(): print('请输入数字') continue choice = int(choice) if choice not in range(len(movie_list)): print('请输入正确编号!') continue movie_name = movie_list[choice] # 上传电影的路径 movie_path = os.path.join(settings.UPLOAD_MOVIE_PATH, movie_name) # 获取电影的md5值 movie_md5 = common.get_movie_md5(movie_path) send_dic = { 'type': 'check_movie', 'session': user_info.get('cookies'), 'movie_md5': movie_md5 } back_dic = common.send_msg(send_dic, client) if back_dic.get('flag'): print(back_dic.get('msg')) is_free = input('是否免费Y/N:').strip() free = 0 if is_free == 'y': print('开始上传') free = 1 send_dic = { 'type': 'upload_movie', 'session': user_info.get('cookies'), 'movie_md5': movie_md5, 'movie_name': movie_name, 'is_free': free, 'movie_size': os.path.getsize(movie_path) } # 开始上传电影 back_dic = common.send_msg(send_dic, client, file=movie_path) # print(back_dic) if back_dic.get('flag'): print(back_dic.get('msg')) break
def upload_movie(client): while True: # 1.打印电影列表 movie_list = common.get_movie_list() for index, movie in enumerate(movie_list): print(index, movie) choice = input('请输入上传的电影编号:').strip() if not choice.isdigit(): print('请输入数字!') continue choice = int(choice) if choice not in range(len(movie_list)): print("请选择正确编号!") continue # 用户选择电影 movie_name = movie_list[choice] # 上传电影绝对路径 movie_path = os.path.join(settings.UPLOAD_FILES, movie_name) # 2.去服务端校验电影是否存在 file_md5 = common.get_movie_md5(movie_path) send_dic = { 'type': 'check_movie', 'session': user_info.get('cookies'), 'file_md5': file_md5 } back_dic = common.send_msg_back_dic(send_dic, client) if back_dic.get('flag'): # 电影可以上传 print(back_dic.get('msg')) # 上传电影功能字典 send_dic = { 'type': 'upload_movie', 'file_md5': file_md5, # 大小用来判断服务端需要接受文件的大小 'file_size': os.path.getsize(movie_path), 'movie_name': movie_name, 'session': user_info.get('cookies') } is_free = input('上传电影是否免费: y/n').strip() if is_free == 'y': send_dic['is_free'] = 1 else: send_dic['is_free'] = 0 back_dic = common.send_msg_back_dic(send_dic, client, file=movie_path) if back_dic.get('flag'): print(back_dic.get('msg')) break else: print(back_dic.get('msg'))
def upload_movie(client): while True: # 判断当前可以上传电影的文件夹是否存在 if os.path.exists(settings.UPLOAD_PATH): movie_list = os.listdir(settings.UPLOAD_PATH) # 如存在,则获取电影列表,让管理员去上传的电影编号 if movie_list: for i,movie in enumerate(movie_list): print(f'{i}--{movie}') choice = input('请选择需要上传的电影编号:').strip() if choice == 'q': break if not choice.isdigit(): print('必须是数字!') continue choice = int(choice) if choice not in range(len(movie_list)): print('输入错误!') continue movie_name = movie_list[choice] movie_path = os.path.join(settings.UPLOAD_PATH,movie_name) # 选择电影编号,发送给服务端,判断电影是否存在,是否可以上传 send_dic = {'type':'check_movie', 'session':user_info.get('cookies'), 'movie_name':movie_name, # 获取电影的md5值,判断电影的数据准确性 'movie_md5':common.get_movie_md5(movie_path)} back_dic = common.send_msg(send_dic,client) # 接收服务端的相应信息,如可以上传,则选择改电影是否是免费 if back_dic.get('flag'): print(back_dic.get('msg')) # 获取电影的大小 movie_size = os.path.getsize(movie_path) is_free = input('是否免费(y:免费/n:收费):').strip() if is_free !='y' and is_free !='Y' and is_free !='n' and is_free !='N': print('输入错误!') continue # 将电影的一系列相关信息,一致发送给服务端 send_dic = {'type':'upload_movie', 'session':user_info.get('cookies'), 'movie_size':movie_size, 'movie_name': movie_name, 'movie_md5':common.get_movie_md5(movie_path), 'is_free':is_free} print('电影正在上传。。。。。。。') back_dic = common.send_msg(send_dic,client,movie_path) if back_dic.get('flag'): print(back_dic.get('msg')) break else: print(back_dic.get('msg')) break else: print(back_dic.get('msg')) break else: print('没有电影可以上传!') break else: print('没有电影可以上传!') break