Beispiel #1
0
def upload_movie(c):
    while True:
        movies_list = comment.get_movies_list()
        comment.show_list(movies_list)
        choose = input("请输入需要上传的电影的序号:")
        movie_path = os.path.join(BASE_UPLOAD_DIR, movies_list[int(choose) - 1])
        movie_md5 = comment.get_movie_md5(movie_path)
        dic1 = {"type": "check_movie", "movie_md5": movie_md5, "session": user_dict.get("session"),
                "user_id": user_dict.get("user_id")}
        comment.client_send(c, dic1)
        dic_back1 = comment.client_recv(c)
        if dic_back1.get("flag") == 2:
            print(dic_back1.get("msg"))
            return
        if dic_back1.get("flag"):
            print(dic_back1.get("msg"))
            break
        else:
            print(dic_back1.get("msg"))
        choose1 = input("是否设置为收费电影(y/n)?").strip().lower()
        is_free = 0 if choose1 == "y" else 1
        dic = {"type": "upload_movie", "name": movies_list[int(choose) - 1],
               "is_free": is_free, "session": user_dict.get("session"),
               "user_id": user_dict.get("user_id"), "file_md5": movie_md5}
        comment.send_movie(c, dic, movie_path)
        dic_back2 = comment.client_recv(c)
        print(dic_back2.get("msg"))
        break
Beispiel #2
0
def select_movie(conn, dic):
    movies_list = comment.get_movies_list()
    if not movies_list:
        dic2 = {"flag": 0, "msg": "暂无可以查看的电影"}
    else:
        dic2 = {"flag": 1, "movies_list": movies_list}
    comment.service_send(conn, dic2)
Beispiel #3
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()
Beispiel #4
0
def upload_movie(c):
    dic = {"type": "upload_movie", "session": user_dic.get("session")}
    comment.client_send(c, dic)
    dic_back = comment.client_recv(c)
    if not dic_back.get("flag"):
        print(dic_back.get("msg"))
        return
    movies_list = comment.get_movies_list()
    if not movies_list:
        print("暂无可以上传的电影!")
        return
    comment.show_list(movies_list)
    choose = input("请选择你要上传的电影的序号:")
    movie_name = movies_list[int(choose) - 1]
    movie_path = os.path.join(UPLOAD_MOVIES, movie_name)
    movie_size = os.path.getsize(movie_path)
    movie_md5 = comment.get_movie_md5(movie_path)
    choose1 = input("是否收费(y/n):").strip()
    is_free = 1 if choose1 == "n" else 0
    dic1 = {
        "movie_name": movie_name,
        "movie_size": movie_size,
        "movie_md5": movie_md5,
        "is_free": is_free
    }
    comment.client_send(c, dic1)
    dic_back1 = comment.client_recv(c)
    if not dic_back1.get("flag"):
        print(dic_back1.get("msg"))
        return
    print(dic_back1.get("msg"))
    r_movie(c, movie_path, movie_size)
    dic_back2 = comment.client_recv(c)
    print(dic_back2.get("msg"))
Beispiel #5
0
def select_movie(conn, dic):
    movies_list = comment.get_movies_list()
    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
Beispiel #6
0
def select_movie(dic, conn):
    res = comment.check_session(dic, conn)
    if res:
        return
    dic1 = {"flag": 1}
    comment.service_send(conn, dic1)
    movies_list = comment.get_movies_list()
    if not movies_list:
        dic2 = {"flag": 0, "msg": "暂无可以查看的电影!"}
    else:
        dic2 = {"flag": 1, "msg": movies_list}
    comment.service_send(conn, dic2)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
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)