Example #1
0
def upload_movie(conn, dic):
    dic_back = comment.service_recv(conn)
    if not dic_back.get("flag", 1):
        return
    movie_name = dic_back.get("movie_name")
    movie_md5 = dic_back.get("movie_md5")
    flag = comment.check_movie_name(movie_name, movie_md5)
    if flag:
        dic2 = {"flag": 0, "msg": "电影已经存在!"}
        comment.service_send(conn, dic2)
        return
    dic2 = {"flag": 1, "msg": "开始上传!"}
    comment.service_send(conn, dic2)
    movie_size = dic_back.get("movie_size")
    movie_path = os.path.join(BASE_UPLOAD_DIR, movie_name)
    w_movie(conn, movie_path, movie_size)
    movie_obj = models.Movie(name=movie_name,
                             path=movie_path,
                             is_free=dic_back.get("is_free"),
                             is_delete=0,
                             file_md5=movie_md5,
                             upload_time=time.strftime("%Y-%m-%d %H:%M:%S"),
                             user_id=dic.get("user_id"))
    movie_obj.save()
    dic3 = {"msg": "上传成功!"}
    comment.service_send(conn, dic3)
Example #2
0
def download_charge_movie(dic, conn):
    res = comment.check_session(dic, conn)
    if res:
        return
    movies_list = comment.get_movies_list(2)
    if movies_list:
        dic_back = {"flag": 1, "movies_list": movies_list}
        comment.service_send(conn, dic_back)
    else:
        dic_back = {"flag": 0, "msg": "暂无可以下载的电影!"}
        comment.service_send(conn, dic_back)
        return
    dic1 = comment.service_recv(conn)
    movie_name = dic1.get("movie_name")
    movie_obj = models.Movie.select(name=movie_name)[0]
    movie_path = movie_obj.path
    movie_size = os.path.getsize(movie_path)
    dic2 = {"movie_size": movie_size}
    comment.service_send(conn, dic2)
    a = 0
    with open(movie_path, "rb") as f:
        while a < movie_size:
            if a + 1024 * 10 > movie_size:
                conn.send(f.read(movie_size - a))
            else:
                conn.send(f.read(1024 * 10))
            a += 1024 * 10
    dic3 = {"msg": "下载完成!"}
    comment.service_send(conn, dic3)
    download_record = models.DownloadRecord(
        user_id=dic.get("user_id"),
        movie_id=movie_obj.id,
        download_time=time.strftime("%Y-%m-%d %H:%M:%S"))
    download_record.save()
Example #3
0
def upload_movie(conn, dic):
    dic1 = comment.service_recv(conn)
    movie_name = dic1.get("movie_name")
    movie_md5 = dic1.get("movie_md5")
    flag = comment.check_movie(movie_name, movie_md5)
    if flag:
        dic_back = {"flag": 0, "msg": "电影已经存在!"}
    else:
        dic_back = {"flag": 1, "msg": "上传准备就绪!"}
    comment.service_send(conn, dic_back)
    movie_size = dic1.get("movie_size")
    movie_path = os.path.join(UPLOAD_MOVIES, movie_name)
    w_movie(conn, movie_path, movie_size)
    dic2 = {"msg": "上传成功!"}
    user_id = dic.get("user_id")
    is_free = dic1.get("is_free")
    movie_obj = models.Movie(name=movie_name,
                             path=movie_path,
                             is_free=is_free,
                             is_delete=0,
                             file_md5=movie_md5,
                             upload_time=comment.get_time(),
                             user_id=user_id)
    movie_obj.save()
    comment.service_send(conn, dic2)
Example #4
0
def release_notice(conn, dic):
    dic_back = comment.service_recv(conn)
    title = dic_back.get("title")
    content = dic_back.get("content")
    user_id = dic.get("user_id")
    notice_obj = models.Notice(title=title,
                               content=content,
                               create_time=comment.get_time(),
                               user_id=user_id)
    notice_obj.save()
    dic1 = {"msg": "发布成功!"}
    comment.service_send(conn, dic1)
Example #5
0
def release_notice(conn, dic):
    dic_back = comment.service_recv(conn)
    notice_title = dic_back.get("notice_title")
    notice_content = dic_back.get("notice_content")
    user_id = dic.get("user_id")
    create_time = time.strftime("%Y-%m-%d %H:%M:%S")
    notice_obj = models.Notice(title=notice_title,
                               content=notice_content,
                               user_id=user_id,
                               create_time=create_time)
    notice_obj.save()
    dic2 = {"msg": "发布成功!"}
    comment.service_send(conn, dic2)
Example #6
0
def working(conn, addr):
    try:
        while True:
            dic = comment.service_recv(conn)
            dic["addr"] = addr
            func_type = dic.get("type")
            func_dict.get(func_type)(conn, dic)
    except ConnectionResetError as e:
        print(addr, e)
        mutex.acquire()
        alive_user.pop(addr)
        mutex.release()
        conn.close()
Example #7
0
def buy_vip(conn, dic):
    dic_back = comment.service_recv(conn)
    if dic_back.get("flag"):
        user_id = dic.get("user_id")
        user_obj = models.User.select(id=user_id)[0]
        if user_obj.is_vip == 1:
            dic2 = {"msg": "您已经是会员了!"}
        else:
            user_obj.is_vip = 1
            user_obj.my_update()
            dic2 = {"msg": "充值成功!"}
    else:
        dic2 = {"msg": "充值失败!"}
    comment.service_send(conn, dic2)
Example #8
0
def delete_movie(conn, dic):
    movies_list = comment.get_movies_list()
    if not movies_list:
        dic_back = {"flag": 0, "msg": "暂无可以删除的电影!"}
        comment.service_send(conn, dic_back)
        return
    dic_back = {"flag": 1, "movies_list": movies_list}
    comment.service_send(conn, dic_back)
    dic1 = comment.service_recv(conn)
    movie_name = dic1.get("movie_name")
    movie_obj = models.Movie.select(name=movie_name)[0]
    movie_obj.is_delete = 1
    movie_obj.my_update()
    dic_back1 = {"msg": "删除成功!"}
    comment.service_send(conn, dic_back1)
Example #9
0
def release_notice(dic, conn):
    res = comment.check_session(dic, conn)
    if res:
        return
    dic_back = {"msg": "请添加公告!"}
    comment.service_send(conn, dic_back)
    dic1 = comment.service_recv(conn)
    title = dic1.get("title")
    content = dic1.get("content")
    user_id = dic.get("user_id")
    notice_obj = models.Notice(title=title,
                               content=content,
                               create_time=time.strftime("%Y-%m-%d %H:%M:%S"),
                               user_id=user_id)
    notice_obj.save()
    dic_back1 = {"msg": "添加成功!"}
    comment.service_send(conn, dic_back1)
Example #10
0
def buy_vip(dic, conn):
    print(dic)
    res = comment.check_session(dic, conn)
    if res:
        return
    dic2 = {"flag": "1"}
    comment.service_send(conn, dic2)
    dic1 = comment.service_recv(conn)
    if dic1.get("flag") == 1:
        user_obj = comment.check_user_id(dic.get("user_id"))
        if user_obj.is_vip == 1:
            dic_back = {"msg": "您已经是会员!"}
        else:
            user_obj.is_vip = 1
            user_obj.mysql_update()
            dic_back = {"msg": "充值成功!"}
    else:
        dic_back = {"msg": "充值失败!"}
    comment.service_send(conn, dic_back)
Example #11
0
def download_charge_movie(conn, dic):
    movies_list = comment.get_movies_list(flag=2)
    if not movies_list:
        dic2 = {"flag": 0, "msg": "暂无可以下载的电影"}
        comment.service_send(conn, dic2)
        return
    else:
        dic2 = {"flag": 1, "movies_list": movies_list}
    comment.service_send(conn, dic2)
    dic_back = comment.service_recv(conn)
    movie_name = dic_back.get("movie_name")
    movie_path = os.path.join(BASE_UPLOAD_DIR, movie_name)
    movie_size = os.path.getsize(movie_path)
    dic3 = {"movie_size": movie_size}
    comment.service_send(conn, dic3)
    r_movie(conn, movie_path, movie_size)
    user_id = dic.get("user_id")
    movie_id = models.Movie.select(name=movie_name)[0].id
    record = models.DownloadRecord(user_id=user_id, movie_id=movie_id, download_time=time.strftime("%Y-%m-%d %H:%M:%S"))
    record.save()
    dic4 = {"msg": "下载成功!"}
    comment.service_send(conn, dic4)
Example #12
0
def delete_movie(dic, conn):
    res = comment.check_session(dic, conn)
    if res:
        return
    movies_list = comment.get_movies_list()
    if movies_list:
        dic_back = {"flag": 1, "movies_list": movies_list}
        comment.service_send(conn, dic_back)
    else:
        dic_back = {"flag": 0, "msg": "暂无可以删除的电影"}
        comment.service_send(conn, dic_back)
        return
    dic1 = comment.service_recv(conn)
    movie_name = dic1.get("movie_name")
    movie_obj = models.Movie.select(name=movie_name)
    if movie_obj:
        movie_obj[0].is_delete = 1
        movie_obj[0].mysql_update()
        dic_back1 = {"msg": "删除成功!"}
    else:
        dic_back1 = {"msg": "删除失败!"}
    comment.service_send(conn, dic_back1)
Example #13
0
def download_charge_movie(conn, dic):
    movies_list = comment.get_movies_list(flag=2)
    if movies_list:
        dic1 = {"flag": 1, "movies_list": movies_list}
        comment.service_send(conn, dic1)
    else:
        dic1 = {"flag": 0, "msg": "暂无可以下载的电影!"}
        comment.service_send(conn, dic1)
        return
    dic_back = comment.service_recv(conn)
    movie_name = dic_back.get("movie_name")
    movie_path = os.path.join(UPLOAD_MOVIES, movie_name)
    movie_size = os.path.getsize(movie_path)
    dic3 = {"movie_size": movie_size}
    comment.service_send(conn, dic3)
    r_movie(conn, movie_path, movie_size)
    user_id = dic.get("user_id")
    movie_id = models.Movie.select(name=movie_name)[0].id
    record = models.DownloadRecord(user_id=user_id, movie_id=movie_id, download_time=comment.get_time())
    record.save()
    dic2 = {"msg": "下载成功!"}
    comment.service_send(conn, dic2)