def delete_movie(client): # 打印数据库中没有被删除的文件还有哪些 send_dic = { 'type': 'check_movie_list', 'session': user_dic['session'], 'movie_type': 'all' } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: file_info = back_dic['msg'] for num, movie_info in enumerate(file_info): print("%s 电影名:%s %s" % (num, movie_info[0], movie_info[1])) choice = input("请选择要删除的文件(序号)>>:") if choice.isdigit(): choice = int(choice) if choice < len(file_info): send_dic = { 'type': 'delete_file', 'session': user_dic['session'], 'file_id': file_info[choice][2], } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: print(back_dic['msg']) else: print(back_dic['msg']) else: print("序号不正确!") else: print("请输入序号!") else: print(back_dic['msg'])
def download_free_movie(client): send_dic = { 'type': 'check_movie_list', 'session': user_dic['session'], 'movie_type': 'free', } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: movie_list = back_dic['msg'] for num, movie_info in enumerate(movie_list): print("%s 电影名:%s %s" % (num, movie_info[0], movie_info[1])) choice = input("请选择要下载的文件(序号)>>:") if choice.isdigit(): choice = int(choice) if choice < len(movie_list): send_dic = { 'type': 'download_movie', 'session': user_dic['session'], 'file_id': movie_list[choice][2] } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: file_name = back_dic['msg']['file_name'] file_size = back_dic['msg']['file_size'] file_path = os.path.join(settings.BASE_DOWNLOAD_MOVIE_DIR, file_name) start = 0 with open(file_path, 'wb') as f: while start < file_size: data = client.recv(1024) f.write(data) start += len(data) _ = start / file_size common.progress_bar(_) f.flush() print() print("电影下载成功!") else: print(back_dic['msg']) else: print("序号不正确!") else: print("请输入数字!") else: print(back_dic['msg'])
def check_notice(client): send_dic = {'type':'check_notice','session':user_dic['session']} back_dic = common.send_back_message(send_dic,client) if back_dic['flag']: notice_list = back_dic['msg'] for num,notice_info in enumerate(notice_list): print("%s 公告名:%s 公告内容:%s" % (num,notice_info[0],notice_info[1])) else: print(back_dic['msg'])
def check_movie_record(client): send_dic = { 'type':'check_movie_record', 'session':user_dic['session'], } back_dic = common.send_back_message(send_dic,client) if back_dic['flag']: movie_info_list = back_dic['msg'] for num,movie_info in enumerate(movie_info_list): print('%s 电影名:%s %s' % (num,movie_info[0],movie_info[1])) else: print(back_dic['msg'])
def check_movie(client): # 查看所有没有被删除的视频 send_dic = { 'type': 'check_movie', 'session': user_dic['session'], 'movie_type': 'all', } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: movie_list = back_dic['msg'] for num, movie_info in enumerate(movie_list): print("%s 电影名:%s %s" % (num, movie_info[0], movie_info[1])) else: print(back_dic['msg'])
def release_notice(client): name = input("请输入公告标题>>:") content = input("请输入公告内容>>:") send_dic = { 'type': 'release_notice', 'session': user_dic['session'], 'name': name, 'content': content, 'create_time': common.get_create_time() } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: print(back_dic['msg']) else: print(back_dic['msg'])
def buy_member(client): temp = input("是否购买会员(y/n)?>>:") if temp == 'y': is_vip = 1 send_dic = {'type': 'buy_member', 'session': user_dic['session'], 'is_vip': is_vip, } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: print(back_dic['msg']) else: print(back_dic['msg']) else: print("购买会员失败!") return
def user_login(client): if user_dic['session']: print("您已经登录!") return while True: name = input("请输入用户名>>:") password = input("请输入密码>>:") send_dic = {'type': 'login', 'name': name, 'password': common.get_md5(password), 'user_type': 'user'} back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: print(back_dic['msg']) user_dic['session'] = back_dic['session'] break else: print(back_dic['msg'])
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 user_register(client): while True: name = input("请输入用户名>>:") password_one = input("请输入密码>>:") password_two = input("请再次输入密码>>:") if password_two == password_one: send_dic = { 'type': 'register', 'name': name, 'password': common.get_md5(password_one), 'is_vip': 0, 'locked': 0, 'user_type': 'user', } back_dic = common.send_back_message(send_dic, client) if back_dic['flag']: print(back_dic['msg']) break else: print(back_dic['msg']) else: print("两次密码不一致!")