def download_video(): movie_list = show_video() if not movie_list: return movie_name = input('请选择要下载的电影名:').strip() if movie_name == 'q': return if not current_user['vip']: for movie in movie_list: if movie[0] == movie_name and movie[3] == 0: request = { 'interface': 'user_interface', 'func': 'download_video', 'name': movie_name } response = tcpclient(request) print('\r%s' % response['msg']) else: print('该电影为会员视频!') request = { 'interface': 'user_interface', 'func': 'download_video', 'name': movie_name, 'uid': current_user['uid'] } response = tcpclient(request) print(response['msg'])
def unlock_account(): request = { 'interface': 'admin_interface', 'func': 'unlock_account', 'task': 'get_account' } response = tcpclient(request) if not response['user']: print('当前无可解锁用户!') return for user in response['user']: print(user) while True: name = input('请输出要解锁的用户名:') if name == 'q': return if name not in response['user']: print('输入的用户名不存在!') continue request = { 'interface': 'admin_interface', 'func': 'unlock_account', 'task': 'lock_account', 'name': name } response = tcpclient(request) print(response['msg']) break
def delete_video(): request = { 'interface': 'admin_interface', 'func': 'delete_video', 'task': 'get_movie' } response = tcpclient(request) if not response['movie']: print('当前无可删除电影!') return for movies in response['movie']: print(movies) while True: name = input('请输出要锁删除的电影名:') if name == 'q': return if name not in response['movie']: print('输入的电影名不存在!') continue request = { 'interface': 'admin_interface', 'func': 'delete_video', 'task': 'delele_movie', 'name': name } response = tcpclient(request) print(response['msg']) break
def upload_video(): while True: name = input('请输入电影名称:(q取消上传电影)') if name == 'q': return author = input('请输入作者:') isvip = input('是否为VIP观看?(y/n)') path = input('请输入电影路径:') path = r'%s' % path if not os.path.exists(path): print('输入路径不存在!') continue if not (name and author and isvip and path): print('输入不能为空!') continue isvip = 1 if isvip == 'y' else 0 size = os.path.getsize(path) format_list = ['mp4', 'avi', 'rmvb', 'flv', 'mkv'] format = path.split(os.path.sep)[-1].lower() for i in format_list: if not format.endswith(i): continue md5 = get_md5(path) request = { 'interface': 'admin_interface', 'func': 'upload_video', 'name': name, 'author': author, 'size': size, 'isvip': isvip, 'path': path, 'md5': md5, 'isfile': False } res = tcpclient(request) if res['status'] == 'error': print(res['msg']) return request = { 'interface': 'admin_interface', 'func': 'upload_video', 'name': name, 'author': author, 'size': size, 'isvip': isvip, 'from_path': path, 'md5': md5, 'isfile': True } res = tcpclient(request, is_upload=True) if res: print('\r%s' % res['msg']) return else: print('不支持的视频格式!') break
def login(identity): while True: username = input('请输入用户名:') if username == 'q': break password = input('请输入密码:') if not username and password: print('用户名或密码不能为空!') continue requeset = { 'interface': 'common', 'func': 'login', 'name': username, 'password': password, 'identity': identity } response = tcpclient(requeset) if response['status'] == 'ok': if response['user']['identity'] == 0: core.user_interface.current_user = response['user'] else: core.admin_interface.current_admin = response['user'] print(response['msg']) break print(response['msg'])
def download_history(): request = { 'interface': 'user_interface', 'func': 'download_history', 'uid': current_user['uid'] } response = tcpclient(request) for history in response['history']: print('下载电影:%s,下载时间:%s' % (history[0], history[1]))
def show_video(): request = {'interface': 'user_interface', 'func': 'show_video'} response = tcpclient(request) if not response['movie']: print('当前服务器无电影!') return for movie in response['movie']: print('电影名:%s,大小:%.2fMB,作者:%s,VIP影片:%s' % (movie[0], float(movie[1]) / 1024 / 1024, movie[2], '是' if movie[3] == 1 else '否')) return response['movie']
def open_member(): while True: choice = input('即将开通会员是否确认?(y/n)') if choice == 'n': return if not choice: print('选择不能为空!') request = { 'interface': 'user_interface', 'func': 'open_member', 'name': current_user['name'] } response = tcpclient(request) print(response['msg']) break
def announce(): while True: title = input('请输入公告标题:').strip() if not title: print('标题不能为空!') continue content = input('请输入内容:') if not content: print('内容不能为空!') continue request = { 'interface': 'admin_interface', 'func': 'announce', 'title': title, 'content': content, 'publisher_id': current_admin['uid'] } response = tcpclient(request) print(response['msg']) break
def register(identity): while True: username = input('请输入注册用户名:') if username == 'q': break password = input('请输入注册密码:') if not username and password: print('用户名或密码不能为空!') continue requeset = { 'interface': 'common', 'func': 'register', 'name': username, 'password': password, 'identity': identity } response = tcpclient(requeset) if response['status'] == 'ok': print(response['msg']) break print(response['msg'])
def view_announcement(): request = {'interface': 'user_interface', 'func': 'view_announcement'} response = tcpclient(request) for announcement in response['msg']: print('标题:%s\n内容:%s\n时间:%s\n\n' % (announcement[0], announcement[1], announcement[2]))